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


Python mathutils.Matrix方法代码示例

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


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

示例1: mat4_svd_decompose_to_mats

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def mat4_svd_decompose_to_mats(mat4):
    """
    Decompose the given matrix into a couple of TRS-decomposable matrices or
    Returns None in case of an error.
    """

    try:
        u, s, vh = np.linalg.svd(mat4.to_3x3())
        mat_u = mathutils.Matrix(u)
        mat_s = mathutils.Matrix([[s[0], 0, 0], [0, s[1], 0], [0, 0, s[2]]])
        mat_vh = mathutils.Matrix(vh)

        # NOTE: a potential reflection part in U and VH matrices isn't considered
        mat_trans = mathutils.Matrix.Translation(mat4.to_translation())
        mat_left = mat_trans @ (mat_u @ mat_s).to_4x4()

        return (mat_left, mat_vh.to_4x4())

    except np.linalg.LinAlgError:
        # numpy failed to decompose the matrix
        return None 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:23,代码来源:utils.py

示例2: get_lookat_aligned_up_matrix

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [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: ai_properties

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def ai_properties(self):
        scale = self.geometry_matrix_scale
        matrix = Matrix([
            [scale.x, 0, 0],
            [0, scale.y, 0],
            [0, 0, scale.z]
        ])
        matrix.rotate(Euler(self.geometry_matrix_rotation))
        matrix = matrix.to_4x4()
        matrix.translation = (self.geometry_matrix_translation)
        return {
            "format": ('STRING', self.format),
            "resolution": ('STRING', self.resolution),
            "portal_mode": ('STRING', self.portal_mode),
            "matrix": ('MATRIX', matrix),
            "camera": ('BOOL', self.camera),
            "diffuse": ('BOOL', self.diffuse),
            "specular": ('BOOL', self.specular),
            "sss": ('BOOL', self.sss),
            "volume": ('BOOL', self.volume),
            "transmission": ('BOOL', self.transmission)
        } 
开发者ID:griffin-copperfield,项目名称:Arnold-For-Blender,代码行数:24,代码来源:nodes.py

示例4: draw_buttons

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def draw_buttons(self, context, layout):
        col = layout.column()
        col.prop(self, "geometry_type")
        col.prop(self, "axis")
        col.prop(self, "ramp")
        col.prop(self, "height_edge")
        col.prop(self, "width_edge")
        col.prop(self, "roundness")
        col.label(text="Matrix:")
        sub = col.box().column()
        sub.prop_search(self, "geometry_matrix_object", context.scene, "objects", text="")
        sub = sub.column()
        sub.enabled = not self.geometry_matrix_object
        sub.template_component_menu(self, "geometry_matrix_scale", name="Weight:")
        sub.template_component_menu(self, "geometry_matrix_rotation", name="Rotation:")
        sub.template_component_menu(self, "geometry_matrix_translation", name="Translation:") 
开发者ID:griffin-copperfield,项目名称:Arnold-For-Blender,代码行数:18,代码来源:nodes.py

示例5: setup_camera

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def setup_camera(scene, fx=572, fy=574, cx=325, cy=242):
    cam = scene.objects['Camera']
    width = scene.render.resolution_x
    height = scene.render.resolution_y
    cam.data.sensor_height = cam.data.sensor_width * height / width
    cam.data.lens = (fx + fy) / 2 * cam.data.sensor_width / width
    cam.data.shift_x = (width / 2 - cx) / width
    cam.data.shift_y = (cy - height / 2) / width
    # change to OpenCV camera coordinate system
    cam.matrix_world = Matrix(((1.0, 0.0, 0.0, 0.0),
                               (0.0, -1.0, 0.0, 0.0),
                               (0.0, 0.0, -1.0, 0.0),
                               (0.0, 0.0, 0.0, 1.0)))
    return cam


# Add material to object 
开发者ID:YoungXIAO13,项目名称:ObjectPoseEstimationSummary,代码行数:19,代码来源:render_random_pose.py

示例6: get_vertical_mode_matrix

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def get_vertical_mode_matrix(is_vertical, camera_rotation):
    if is_vertical:
    # Get the up direction of the camera
        up_vec = mathutils.Vector((0.0, 1.0, 0.0))
        up_vec.rotate(camera_rotation)
        # Decide around which axis to rotate
        vert_mode_rotate_x = abs(up_vec[0]) < abs(up_vec[1])
        # Create rotation matrix
        if vert_mode_rotate_x:
            vert_angle = pi / 2 if up_vec[1] > 0 else -pi / 2
            return mathutils.Matrix().Rotation(vert_angle, 3, "X")
        else:
            vert_angle = pi / 2 if up_vec[0] < 0 else -pi / 2
            return mathutils.Matrix().Rotation(vert_angle, 3, "Y")
    else:
        return mathutils.Matrix().Identity(3) 
开发者ID:mrossini-ethz,项目名称:camera-calibration-pvr,代码行数:18,代码来源:camera-calibration-pvr.py

示例7: get_view_projection_matrix

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def get_view_projection_matrix(context, settings):
	"""
	Returns view projection matrix.
	Projection matrix is either identity if 3d export is selected or
	camera projection if a camera or view is selected.
	Currently only orthographic projection is used. (Subject to discussion).
	"""	
	cam = settings['projectionThrough']
	if cam == None:
		mw = mathutils.Matrix()
		mw.identity()
	elif cam in projectionMapping.keys():
		projection = mathutils.Matrix.OrthoProjection(projectionMapping[cam], 4)
		mw = projection
	else: # get camera with given name
		c = context.scene.objects[cam]
		mw = getCameraMatrix(c)
	return mw 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:export_dxf.py

示例8: finalize_islands

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def finalize_islands(self, title_height=0):
        for island in self.islands:
            if title_height:
                island.title = "[{}] {}".format(island.abbreviation, island.label)
            points = list(vertex.co for vertex in island.verts) + island.fake_verts
            angle = M.geometry.box_fit_2d(points)
            rot = M.Matrix.Rotation(angle, 2)
            for point in points:
                # note: we need an in-place operation, and Vector.rotate() seems to work for 3d vectors only
                point[:] = rot * point
            for marker in island.markers:
                marker.rot = rot * marker.rot
            bottom_left = M.Vector((min(v.x for v in points), min(v.y for v in points) - title_height))
            for point in points:
                point -= bottom_left
            island.bounding_box = M.Vector((max(v.x for v in points), max(v.y for v in points))) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:io_export_paper_model.py

示例9: to_matrix

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def to_matrix(self):
        """
        mat = M(to original transform)^-1 * Mt(to origin) * Ms *
              Mt(to origin)^-1 * M(to original transform)
        """
        m = self.__mat
        mi = self.__mat.inverted()
        mtoi = mathutils.Matrix.Translation((-self.__iox, -self.__ioy, 0.0))
        mto = mathutils.Matrix.Translation((self.__iox, self.__ioy, 0.0))
        # every point must be transformed to origin
        t = m * mathutils.Vector((self.__ix, self.__iy, 0.0))
        tix, tiy = t.x, t.y
        t = m * mathutils.Vector((self.__ox, self.__oy, 0.0))
        tox, toy = t.x, t.y
        t = m * mathutils.Vector((self.__x, self.__y, 0.0))
        tx, ty = t.x, t.y
        ms = mathutils.Matrix()
        ms.identity()
        if self.__dir_x == 1:
            ms[0][0] = (tx - tox) * self.__dir_x / (tix - tox)
        if self.__dir_y == 1:
            ms[1][1] = (ty - toy) * self.__dir_y / (tiy - toy)
        return mi * mto * ms * mtoi * m 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:muv_uvbb_ops.py

示例10: fix_matrix

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def fix_matrix(mtx):
    """ Shuffles a matrix to change from y-up to z-up"""
    # TODO: can this be replaced my a matrix multiplcation?
    trans = mathutils.Matrix(mtx)
    up_axis = 2

    for i in range(3):
        trans[1][i], trans[up_axis][i] = trans[up_axis][i], trans[1][i]
    for i in range(3):
        trans[i][1], trans[i][up_axis] = trans[i][up_axis], trans[i][1]

    trans[1][3], trans[up_axis][3] = trans[up_axis][3], trans[1][3]

    trans[up_axis][0] = -trans[up_axis][0]
    trans[up_axis][1] = -trans[up_axis][1]
    trans[0][up_axis] = -trans[0][up_axis]
    trans[1][up_axis] = -trans[1][up_axis]
    trans[up_axis][3] = -trans[up_axis][3]

    return trans 
开发者ID:godotengine,项目名称:godot-blender-exporter,代码行数:22,代码来源:structures.py

示例11: add_obj_xform_track

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def add_obj_xform_track(self, node_type, track_path,
                            xform_frames_list, frame_range,
                            parent_mat_inverse=mathutils.Matrix.Identity(4)):
        """Add a object transform track to AnimationResource"""
        track = TransformTrack(
            track_path,
            frames_iter=range(frame_range[0], frame_range[1]),
            values_iter=xform_frames_list,
        )
        track.set_parent_inverse(parent_mat_inverse)
        if node_type in ("SpotLight", "DirectionalLight",
                         "Camera", "CollisionShape"):
            track.is_directional = True

        self.add_track(track)

    # pylint: disable-msg=too-many-arguments 
开发者ID:godotengine,项目名称:godot-blender-exporter,代码行数:19,代码来源:serializer.py

示例12: get_mvp_matrix

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def get_mvp_matrix(self, view3D=True):
        '''
        if view3D == True: returns MVP for 3D view
        else: returns MVP for pixel view
        TODO: compute separate M,V,P matrices
        '''
        if not self.r3d: return None
        if view3D:
            # 3D view
            return self.r3d.perspective_matrix
        else:
            # pixel view
            return self.get_pixel_matrix()

        mat_model = Matrix()
        mat_view = Matrix()
        mat_proj = Matrix()

        view_loc = self.r3d.view_location # vec
        view_rot = self.r3d.view_rotation # quat
        view_per = self.r3d.view_perspective # 'PERSP' or 'ORTHO'

        return mat_model,mat_view,mat_proj 
开发者ID:CGCookie,项目名称:addon_common,代码行数:25,代码来源:drawing.py

示例13: _create_bone

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def _create_bone(self, rig, name, delta_pos):
        b = rig.data.edit_bones.new('DEF-' + name)

        b.head = self.bones_position[name] + delta_pos
        b.tail = b.head
        if name == 'Body':
            b.tail.y += b.tail.z * 4
        else:
            b.tail.y += b.tail.z

        target_obj_name = self.target_objects_name.get(name)
        if target_obj_name is not None and target_obj_name in bpy.context.scene.objects:
            target_obj = bpy.context.scene.objects[target_obj_name]
            if name == 'Body':
                b.tail = b.head
                b.tail.y += target_obj.dimensions[1] / 2 if target_obj.dimensions and target_obj.dimensions[0] != 0 else 1
            target_obj.parent = rig
            target_obj.parent_bone = b.name
            target_obj.parent_type = 'BONE'
            target_obj.location += rig.matrix_world.to_translation()
            target_obj.matrix_parent_inverse = (rig.matrix_world @ mathutils.Matrix.Translation(b.tail)).inverted()

        return b 
开发者ID:digicreatures,项目名称:rigacar,代码行数:25,代码来源:car_rig.py

示例14: offscreen_refresh

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def offscreen_refresh(self, context):
        if self.offscreen is not None:
            self.offscreen.free()

        width = self.region.width
        height = self.region.height
        self.offscreen = gpu.types.GPUOffScreen(width, height)

        mat_offscreen = Matrix()
        mat_offscreen[0][0] = 2 / width
        mat_offscreen[0][3] = -1
        mat_offscreen[1][1] = 2 / height
        mat_offscreen[1][3] = -1

        with self.offscreen.bind():
            bgl.glClear(bgl.GL_COLOR_BUFFER_BIT)

            with gpu.matrix.push_pop():
                gpu.matrix.load_matrix(mat_offscreen)
                gpu.matrix.load_projection_matrix(Matrix())

                self.draw_gems(context) 
开发者ID:mrachinskiy,项目名称:jewelcraft,代码行数:24,代码来源:offscreen.py

示例15: get_3x4_RT_matrix_from_blender

# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Matrix [as 别名]
def get_3x4_RT_matrix_from_blender(camera):
    # bcam stands for blender camera
    R_bcam2cv = Matrix(
        ((1, 0,  0),
         (0, -1, 0),
         (0, 0, -1)))

    # Use matrix_world instead to account for all constraints
    location, rotation = camera.matrix_world.decompose()[0:2]
    R_world2bcam = rotation.to_matrix().transposed()

    # Convert camera location to translation vector used in coordinate changes
    # Use location from matrix_world to account for constraints:
    T_world2bcam = -1 * R_world2bcam * location

    # Build the coordinate transform matrix from world to computer vision camera
    R_world2cv = R_bcam2cv * R_world2bcam
    T_world2cv = R_bcam2cv * T_world2bcam

    # put into 3x4 matrix
    RT = Matrix((R_world2cv[0][:] + (T_world2cv[0],),
                 R_world2cv[1][:] + (T_world2cv[1],),
                 R_world2cv[2][:] + (T_world2cv[2],)))
    return RT 
开发者ID:zju3dv,项目名称:pvnet-rendering,代码行数:26,代码来源:blender_utils.py


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