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


Python Matrix.to_4x4方法代码示例

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


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

示例1: __getAxisAngleBasedRotation

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_4x4 [as 别名]
    def __getAxisAngleBasedRotation(self, rotate, translate):

        euler = Euler(rotate)

        self.logger.debug("Injecting rotation: '%s'", str(euler))

        vector_translate = Vector((translate[0], translate[1], translate[2]))

        # actually the translation is also needed to be passed here
        rotate_mtx = Matrix.to_4x4(euler.to_matrix())
        translate_mtx = Matrix.Translation(vector_translate)

        cameraMatrix = translate_mtx * rotate_mtx

        # global matrix rotate (guess it is for world coordinate system rotating)

        mtx = Matrix.Rotation(-(math.pi / 2.0), 4, 'X')
        mtx = mtx * cameraMatrix

        (loc, quat, _) = mtx.decompose()

        # get the values the way that in x3d exporter does
        quat = quat.normalized()

        # some weird stuff
        axises = list(quat.axis.to_tuple())
        angle = quat.angle

        orientation = self.__getStringRepresentation(axises) + " " + str(angle)
        translation = self.__getStringRepresentation(loc)

        return translation, orientation
开发者ID:Dzess,项目名称:ALFIRT,代码行数:34,代码来源:SceneInjecterX3D.py

示例2: focus_view_on

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_4x4 [as 别名]
def focus_view_on(region_3d, location):
    r3d = region_3d

    a = r3d.view_location.copy()
    b = location
    mm = r3d.view_matrix.inverted()

    vr = mm.to_3x3()
    loc = mm.translation

    n = (a-loc).cross(b-loc).normalized()
    alp = math.acos( max(-1.0,min(1.0,  (a-loc).normalized().dot( (b-loc).normalized() )  )))

    zero = Vector()
    u0,v0,w0 = vr.transposed()
    u = rot_on( zero, n, alp, u0 )
    v = rot_on( zero, n, alp, v0 )
    w = rot_on( zero, n, alp, w0 )

    if bpy.context.user_preferences.inputs.view_rotate_method == 'TURNTABLE':
        ez = Vector((0,0,1))
        u2 = ez.cross(w)
        v2 = w.cross(u2)
        u,v = u2,v2

    vr2 = Matrix((u,v,w)).transposed()

    mm2 = vr2.to_4x4()
    mm2[0][3] = loc[0]
    mm2[1][3] = loc[1]
    mm2[2][3] = loc[2]

    dist0 = (loc-location).length
    r3d.view_distance = dist0
    r3d.view_matrix = mm2.inverted()
开发者ID:a-nakanosora,项目名称:Focus-on-Mouse,代码行数:37,代码来源:view3d_focus_on_mouse.py

示例3: to_Scene

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_4x4 [as 别名]
 def to_Scene(self):
     if self.hasOpened:
         #      Load table
         #
         #Get the tag objects from the scene by filtering objects with 
         # hexadecimal strings as the first 8 chars of their name
         tag_objs = {obj.name[:8]:obj for obj in bpy.data.objects if isHex(obj.name[:8])}
         #
         #      Load placements
         #
         #Create a parent object to contain all placement objects
         for i, p in enumerate(self.placements):
             mesh = None # the mesh for the object
             #The placement's index references a table item that has a tag index
             if p.index >= 0 and p.index < self.n_table_items: # the index must be in the range of the table items
                 palette_tag_idx = self.table_items[p.index].index 
                 try:
                     #apply the data if found
                     mesh = tag_objs[str('%08x' % palette_tag_idx).upper()].data
                 except KeyError:
                     print("Could not find tag '%08x' for placement %d" % (palette_tag_idx, i))
             object = bpy.data.objects.new("Placement.%03d" % i, mesh)
             #link the object to the active scene (ususally scene 0)
             bpy.context.scene.objects.link(object)
             for j in range(3):
                 object.lock_scale[j] = True #objects in forge can be only moved or rotated
             #
             #    Apply a matrix to the object to place it correctly in the scene
             #
             #Recreate col1 using cross product of column vectors: col0 
             # and col2 that are perpendicular to one another
             col2 = p.col2
             col0 = p.col0
             col1 = col0.cross(col2)
             pos = p.pos
             #Construct 3x3 matrix with column vectors for rows
             mat = Matrix((col0, col1, col2))
             mat.transpose() # Matrix is now correct
             #Increase size from 3x3 to 4x4 to move 3D points 
             # as well as to rotate/scale them like a 3x3 could
             mat = mat.to_4x4() 
             for i in range(3):
                 mat[i][3] = pos[i]
             object.matrix_local = mat
             #object.
             #Assign 'Custom Properties' to the object with values from the Placement
             # in order to serialize the placement later
             pd = vars(p)
             for key in pd.keys():
                 object[key] = pd[key]
             #Assign the item table to the scene in order to serialize later
             bpy.data.scenes[0]['item_table'] = [l.to_list() for l in self.table_items]
             #Assign the entire 60k file to the scene
             bpy.data.scenes[0]['usermap_data'] = struct.unpack("B" * len(self.data), self.data)
开发者ID:Gurten,项目名称:HaloOnlineTagTool,代码行数:56,代码来源:HaloOnline_usermap_io.py

示例4: align

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_4x4 [as 别名]
def align(aligny=Vector((0,1,0)), alignz=Vector((0,0,1))):
    '''
    Get a Rotation Matrix.
    The Matrix Local +Y Axis gets aligned with aligny.
    The +Z Local Axis gets aligned with alignz as best as possible,
    without disturbing the Y alignment.
    This implementation looks a little brutish to the Coders eyes.
    Better ideas are very welcome.
    '''
    X=Vector((1,0,0))
    Y=Vector((0,1,0))
    Z=Vector((0,0,1))
    if alignz.length == 0:
        alignz = Z.copy()
    mat = Matrix().to_3x3()
    #Align local-Y axis with aligny
    axis, angle = axisangle(Y, aligny)
    if axis.length == 0:
        axis = X
    rot_to_y = Matrix.Rotation(angle,3,axis)
    bm1 = get_axis_aligned_bm(rot_to_y)
    #Align local-Z with projected alignz
    eul = rot_to_y.to_euler()
    target_localx = aligny.cross(alignz).normalized()
    target_localz = target_localx.cross(aligny).normalized()
    angle = target_localz.angle(bm1.verts[2].co)
    ### NEED SOME TEST FOR ANGLE FLIPPING
    eul.rotate_axis('Y', angle)
    mat = eul.to_matrix().to_4x4()
    ### Test if rotation is good
    bmf = get_axis_aligned_bm(mat)
    dist = distance_point_to_plane(bmf.verts[2].co, target_localz, target_localz.cross(alignz))
    error = 1e-06
    ### Flip the angle
    if abs(dist)>error:
        eul = rot_to_y.to_euler()
        eul.rotate_axis('Y', -angle)
        mat = eul.to_matrix().to_4x4()
    bm1.free()
    bmf.free()
    return mat.to_4x4()
开发者ID:florianfelix,项目名称:ivy_generator,代码行数:43,代码来源:curve_add_leafs.py


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