本文整理汇总了Python中mathutils.Quaternion方法的典型用法代码示例。如果您正苦于以下问题:Python mathutils.Quaternion方法的具体用法?Python mathutils.Quaternion怎么用?Python mathutils.Quaternion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils
的用法示例。
在下文中一共展示了mathutils.Quaternion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_node_trs
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def get_node_trs(op, node):
"""Gets the TRS proerties from a glTF node JSON object."""
if 'matrix' in node:
m = node['matrix']
# column-major to row-major
m = Matrix([m[0:4], m[4:8], m[8:12], m[12:16]])
m.transpose()
loc, rot, sca = m.decompose()
# wxyz -> xyzw
# convert_rotation will switch back
rot = [rot[1], rot[2], rot[3], rot[0]]
else:
sca = node.get('scale', [1.0, 1.0, 1.0])
rot = node.get('rotation', [0.0, 0.0, 0.0, 1.0])
loc = node.get('translation', [0.0, 0.0, 0.0])
# Switch glTF coordinates to Blender coordinates
sca = op.convert_scale(sca)
rot = op.convert_rotation(rot)
loc = op.convert_translation(loc)
return [Vector(loc), Quaternion(rot), Vector(sca)]
示例2: rotate_tool_gvert_neighbors
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def rotate_tool_gvert_neighbors(self, command, eventd):
if command == 'init':
self.footer = 'Rotating GVerts'
self.tool_data = [(gv,Vector(gv.position)) for gv in self.sel_gvert.get_inner_gverts()]
elif command == 'commit':
pass
elif command == 'undo':
for gv,p in self.tool_data:
gv.position = p
gv.update()
else:
ang = command
q = Quaternion(self.sel_gvert.snap_norm, ang)
p = self.sel_gvert.position
for gv,up in self.tool_data:
gv.position = p+q*(up-p)
gv.update()
示例3: circleVerts
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def circleVerts(radius: float, seg: int, IDs_Offset: int):
verts = []
vertIDs = []
if radius <= 0:
return [Vector((0, 0, 0))], [IDs_Offset]
if seg < 3:
seg = 3
stepAngle = (2 * pi) / seg
for i in range(seg):
vertIDs.append(i + IDs_Offset)
quat = Quaternion((0, 0, 1), i * stepAngle)
verts.append(quat * Vector((radius, 0.0, 0.0)))
return verts, vertIDs
示例4: relocation_taper_and_bevel
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def relocation_taper_and_bevel(main_ob, sub_ob, is_taper):
# 位置変更
if len(main_ob.data.splines):
if len(main_ob.data.splines[0].points):
end_co = main_ob.matrix_world * mathutils.Vector(main_ob.data.splines[0].points[-1].co[:3])
sub_ob.location = end_co.copy()
# 回転変更
if len(main_ob.data.splines):
spline = main_ob.data.splines[0]
if 2 <= len(spline.points):
# 最後の辺をトラック
sub_ob.rotation_mode = 'QUATERNION'
last_direction = main_ob.matrix_world * mathutils.Vector(spline.points[-2].co[:3]) - main_ob.matrix_world * mathutils.Vector(spline.points[-1].co[:3])
up_direction = mathutils.Vector((0, 0, 1))
sub_ob.rotation_quaternion = up_direction.rotation_difference(last_direction)
# Z回転
diff_co = main_ob.matrix_world * mathutils.Vector(spline.points[-1].co[:3]) - main_ob.matrix_world * mathutils.Vector(spline.points[0].co[:3])
rotation_z = math.atan2(diff_co.y, diff_co.x) - spline.points[-1].tilt
if is_taper: sub_ob.rotation_quaternion *= mathutils.Quaternion((0, 0, 1), rotation_z)
else : sub_ob.rotation_quaternion *= mathutils.Quaternion((0, 0, 1), rotation_z - math.radians(90))
示例5: __init__
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def __init__(self):
self.name = None
self.default_name = 'Node' # fallback when no name
self.children = []
self.parent = None
self.type = VNode.Object
self.is_arma = False
self.base_trs = (
Vector((0, 0, 0)),
Quaternion((1, 0, 0, 0)),
Vector((1, 1, 1)),
)
# Additional rotations before/after the base TRS.
# Allows per-vnode axis adjustment. See local_rotation.
self.rotation_after = Quaternion((1, 0, 0, 0))
self.rotation_before = Quaternion((1, 0, 0, 0))
# Indices of the glTF node where the mesh, etc. came from.
# (They can get moved around.)
self.mesh_node_idx = None
self.camera_node_idx = None
self.light_node_idx = None
示例6: list_to_mathutils
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def list_to_mathutils(values: typing.List[float], data_path: str) -> typing.Union[Vector, Quaternion, Euler]:
"""Transform a list to blender py object."""
target = get_target_property_name(data_path)
if target == 'delta_location':
return Vector(values) # TODO Should be Vector(values) - Vector(something)?
elif target == 'delta_rotation_euler':
return Euler(values).to_quaternion() # TODO Should be multiply(Euler(values).to_quaternion(), something)?
elif target == 'location':
return Vector(values)
elif target == 'rotation_axis_angle':
angle = values[0]
axis = values[1:]
return Quaternion(axis, math.radians(angle))
elif target == 'rotation_euler':
return Euler(values).to_quaternion()
elif target == 'rotation_quaternion':
return Quaternion(values)
elif target == 'scale':
return Vector(values)
elif target == 'value':
return Vector(values)
return values
示例7: swizzle_yup
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def swizzle_yup(v: typing.Union[Vector, Quaternion], data_path: str) -> typing.Union[Vector, Quaternion]:
"""Manage Yup."""
target = get_target_property_name(data_path)
swizzle_func = {
"delta_location": swizzle_yup_location,
"delta_rotation_euler": swizzle_yup_rotation,
"location": swizzle_yup_location,
"rotation_axis_angle": swizzle_yup_rotation,
"rotation_euler": swizzle_yup_rotation,
"rotation_quaternion": swizzle_yup_rotation,
"scale": swizzle_yup_scale,
"value": swizzle_yup_value
}.get(target)
if swizzle_func is None:
raise RuntimeError("Cannot transform values at {}".format(data_path))
return swizzle_func(v)
示例8: transform
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def transform(v: typing.Union[Vector, Quaternion], data_path: str, transform: Matrix = Matrix.Identity(4)) -> typing \
.Union[Vector, Quaternion]:
"""Manage transformations."""
target = get_target_property_name(data_path)
transform_func = {
"delta_location": transform_location,
"delta_rotation_euler": transform_rotation,
"location": transform_location,
"rotation_axis_angle": transform_rotation,
"rotation_euler": transform_rotation,
"rotation_quaternion": transform_rotation,
"scale": transform_scale,
"value": transform_value
}.get(target)
if transform_func is None:
raise RuntimeError("Cannot transform values at {}".format(data_path))
return transform_func(v, transform)
示例9: euler_to_quaternion
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def euler_to_quaternion(roll, pitch, yaw):
"""Converts Euler Rotation to Quaternion Rotation.
Args:
roll: Roll in Euler rotation
pitch: Pitch in Euler rotation
yaw: Yaw in Euler rotation
Returns:
Quaternion Rotation.
"""
# fmt: off
quat_x = (np.sin(roll/2) * np.cos(pitch/2) * np.cos(yaw/2)
- np.cos(roll/2) * np.sin(pitch/2) * np.sin(yaw/2))
quat_y = (np.cos(roll/2) * np.sin(pitch/2) * np.cos(yaw/2)
+ np.sin(roll/2) * np.cos(pitch/2) * np.sin(yaw/2))
quat_z = (np.cos(roll/2) * np.cos(pitch/2) * np.sin(yaw/2)
- np.sin(roll/2) * np.sin(pitch/2) * np.cos(yaw/2))
quat_w = (np.cos(roll/2) * np.cos(pitch/2) * np.cos(yaw/2)
+ np.sin(roll/2) * np.sin(pitch/2) * np.sin(yaw/2))
# fmt: on
return Quaternion((quat_w, quat_x, quat_y, quat_z))
示例10: execute
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def execute(self, context):
"""View Rotation by Absolute Values.
Note:
Rotations are converted to 3x3 Quaternion Rotation Matrix.
This is an Absolute Rotation, not an Incremental Orbit.
Uses pg.rotation_coords scene variable
Args:
context: Blender bpy.context instance.
Returns:
Status Set.
"""
scene = context.scene
pg = scene.pdt_pg
roll_value = euler_to_quaternion(
pg.rotation_coords.x * pi / 180,
pg.rotation_coords.y * pi / 180,
pg.rotation_coords.z * pi / 180,
)
context.region_data.view_rotation = roll_value
return {"FINISHED"}
示例11: circleVerts
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def circleVerts(radius: float, seg: int, IDs_Offset: int):
verts = []
vertIDs = []
if radius <= 0:
return [Vector((0, 0, 0))], [IDs_Offset]
if seg < 3:
seg = 3
stepAngle = (2 * pi) / seg
for i in range(seg):
vertIDs.append(i + IDs_Offset)
quat = Quaternion((0, 0, 1), i * stepAngle)
verts.append(quat @ Vector((radius, 0.0, 0.0)))
return verts, vertIDs
示例12: create_railing_top
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def create_railing_top(bm, top_edge, prop):
ret = bmesh.ops.duplicate(bm, geom=[top_edge])
top_dup_edge = filter_geom(ret["geom"], BMEdge)[0]
vec = edge_vector(top_dup_edge)
up = vec.copy()
horizon = vec.cross(Vector((0., 0., 1.)))
up.rotate(Quaternion(horizon, math.pi/2).to_euler())
sloped = edge_is_sloped(top_dup_edge)
cylinder = edge_to_cylinder(bm, top_dup_edge, prop.corner_post_width/2, up)
if sloped:
rotate_sloped_rail_bounds(bm, cylinder, vec)
bmesh.ops.translate(bm, verts=top_edge.verts, vec=Vector((0., 0., -1.))*prop.corner_post_width/2)
return list({f for v in cylinder for f in v.link_faces})
示例13: execute
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def execute(self, context):
obj = context.active_object
root = mmd_model.Model.findRoot(obj)
rig = mmd_model.Model(root)
armature = rig.armature()
mmd_root = root.mmd_root
morph = mmd_root.bone_morphs[mmd_root.active_morph]
morph.data.clear()
morph.active_data = 0
def_loc = Vector((0,0,0))
def_rot = Quaternion((1,0,0,0))
for p_bone in armature.pose.bones:
if p_bone.location != def_loc or p_bone.rotation_quaternion != def_rot:
item = morph.data.add()
item.bone = p_bone.name
item.location = p_bone.location
item.rotation = p_bone.rotation_quaternion
p_bone.bone.select = True
else:
p_bone.bone.select = False
return { 'FINISHED' }
示例14: convert_swizzle_rotation
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def convert_swizzle_rotation(rot):
"""
Converts a quaternion rotation from Blender coordinate system to glTF coordinate system.
'w' is still at first position.
"""
return mathutils.Quaternion((rot[0], rot[1], rot[3], -rot[2]))
示例15: convert_swizzle_matrix
# 需要导入模块: import mathutils [as 别名]
# 或者: from mathutils import Quaternion [as 别名]
def convert_swizzle_matrix(matrix):
"""
Converts a matrix from Blender coordinate system to glTF coordinate system.
"""
translation, rotation, scale = decompose_transform_swizzle(matrix)
mat_trans = mathutils.Matrix.Translation(translation)
mat_rot = mathutils.Quaternion(rotation).to_matrix().to_4x4()
mat_sca = mathutils.Matrix()
mat_sca[0][0] = scale[0]
mat_sca[1][1] = scale[1]
mat_sca[2][2] = scale[2]
return mat_trans @ mat_rot @ mat_sca