コード例 #1
0
ファイル: base.py プロジェクト: j20232/bnp
def insert_keyframe(
        obj: bpy.types.Object,
        vec: np.ndarray,
        datapath: str,
        frame: int = bpy.context.scene.frame_current) -> np.ndarray:
    bpy.context.scene.frame_set(frame)
    if datapath == "rotation":
        if obj.rotation_mode == "AXIS_ANGLE":
            datapath = "rotation_axis_angle"
        elif obj.rotation_mode == "QUATERNION":
            datapath = "rotation_quaternion"
        else:
            datapath = "rotation_euler"

    if datapath == "location":
        obj.location = (vec[0], vec[1], vec[2])
    elif datapath == "rotation_euler":
        obj.rotation_mode = "XYZ"
        obj.rotation_euler = (vec[0], vec[1], vec[2])
    elif datapath == "rotation_quaternion":
        obj.rotation_mode = "QUATERNION"
        obj.rotation_quaternion = (vec[0], vec[1], vec[2], vec[3])
    elif datapath == "rotation_axis_angle":
        obj.rotation_mode = "AXIS_ANGLE"
        obj.rotation_axis_angle = (vec[0], vec[1], vec[2], vec[3])
    elif datapath == "scale":
        obj.scale = (vec[0], vec[1], vec[2])
    else:
        raise NotImplementedError("Illegal datapath!")
    obj.keyframe_insert(data_path=datapath, frame=frame)
コード例 #2
0
def setObjectRotationQuaternion(obj: bpy.types.Object, rot: Quaternion):
    if obj.rotation_mode == "QUATERNION":
        obj.rotation_quaternion = rot
    elif obj.rotation_mode == "AXIS_ANGLE":
        obj.rotation_axis_angle = rot.to_axis_angle()
    else:
        obj.rotation_euler = rot.to_euler(obj.rotation_mode)
コード例 #3
0
def set_transformation(obj: bpy.types.Object, transf: Dict[str, str]) -> None:
    """set the transformation of an object"""

    trans = transf['translation']
    rot = transf['rotation']

    obj.location = trans
    # blender.point_at(cam, root_obj, 'TRACK_NEGATIVE_Z', 'UP_Y')

    if isinstance(rot, dict):
        point_at_obj = blender.get_obj_by_name(rot['point_at'])
        blender.point_at(obj, point_at_obj,
                         blender.TRACK_AXIS[rot.get('track_axis', '-z')],
                         blender.UP_AXIS[rot.get('up_axis', 'y')])
    else:
        if len(rot) == 3:
            # I think Panda3D's HPR is intrinsic
            # If Blender is extrinsic, the order can just be reversed, LOL
            # rot is in HPR form
            # H -> Z
            # P -> X
            # R -> Y
            obj.rotation_mode = 'ZXY'
            obj.rotation_euler = (
                math.radians(rot[1]),  # X == (ZXY)[1]
                math.radians(rot[2]),  # Y == (ZXY)[2]
                math.radians(rot[0]),  # Z == (ZXY)[0]
            )
        else:
            obj.rotation_mode = 'QUATERNION'
            obj.rotation_quaternion = rot
コード例 #4
0
ファイル: base.py プロジェクト: j20232/bnp
def change_rotation_mode(obj: bpy.types.Object,
                         rotation_mode: str,
                         normalized: bool = True):
    if rotation_mode == "rotation_axis_angle":
        rotation_mode = "AXIS_ANGLE"
    elif rotation_mode == "rotation_quaternion":
        rotation_mode = "QUATERNION"
    elif rotation_mode == "rotation_euler":
        rotation_mode = "XYZ"
    obj.rotation_mode = rotation_mode
    if normalized and obj.rotation_mode == "AXIS_ANGLE":
        axis_angle = normalize_axis_angle(vec2np(obj.rotation_axis_angle))[0]
        obj.rotation_axis_angle = (axis_angle[0], axis_angle[1], axis_angle[2],
                                   axis_angle[3])
    elif normalized and obj.rotation_mode == "QUATERNION":
        quat = normalize_quaternion(vec2np(obj.rotation_quaternion))[0]
        obj.rotation_quaternion = (quat[0], quat[1], quat[2], quat[3])
コード例 #5
0
def set_rotation(blender_object: bpy.types.Object, rotation: Any,
                 rotation_mode: str) -> None:
    """
    Sets the rotation of a Blender Object and takes care of picking which
    rotation type to give the value to
    """
    if rotation_mode == "AXIS_ANGLE":
        assert len(rotation[1]) == 3
        blender_object.rotation_axis_angle = rotation
    elif rotation_mode == "QUATERNION":
        assert len(rotation) == 4
        blender_object.rotation_quaternion = rotation
    elif set(rotation_mode) == {"X", "Y", "Z"}:
        assert len(rotation) == 3
        blender_object.rotation_euler = rotation
    else:
        assert False, "Unsupported rotation mode: " + blender_object.rotation_mode
コード例 #6
0
ファイル: piece.py プロジェクト: Khrisbie/blender-woodworking
 def set_object_rotation(context,
                         position_properties: WorkpiecePosition,
                         scene_object: bpy.types.Object):
     rotations = WorkpieceOperator.visible_surface_rotation(
         position_properties.visible_surface)
     rotations.extend(WorkpieceOperator.view_rotation(
         context,
         position_properties.view))
     rotations.extend(WorkpieceOperator.orientation_rotation(
         context,
         position_properties.orientation,
         position_properties.view))
     scene_object.rotation_mode = 'QUATERNION'
     object_rotations = scene_object.rotation_quaternion.copy()
     for rotation in rotations:
         object_rotations = WorkpieceOperator.quaternion_rotation(
             rotation, object_rotations)
     scene_object.rotation_quaternion = object_rotations
コード例 #7
0
ファイル: utils.py プロジェクト: BlenderCN-Org/blender-ijim
def setObjQuaternionRotation(obj: bpy.types.Object, rotation: Vector3f):
    obj.rotation_mode = 'QUATERNION'
    obj.rotation_quaternion = makeQuaternionRotation(rotation)