Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Blender Python exporter中旋转模型_Python_3d_Rotation_Blender_Coordinate Systems - Fatal编程技术网

在Blender Python exporter中旋转模型

在Blender Python exporter中旋转模型,python,3d,rotation,blender,coordinate-systems,Python,3d,Rotation,Blender,Coordinate Systems,我在写一个模型导出器。我想在导出器脚本中将整个模型在X轴上旋转90度。问题是,如果模型包含多个网格,则网格位置错误。以下是我的出口商的相关部分: objects = [Object for Object in context.selected_objects if Object.type in ("MESH")] for obj in objects: ... mat_x90 = mathutils.Matrix.Rotation(-math.pi

我在写一个模型导出器。我想在导出器脚本中将整个模型在X轴上旋转90度。问题是,如果模型包含多个网格,则网格位置错误。以下是我的出口商的相关部分:

    objects = [Object for Object in context.selected_objects if Object.type in ("MESH")]
    for obj in objects:
        ...
        mat_x90 = mathutils.Matrix.Rotation(-math.pi/2, 4, 'X')
        obj.data.transform(mat_x90)

        object[ OBJ.MAT ] = obj.matrix_world.copy()
        object[ OBJ.LOC ] = object[ OBJ.MAT ].to_translation()
        object[ OBJ.ROT ] = object[ OBJ.MAT ].to_quaternion()
        object[ OBJ.SCA ] = object[ OBJ.MAT ].to_scale()
        object[ OBJ.UVL ] = None

        ...
        for face in obj.data.tessfaces:
            for vertex_id in (0, 1, 2):
                vertex_pnt = self.get_vertex_pnt(object, obj.data, face, vertex_id)
                mesh.vertices.append( vertex_pnt )

        ...
def get_vertex_pnt( self, obj_prop, mesh, face, face_vi ):
    # position
    co = obj_prop[ OBJ.LOC ] + 
    mathutils.Vector(obj_prop[OBJ.ROT] * mathutils.Vector([                                                                                                
    mesh.vertices[face.vertices[face_vi]].co[0] * obj_prop[OBJ.SCA][0], \                                                                                 
    mesh.vertices[face.vertices[face_vi]].co[1] * obj_prop[OBJ.SCA][1], \                                                                                
    mesh.vertices[face.vertices[face_vi]].co[2] * obj_prop[OBJ.SCA][2] \
                                                                                    ]))
如果我没有在循环开始时应用90度旋转,网格位置是可以的,但是模型在X轴上旋转了90度,这是我不想要的

基本上,我想在脚本中执行此操作:

完成手动选择要导出的所有网格

按“r”启动旋转

按“x”键并旋转90度

编辑:在从Blender导出之前和之后附上屏幕截图: 终于找到了一个:


如果模型包含多个网格,那么网格位置是错误的,您能简单解释一下吗?
def get_override(area_type, region_type):
    for area in bpy.context.screen.areas: 
        if area.type == area_type:             
            for region in area.regions:                 
                if region.type == region_type:                    
                    override = {'area': area, 'region': region} 
                    return override
    #error message if the area or region wasn't found
    raise RuntimeError("Wasn't able to find", region_type," in area ", area_type,
                    "\n Make sure it's open while executing script.")


#we need to override the context of our operator    
override = get_override( 'VIEW_3D', 'WINDOW' )
#rotate about the X-axis by 45 degrees
bpy.ops.transform.rotate(override, value=6.283/8, axis=(1,0,0))