本文整理汇总了Python中mathutils.Matrix.transpose方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.transpose方法的具体用法?Python Matrix.transpose怎么用?Python Matrix.transpose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Matrix
的用法示例。
在下文中一共展示了Matrix.transpose方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copyto
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
def copyto(scene, source_obj, pos, xdir, zdir, axes, scale=None):
"""
copy the source_obj to pos, so its primary axis points in zdir and its
secondary axis points in xdir
"""
copy_obj = source_obj.copy()
scene.objects.link(copy_obj)
xdir = xdir.normalized()
zdir = zdir.normalized()
#rotation first
z_axis = zdir
x_axis = xdir
y_axis = z_axis.cross(x_axis)
#use axes_dict to assign the axis as chosen in panel
A, B, C = axes_dict[axes]
rot_mat = Matrix()
rot_mat[A].xyz = x_axis
rot_mat[B].xyz = y_axis
rot_mat[C].xyz = z_axis
rot_mat.transpose()
#rotate object
copy_obj.matrix_world = rot_mat
#move object into position
copy_obj.location = pos
#scale object
if scale != None:
copy_obj.scale = scale
return copy_obj
示例2: matchPoseReverse
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
def matchPoseReverse(pb, src):
gmat = src.matrix
tail = gmat.col[3] + src.length * gmat.col[1]
rmat = Matrix((gmat.col[0], -gmat.col[1], -gmat.col[2], tail))
rmat.transpose()
pmat = getPoseMatrix(rmat, pb)
pb.matrix_basis = pmat
insertRotation(pb, pmat)
示例3: to_Scene
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [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)
示例4: make_strut
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
def make_strut(v1, v2, id, od, n, solid, loops):
v1 = Vector(v1)
v2 = Vector(v2)
axis = v2 - v1
pos = [(0, od / 2)]
if loops:
pos += [((od - id) / 2, od / 2),
(axis.length - (od - id) / 2, od / 2)]
pos += [(axis.length, od / 2)]
if solid:
pos += [(axis.length, id / 2)]
if loops:
pos += [(axis.length - (od - id) / 2, id / 2),
((od - id) / 2, id / 2)]
pos += [(0, id / 2)]
vps = len(pos)
fps = vps
if not solid:
fps -= 1
fw = axis.copy()
fw.normalize()
if (abs(axis[0] / axis.length) < 1e-5
and abs(axis[1] / axis.length) < 1e-5):
up = Vector((-1, 0, 0))
else:
up = Vector((0, 0, 1))
lf = up.cross(fw)
lf.normalize()
up = fw.cross(lf)
mat = Matrix((fw, lf, up))
mat.transpose()
verts = [None] * n * vps
faces = [None] * n * fps
for i in range(n):
base = (i - 1) * vps
x = cossin[i][0]
y = cossin[i][1]
for j in range(vps):
p = Vector((pos[j][0], pos[j][1] * x, pos[j][1] * y))
p = mat * p
verts[i * vps + j] = p + v1
if i:
for j in range(fps):
f = (i - 1) * fps + j
faces[f] = [base + j, base + vps + j,
base + vps + (j + 1) % vps, base + (j + 1) % vps]
base = len(verts) - vps
i = n
for j in range(fps):
f = (i - 1) * fps + j
faces[f] = [base + j, j, (j + 1) % vps, base + (j + 1) % vps]
#print(verts,faces)
return verts, faces
示例5: getWorld
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
def getWorld(self):
t = Vector(self.translation).to_4d()
mr = Matrix()
for row in range(3):
mr[row][0:3] = self.rotation[row]
mr.transpose() # = Inverse rotation
p = -(mr * t) # Camera position in world coordinates
p[3] = 1.0
m = mr.copy()
m.col[3] = p # Set translation to camera position
return m
示例6: getTranslationOrientation
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
def getTranslationOrientation(ob, file):
if isinstance(ob, bpy.types.Bone):
ob_matrix_local = ob.matrix_local.copy()
ob_matrix_local.transpose()
t = ob_matrix_local
ob_matrix_local = Matrix([[-t[2][0], -t[2][1], -t[2][2], -t[2][3]],
[t[1][0], t[1][1], t[1][2], t[1][3]],
[t[0][0], t[0][1], t[0][2], t[0][3]],
[t[3][0], t[3][1], t[3][2], t[3][3]]])
rotMatrix_z90_4x4 = Matrix.Rotation(math.radians(90.0), 4, 'Z')
rotMatrix_z90_4x4.transpose()
file.write('Name:%s\n' % ob.name)
t = rotMatrix_z90_4x4 * ob_matrix_local
matrix = Matrix([[t[0][0], t[0][1], t[0][2], t[0][3]],
[t[1][0], t[1][1], t[1][2], t[1][3]],
[t[2][0], t[2][1], t[2][2], t[2][3]],
[t[3][0], t[3][1], t[3][2], t[3][3]]])
parent = ob.parent
if parent:
parent_matrix_local = parent.matrix_local.copy()
parent_matrix_local.transpose()
t = parent_matrix_local
parent_matrix_local = Matrix([[-t[2][0], -t[2][1], -t[2][2], -t[2][3]],
[t[1][0], t[1][1], t[1][2], t[1][3]],
[t[0][0], t[0][1], t[0][2], t[0][3]],
[t[3][0], t[3][1], t[3][2], t[3][3]]])
par_matrix = rotMatrix_z90_4x4 * parent_matrix_local
par_matrix_cpy = par_matrix.copy()
par_matrix_cpy.invert()
matrix = matrix * par_matrix_cpy
matrix.transpose()
loc, rot, sca = matrix.decompose()
else:
matrix = ob.matrix_world
if matrix:
loc, rot, sca = matrix.decompose()
else:
raise "error: this should never happen!"
return loc, rot
示例7: execute
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
def execute(self, context):
ob = context.object
transform = Matrix([[ob.affine_tx_00, ob.affine_tx_01, ob.affine_tx_02, ob.affine_tx_03],
[ob.affine_tx_10, ob.affine_tx_11, ob.affine_tx_12, ob.affine_tx_13],
[ob.affine_tx_20, ob.affine_tx_21, ob.affine_tx_22, ob.affine_tx_23],
[ob.affine_tx_30, ob.affine_tx_31, ob.affine_tx_32, ob.affine_tx_33]])
transform.transpose()
print ("Applying post-transform!")
for vert in ob.data.vertices:
txd = vert.co
txd[0] = (txd[0] - ob.affine_after_origin[0])/ob.affine_after_voxel_spacing[0]
txd[1] = (txd[1] - ob.affine_after_origin[1])/ob.affine_after_voxel_spacing[1]
txd[2] = (txd[2] - ob.affine_after_origin[2])/ob.affine_after_voxel_spacing[2]
txd = vert.co*transform
vert.co = txd
return {'FINISHED'}
示例8: matrix_gltf_to_blender
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
def matrix_gltf_to_blender(mat_input):
"""Matrix from glTF format to Blender format."""
mat = Matrix([mat_input[0:4], mat_input[4:8], mat_input[8:12], mat_input[12:16]])
mat.transpose()
return mat
示例9: zip
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
X,Y,Z = np.meshgrid(xs,ys,zs)
X = X.ravel()
Y = Y.ravel()
Z = Z.ravel()
centers = zip(X,Y,Z)
ex = np.array([1,0,0])
ey = np.array([0,1,0])
rr = .75
for cc in centers:
x,y,z = cc
vv = [x,y,z]
ehn = np.array([.5*y,-.5*x,1])
bpy.ops.mesh.primitive_plane_add(location = vv[:])
bb = bpy.context.scene.objects.active
X = np.array([ehn,ex,ey])
X = gs_3D(ehn)
X = Matrix([X[k] for k in [1,2,0]])
X.transpose()
bb.scale = [rr,rr,rr]
bb.rotation_euler = X.to_euler()[:]
示例10: createTubesAndSpheres
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
def createTubesAndSpheres(geometryObject, material):
mesh = geometryObject.data
sphereRadiiWorldCoordinates = material['pointShader.radiiWorldCoordinates']
tubeRadiiWorldCoordinates = material['lineShader.radiiWorldCoordinates']
if material['radiiWorldCoordinates']:
sphereRadiiWorldCoordinates = True
tubeRadiiWorldCoordinates = True
if material['pointShader.spheresDraw'] and material['showPoints'] and type(mesh) == bpy.types.Mesh and mesh.vertices:
# TODO: respect radii world coordinates flag here and for tubes
sphereRadius = material['pointShader.pointRadius']
if sphereRadiiWorldCoordinates:
sphereRadius /= getWorldScale()
spheresObject = bpy.data.objects.new(name='Vertex Spheres', object_data=None)
spheresObject.parent = geometryObject
spheresObject.hide = geometryObject.hide
spheresObject.hide_render = geometryObject.hide_render
bpy.context.scene.objects.link(spheresObject)
sphereGeometry = createNURBSSphereData('NURBS Sphere')
for v in mesh.vertices:
radius = sphereRadius
if 'relativePointRadii' in mesh:
radius *= mesh['relativePointRadii'][v.index][0]
sphereObject = bpy.data.objects.new(name='Sphere', object_data=sphereGeometry)
sphereObject.parent = spheresObject
sphereObject.hide = geometryObject.hide
sphereObject.hide_render = geometryObject.hide_render
sphereObject.location = v.co
sphereObject.scale = [radius, radius, radius]
bpy.context.scene.objects.link(sphereObject)
mat = createSphereMaterial(mesh, v.index, material)
sphereObject.material_slots[0].link = 'OBJECT'
sphereObject.material_slots[0].material = mat
if not material['lineShader.blender.useSkinTubes'] and \
material['lineShader.tubeDraw'] and \
material['showLines'] and \
type(mesh) == bpy.types.Mesh and \
mesh.edges:
tubeRadius = material['lineShader.tubeRadius']
if tubeRadiiWorldCoordinates:
tubeRadius /= getWorldScale()
tubesObject = bpy.data.objects.new(name='Edge Tubes', object_data=None)
tubesObject.parent = geometryObject
tubesObject.hide = geometryObject.hide
tubesObject.hide_render = geometryObject.hide_render
bpy.context.scene.objects.link(tubesObject)
tubeGeometry = createNURBSCylinderData('NURBS Cylinder')
for e in mesh.edges:
radius = tubeRadius
if 'relativeLineRadii' in mesh:
radius *= mesh['relativeLineRadii'][e.index][0]
v0 = mesh.vertices[e.vertices[0]].co
v1 = mesh.vertices[e.vertices[1]].co
mid = (v0 + v1) / 2
length = (v0 - v1).length
targetZ = (v0 - v1).normalized()
seed = Vector([[1, 0, 0],[0, 1, 0]][targetZ[0] != 0])
targetX = targetZ.cross(seed).normalized()
targetY = targetX.cross(targetZ)
T = Matrix([targetX, targetY, targetZ])
T.transpose()
T.resize_4x4()
T[0][3] = mid[0]
T[1][3] = mid[1]
T[2][3] = mid[2]
tubeObject = bpy.data.objects.new(name='Tube', object_data=tubeGeometry)
tubeObject.parent = tubesObject
tubeObject.hide = geometryObject.hide
tubeObject.hide_render = geometryObject.hide_render
tubeObject.matrix_local = T
tubeObject.scale = [radius, radius, length/2]
bpy.context.scene.objects.link(tubeObject)
mat = createTubeMaterial(mesh, e.index, material)
tubeObject.material_slots[0].link = 'OBJECT'
tubeObject.material_slots[0].material = mat
示例11: _matrix
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
def _matrix(matrix):
m = Matrix(matrix)
if bpy.app.version < (2, 62):
m.transpose()
return m
示例12: CreateBlenderMesh
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
#.........这里部分代码省略.........
struct.unpack('<3f', honchunk.read(12)) + (0.0,),
struct.unpack('<3f', honchunk.read(12)) + (1.0,)))
matrix = Matrix((struct.unpack('<3f', honchunk.read(12)) + (0.0,),
struct.unpack('<3f', honchunk.read(12)) + (0.0,),
struct.unpack('<3f', honchunk.read(12)) + (0.0,),
struct.unpack('<3f', honchunk.read(12)) + (1.0,)))
name_length = struct.unpack("B" , honchunk.read(1))[0]
name = honchunk.read(name_length)
honchunk.read(1) #zero
elif version == 1:
name = ''
pos = honchunk.tell() - 4
b = honchunk.read(1)
while b != '\0':
name += b
b = honchunk.read(1)
honchunk.seek(pos + 0x24)
inv_matrix = Matrix((struct.unpack('<4f', honchunk.read(16)),
struct.unpack('<4f', honchunk.read(16)),
struct.unpack('<4f', honchunk.read(16)),
struct.unpack('<4f', honchunk.read(16))))
matrix = Matrix((struct.unpack('<4f', honchunk.read(16)),
struct.unpack('<4f', honchunk.read(16)),
struct.unpack('<4f', honchunk.read(16)),
struct.unpack('<4f', honchunk.read(16))))
name = name.decode()
log("bone name: %s,parent %d" % (name,parent_bone_index))
bone_names.append(name)
matrix.transpose()
matrix = roundMatrix(matrix,4)
pos = matrix.translation
axis, roll = mat3_to_vec_roll(matrix.to_3x3())
bone = armature_data.edit_bones.new(name)
bone.head = pos
bone.tail = pos + axis
bone.roll = roll
parents.append(parent_bone_index)
bones.append(bone)
for i in range(num_bones):
if parents[i] != -1:
bones[i].parent = bones[parents[i]]
honchunk.skip()
bpy.ops.object.mode_set(mode='OBJECT')
rig.show_x_ray = True
rig.update_tag()
scn.update()
try:
honchunk = chunk.Chunk(file,bigendian=0,align=0)
except EOFError:
log('error reading mesh chunk')
return
while honchunk and honchunk.getname() in [b'mesh', b'surf']:
verts = []
faces = []
signs = []
nrml = []
texc = []
colors = []
示例13: ReadMesh
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transpose [as 别名]
def ReadMesh(self, mesh):
print("Name: {}".format(mesh["name"]))
print("Num Verts: {}".format(len(mesh["vertices"])))
print("Num Indices: {}".format(len(mesh["indices"][0])))
scn = bpy.context.scene
for o in scn.objects:
o.select = False
blenmesh = bpy.data.meshes.new(mesh["name"])
blenmesh.vertices.add(len(mesh["vertices"]))
blenmesh.vertices.foreach_set("co", unpack_list(mesh["vertices"]))
blenmesh.tessfaces.add(len(mesh["indices"][0]))
# Add faces
blenmesh.tessfaces.foreach_set("vertices_raw", unpack_face_list(mesh["indices"][0]))
uvlay = blenmesh.tessface_uv_textures.new()
for i, f in enumerate(uvlay.data):
index = mesh["indices"][0][i]
for j, uv in enumerate(f.uv):
uv[0] = mesh["uvs"][index[j]][0]
uv[1] = mesh["uvs"][index[j]][1]
#add object to scene
blenmesh.update()
blenmesh.validate()
nobj = bpy.data.objects.new(mesh["name"], blenmesh)
scn.objects.link(nobj)
#print("Skel: {}".format(mesh["skeleton"]))
# Create Armature and Object
bpy.ops.object.add(type='ARMATURE', enter_editmode=True)
object = bpy.context.object
object.name = 'armguy'
armature = object.data
armature.name = 'armguy'
#create bones
for the_bone in mesh["skeleton"]:
nobj.vertex_groups.new(name=the_bone["name"])
bone = armature.edit_bones.new(the_bone["name"])
bone.tail = Vector([0,0,0.1]) # if you won't do it, the bone will have zero lenghtand will be removed immediately by Blender
#map parents
for the_bone in mesh["skeleton"]:
if 'parent' in the_bone:
armature.edit_bones[the_bone['name']].parent = armature.edit_bones[the_bone['parent']]
parent = self.FindBoneByName(mesh["skeleton"], the_bone['parent'])
for the_bone in mesh["skeleton"]:
matrix = Matrix(the_bone["matrix"])
matrix.transpose()
matrix = matrix.inverted()
armature.edit_bones[the_bone['name']].transform(matrix)
for vidx in range(0, len(mesh["vertices"])):
bones = mesh["bone_indices"][0][vidx]
weights = mesh["weights"][0][vidx]
print("Vertex: {}".format(vidx))
print("Data: {} {}".format(bones, weights))
for widx in range(0, len(weights)):
bone_idx = bones[widx]
if bone_idx == 0:
break
weight = weights[widx]
nobj.vertex_groups[bone_idx].add([vidx], weight, 'ADD')
# for vwidx, wval in enumerate(mesh["weights"][0]):
# bones = mesh["bone_indices"][0][vwidx]
# print("Vertex: {}".format(vwidx))
# print("Data: {} {}".format(bones, wval))
# for vwsidx, vwsval in enumerate(wval):
# bone_idx = bones[vwsidx]
# the_bone = mesh["skeleton"][bone_idx]
# print("Bone: {} ({}): {}".format(bone_idx, the_bone["name"], vwsval))
# nobj.vertex_groups[bone_idx].add([vwidx], vwsval, 'ADD')
return nobj