当前位置: 首页>>代码示例>>Python>>正文


Python mathutils.Quaternion方法代码示例

本文整理汇总了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)] 
开发者ID:ksons,项目名称:gltf-blender-importer,代码行数:25,代码来源:vnode.py

示例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() 
开发者ID:CGCookie,项目名称:retopology-polystrips,代码行数:19,代码来源:__init__.py

示例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 
开发者ID:WiresoulStudio,项目名称:Wonder_Mesh,代码行数:20,代码来源:gen_func.py

示例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)) 
开发者ID:relarar,项目名称:Blender-AnimeHairSupporter,代码行数:23,代码来源:_common.py

示例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 
开发者ID:KhronosGroup,项目名称:glTF-Blender-IO,代码行数:24,代码来源:gltf2_blender_vnode.py

示例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 
开发者ID:KhronosGroup,项目名称:glTF-Blender-IO,代码行数:26,代码来源:gltf2_blender_math.py

示例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) 
开发者ID:KhronosGroup,项目名称:glTF-Blender-IO,代码行数:20,代码来源:gltf2_blender_math.py

示例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) 
开发者ID:KhronosGroup,项目名称:glTF-Blender-IO,代码行数:21,代码来源:gltf2_blender_math.py

示例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)) 
开发者ID:Clockmender,项目名称:Precision-Drawing-Tools,代码行数:25,代码来源:pdt_functions.py

示例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"} 
开发者ID:Clockmender,项目名称:Precision-Drawing-Tools,代码行数:26,代码来源:pdt_view.py

示例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 
开发者ID:WiresoulStudio,项目名称:W_Mesh_28x,代码行数:20,代码来源:genFunctions.py

示例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}) 
开发者ID:ranjian0,项目名称:building_tools,代码行数:18,代码来源:railing.py

示例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' } 
开发者ID:GiveMeAllYourCats,项目名称:cats-blender-plugin,代码行数:23,代码来源:morph.py

示例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])) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:8,代码来源:gltf2_extract.py

示例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 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:16,代码来源:gltf2_extract.py


注:本文中的mathutils.Quaternion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。