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


Python mathutils.Vector方法代码示例

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


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

示例1: check_and_store_bone_scaling

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def check_and_store_bone_scaling(self, context):
        anim_collections = self.sprite_object.coa_anim_collections
        bone_scaled = {}
        for anim_index, anim in enumerate(anim_collections):
            if anim.name not in ["NO ACTION"]:
                if anim.name == "Restpose":
                    if "default" in anim_collections:
                        continue
                anim_name = anim.name if anim.name != "Restpose" else "default"
                self.sprite_object.coa_anim_collections_index = anim_index  ### set animation

                for frame in range(anim.frame_end+1):
                    context.scene.frame_set(frame)
                    for bone in self.armature.pose.bones:
                        bone_scale = bone.matrix.to_scale()
                        bone_scale = Vector((round(bone_scale.x,1), round(bone_scale.y,1), round(bone_scale.z,1)))
                        if bone_scale != Vector((1, 1, 1)):
                            if anim_name not in bone_scaled:
                                bone_scaled[anim_name] = []
                            bone_scaled[anim_name].append(bone.name)
        return bone_scaled 
开发者ID:ndee85,项目名称:coa_tools,代码行数:23,代码来源:export_creature.py

示例2: get_lookat_aligned_up_matrix

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def get_lookat_aligned_up_matrix(eye, target):

    """
    This method uses camera axes for building the matrix.
    """

    axis_z = (eye - target).normalized()

    if axis_z.length == 0:
        axis_z = mathutils.Vector((0, -1, 0))

    axis_x = mathutils.Vector((0, 0, 1)).cross(axis_z)

    if axis_x.length == 0:
        axis_x = mathutils.Vector((1, 0, 0))

    axis_y = axis_z.cross(axis_x)

    return mathutils.Matrix([
        axis_x,
        axis_y,
        axis_z,
    ]).transposed() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:25,代码来源:utils.py

示例3: get_joint3d_positions

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def get_joint3d_positions(joint_names, frame_idx):
    """
    Get joint3d positions for current armature and given frame index.

    :param frame_idx: frame index
    :param joint_names: list of joint names
    :return: dict, {'pose_keypoints_3d': [x1, y1, z1, x2, y2, z2, ...]}
    """
    bpy.context.scene.frame_set(frame_idx)

    posebones = bpy.data.objects['Armature'].pose.bones
    armature = bpy.data.objects['Armature']

    out_dict = {'pose_keypoints_3d': []}
    for name in joint_names:
        global_location = armature.matrix_world * posebones[name].matrix * Vector((0, 0, 0))
        l = [global_location[0], global_location[1], global_location[2]]
        out_dict['pose_keypoints_3d'].extend(l)
    return out_dict 
开发者ID:ChrisWu1997,项目名称:2D-Motion-Retargeting,代码行数:21,代码来源:fbx2joints3d.py

示例4: add

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def add(self, child):
        self.children.append(child)
        if len(self.children) == 1:
            self.top_left = top_left(child)
            self.bottom_right = bottom_right(child)
        else:
            tl = top_left(child)
            br = bottom_right(child)
            self.top_left = Vector((
                min(self.top_left[0], tl[0]),
                max(self.top_left[1], tl[1]),
            ))
            self.bottom_right = Vector((
                max(self.bottom_right[0], br[0]),
                min(self.bottom_right[1], br[1]),
            )) 
开发者ID:ksons,项目名称:gltf-blender-importer,代码行数:18,代码来源:block.py

示例5: get_node_trs

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def get_node_trs(op, node):
    """Gets the TRS proerties from a glTF node JSON object."""
    if 'matrix' in node:
        m = node['matrix']
        # column-major to row-major
        m = Matrix([m[0:4], m[4:8], m[8:12], m[12:16]])
        m.transpose()
        loc, rot, sca = m.decompose()
        # wxyz -> xyzw
        # convert_rotation will switch back
        rot = [rot[1], rot[2], rot[3], rot[0]]

    else:
        sca = node.get('scale', [1.0, 1.0, 1.0])
        rot = node.get('rotation', [0.0, 0.0, 0.0, 1.0])
        loc = node.get('translation', [0.0, 0.0, 0.0])

    # Switch glTF coordinates to Blender coordinates
    sca = op.convert_scale(sca)
    rot = op.convert_rotation(rot)
    loc = op.convert_translation(loc)

    return [Vector(loc), Quaternion(rot), Vector(sca)] 
开发者ID:ksons,项目名称:gltf-blender-importer,代码行数:25,代码来源:vnode.py

示例6: realize_bone

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def realize_bone(op, vnode):
    """Create a real EditBone for a BONE vnode."""
    armature = vnode.armature_vnode.blender_armature
    editbone = armature.edit_bones.new(vnode.name)

    editbone.use_connect = False

    # Bones transforms are given, not by giving their local-to-parent transform,
    # but by giving their head, tail, and roll in armature space. So we need the
    # local-to-armature transform.
    m = vnode.editbone_local_to_armature
    editbone.head = mul(m, Vector((0, 0, 0)))
    editbone.tail = mul(m, Vector((0, vnode.bone_length, 0)))
    editbone.align_roll(mul(m, Vector((0, 0, 1))) - editbone.head)

    vnode.blender_name = editbone.name
    # NOTE: can't access this after we leave edit mode
    vnode.blender_editbone = editbone

    # Set parent
    if vnode.parent:
        if getattr(vnode.parent, 'blender_editbone', None):
            editbone.parent = vnode.parent.blender_editbone 
开发者ID:ksons,项目名称:gltf-blender-importer,代码行数:25,代码来源:node.py

示例7: check_region

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def check_region(context,event):
    in_view_3d = False
    if context.area != None:
        if context.area.type == "VIEW_3D":
            t_panel = context.area.regions[1]
            n_panel = context.area.regions[3]
            
            view_3d_region_x = Vector((context.area.x + t_panel.width, context.area.x + context.area.width - n_panel.width))
            view_3d_region_y = Vector((context.region.y, context.region.y+context.region.height))
            
            if event.mouse_x > view_3d_region_x[0] and event.mouse_x < view_3d_region_x[1] and event.mouse_y > view_3d_region_y[0] and event.mouse_y < view_3d_region_y[1]:
                in_view_3d = True
            else:
                in_view_3d = False
        else:
            in_view_3d = False
    return in_view_3d 
开发者ID:ndee85,项目名称:coa_tools,代码行数:19,代码来源:functions.py

示例8: set_uv_default_coords

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def set_uv_default_coords(context,obj):
    uv_coords = obj.data.uv_layers[obj.data.uv_layers.active.name].data
    ### add uv items
    for i in range(len(uv_coords)-len(obj.coa_uv_default_state)):
        item = obj.coa_uv_default_state.add()
    ### remove unneeded uv items    
    if len(uv_coords) < len(obj.coa_uv_default_state):
        for i in range(len(obj.coa_uv_default_state) - len(uv_coords)):
            obj.coa_uv_default_state.remove(0)

    ### set default uv coords
    frame_size = Vector((1 / obj.coa_tiles_x,1 / obj.coa_tiles_y))
    pos_x = frame_size.x * (obj.coa_sprite_frame % obj.coa_tiles_x)
    pos_y = frame_size.y *  -int(int(obj.coa_sprite_frame) / int(obj.coa_tiles_x))
    frame = Vector((pos_x,pos_y))
    offset = Vector((0,1-(1/obj.coa_tiles_y)))
    
    
    for i,coord in enumerate(uv_coords):    
        uv_vec_x = (coord.uv[0] - frame[0]) * obj.coa_tiles_x 
        uv_vec_y = (coord.uv[1] - offset[1] - frame[1]) * obj.coa_tiles_y
        uv_vec = Vector((uv_vec_x,uv_vec_y)) 
        obj.coa_uv_default_state[i].uv = uv_vec 
开发者ID:ndee85,项目名称:coa_tools,代码行数:25,代码来源:functions.py

示例9: create_cleaned_armature_copy

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def create_cleaned_armature_copy(self, context, armature_orig):
        armature = armature_orig

        selected_objects = bpy.context.selected_objects[:]
        active_object = bpy.context.active_object
        for ob in selected_objects:
            ob.select = False
        context.scene.objects.active = armature
        bpy.ops.object.mode_set(mode="EDIT")
        for bone in armature.data.edit_bones:
            self.init_bone_positions[bone.name] = {"head": Vector(bone.head), "tail": Vector(bone.tail)}

        bpy.ops.object.mode_set(mode="OBJECT")
        for ob in context.selected_objects:
            ob.select = False
        for ob in selected_objects:
            ob.select = True
        context.scene.objects.active = active_object
        return armature 
开发者ID:ndee85,项目名称:coa_tools,代码行数:21,代码来源:export_creature.py

示例10: scale_verts_by_bone

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def scale_verts_by_bone(self, pbone, armature, mesh_object, vert_co, weight=1.0):
        # verts = mesh_object.data.vertices
        bone = armature.data.bones[pbone.name]
        bone_head = self.init_bone_positions[bone.name]["head"]
        bone_tail = self.init_bone_positions[bone.name]["tail"]
        bone_axis_x = (bone_tail - bone_head).normalized().xz
        bone_axis_y = bone_axis_x.orthogonal().normalized()

        world_axis_x = Vector((bone_axis_x.dot(Vector((1, 0))), bone_axis_y.dot(Vector((1, 0)))))
        world_axis_y = Vector((bone_axis_x.dot(Vector((0, 1))), bone_axis_y.dot(Vector((0, 1)))))

        bone_system_origin = (mesh_object.matrix_world.inverted() * (armature.matrix_world * bone_head)).xz

        bone_scale = pbone.matrix.to_scale()
        bone_scale_2d = Vector(( self.lerp( 1.0, bone_scale.y, weight), self.lerp(1.0, bone_scale.x, weight) ))

        vert_delta_co = vert_co.xz
        vert_delta_co -= bone_system_origin
        vert_delta_co = Vector((bone_axis_x.dot(vert_delta_co), bone_axis_y.dot(vert_delta_co)))
        vert_delta_co = Vector((vert_delta_co.x * bone_scale_2d.x, vert_delta_co.y * bone_scale_2d.y))
        vert_delta_co = Vector((world_axis_x.dot(vert_delta_co), world_axis_y.dot(vert_delta_co)))
        vert_delta_co += bone_system_origin

        scaled_vert_co = Vector((vert_delta_co.x, 0, vert_delta_co.y))
        return scaled_vert_co 
开发者ID:ndee85,项目名称:coa_tools,代码行数:27,代码来源:export_creature.py

示例11: get_bone_head_tail

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def get_bone_head_tail(self, pbone, local=True):
        parent_x_axis = Vector((1, 0))
        parent_y_axis = Vector((0, 1))
        space_origin = Vector((0, 0))
        if pbone.parent != None and local:
            parent_x_axis = (pbone.parent.tail.xz - pbone.parent.head.xz).normalized()
            parent_y_axis = parent_x_axis.orthogonal().normalized()
            space_origin = pbone.parent.tail.xz

        head = pbone.head.xz - space_origin
        tail = pbone.tail.xz - space_origin

        local_tail_x = round(tail.dot(parent_x_axis), 3) * self.armature_export_scale
        local_tail_y = round(tail.dot(parent_y_axis), 3) * self.armature_export_scale

        local_head_x = round(head.dot(parent_x_axis), 3) * self.armature_export_scale
        local_head_y = round(head.dot(parent_y_axis), 3) * self.armature_export_scale

        local_tail_vec = Vector((local_tail_x, 0, local_tail_y))
        local_head_vec = Vector((local_head_x, 0, local_head_y))

        return {"head": local_head_vec.xz, "tail": local_tail_vec.xz} 
开发者ID:ndee85,项目名称:coa_tools,代码行数:24,代码来源:export_creature.py

示例12: project_cursor

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def project_cursor(self, event):
        coord = mathutils.Vector((event.mouse_region_x, event.mouse_region_y))
        transform = bpy_extras.view3d_utils.region_2d_to_location_3d
        region = bpy.context.region
        rv3d = bpy.context.space_data.region_3d
        #### cursor used for the depth location of the mouse
        depth_location = bpy.context.scene.cursor_location
        #depth_location = bpy.context.active_object.location
        ### creating 3d vector from the cursor
        end = transform(region, rv3d, coord, depth_location)
        #end = transform(region, rv3d, coord, bpy.context.space_data.region_3d.view_location)
        ### Viewport origin
        start = bpy_extras.view3d_utils.region_2d_to_origin_3d(region, rv3d, coord)
        
        ### Cast ray from view to mouselocation
        if b_version_bigger_than((2,76,0)):
            ray = bpy.context.scene.ray_cast(start, (start+(end-start)*2000)-start )
        else:    
            ray = bpy.context.scene.ray_cast(start, start+(end-start)*2000)
            
        ### ray_cast return values have changed after blender 2.67.0 
        if b_version_bigger_than((2,76,0)):
            ray = [ray[0],ray[4],ray[5],ray[1],ray[2]]
        
        return start, end, ray 
开发者ID:ndee85,项目名称:coa_tools,代码行数:27,代码来源:edit_armature.py

示例13: execute

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def execute(self,context):
        armature = context.active_object
        p_bone = armature.pose.bones[context.active_pose_bone.name]
        bpy.ops.object.mode_set(mode="EDIT")
        
        bone_name = "Stretch_"+p_bone.name
        stretch_to_bone = armature.data.edit_bones.new(bone_name)
        stretch_to_bone.use_deform = False
        if p_bone.parent != None:
            stretch_to_bone.parent = context.active_object.data.edit_bones[p_bone.name].parent
        length = Vector(p_bone.tail - p_bone.head).length
        stretch_to_bone.head =  p_bone.tail
        stretch_to_bone.tail = Vector((p_bone.tail[0],0, p_bone.tail[2] + length * .5))
        bpy.ops.object.mode_set(mode="POSE")
        
        stretch_to_constraint = p_bone.constraints.new("STRETCH_TO")
        stretch_to_constraint.target = context.active_object
        stretch_to_constraint.subtarget = bone_name
        stretch_to_constraint.keep_axis = "PLANE_Z" 
        stretch_to_constraint.volume = "VOLUME_X"
        set_bone_group(self, context.active_object, context.active_object.pose.bones[bone_name],group="stretch_to",theme = "THEME07")
        return{'FINISHED'}

######################################################################################################################################### Set IK Constraint 
开发者ID:ndee85,项目名称:coa_tools,代码行数:26,代码来源:edit_armature.py

示例14: create_verts

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def create_verts(self,width,height,pos,me,tag_hide=False):
        bpy.ops.object.mode_set(mode="EDIT")
        bm = bmesh.from_edit_mesh(me)
        vert1 = bm.verts.new(Vector((0,0,-height))*self.scale)
        vert2 = bm.verts.new(Vector((width,0,-height))*self.scale)
        vert3 = bm.verts.new(Vector((width,0,0))*self.scale)
        vert4 = bm.verts.new(Vector((0,0,0))*self.scale)
        
        bm.faces.new([vert1,vert2,vert3,vert4])
                
        bmesh.update_edit_mesh(me)
        
        if tag_hide:
            for vert in bm.verts:
                vert.hide = True    
                
            for edge in bm.edges:
                edge.hide = True    
        
        bmesh.update_edit_mesh(me)
        bpy.ops.object.mode_set(mode="OBJECT") 
开发者ID:ndee85,项目名称:coa_tools,代码行数:23,代码来源:import_sprites.py

示例15: move_verts

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Vector [as 别名]
def move_verts(self,obj,ratio_x,ratio_y):
        bpy.ops.object.mode_set(mode="EDIT")
        bpy.ops.mesh.reveal()
        bpy.ops.object.mode_set(mode="OBJECT")
        
        shapekeys = [obj.data.vertices]
        if obj.data.shape_keys != None:
            shapekeys = []
            for shapekey in obj.data.shape_keys.key_blocks:
                shapekeys.append(shapekey.data)
        
        for shapekey in shapekeys:
            for vert in shapekey:
                co_x = vert.co[0] * ratio_x
                co_y = vert.co[2] * ratio_y
                vert.co = Vector((co_x,0,co_y))
            
            
        obj.coa_sprite_dimension = Vector((get_local_dimension(obj)[0],0,get_local_dimension(obj)[1]))
        obj.coa_tiles_x = self.tiles_x
        obj.coa_tiles_y = self.tiles_y 
开发者ID:ndee85,项目名称:coa_tools,代码行数:23,代码来源:import_sprites.py


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