本文整理汇总了Python中mathutils.Quaternion.normalize方法的典型用法代码示例。如果您正苦于以下问题:Python Quaternion.normalize方法的具体用法?Python Quaternion.normalize怎么用?Python Quaternion.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Quaternion
的用法示例。
在下文中一共展示了Quaternion.normalize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import normalize [as 别名]
def process(self):
if not self.outputs['Quaternions'].is_linked:
return
inputs = self.inputs
quaternionList = []
if self.mode == "WXYZ":
I = [inputs[n].sv_get()[0] for n in "WXYZ"]
params = match_long_repeat(I)
for wxyz in zip(*params):
q = Quaternion(wxyz)
if self.normalize:
q.normalize()
quaternionList.append(q)
elif self.mode == "SCALARVECTOR":
I = [inputs[n].sv_get()[0] for n in ["Scalar", "Vector"]]
params = match_long_repeat(I)
for scalar, vector in zip(*params):
q = Quaternion([scalar, *vector])
if self.normalize:
q.normalize()
quaternionList.append(q)
elif self.mode == "EULER":
I = [inputs["Angle " + n].sv_get()[0] for n in "XYZ"]
params = match_long_repeat(I)
au = angleConversion[self.angleUnits]
for angleX, angleY, angleZ in zip(*params):
euler = Euler((angleX * au, angleY * au, angleZ * au), self.eulerOrder)
q = euler.to_quaternion()
if self.normalize:
q.normalize()
quaternionList.append(q)
elif self.mode == "AXISANGLE":
I = [inputs[n].sv_get()[0] for n in ["Axis", "Angle"]]
params = match_long_repeat(I)
au = angleConversion[self.angleUnits]
for axis, angle in zip(*params):
q = Quaternion(axis, angle * au)
if self.normalize:
q.normalize()
quaternionList.append(q)
elif self.mode == "MATRIX":
input_M = inputs["Matrix"].sv_get(default=idMat)
for m in input_M:
q = Matrix(m).to_quaternion()
if self.normalize:
q.normalize()
quaternionList.append(q)
self.outputs['Quaternions'].sv_set([quaternionList])
示例2: _arc_segment
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import normalize [as 别名]
def _arc_segment(v_1, v_2):
ELorigin = bpy.context.scene.objects['ELorigin']
ELground = bpy.context.scene.objects['ELground']
v = v_2 - v_1
d = v.length
ELorigin.location = Vector((0, 0, 0))
ELground.location = Vector((0, 0, -d))
v_L = ELground.location - ELorigin.location
q = Quaternion()
c = Vector.cross(v_L, v)
q.x = c.x
q.y = c.y
q.z = c.z
q.w = sqrt((v_L.length ** 2) * (v.length ** 2)) + \
Vector.dot(v_L, v)
q.normalize()
euler = q.to_euler()
bpy.ops.object.runfslg_operator()
laALL = bpy.context.scene.objects['laALL']
laALL.name = 'lARC'
laALL.rotation_euler = euler
laALL.location = v_1
bpy.context.active_object.select = False
laALL.select = True
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
laALL.select = False
bpy.context.active_object.select = True
return laALL
示例3: drawBone2
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import normalize [as 别名]
def drawBone2(p1, p2, radiuses, material):
length = dist(p1,p2)
print('length :',length)
v = Vector(diffv(p1, p2))
up = Vector((0,0,1))
if v!=-up:
rot = up.rotation_difference(v)
else:
rot = Quaternion((1,0,0),math.pi)
s1 = drawEllipsoid((0,0,-0.5*length),radiuses,material)
s2 = drawEllipsoid((0,0,0.5*length),radiuses,material)
c1 = drawCylinder(zero,radiuses,length,materials.blue)
s1.select = True
s2.select = True
c1.select = True
#bpy.ops.transform.translate(value=(0,0,length/2))
#bpy.ops.object.editmode_toggle()
bpy.ops.transform.rotate(value=rot.angle, axis=rot.axis)
#bpy.ops.object.editmode_toggle()
#bpy.ops.transform.translate(value=Vector((0,0,-0.5*length))*rot.to_matrix())
rot.normalize();
bpy.ops.transform.translate(value=Vector((0,0,0.5*length))*rot.to_matrix())
bpy.ops.transform.translate(value=p1)
return (s1,s2,c1)
示例4: transform_rotation
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import normalize [as 别名]
def transform_rotation(rotation: Quaternion, transform: Matrix = Matrix.Identity(4)) -> Quaternion:
"""Transform rotation."""
rotation.normalize()
m = rotation.to_matrix().to_4x4()
m = multiply(transform, m)
return m.to_quaternion()
示例5: save
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import normalize [as 别名]
def save(operator, context, filepath=""):
bpy.ops.object.mode_set(mode='OBJECT')
poseLib = None
armature = None
for object in bpy.data.objects:
if object.type == 'ARMATURE':
poseLib = object.pose_library
armature = object.data
break
if poseLib == None or armature == None:
raise NameError("Cannot export Pose Library %s, there is no armatures" % filepath)
numPoses = len(poseLib.groups[0].channels[4].keyframe_points)
numBones = len(poseLib.groups)
poseArray = []
nameArray = []
print("Exporting")
oglBoneArray = []
oglBoneDirectionArray = []
startNodes = []
for i in range(0, len(armature.bones)):
bone = armature.bones[i]
if bone.parent == None:
dupIndex = -1
for j in range(0, len(startNodes)):
if bone.head[:] == startNodes[j][:]:
dupIndex = j
break
if dupIndex == -1:
baseNode = bone.head_local
startNodes.append((baseNode.x, baseNode.y, baseNode.z))
oglBoneArray.append(-1)
oglBoneArray.append(i)
boneDirection = bone.tail_local - bone.head_local
oglBoneDirectionArray.append(boneDirection)
for i in range(0, numPoses):
nameArray.append(poseLib.pose_markers[i].name)
boneArray = []
for j in range(0, len(oglBoneArray)):
index = oglBoneArray[j]
q = Quaternion()
if index == -1:
q = Quaternion([1, 0, 0, 0])
else:
quat = Quaternion([1, 0, 0, 0])
for k in range(0, 4):
quat[k] = poseLib.groups[index].channels[k + 3].keyframe_points[i].co.y
axisVector = Vector([0, 1, 0])
boneVector = oglBoneDirectionArray[index]
quatBetween = getQuatBetweenVectors(boneVector, axisVector)
q = quatBetween.inverted() * quat * quatBetween
q.normalize()
boneArray.append(tuple([q.w, q.x, q.z, -q.y]))
poseArray.append(boneArray)
print(filepath)
file = open(filepath, 'w')
fw = file.write
fw("poslib\n")
fw("%d %d\n" % (numPoses, len(oglBoneArray)))
for i in range(0, numPoses):
fw("n " + nameArray[i] + '\n')
for j in range(0, len(oglBoneArray)):
q = poseArray[i][j]
fw("q %f %f %f %f\n" % (q[0], q[1], q[2], q[3]))
fw('f\n')
file.close()
print("Finished Exporting")
return {'FINISHED'}