当前位置: 首页>>代码示例>>Python>>正文


Python Vector.resize方法代码示例

本文整理汇总了Python中mathutils.Vector.resize方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.resize方法的具体用法?Python Vector.resize怎么用?Python Vector.resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mathutils.Vector的用法示例。


在下文中一共展示了Vector.resize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: discard_outside_of_view

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import resize [as 别名]
    def discard_outside_of_view(self, view): 
        # Assume that the mesh object's bounding box is fully contained in the
        # view projection, and test this assumption.
        bounding_box = mesh_object.bound_box
        bounding_box_contained_in_projection = True

        # Transform the coordinates of each vertex of the bounding box from
        # object space to clip space.  As soon as any single vertex is
        # found to be outside of the view projection, duly indicate, and exit
        # the loop.
        projection_matrix = view.projection_matrix
        for vertex in bounding_box:
            co = Vector(vertex)
            co.resize(4)
            co.w = 1
            co.xyzw = projection_matrix * co
            w = co.w

            # Determine if the coordinates are within the view projection.
            if abs(co.x) > w or\
               abs(co.y) > w or\
               abs(co.z) > w:
                bounding_box_contained_in_projection = False
                break

        # If the bounding box is not entirely contained within the view
        # projection then some vertices may exist outside of the view
        # projection.
        if not bounding_box_contained_in_projection: 
            clip_space_map = self.coordinate_map

            # Retain each clip space vertex that is inside of the view
            # projection.
            indices = self.indices
            self.indices = [
                index
                for index in indices
                if abs(clip_space_map[index].x) < clip_space_map[index].w and\
                   abs(clip_space_map[index].y) < clip_space_map[index].w and\
                   abs(clip_space_map[index].z) < clip_space_map[index].w
            ] 
开发者ID:fedackb,项目名称:surface-constraint-tools,代码行数:43,代码来源:VertexFilter.py

示例2: resize_primary_brush

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import resize [as 别名]
    def resize_primary_brush(self, radius):
        context = bpy.context
        primary_brush = self.primary_brush
        region_height = context.region.height
        region_width = context.region.width

        # Determine the world space radius of the primary brush necessary to
        # project a circle onto the view plane with the specified region space
        # radius.

        # Determine the z-depth of the primary brush's center in normalized
        # device coordinates.
        projection_matrix = context.region_data.perspective_matrix
        co = primary_brush.center.copy()
        co.resize(4)
        co.w = 1
        co.xyzw = projection_matrix * co
        w = co.w
        co.xyz /= w
        NDC_z_depth = co.z

        # Determine the region space coordinates of the primary brush's center.
        region_x = (co.x + 1) * region_width / 2
        region_y = (co.y + 1) * region_height / 2

        # Determine the NDC coordinates of a point on the edge of the
        # circle that should result from projecting the brush onto the view
        # plane.
        co = Vector((region_x, region_y)) + Vector((radius, 0))

        co.x = co.x * 2 / region_width - 1
        co.y = co.y * 2 / region_height - 1
        co.resize(3)
        co.z = NDC_z_depth

        # Calculate the world space radius of the primary brush.
        co.resize(4)
        co.w = 1
        co.xyzw = projection_matrix.inverted() * co
        w = co.w
        co.resize(3)
        co.xyz /= w
        primary_brush.radius = (co - primary_brush.center).length
开发者ID:Italic-,项目名称:blenderpython,代码行数:45,代码来源:Brushes.py

示例3: stroke

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import resize [as 别名]
    def stroke(self, region_x, region_y):
        props = self.props
        brushes = props.brushes
        derived_brushes = brushes.derived_brushes
        primary_brush = brushes.primary_brush

        active_object = bpy.context.active_object
        indices_affected_by_stroke = self.indices_affected_by_stroke
        vertices = active_object.data.vertices

        # The primary brush must be on the mesh in order to execute a stroke.
        if not primary_brush.is_on_mesh:
            return

        # Only proceed if at least one vertex is affected by the stroke.
        if not indices_affected_by_stroke:
            return

        # Determine the terminal position of the stroke in world space
        # coordinates.
        inverted_perspective_matrix =\
            bpy.context.region_data.perspective_matrix.inverted()
        co = Vector((region_x, region_y))
        co.x = co.x * 2 / bpy.context.region.width - 1
        co.y = co.y * 2 / bpy.context.region.height - 1
        co.resize(4)
        co.z = self.stroke_z_depth
        co.w = 1
        co = inverted_perspective_matrix * co
        w = co.w
        co.resize(3)
        co /= w
        stroke_terminal_co = co

        # Apply the stroke to each brush.
        inverted_model_matrix = active_object.matrix_world.inverted()
        for brush in [primary_brush] + brushes.derived_brushes:
            # Determine the displaced position of the brush caused by the
            # stroke.
            displaced_brush_center =\
                brush.transformation_matrix * stroke_terminal_co

            # Calculate an object space displacement vector between the brush's
            # original position and its displaced position.
            object_space_displacement = (
                inverted_model_matrix *  displaced_brush_center -
                inverted_model_matrix * brush.center
            )

            # Move the brush to its displaced position.
            brush.center = displaced_brush_center

            # Add the displacement vector to the coordinates of the brush's
            # affected vertices, taking into account brush falloff.
            falloff_map = brush.falloff_map
            for index in brush.indices:
                vertices[index].co +=\
                    falloff_map[index] * object_space_displacement

        # Constrain the vertices to the specified target, if necessary.
        if self.target:
            surface_constraint_props = self.surface_constraint_props
            apply_shrinkwrap(
                offset = self.offset, target = self.target,
                wrap_method = surface_constraint_props.wrap_method_map[
                    surface_constraint_props.direction
                ],
                affected_indices = list(indices_affected_by_stroke)
            )

        # Update the octree's coordinate map.
        model_matrix = active_object.matrix_world
        world_space_submap = {
            index : model_matrix * vertices[index].co
            for index in indices_affected_by_stroke
        }
        self.props.octree.coordinate_map.update(world_space_submap)
开发者ID:BitByte01,项目名称:myblendercontrib,代码行数:79,代码来源:StrokeMove.py


注:本文中的mathutils.Vector.resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。