本文整理汇总了Python中mathutils.Matrix.determinant方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.determinant方法的具体用法?Python Matrix.determinant怎么用?Python Matrix.determinant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Matrix
的用法示例。
在下文中一共展示了Matrix.determinant方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unit_normal
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import determinant [as 别名]
def unit_normal(a, b, c):
mat_x = Matrix(((1, a[1], a[2]), (1, b[1], b[2]), (1, c[1], c[2])))
mat_y = Matrix(((a[0], 1, a[2]), (b[0], 1, b[2]), (c[0], 1, c[2])))
mat_z = Matrix(((a[0], a[1], 1), (b[0], b[1], 1), (c[0], c[1], 1)))
x = Matrix.determinant(mat_x)
y = Matrix.determinant(mat_y)
z = Matrix.determinant(mat_z)
magnitude = (x**2 + y**2 + z**2)**.5
return (x/magnitude, y/magnitude, z/magnitude)
示例2: pointInTri2D
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import determinant [as 别名]
def pointInTri2D(v, v1, v2, v3):
global dict_matrix
key = v1.x, v1.y, v2.x, v2.y, v3.x, v3.y
# Commented because its slower to do teh bounds check, we should realy cache the bounds info for each face.
'''
# BOUNDS CHECK
xmin= 1000000
ymin= 1000000
xmax= -1000000
ymax= -1000000
for i in (0,2,4):
x= key[i]
y= key[i+1]
if xmax<x: xmax= x
if ymax<y: ymax= y
if xmin>x: xmin= x
if ymin>y: ymin= y
x= v.x
y= v.y
if x<xmin or x>xmax or y < ymin or y > ymax:
return False
# Done with bounds check
'''
try:
mtx = dict_matrix[key]
if not mtx:
return False
except:
side1 = v2 - v1
side2 = v3 - v1
nor = side1.cross(side2)
mtx = Matrix((side1, side2, nor))
# Zero area 2d tri, even tho we throw away zerop area faces
# the projection UV can result in a zero area UV.
if not mtx.determinant():
dict_matrix[key] = None
return False
mtx.invert()
dict_matrix[key] = mtx
uvw = (v - v1) * mtx
return 0 <= uvw[0] and 0 <= uvw[1] and uvw[0] + uvw[1] <= 1
示例3: physics_mass_center
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import determinant [as 别名]
def physics_mass_center(mesh):
'''Calculate (final triangulated) mesh's mass and center of mass based on volume'''
volume = 0.
mass = 0.
com = Vector()
# Based on Stan Melax's volint
for face in mesh.polygons:
a = Matrix((mesh.vertices[face.vertices[0]].co, mesh.vertices[face.vertices[1]].co, mesh.vertices[face.vertices[2]].co))
vol = a.determinant()
volume += vol
com += vol * (a[0] + a[1] + a[2])
if volume > 0:
com /= volume * 4.
mass = volume / 6.
return mass, com
else:
return mass, Vector()
示例4: loadStatueMinusPose
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import determinant [as 别名]
def loadStatueMinusPose(context):
ob,statue,scn = getMeshes(context)
ob,rig,posed = applyArmature(context)
posed.name = "Temporary"
nVerts = len(ob.data.vertices)
relMats = {}
for vg in ob.vertex_groups:
try:
pb = rig.pose.bones[vg.name]
except KeyError:
pb = None
if pb:
relMats[vg.index] = pb.matrix * pb.bone.matrix_local.inverted()
else:
print("Skipping vertexgroup %s" % vg.name)
relMats[vg.index] = Matrix().identity()
svs = statue.data.vertices
pvs = posed.data.vertices
ovs = ob.data.vertices
skey = createNewMeshShape(ob, statue.name, scn)
relmat = Matrix()
y = Vector((0,0,0,1))
for v in ob.data.vertices:
vn = v.index
diff = svs[vn].co - pvs[vn].co
if diff.length > 1e-4:
relmat.zero()
wsum = 0.0
for g in v.groups:
w = g.weight
relmat += w * relMats[g.group]
wsum += w
factor = 1.0/wsum
relmat *= factor
y[:3] = svs[vn].co
x = relmat.inverted() * y
skey.data[vn].co = Vector(x[:3])
z = relmat * x
xdiff = skey.data[vn].co - ovs[vn].co
if False and vn in [8059]:
print("\nVert", vn, diff.length, xdiff.length)
print("det", relmat.determinant())
print("d (%.4f %.4f %.4f)" % tuple(diff))
print("xd (%.4f %.4f %.4f)" % tuple(xdiff))
checkRotationMatrix(relmat)
print("Rel", relmat)
print("Inv", relmat.inverted())
s = pvs[vn].co
print("s ( %.4f %.4f %.4f)" % (s[0],s[1],s[2]))
print("x ( %.4f %.4f %.4f)" % (x[0],x[1],x[2]))
print("y ( %.4f %.4f %.4f)" % (y[0],y[1],y[2]))
print("z ( %.4f %.4f %.4f)" % (z[0],z[1],z[2]))
o = ovs[vn].co
print("o (%.4f %.4f %.4f)" % (o[0],o[1],o[2]))
print("r (%.4f %.4f %.4f)" % tuple(skey.data[vn].co))
for g in v.groups:
print("\nGrp %d %f %f" % (g.group, g.weight, relMats[g.group].determinant()))
print("Rel", relMats[g.group])
#halt
#scn.objects.unlink(statue)
scn.objects.unlink(posed)
示例5: RipConversion
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import determinant [as 别名]
#.........这里部分代码省略.........
return {}
all_indices = concat_attrs(list(map(lambda attr: attr.data, indices)))
all_weights = concat_attrs(list(map(lambda attr: attr.as_floats(), weights)))
count = min(len(all_indices[0]), len(all_weights[0]))
groups = {}
for i in range(rip.num_verts):
for j in range(count):
idx = all_indices[i][j]
weight = all_weights[i][j]
if weight != 0:
if idx not in groups:
groups[idx] = {}
groups[idx][i] = weight
return groups
def apply_matrix(self, vec):
return self.matrix * Vector(vec).to_3d()
def apply_matrix_list(self, lst):
return list(map(self.apply_matrix, lst))
def convert_mesh(self, rip):
pos_attrs = self.find_attrs(rip, 'POSITION')
if len(pos_attrs) == 0:
pos_attrs = rip.attributes[0:1]
vert_pos = self.apply_matrix_list(pos_attrs[0].as_floats(3))
# Rewind triangles when necessary
faces = rip.faces
if (self.matrix.determinant() < 0) != self.flip_winding:
faces = list(map(lambda f: (f[1],f[0],f[2]), faces))
# Create mesh
mesh = bpy.data.meshes.new(rip.basename)
mesh.from_pydata(vert_pos, [], faces)
# Assign normals
mesh.polygons.foreach_set("use_smooth", [True] * len(faces))
if self.use_normals:
normals = self.get_normals(rip)
if normals is not None:
mesh.use_auto_smooth = True
mesh.show_normal_vertex = True
mesh.show_normal_loop = True
mesh.normals_split_custom_set_from_vertices(self.apply_matrix_list(normals))
mesh.update()
# Switch to bmesh
bm = bmesh.new()
vgroup_names = []
try:
bm.from_mesh(mesh)
bm.verts.ensure_lookup_table()
# Create UV maps
uv_maps = self.get_uv_maps(rip)
for idx,uvdata in enumerate(uv_maps):
layer = bm.loops.layers.uv.new('uv'+str(idx))