本文整理汇总了Python中mathutils.Quaternion.inverted方法的典型用法代码示例。如果您正苦于以下问题:Python Quaternion.inverted方法的具体用法?Python Quaternion.inverted怎么用?Python Quaternion.inverted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Quaternion
的用法示例。
在下文中一共展示了Quaternion.inverted方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import inverted [as 别名]
def execute(self, context):
scn = context.scene
if 'localgrid_menu_items_strings' in scn and \
'localgrid_menu_items_float' in scn:
strings_dict = scn['localgrid_menu_items_strings']
float_dict = scn['localgrid_menu_items_float']
for i in range(len(strings_dict.keys())):
strings = strings_dict[str(i)]
icon, name = strings.split(',', 1)
ls = float_dict[str(i)]
orig = Vector([ls[0], ls[1], ls[2]])
quat = Quaternion([ls[3], ls[4], ls[5], ls[6]])
item = scn.local_grid.items.add()
item.item_name = name
item.icon = icon
item.orig = orig
item.quat = quat.inverted()
if 'localgrid_menu_items_strings' in scn:
del(scn['localgrid_menu_items_strings'])
if 'localgrid_menu_items_float' in scn:
del(scn['localgrid_menu_items_float'])
if hasattr(scn, 'localgrid_menu_items_strings'):
del(scn.localgrid_menu_items_strings)
if hasattr(scn, 'localgrid_menu_items_float'):
del(scn.localgrid_menu_items_float)
return {'FINISHED'}
示例2: compute_pose
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import inverted [as 别名]
def compute_pose(self, world_poses, local_rotations, joint_offsets, index):
"""
Compute a pose for an index. Returns the resulting mat4
"""
parent_quat = Quaternion([1, 0, 0, 0])
parent_pose = Matrix()
if index > 0:
parent_quat = local_rotations[index - 1]
parent_pose = world_poses[index - 1]
local_pose = (parent_quat.inverted() * local_rotations[index]).to_matrix()
local_pose.resize_4x4()
return parent_pose * joint_offsets[index] * local_pose
示例3: createTPose
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import inverted [as 别名]
def createTPose(context):
rig = context.object
scn = context.scene
if rig.McpHasTPose:
setTPose(context)
return
filepath = os.path.join(os.path.dirname(__file__), "t_pose.json")
struct = loadJson(filepath)
for name,value in struct:
pb = rig.pose.bones[name]
quat = Quaternion(value)
pb.matrix_basis = quat.to_matrix().to_4x4()
rest = quat.inverted()
pb["McpRestW"] = rest.w
pb["McpRestX"] = rest.x
pb["McpRestY"] = rest.y
pb["McpRestZ"] = rest.z
children = []
for ob in scn.objects:
if ob.type != 'MESH':
continue
for mod in ob.modifiers:
if (mod.type == 'ARMATURE' and
mod.object == rig):
children.append((ob, mod.name))
scn.objects.active = ob
bpy.ops.object.modifier_apply(apply_as='SHAPE', modifier=mod.name)
ob.data.shape_keys.key_blocks[mod.name].value = 1
scn.objects.active = rig
bpy.ops.pose.armature_apply()
for ob,name in children:
scn.objects.active = ob
mod = ob.modifiers.new(name, 'ARMATURE')
mod.object = rig
mod.use_vertex_groups = True
bpy.ops.object.modifier_move_up(modifier=name)
setShapeKey(ob, name, 1.0)
scn.objects.active = rig
rig.McpHasTPose = True
print("Created T-pose")
示例4: extract_current_pose
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import inverted [as 别名]
def extract_current_pose():
"""
Convert current object's pose to OpenCV's "rvec" and "tvec".
"""
ob = bpy.context.object
if ob.rotation_mode == "QUATERNION":
q = ob.rotation_quaternion
elif ob.rotation_mode == "AXIS_ANGLE":
q = Quaternion(ob.rotation_axis_angle[1:4], ob.rotation_axis_angle[0])
else:
assert ob.rotation_mode in ("XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX")
q = ob.rotation_euler.to_quaternion()
# Rotate 180 deg around local X because a blender camera has Y and Z axes opposite to OpenCV's
q *= Quaternion((1.0, 0.0, 0.0), radians(180.0))
aa = q.to_axis_angle()
rvec = [c * -aa[1] for c in aa[0]]
tvec = list(q.inverted() * (-ob.location))
return rvec, tvec
示例5: invertQuats
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import inverted [as 别名]
def invertQuats(rig):
for pb in rig.pose.bones:
quat = Quaternion((pb.McpQuatW, pb.McpQuatX, pb.McpQuatY, pb.McpQuatZ))
pb.McpQuatW, pb.McpQuatX, pb.McpQuatY, pb.McpQuatZ = quat.inverted()
示例6: get_vector
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import inverted [as 别名]
def get_vector(loop_act, loop_prev, f_normal_act=None, f_normal_prev=None, rotaxis=None, threshold=1.0e-4):
vec_edge_act = loop_act.link_loop_next.vert.co - loop_act.vert.co
vec_edge_act.normalize()
vec_edge_prev = loop_prev.vert.co - loop_prev.link_loop_next.vert.co
vec_edge_prev.normalize()
f_cross = None
rotated = False
if f_normal_act and f_normal_prev:
f_normal_act = f_normal_act.normalized()
f_normal_prev = f_normal_prev.normalized()
f_angle = f_normal_act.angle(f_normal_prev)
if threshold < f_angle < ANGLE_180 - threshold:
vec_normal = f_normal_act + f_normal_prev
vec_normal.normalize()
f_cross = f_normal_act.cross(f_normal_prev)
f_cross.normalize()
elif f_angle > ANGLE_180 - threshold and rotaxis:
# vec_edge and f_normal are slightly rotated
# in order to manage folding faces.
vec_edge_act_orig = vec_edge_act.copy()
vec_edge_prev_orig = vec_edge_prev.copy()
rot_act = Quaternion(rotaxis, 2 * threshold)
rot_prev = rot_act.inverted()
vec_edge_act.rotate(rot_act)
vec_edge_prev.rotate(rot_prev)
f_normal_act.rotate(rot_act)
f_normal_prev.rotate(rot_prev)
vec_normal = f_normal_act + f_normal_prev
vec_normal.normalize()
rotated = True
else:
vec_normal = f_normal_act
elif f_normal_act or f_normal_prev:
vec_normal = (f_normal_act or f_normal_prev).normalized()
else:
vec_normal = loop_act.face.normal.copy()
if vec_normal.length == 0.0:
if threshold < vec_edge_act.angle(Z_UP) < ANGLE_180 - threshold:
vec_normal = Z_UP - Z_UP.project(vec_edge_act)
vec_normal.normalize()
else:
# vec_edge is parallel to Z_UP
vec_normal = Vector((0.0, 1.0, 0.0))
# 2d edge vectors are perpendicular to vec_normal
vec_edge_act2d = vec_edge_act - vec_edge_act.project(vec_normal)
vec_edge_act2d.normalize()
vec_edge_prev2d = vec_edge_prev - vec_edge_prev.project(vec_normal)
vec_edge_prev2d.normalize()
angle2d = vec_edge_act2d.angle(vec_edge_prev2d)
if angle2d < threshold:
# folding corner
corner_type = "FOLD"
vec_tangent = vec_edge_act2d
vec_angle2d = ANGLE_360
elif angle2d > ANGLE_180 - threshold:
# straight corner
corner_type = "STRAIGHT"
vec_tangent = vec_edge_act2d.cross(vec_normal)
vec_angle2d = ANGLE_180
else:
direction = vec_edge_act2d.cross(vec_edge_prev2d).dot(vec_normal)
if direction > 0.0:
# convex corner
corner_type = "CONVEX"
vec_tangent = -(vec_edge_act2d + vec_edge_prev2d)
vec_angle2d = angle2d
else:
# concave corner
corner_type = "CONCAVE"
vec_tangent = vec_edge_act2d + vec_edge_prev2d
vec_angle2d = ANGLE_360 - angle2d
if vec_tangent.dot(vec_normal):
# Make vec_tangent perpendicular to vec_normal
vec_tangent -= vec_tangent.project(vec_normal)
vec_tangent.normalize()
if f_cross:
if vec_tangent.dot(f_cross) < 0.0:
f_cross *= -1
angle_a = f_cross.angle(vec_edge_act2d)
angle_p = f_cross.angle(vec_edge_prev2d)
angle_sum = vec_angle2d + angle_a + angle_p
if angle_a < threshold or angle_p < threshold or angle_sum > ANGLE_360 + threshold:
# For the case in which vec_tangent is not
# between vec_edge_act2d and vec_edge_prev2d.
# Probably using 3d edge vectors is
# more intuitive than 2d edge vectors.
if corner_type == "CONVEX":
vec_tangent = -(vec_edge_act + vec_edge_prev)
#.........这里部分代码省略.........
示例7: execute
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import inverted [as 别名]
def execute(self, context):
if self.type == "ACTIVE":
actob = context.active_object
if actob:
rotation = actob.matrix_world.to_quaternion()
else:
return {"FINISHED"}
elif self.type == "GRID":
v3d = context.space_data
if v3d.use_local_grid:
rotation = v3d.local_grid_rotation
else:
rotation = Quaternion((1, 0, 0, 0))
else:
rotation = self.rotation
# world_rot = parent_mat * parent_inv * delta_rot * rot
override = context.copy()
for ob in vaob.sorted_objects(context.selected_objects):
if self.type == "ACTIVE" and ob == context.active_object:
continue
# オペレータのソース部分を見ないと判らないってのはどうなのよ
override["selected_objects"] = [ob]
override["selected_editable_objects"] = [ob]
if ob.parent:
parent_mat = ob.parent.matrix_world.to_3x3()
parent_inv = ob.matrix_parent_inverse.to_3x3()
mat = parent_mat * parent_inv
target_quat = mat.inverted().to_quaternion() * rotation
else:
target_quat = rotation
if ob.rotation_mode == "AXIS_ANGLE":
def rotate(quat):
angle, *axis = ob.rotation_axis_angle
local_quat = Quaternion(axis, angle)
q = quat * local_quat
axis, angle = q.to_axis_angle()
ob.rotation_axis_angle = [angle] + list(axis)
rotate(target_quat.inverted())
context.scene.update()
bpy.ops.object.transform_apply(override, rotation=True)
rotate(target_quat)
elif ob.rotation_mode == "QUATERNION":
# transform_apply()は
# delta_rotation_quaternion * rotation_quaternion の回転状態で
# 計算される。その後rotation_quaternionはクリアされるが
# delta_rotation_quaternionの数値はそのまま残る
if self.use_delta:
delta = ob.delta_rotation_quaternion
# normalize()必要?
else:
delta = Quaternion([1, 0, 0, 0])
rot = ob.rotation_quaternion
# target_quatの逆回転を行いtransform_apply()、
# そしてtarget_quat分回転する
# target.inverted() * delta * rot = delta * quat
# quat = delta.inverted() * target.inverted() * delta * rot
quat = delta.inverted() * target_quat.inverted() * delta * rot
ob.rotation_quaternion = quat
# ob.update_tag({'OBJECT', 'DATA'})
context.scene.update()
bpy.ops.object.transform_apply(override, rotation=True)
ob.rotation_quaternion = target_quat * ob.rotation_quaternion
# ob.update_tag({'OBJECT', 'DATA'})
else:
if self.use_delta:
delta = ob.delta_rotation_euler.to_quaternion()
else:
delta = Quaternion([1, 0, 0, 0])
rot = ob.rotation_euler.to_quaternion()
quat = delta.inverted() * target_quat.inverted() * delta * rot
ob.rotation_euler = quat.to_euler(ob.rotation_mode)
context.scene.update()
bpy.ops.object.transform_apply(override, rotation=True)
ob.rotation_euler = target_quat.to_euler(ob.rotation_mode)
context.scene.update()
return {"FINISHED"}