本文整理汇总了Python中mathutils.Matrix.Identity方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.Identity方法的具体用法?Python Matrix.Identity怎么用?Python Matrix.Identity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Matrix
的用法示例。
在下文中一共展示了Matrix.Identity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format_mesh
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def format_mesh(self, exportable, matrix):
m = Mesh(exportable['object'])
surfaces = m.surfaces
num_kids = len(surfaces)+len(exportable['children'])+1
bones = ''
arm = m.armature
if arm and CONFIG.export_animation:
bones = utils.join_map(self.format_bone, arm.bones)
if bones:
num_kids += len(arm.bones)
matrix = Matrix.Identity(4)
context = {
'code': constants.MDL_MESH,
'num_kids': num_kids,
'matrix': utils.format_floats_box(matrix),
'props': self.format_props([['name', m.name]]),
'surfaces': utils.join_map(self.format_surface, surfaces),
'bones': bones,
'childs': utils.join_map(self.format_block, exportable['children'])
}
return templates.render('MESH', context)
示例2: transform
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def transform(v: typing.Union[Vector, Quaternion], data_path: str, transform: Matrix = Matrix.Identity(4)) -> typing \
.Union[Vector, Quaternion]:
"""Manage transformations."""
target = get_target_property_name(data_path)
transform_func = {
"delta_location": transform_location,
"delta_rotation_euler": transform_rotation,
"location": transform_location,
"rotation_axis_angle": transform_rotation,
"rotation_euler": transform_rotation,
"rotation_quaternion": transform_rotation,
"scale": transform_scale,
"value": transform_value
}.get(target)
if transform_func is None:
raise RuntimeError("Cannot transform values at {}".format(data_path))
return transform_func(v, transform)
示例3: __exportBones
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def __exportBones(self, armObj, converters=None, matrix_basis_map=None):
if armObj is None:
return None
pose_bones = armObj.pose.bones
if converters is None:
converters = self.__getConverters(pose_bones)
if matrix_basis_map is None:
matrix_basis_map = {}
matrix_identity = Matrix.Identity(4)
vpd_bones = []
for b in pose_bones:
if b.is_mmd_shadow_bone:
continue
if b.matrix_basis == matrix_basis_map.get(b, matrix_identity):
continue
bone_name = b.mmd_bone.name_j or b.name
converter = converters[b]
location = converter.convert_location(b.location)
w, x, y, z = b.matrix_basis.to_quaternion()
w, x, y, z = converter.convert_rotation([x, y, z, w])
vpd_bones.append(vpd.VpdBone(bone_name, location, [x, y, z, w]))
return vpd_bones
示例4: circleOfTriangle
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def circleOfTriangle(a, b, c):
# https://en.wikipedia.org/wiki/Circumscribed_circle#Cartesian_coordinates_from_cross-_and_dot-products
dirBA = a-b
dirCB = b-c
dirAC = c-a
normal = dirBA.cross(dirCB)
lengthBA = dirBA.length
lengthCB = dirCB.length
lengthAC = dirAC.length
lengthN = normal.length
if lengthN == 0:
return None
factor = -1/(2*lengthN*lengthN)
alpha = (dirBA@dirAC)*(lengthCB*lengthCB*factor)
beta = (dirBA@dirCB)*(lengthAC*lengthAC*factor)
gamma = (dirAC@dirCB)*(lengthBA*lengthBA*factor)
center = a*alpha+b*beta+c*gamma
radius = (lengthBA*lengthCB*lengthAC)/(2*lengthN)
tangent = (a-center).normalized()
orientation = Matrix.Identity(3)
orientation.col[2] = normal/lengthN
orientation.col[1] = (a-center).normalized()
orientation.col[0] = orientation.col[1].xyz.cross(orientation.col[2].xyz)
return Circle(orientation=orientation, center=center, radius=radius)
示例5: bezierArcAt
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def bezierArcAt(tangent, normal, center, radius, angle, tollerance=0.99999):
transform = Matrix.Identity(4)
transform.col[0].xyz = tangent.cross(normal)*radius
transform.col[1].xyz = tangent*radius
transform.col[2].xyz = normal*radius
transform.col[3].xyz = center
segments = []
segment_count = math.ceil(abs(angle)/(math.pi*0.5)*tollerance)
angle /= segment_count
x0 = math.cos(angle*0.5)
y0 = math.sin(angle*0.5)
x1 = (4.0-x0)/3.0
y1 = (1.0-x0)*(3.0-x0)/(3.0*y0)
points = [
Vector((x0, -y0, 0)),
Vector((x1, -y1, 0)),
Vector((x1, y1, 0)),
Vector((x0, y0, 0))
]
for i in range(0, segment_count):
rotation = Matrix.Rotation((i+0.5)*angle, 4, 'Z')
segments.append(list(map(lambda v: transform@(rotation@v), points)))
return segments
示例6: _get_delta_matrix
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def _get_delta_matrix(bone_rest_matrix_scs, parent_bone_rest_matrix_scs, bone_animation_matrix_scs, import_scale):
"""."""
scale_matrix = Matrix.Scale(import_scale, 4)
# NOTE: apply scaling bone rest matrix, because it's subtracted by bone rest matrix inverse
loc, rot, sca = bone_rest_matrix_scs.decompose()
scale = Matrix.Identity(4)
scale[0] = (sca[0], 0, 0, 0)
scale[1] = (0, sca[1], 0, 0)
scale[2] = (0, 0, sca[2], 0)
return (scale_matrix @
scale @
bone_rest_matrix_scs.inverted() @
parent_bone_rest_matrix_scs @
bone_animation_matrix_scs)
示例7: __init__
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def __init__(self):
# The ID of the glTF node this vnode was created from, or None if there
# wasn't one
self.node_id = None
# List of child vnodes
self.children = []
# Parent vnode, or None for the root
self.parent = None
# (Vector, Quaternion, Vector) triple of the local-to-parent TRS transform
self.trs = (Vector((0, 0, 0)), Quaternion((1, 0, 0, 0)), Vector((1, 1, 1)))
# What type of Blender object will be created for this vnode: one of
# OBJECT, ARMATURE, BONE, or ROOT (for the special vnode that we use the
# turn the forest into a tree to make things easier to process).
self.type = 'OBJECT'
# Dicts of instance data
self.mesh = None
self.camera = None
self.light = None
# If this node had an instance in glTF but we moved it to another node,
# we record where we put it here
self.mesh_moved_to = None
self.camera_moved_to = None
self.light_moved_to = None
# These will be filled out after realization with the Blender data
# created for this vnode.
self.blender_object = None
self.blender_armature = None
self.blender_editbone = None
self.blender_name = None
# The editbone's (Translation, Rotation)
self.editbone_tr = None
self.posebone_s = None
self.editbone_local_to_armature = Matrix.Identity(4)
self.bone_length = 0
# Correction to apply to the original TRS to get the editbone TR
self.correction_rotation = Quaternion((1, 0, 0, 0))
self.correction_homscale = 1
示例8: __fake_keyframe
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def __fake_keyframe(self):
return Matrix.Identity(4)
示例9: execute
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def execute(self, context):
from bpy_extras.io_utils import unpack_list
sc = context.space_data
clip = sc.clip
tracking_object = clip.tracking.objects.active
new_verts = []
scene = context.scene
camera = scene.camera
matrix = Matrix.Identity(4)
if camera:
reconstruction = tracking_object.reconstruction
framenr = scene.frame_current - clip.frame_start + 1
reconstructed_matrix = reconstruction.cameras.matrix_from_frame(framenr)
matrix = camera.matrix_world * reconstructed_matrix.inverted()
mesh = bpy.data.meshes.new(name="Tracks")
for track in tracking_object.tracks:
if track.has_bundle:
new_verts.append(track.bundle)
if new_verts:
mesh.vertices.add(len(new_verts))
mesh.vertices.foreach_set("co", unpack_list(new_verts))
ob = bpy.data.objects.new(name="Tracks", object_data=mesh)
ob.matrix_world = matrix
context.scene.objects.link(ob)
return {'FINISHED'}
示例10: MatrixCompose
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def MatrixCompose(*args):
size = len(args)
m = Matrix.Identity(size)
axes = m.col # m.row
if size == 2:
for i in (0, 1):
c = args[i]
if isinstance(c, Vector):
axes[i] = c.to_2d()
elif hasattr(c, "__iter__"):
axes[i] = Vector(c).to_2d()
else:
axes[i][i] = c
else:
for i in (0, 1, 2):
c = args[i]
if isinstance(c, Vector):
axes[i][:3] = c.to_3d()
elif hasattr(c, "__iter__"):
axes[i][:3] = Vector(c).to_3d()
else:
axes[i][i] = c
if size == 4:
c = args[3]
if isinstance(c, Vector):
m.translation = c.to_3d()
elif hasattr(c, "__iter__"):
m.translation = Vector(c).to_3d()
return m
示例11: calc_bone_matrices
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def calc_bone_matrices(gltf):
"""
Calculate the transformations from bone space to arma space in the bind
pose and in the edit bone pose.
"""
def visit(vnode_id): # Depth-first walk
vnode = gltf.vnodes[vnode_id]
if vnode.type == VNode.Bone:
if gltf.vnodes[vnode.parent].type == VNode.Bone:
parent_bind_mat = gltf.vnodes[vnode.parent].bind_arma_mat
parent_editbone_mat = gltf.vnodes[vnode.parent].editbone_arma_mat
else:
parent_bind_mat = Matrix.Identity(4)
parent_editbone_mat = Matrix.Identity(4)
t, r = vnode.bind_trans, vnode.bind_rot
local_to_parent = Matrix.Translation(t) @ Quaternion(r).to_matrix().to_4x4()
vnode.bind_arma_mat = parent_bind_mat @ local_to_parent
t, r = vnode.editbone_trans, vnode.editbone_rot
local_to_parent = Matrix.Translation(t) @ Quaternion(r).to_matrix().to_4x4()
vnode.editbone_arma_mat = parent_editbone_mat @ local_to_parent
for child in vnode.children:
visit(child)
visit('root')
示例12: transform_location
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def transform_location(location: Vector, transform: Matrix = Matrix.Identity(4)) -> Vector:
"""Transform location."""
m = Matrix.Translation(location)
m = multiply(transform, m)
return m.to_translation()
示例13: transform_rotation
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def transform_rotation(rotation: Quaternion, transform: Matrix = Matrix.Identity(4)) -> Quaternion:
"""Transform rotation."""
rotation.normalize()
m = rotation.to_matrix().to_4x4()
m = multiply(transform, m)
return m.to_quaternion()
示例14: transform_value
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def transform_value(value: Vector, _: Matrix = Matrix.Identity(4)) -> Vector:
"""Transform value."""
return value
示例15: generateRotationMatrix
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Identity [as 别名]
def generateRotationMatrix(direction, guide, trackAxis = "Z", guideAxis = "X"):
'''
trackAxis in ("X", "Y", "Z", "-X", "-Y", "-Z")
guideAxis in ("X", "Y", "Z")
'''
matrix = Matrix.Identity(4)
if guideAxis[-1:] == trackAxis[-1:]:
return matrix
if direction == zero:
return matrix
z = direction.normalized()
y = z.cross(guide.normalized())
if y == zero:
if guideAxis == "X":
if z.cross(xAxis) != zero: y = z.cross(xAxis)
else: y = zAxis
elif guideAxis == "Y":
if z.cross(yAxis) != zero: y = z.cross(yAxis)
else: y = zAxis
elif guideAxis == "Z":
if z.cross(zAxis) != zero: y = z.cross(zAxis)
else: y = yAxis
x = y.cross(z)
mx, my, mz = changeAxesDict[(trackAxis, guideAxis)](x, y, z)
matrix.col[0][:3] = mx
matrix.col[1][:3] = my
matrix.col[2][:3] = mz
return matrix