本文整理汇总了Python中mathutils.Matrix.transposed方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.transposed方法的具体用法?Python Matrix.transposed怎么用?Python Matrix.transposed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Matrix
的用法示例。
在下文中一共展示了Matrix.transposed方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_mat
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transposed [as 别名]
def print_mat(label, matrix, column=4):
if isinstance(matrix[0], (float, int)):
# buffer用
if len(matrix) == 16:
mat = [matrix[:4], matrix[4:8], matrix[8:12], matrix[12:16]]
matrix = Matrix(mat)
elif len(matrix) == 9:
matrix = Matrix([matrix[:3], matrix[3:6], matrix[6:9]])
elif len(matrix) == 4:
matrix = Matrix([matrix[:2], matrix[2:4]])
print(label)
t2 = 'row{0} [{1:>{5}.{6}f}, {2:>{5}.{6}f}]'
t3 = 'row{0} [{1:>{5}.{6}f}, {2:>{5}.{6}f}, {3:>{5}.{6}f}]'
t4 = 'row{0} [{1:>{5}.{6}f}, {2:>{5}.{6}f}, {3:>{5}.{6}f}, {4:>{5}.{6}f}]'
m = matrix.transposed()
for cnt, row in enumerate(m):
if len(row) == 2:
print(t2.format(cnt, row[0], row[1], 0, 0, column + 3, column))
elif len(row) == 3:
print(t3.format(cnt, row[0], row[1], row[2], 0,
column + 3, column))
else:
print(t4.format(cnt, row[0], row[1], row[2], row[3],
column + 3, column))
示例2: _convertMatrixTo4x4
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transposed [as 别名]
def _convertMatrixTo4x4(self, value):
matrix = Matrix()
matrix[0] = value[0:4]
matrix[1] = value[4:8]
matrix[2] = value[8:12]
matrix[3] = value[12:16]
return matrix.transposed()
示例3: update
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transposed [as 别名]
def update(self):
if 'vertices' in self.inputs and self.inputs['vertices'].links \
and self.inputs['edg_pol'].links \
and self.inputs['cut_matrix'].links:
verts_ob = Vector_generate(SvGetSocketAnyType(self,self.inputs['vertices']))
edg_pols_ob = SvGetSocketAnyType(self,self.inputs['edg_pol'])
if self.inputs['matrix'].links:
matrixs = SvGetSocketAnyType(self,self.inputs['matrix'])
else:
matrixs = []
for le in verts_ob:
matrixs.append(Matrix())
cut_mats = SvGetSocketAnyType(self,self.inputs['cut_matrix'])
verts_out = []
edges_out = []
for cut_mat in cut_mats:
cut_mat = Matrix(cut_mat)
pp = Vector((0.0, 0.0, 0.0)) * cut_mat.transposed()
pno = Vector((0.0, 0.0, 1.0)) * cut_mat.to_3x3().transposed()
verts_pre_out = []
edges_pre_out = []
for idx_mob, matrix in enumerate(matrixs):
idx_vob = min(idx_mob, len(verts_ob)-1)
idx_epob = min(idx_mob, len(edg_pols_ob)-1)
matrix = Matrix(matrix)
x_me = section(verts_ob[idx_vob], edg_pols_ob[idx_epob], matrix, pp, pno, self.fill_check, self.tri)
if x_me:
verts_pre_out.append(x_me['Verts'])
edges_pre_out.append(x_me['Edges'])
if verts_pre_out:
verts_out.extend(verts_pre_out)
edges_out.extend(edges_pre_out)
if 'vertices' in self.outputs and self.outputs['vertices'].links:
output = Vector_degenerate(verts_out)
SvSetSocketAnyType(self,'vertices',output)
if 'edges' in self.outputs and self.outputs['edges'].links:
SvSetSocketAnyType(self,'edges',edges_out)
else:
pass
示例4: get_mats
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transposed [as 别名]
def get_mats(mx: Matrix):
smat, d = str(mx), XForm.get_mats.__dict__
if smat not in d:
m = {
'mx_p': None, 'imx_p': None,
'mx_d': None, 'imx_d': None,
'mx_n': None, 'imx_n': None
}
m['mx_p'] = Matrix(mx)
m['mx_t'] = mx.transposed()
m['imx_p'] = mx.inverted()
m['mx_d'] = mx.to_3x3()
m['imx_d'] = m['mx_d'].inverted()
m['mx_n'] = m['imx_d'].transposed()
m['imx_n'] = m['mx_d'].transposed()
d[smat] = m
return d[smat]
示例5: process
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transposed [as 别名]
def process(self):
mandatory_sockets = [self.inputs['vertices'], self.inputs['edg_pol'], self.inputs['cut_matrix']]
if not all([s.is_linked for s in mandatory_sockets]):
return
verts_ob = Vector_generate(self.inputs['vertices'].sv_get())
edg_pols_ob = self.inputs['edg_pol'].sv_get()
if self.inputs['matrix'].is_linked:
matrixs = self.inputs['matrix'].sv_get()
else:
matrixs = []
for le in verts_ob:
matrixs.append(Matrix())
cut_mats = self.inputs['cut_matrix'].sv_get()
verts_out = []
edges_out = []
for cut_mat in cut_mats:
cut_mat = Matrix(cut_mat)
pp = Vector((0.0, 0.0, 0.0)) * cut_mat.transposed()
pno = Vector((0.0, 0.0, 1.0)) * cut_mat.to_3x3().transposed()
verts_pre_out = []
edges_pre_out = []
for idx_mob, matrix in enumerate(matrixs):
idx_vob = min(idx_mob, len(verts_ob)-1)
idx_epob = min(idx_mob, len(edg_pols_ob)-1)
matrix = Matrix(matrix)
x_me = section(verts_ob[idx_vob], edg_pols_ob[idx_epob], matrix, pp, pno, self.fill_check, self.tri)
if x_me:
verts_pre_out.append(x_me['Verts'])
edges_pre_out.append(x_me['Edges'])
if verts_pre_out:
verts_out.extend(verts_pre_out)
edges_out.extend(edges_pre_out)
self.outputs['vertices'].sv_set(Vector_degenerate(verts_out))
self.outputs['edges'].sv_set(edges_out)
示例6: CNT
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transposed [as 别名]
def CNT(type = 1,res = 1, m=10,n=5,bL=1.56,bR=.1,aR=.2):
import bpy
from fractions import gcd
from math import cos, sin, acos,sqrt,copysign,ceil,floor,pi
from mathutils import Vector, Matrix,Quaternion
print("Tube: (",m,",",n,"); Radius: ",bL*sqrt(m*m+n*n+m*n)/(2*pi))
cntR = bL*sqrt(m*m+n*n+m*n)/(2*pi)
a1=Vector((bL*sqrt(3)/2,bL/2))
a2=Vector((bL*sqrt(3)/2,-bL/2))
x=Vector((bL/sqrt(3),0))
def Lattice2D(i,j,k):
return i*a1+j*a2+k*x
o = Lattice2D(0,0,0)
c = Lattice2D(m,n,0)
d = gcd(2*n+m,2*m+n)
t = Lattice2D((2*n+m)/d,-(2*m+n)/d,0);print("Unit Length: ",t.magnitude)
theta = acos(c.normalized()[0]*copysign(1,c[1]))
u = Matrix(((cos(theta),sin(theta)),(-sin(theta),cos(theta))))
def Lattice3D(i,j,k):
r = c.magnitude/(2*pi)
p = Lattice2D(i,j,k)*u.transposed()
return Vector([r*cos(p[0]/r),r*sin(p[0]/r),p[1]])
imax = 2*(n+m); imin = 0
jmax = n; jmin = -(2*m+n)
indices = []
for i in range(imin,imax+1):
for j in range(jmin,jmax+1):
for k in range(2):
p = Lattice2D(i,j,k)*u.transposed()
if p[0]>=0-bL/5 and p[0]<=c.magnitude-bL/5 and p[1]>=0+bL/10 and p[1]<=t.magnitude+bL/10:
indices.append([i,j,k])
print("indices: ",len(indices))
points2D = list(map(lambda x:Lattice2D(x[0],x[1],x[2])*u.transposed(),indices))
print("points2D: ",len(points2D))
bonds2D = []
for i in range(len(indices)):
if indices[i][2] == 0:
p1=Lattice2D(indices[i][0],indices[i][1],0)*u.transposed()
p2=Lattice2D(indices[i][0],indices[i][1],1)*u.transposed()
if p2[0]>=0-bL/5 and p2[0]<=c.magnitude+bL/5 and p2[1]>=0-bL/10 and p2[1]<=t.magnitude+bL:
bonds2D.append([p1,p2])
p2=Lattice2D(indices[i][0]-1,indices[i][1],1)*u.transposed()
if p2[0]>=0-bL/5 and p2[0]<=c.magnitude+bL/5 and p2[1]>=0-bL/10 and p2[1]<=t.magnitude+bL:
bonds2D.append([p1,p2])
p2=Lattice2D(indices[i][0],indices[i][1]-1,1)*u.transposed()
if p2[0]>=0-bL/5 and p2[0]<=c.magnitude+bL/5 and p2[1]>=0-bL/10 and p2[1]<=t.magnitude+bL:
bonds2D.append([p1,p2])
print("bonds2D: ",len(bonds2D))
if type == 0:
lyrs = [False]*20; lyrs[3] = True
if bpy.data.scenes[0].layers[3] == False:
bpy.data.scenes[0].layers[3] = True
bpy.ops.object.select_by_layer(extend=False, layers=4)
bpy.ops.object.delete()
if res < 0:
res = 1
if bR > 0:
for i in range(len(bonds2D)):
temp3D1 = Vector([bonds2D[i][0][0],bonds2D[i][0][1],0])
temp3D2 = Vector([bonds2D[i][1][0],bonds2D[i][1][1],0])
p = (temp3D1+temp3D2)*.5
v = ((temp3D2-temp3D1).normalized()+Vector((0,0,1)))/2
qu = Quaternion((v[0],v[1],v[2]),pi)
eu = qu.to_euler()
bpy.ops.mesh.primitive_cylinder_add(vertices=res*4,depth=(temp3D2-temp3D1).magnitude*1.05,radius=bR, end_fill_type='NOTHING', location=(p[0], p[1], p[2]), rotation=eu,layers=lyrs)
if res > 1:
bpy.ops.object.shade_smooth()
print("C bonds rendered")
if aR > 0:
for i in range(len(points2D)):
bpy.ops.mesh.primitive_uv_sphere_add(segments=res*4,ring_count=res*2,size=aR,location=(points2D[i][0],points2D[i][1],0),layers=lyrs)
if res > 1:
bpy.ops.object.shade_smooth()
print("C atoms rendered")
bpy.ops.mesh.primitive_uv_sphere_add(size=0,layers=lyrs)
bpy.ops.object.select_by_layer(extend=False, layers=4)
bpy.ops.object.join()
bpy.ops.object.modifier_add(type='ARRAY')
bpy.context.active_object.modifiers['Array'].count=1
bpy.context.active_object.modifiers['Array'].use_relative_offset=False
bpy.context.active_object.modifiers['Array'].use_constant_offset=True
bpy.context.active_object.modifiers['Array'].constant_offset_displace.y=t.magnitude
#bpy.ops.curve.primitive_bezier_circle_add(rotation=(0, pi/2, 0), layers=lyrs)
#need to select cnt now.
#bpy.ops.object.modifier_add(type='CURVE')
#.........这里部分代码省略.........
示例7: execute
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transposed [as 别名]
def execute(self, context):
cml = context.user_preferences.addons['cmu_mocap_browser'].preferences
self.src, self.dst = scan_armatures(context)
context.scene.frame_set(0)
SMW = self.src.matrix_world
DMW = self.dst.matrix_world
SPB = self.src.pose.bones
DPB = self.dst.pose.bones
# clear frame poses, leave source selected
for o in self.dst, self.src:
context.scene.objects.active = o
bpy.ops.object.mode_set(mode='POSE')
bpy.ops.pose.select_all(action='SELECT')
bpy.ops.pose.rot_clear()
bpy.ops.pose.loc_clear()
bpy.ops.pose.scale_clear()
# create the head IK target if it doesn't exist
if 'head_ik' not in SPB:
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.armature.select_all(action='DESELECT')
self.src.data.edit_bones['upperneck'].select_tail = True
bpy.ops.armature.extrude()
self.src.data.edit_bones[-1].name = 'head_ik'
self.src.data.edit_bones[-1].use_connect = False
bpy.ops.transform.translate(value=(.1, 0, 0))
bpy.ops.armature.extrude()
self.src.data.edit_bones[-1].name = 'head_pole'
bpy.ops.transform.translate(value=(.1, 0, 0))
bpy.ops.object.mode_set(mode='POSE')
bpy.ops.pose.select_all(action='SELECT')
# get reference points
a_s = SPB['upperneck'].matrix.translation
c_s = SPB['lfemur'].matrix.translation
b_s = .5 * (c_s + SPB['rfemur'].matrix.translation)
a_d = DPB['Shoulders'].matrix.translation
c_d = DPB['Hip_L'].matrix.translation
b_d = .5 * (c_d + DPB['Hip_R'].matrix.translation)
# get alignment matrix
S = Matrix().to_3x3()
S[0] = (c_s - b_s).normalized()
S[1] = (a_s - b_s).normalized()
S[2] = -S[0].cross(S[1])
S = SMW.to_3x3() * S
D = Matrix().to_3x3()
D[0] = (c_d - b_d).normalized()
D[1] = (a_d - b_d).normalized()
D[2] = -D[0].cross(D[1])
D = DMW.to_3x3() * D
T = D * S.transposed()
# scale source to match destination
s = (a_d - b_d).length / (a_s - b_s).length
bpy.ops.transform.resize(value=(s, s, s))
# align armatures
rot = T.to_quaternion()
bpy.ops.transform.rotate(value=rot.angle, axis=rot.axis)
a_s = SPB['upperneck'].matrix.translation
a_s = SMW * a_s
bpy.ops.transform.translate(value=a_d - a_s)
bpy.ops.pose.select_all(action='DESELECT')
for bdef in T_pose_align:
for side in "lr":
sb = side + bdef[0]
db = bdef[1] + "_" + side.upper()
scale = 1. if len(bdef) == 2 else float(bdef[2])
SPB[sb].bone.select = True
a = SMW * SPB[sb].tail
b = SMW * SPB[sb].head
c = DMW * DPB[db].head
rot = (a - b).rotation_difference(c - b)
bpy.ops.transform.rotate(value=rot.angle, axis=rot.axis)
s = (c - b).length / (a - b).length * scale
bpy.ops.transform.resize(value=(s, s, s))
if cml.feet_angle:
if bdef[0] == 'foot':
bpy.ops.transform.rotate(
value=radians(cml.feet_angle),
axis=(1, 0, 0)
)
SPB[sb].bone.select = False
SPB['head_ik'].bone.select = True
b = SMW * SPB['head_ik'].head
c = DMW * DPB['Head'].head
bpy.ops.transform.translate(value=(c-b))
# record pose
bpy.ops.pose.select_all(action='SELECT')
bpy.ops.anim.keyframe_insert_menu(type='LocRotScale')
return {'FINISHED'}
示例8: update
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import transposed [as 别名]
def update(self):
if 'vertices' in self.inputs and self.inputs['vertices'].links \
and self.inputs['edg_pol'].links \
and self.inputs['cut_matrix'].links:
if not self.inputs['vertices'].node.socket_value_update:
self.inputs['vertices'].node.update()
if not self.inputs['edg_pol'].node.socket_value_update:
self.inputs['edg_pol'].node.update()
if not self.inputs['cut_matrix'].node.socket_value_update:
self.inputs['cut_matrix'].node.update()
verts_ob = Vector_generate(eval(self.inputs['vertices'].links[0].from_socket.VerticesProperty))
edg_pols_ob = eval(self.inputs['edg_pol'].links[0].from_socket.StringsProperty)
if self.inputs['matrix'].links:
if not self.inputs['matrix'].node.socket_value_update:
self.inputs['matrix'].node.update()
matrixs = eval(self.inputs['matrix'].links[0].from_socket.MatrixProperty)
else:
matrixs = []
for le in verts_ob:
matrixs.append(Matrix())
cut_mats = eval(self.inputs['cut_matrix'].links[0].from_socket.MatrixProperty)
verts_out = []
edges_out = []
for cut_mat in cut_mats:
cut_mat = Matrix(cut_mat)
pp = Vector((0.0, 0.0, 0.0)) * cut_mat.transposed()
pno = Vector((0.0, 0.0, 1.0)) * cut_mat.to_3x3().transposed()
verts_pre_out = []
edges_pre_out = []
for idx_mob, matrix in enumerate(matrixs):
idx_vob = min(idx_mob, len(verts_ob)-1)
idx_epob = min(idx_mob, len(edg_pols_ob)-1)
matrix = Matrix(matrix)
x_me = section(verts_ob[idx_vob], edg_pols_ob[idx_epob], matrix, pp, pno, self.fill_check, self.tri)
if x_me:
verts_pre_out.append(x_me['Verts'])
edges_pre_out.append(x_me['Edges'])
if verts_pre_out:
verts_out.extend(verts_pre_out)
edges_out.extend(edges_pre_out)
if 'vertices' in self.outputs and len(self.outputs['vertices'].links)>0:
if not self.outputs['vertices'].node.socket_value_update:
self.outputs['vertices'].node.update()
output = Vector_degenerate(verts_out)
self.outputs['vertices'].VerticesProperty = str(output)
if 'edges' in self.outputs and len(self.outputs['edges'].links)>0:
if not self.outputs['edges'].node.socket_value_update:
self.outputs['edges'].node.update()
self.outputs['edges'].StringsProperty = str(edges_out)
else:
self.outputs['vertices'].VerticesProperty = str([])
self.outputs['edges'].StringsProperty = str([])