本文整理汇总了Python中mathutils.Matrix.Translation方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.Translation方法的具体用法?Python Matrix.Translation怎么用?Python Matrix.Translation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Matrix
的用法示例。
在下文中一共展示了Matrix.Translation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _findOrCreateCamera
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def _findOrCreateCamera(context):
scene = context.scene
if scene.camera:
return scene.camera
cam = bpy.data.cameras.new(name="Camera")
camob = bpy.data.objects.new(name="Camera", object_data=cam)
scene.objects.link(camob)
scene.camera = camob
camob.matrix_local = (Matrix.Translation((7.481, -6.508, 5.344)) *
Matrix.Rotation(0.815, 4, 'Z') *
Matrix.Rotation(0.011, 4, 'Y') *
Matrix.Rotation(1.109, 4, 'X'))
return camob
示例2: importLamp_PointLight
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def importLamp_PointLight(node, ancestry):
vrmlname = node.getDefName()
if not vrmlname:
vrmlname = 'PointLight'
# ambientIntensity = node.getFieldAsFloat('ambientIntensity', 0.0, ancestry) # TODO
# attenuation = node.getFieldAsFloatTuple('attenuation', (1.0, 0.0, 0.0), ancestry) # TODO
color = node.getFieldAsFloatTuple('color', (1.0, 1.0, 1.0), ancestry)
intensity = node.getFieldAsFloat('intensity', 1.0, ancestry) # max is documented to be 1.0 but some files have higher.
location = node.getFieldAsFloatTuple('location', (0.0, 0.0, 0.0), ancestry)
# is_on = node.getFieldAsBool('on', True, ancestry) # TODO
radius = node.getFieldAsFloat('radius', 100.0, ancestry)
bpylamp = bpy.data.lamps.new(vrmlname, 'POINT')
bpylamp.energy = intensity
bpylamp.distance = radius
bpylamp.color = color
mtx = Matrix.Translation(Vector(location))
return bpylamp, mtx
示例3: importViewpoint
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def importViewpoint(bpyscene, node, ancestry, global_matrix):
name = node.getDefName()
if not name:
name = 'Viewpoint'
fieldOfView = node.getFieldAsFloat('fieldOfView', 0.785398, ancestry) # max is documented to be 1.0 but some files have higher.
# jump = node.getFieldAsBool('jump', True, ancestry)
orientation = node.getFieldAsFloatTuple('orientation', (0.0, 0.0, 1.0, 0.0), ancestry)
position = node.getFieldAsFloatTuple('position', (0.0, 0.0, 0.0), ancestry)
description = node.getFieldAsString('description', '', ancestry)
bpycam = bpy.data.cameras.new(name)
bpycam.angle = fieldOfView
mtx = Matrix.Translation(Vector(position)) * translateRotation(orientation)
bpyob = node.blendData = node.blendObject = bpy.data.objects.new(name, bpycam)
bpyscene.objects.link(bpyob).select = True
bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry, global_matrix)
示例4: SVGTransformRotate
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def SVGTransformRotate(params):
"""
skewX SVG transform command
"""
ang = float(params[0]) * pi / 180.0
cx = cy = 0.0
if len(params) >= 3:
cx = float(params[1])
cy = float(params[2])
tm = Matrix.Translation(Vector((cx, cy, 0.0)))
rm = Matrix.Rotation(ang, 4, Vector((0.0, 0.0, 1.0)))
return tm * rm * tm.inverted()
示例5: _doCreateGeom
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def _doCreateGeom(self, instancing):
"""
Create real geometries
"""
rect = SVGRectFromNode(self._node, self._context)
self._pushRect(rect)
matrix = self.getNodeMatrix()
# Better Inkscape compatibility: match document origin with
# 3D space origin.
if self._node.getAttribute('inkscape:version'):
raw_height = self._node.getAttribute('height')
document_height = SVGParseCoord(raw_height, 1.0)
matrix = matrix * Matrix.Translation([0.0, -document_height , 0.0])
self._pushMatrix(matrix)
super()._doCreateGeom(False)
self._popRect()
self._popMatrix()
示例6: convert_swizzle_normal
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def convert_swizzle_normal(loc, armature, blender_object, export_settings):
"""Convert a normal data from Blender coordinate system to glTF coordinate system."""
if (not armature) or (not blender_object):
# Classic case. Mesh is not skined, no need to apply armature transfoms on vertices / normals / tangents
if export_settings[gltf2_blender_export_keys.YUP]:
return Vector((loc[0], loc[2], -loc[1]))
else:
return Vector((loc[0], loc[1], loc[2]))
else:
# Mesh is skined, we have to apply armature transforms on data
apply_matrix = (armature.matrix_world.inverted() @ blender_object.matrix_world).to_3x3().inverted()
apply_matrix.transpose()
new_loc = ((armature.matrix_world.to_3x3() @ apply_matrix).to_4x4() @ Matrix.Translation(Vector((loc[0], loc[1], loc[2])))).to_translation()
new_loc.normalize()
if export_settings[gltf2_blender_export_keys.YUP]:
return Vector((new_loc[0], new_loc[2], -new_loc[1]))
else:
return Vector((new_loc[0], new_loc[1], new_loc[2]))
示例7: convert_swizzle_location
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def convert_swizzle_location(loc, armature, blender_object, export_settings):
"""Convert a location from Blender coordinate system to glTF coordinate system."""
if (not armature) or (not blender_object):
# Classic case. Mesh is not skined, no need to apply armature transfoms on vertices / normals / tangents
if export_settings[gltf2_blender_export_keys.YUP]:
return Vector((loc[0], loc[2], -loc[1]))
else:
return Vector((loc[0], loc[1], loc[2]))
else:
# Mesh is skined, we have to apply armature transforms on data
apply_matrix = armature.matrix_world.inverted() @ blender_object.matrix_world
new_loc = (armature.matrix_world @ apply_matrix @ Matrix.Translation(Vector((loc[0], loc[1], loc[2])))).to_translation()
if export_settings[gltf2_blender_export_keys.YUP]:
return Vector((new_loc[0], new_loc[2], -new_loc[1]))
else:
return Vector((new_loc[0], new_loc[1], new_loc[2]))
示例8: random_scale_and_translate
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def random_scale_and_translate(bm, middle_edge):
"""scale and translate an edge randomly along its axis
"""
verts = list(middle_edge.verts)
length = middle_edge.calc_length()
median = calc_edge_median(middle_edge)
axis = Vector((1, 0, 0)) if verts[0].co.y == verts[1].co.y else Vector((0, 1, 0))
scale_factor = clamp(random.random() * 3, 1, 2.95)
bmesh.ops.scale(
bm, verts=verts, vec=axis * scale_factor, space=Matrix.Translation(-median)
)
if random.choice([0, 1]):
rand_offset = random.random() * length
bmesh.ops.translate(bm, verts=verts, vec=axis * rand_offset)
示例9: face_pos
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def face_pos():
depsgraph = bpy.context.evaluated_depsgraph_get()
mats = []
for ob in bpy.context.objects_in_mode:
ob.update_from_editmode()
depsgraph.update()
ob_eval = ob.evaluated_get(depsgraph)
me = ob_eval.to_mesh()
me.transform(ob.matrix_world)
for poly in me.polygons:
if poly.select:
mat_loc = Matrix.Translation(poly.center)
mat_rot = poly.normal.to_track_quat("Z", "Y").to_matrix().to_4x4()
mat = mat_loc @ mat_rot
mats.append(mat)
ob_eval.to_mesh_clear()
return mats
示例10: from_spline
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def from_spline(self, context, wM, resolution, spline):
pts = self.coords_from_spline(
spline,
wM,
resolution,
ccw=(self.operation == 'INTERSECTION'),
cw=(self.operation != 'INTERSECTION'),
close=True
)
# pretranslate
o = self.find_in_selection(context, self.auto_update)
o.matrix_world = Matrix.Translation(pts[0].copy())
self.auto_update = False
self.from_points(pts)
self.auto_update = True
self.update_parent(context, o)
示例11: draw_model_box
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def draw_model_box(mat, scs_globals):
"""
Draw Cube for Model locator.
:param mat:
:param scs_globals:
:return:
"""
mat1 = mat @ (Matrix.Translation((0.0, 0.0, 0.0)) @
Matrix.Scale(scs_globals.locator_size / 5, 4, (1.0, 0.0, 0.0)) @
Matrix.Scale(scs_globals.locator_size / 5, 4, (0.0, 1.0, 0.0)) @
Matrix.Scale(scs_globals.locator_size / 5, 4, (0.0, 0.0, 1.0)))
cube_vertices, cube_faces, cube_wire_lines = _primitive.get_box_data()
_primitive.draw_polygon_object(mat1,
cube_vertices,
cube_faces,
scs_globals.locator_coll_face_color,
False,
True,
wire_lines=cube_wire_lines,
wire_color=scs_globals.locator_model_wire_color)
示例12: __init__
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [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
示例13: get_bone_matrix
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def get_bone_matrix(armature,bone,relative=True):
pose_bone = armature.pose.bones[bone.name]
m = Matrix() ### inverted posebone origin matrix
m.row[0] = [0,0,1,0]
m.row[1] = [1,0,0,0]
m.row[2] = [0,1,0,0]
m.row[3] = [0,0,0,1]
if bone.parent == None:
mat_bone_space = m * pose_bone.matrix
else:
if relative:
#if bone.use_inherit_rotation and bone.use_inherit_scale:
# mat_bone_space = pose_bone.parent.matrix.inverted() * pose_bone.matrix
mat_bone_space = pose_bone.matrix
for parent in pose_bone.parent_recursive:
pose_bone_matrix = parent.matrix.inverted() * mat_bone_space
mat_bone_space = pose_bone.parent.matrix.inverted() * pose_bone.matrix
else:
mat_bone_space = m * pose_bone.matrix
#### remap matrix
loc, rot, scale = mat_bone_space.decompose()
#if not bone.use_inherit_scale:
# scale = (m * pose_bone.matrix).decompose()[2]
loc_mat = Matrix.Translation(loc)
rot_mat = rot.inverted().to_matrix().to_4x4()
scale_mat = Matrix()
scale_mat[0][0] = scale[1]
scale_mat[1][1] = scale[0]
scale_mat[2][2] = scale[2]
mat_bone_space = loc_mat * rot_mat * scale_mat
return mat_bone_space
示例14: geometry
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def geometry(self, frame=0):
t = frame / self.frames
Rot = Matrix.Rotation(0.5*pi, 4, 'Y')
bm = bmesh.new()
for i in range(self.n):
t0 = i / self.n
r0, theta = t0*self.r0, i*goldenAngle - frame*goldenAngle + t*self.offset
x = r0*cos(theta)
y = r0*sin(theta)
z = self.h0/2 - (self.h0 / (self.r0*self.r0))*r0*r0
p0 = Vector((x, y, z))
T0, N0, B0 = getTNBfromVector(p0)
M0 = Matrix([T0, B0, N0]).to_4x4().transposed()
for j in range(self.m):
t1 = j / self.m
t2 = 0.4 + 0.6*t0
r1, theta = t2*t1*self.r1, j*goldenAngle #- frame*goldenAngle + t*self.offset
x = r1*cos(theta)
y = r1*sin(theta)
z = self.h1 - (self.h1 / (self.r1*self.r1))*r1*r1
p1 = Vector((x, y, z))
T1, N1, B1 = getTNBfromVector(p1)
M1 = Matrix([T1, B1, N1]).to_4x4().transposed()
p = p0 + M0*p1
r2 = t2*t1*self.r2
T = Matrix.Translation(p)
bmesh.ops.create_cone(bm,
cap_ends=True, segments=6,
diameter1=r2, diameter2=r2,
depth=0.1*r2, matrix=T*M0*M1*Rot)
return bm
示例15: _createLamp
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import Translation [as 别名]
def _createLamp(scene):
lamp = bpy.data.lamps.new(name="Lamp", type='POINT')
lampob = bpy.data.objects.new(name="Lamp", object_data=lamp)
scene.objects.link(lampob)
lampob.matrix_local = Matrix.Translation((4.076, 1.005, 5.904))
lamp.distance = 30
lamp.shadow_method = 'RAY_SHADOW'
return lampob