本文整理汇总了Python中mathutils.Matrix.to_3x3方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.to_3x3方法的具体用法?Python Matrix.to_3x3怎么用?Python Matrix.to_3x3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Matrix
的用法示例。
在下文中一共展示了Matrix.to_3x3方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_matrix_to_3x3
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_3x3 [as 别名]
def test_matrix_to_3x3(self):
# mat =
# [ 1 2 3 4 ]
# [ 2 4 6 8 ]
# [ 3 6 9 12 ]
# [ 4 8 12 16 ]
mat = Matrix(tuple((i, 2 * i, 3 * i, 4 * i) for i in range(1, 5)))
mat_correct = Matrix(((1, 2, 3), (2, 4, 6), (3, 6, 9)))
self.assertEqual(mat.to_3x3(), mat_correct)
示例2: update
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_3x3 [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
示例3: get_obb
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_3x3 [as 别名]
def get_obb(vectors):
"""
Return OBB.
vectors: list of Vector(2d or 3d) or
2d array (shape=(-1, 3) or (-1, 2)) (row-major)
return: (rotation and translation matrix, bounding box scale)
X軸,Y軸,Z軸の順に長くなるようにソートしてある。
"""
if len(vectors) == 0:
return None, None
# np.ndarrayに変換して計算
size = 3 if len(vectors[0]) == 3 else 2
is_numpy_array = isinstance(vectors, np.ndarray)
if is_numpy_array:
arr = vectors
else:
arr = np.array(vectors)
w, rotmat = pca(arr, to_rotation=True) # rotmatはObject.matrix_worldと同じように考えればいい
# world座標のarrを、rotmat座標に変換。(world座標->local座標への変換と考えればいい)
# vec * matの順で計算したいならrotmatを転値する必要がある
invmat = np.linalg.inv(rotmat)
arr_in_rotmat_coordinate = np.dot(arr, invmat.transpose())
max_vals = np.max(arr_in_rotmat_coordinate, axis=0)
min_vals = np.min(arr_in_rotmat_coordinate, axis=0)
bb_location = np.dot((max_vals + min_vals) / 2, rotmat.transpose())
bb_scale = max_vals - min_vals
# convert
if is_numpy_array:
obb_matrix = np.identity(size + 1)
obb_matrix[:size, :size] = rotmat[:size, :size]
# %元から間違ってた?obb_matrix[size, :size] = bb_location
obb_matrix[:size, size] = bb_location
else:
if size == 3:
# %obb_matrix = Matrix(rotmat.transpose()).to_4x4()
obb_matrix = Matrix(rotmat).to_4x4()
else:
# %obb_matrix = Matrix(rotmat.transpose())
obb_matrix = Matrix(rotmat)
obb_matrix.resize_4x4()
obb_matrix = obb_matrix.to_3x3() # bug? need ->4->3
# %obb_matrix[size][:size] = bb_location
obb_matrix.col[size][:size] = bb_location
bb_scale = list(bb_scale)
return obb_matrix, bb_scale
示例4: calc_cam_matrix
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_3x3 [as 别名]
def calc_cam_matrix(self, context, cam_name):
scene = context.scene
cam_obj = scene.objects.get(cam_name, scene.camera)
if (not cam_obj) or (not cam_obj.data): return (Matrix(), Vector((1,1,0)))
m = Matrix(cam_obj.matrix_world)
m.col[0] *= (1.0 / m.col[0].magnitude)
m.col[1] *= (1.0 / m.col[1].magnitude)
m.col[2] *= -(1.0 / m.col[2].magnitude)
m3 = m.to_3x3()
s, d = BlUtil.Camera.projection_info(cam_obj.data, context.scene)
p = Vector((2.0/s.x, 2.0/s.y, s.z)).lerp(Vector((2.0*d.z/s.x, 2.0*d.z/s.y, s.z)), s.z)
x = m3 * Vector((1, 0, 0))
y = m3 * Vector((0, 1, 0))
z = m3 * Vector((d.x, d.y, 1.0)).lerp(Vector((d.x/d.z, d.y/d.z, 1.0)), s.z)
t = m.translation
return (matrix_compose(x, y, -z, t), p)
示例5: get_mats
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_3x3 [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]
示例6: get_aabb
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_3x3 [as 别名]
def get_aabb(vecs, matrix=None):
"""
Return AABB.
vecs: 2次元か3次元のVectorのリスト。Vectorの他にnp.dnarray, list, tupleが使える。
matrix: この座標系に回転・拡縮したAABBで計算する。(返り値のbb_matrixはworld座標系のまま)
retrurn: (rotation and translation matrix, bounding box scale)
"""
if len(vecs) == 0:
return None, None
dim = 2 if len(vecs[0]) == 2 else 3
is_numpy_array = True if isinstance(vecs, np.ndarray) else False
arr = np.array(vecs) if not is_numpy_array else vecs
if matrix:
mat = np.array(matrix)[:dim, :dim]
invmat = np.linalg.inv(mat)
arr_bb = np.dot(arr, invmat)
max_vals = np.max(arr_bb, axis=0)
min_vals = np.min(arr_bb, axis=0)
bb_location = np.dot((max_vals + min_vals) / 2, mat)
else:
mat = np.identity(dim)
max_vals = np.max(arr, axis=0)
min_vals = np.min(arr, axis=0)
bb_location = (max_vals + min_vals) / 2
bb_scale = max_vals - min_vals
# arr -> py
if is_numpy_array:
bb_matrix = np.identity(dim + 1)
bb_matrix[:dim, :dim] = mat[:dim, :dim]
# %bb_matrix[dim, :dim] = bb_location
bb_matrix[:dim, dim] = bb_location
else:
if dim == 3:
bb_matrix = Matrix(mat).to_4x4()
else:
bb_matrix = Matrix(mat)
bb_matrix.resize_4x4()
bb_matrix = bb_matrix.to_3x3() # bug? need ->4->3
# %bb_matrix[dim][:dim] = bb_location
bb_matrix.col[dim][:dim] = bb_location
bb_scale = list(bb_scale)
return bb_matrix, bb_scale
示例7: process
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_3x3 [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)
示例8: CreateBlenderMesh
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_3x3 [as 别名]
#.........这里部分代码省略.........
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 = []
surf_planes = []
surf_points = []
surf_edges = []
示例9: update
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import to_3x3 [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([])