def draw(self, context):
        obj = context.active_object

        layout = self.layout

        if MMDCamera.isMMDCamera(obj):
            mmd_cam = MMDCamera(obj)
            empty = mmd_cam.object()
            camera = mmd_cam.camera()

            row = layout.row()

            c = row.column()
            c.prop(empty, 'location')
            c.prop(camera, 'location', index=1, text='Distance')

            c = row.column()
            c.prop(empty, 'rotation_euler')

            layout.prop(empty.mmd_camera, 'angle')
            layout.prop(empty.mmd_camera, 'is_perspective')
        else:
            layout.operator('mmd_tools.convert_to_mmd_camera', text='Convert')
Example #2
0
    def __exportCameraAnimation(self, cameraObj):
        if cameraObj is None:
            return None
        if not MMDCamera.isMMDCamera(cameraObj):
            logging.warning('[WARNING] camera "%s" is not MMDCamera',
                            cameraObj.name)
            return None

        cam_rig = MMDCamera(cameraObj)
        mmd_cam = cam_rig.object()
        camera = cam_rig.camera()

        vmd_cam_anim = vmd.CameraAnimation()

        data = list(mmd_cam.location) + list(mmd_cam.rotation_euler)
        data.append(mmd_cam.mmd_camera.angle)
        data.append(mmd_cam.mmd_camera.is_perspective)
        data.append(camera.location.y)
        cam_curves = [_FCurve(i) for i in data
                      ]  # x, y, z, rx, ry, rz, fov, persp, distance

        animation_data = mmd_cam.animation_data
        if animation_data and animation_data.action:
            for fcurve in animation_data.action.fcurves:
                if fcurve.data_path == 'location':  # x, y, z
                    cam_curves[fcurve.array_index].setFCurve(fcurve)
                elif fcurve.data_path == 'rotation_euler':  # rx, ry, rz
                    cam_curves[3 + fcurve.array_index].setFCurve(fcurve)
                elif fcurve.data_path == 'mmd_camera.angle':  # fov
                    cam_curves[6].setFCurve(fcurve)
                elif fcurve.data_path == 'mmd_camera.is_perspective':  # persp
                    cam_curves[7].setFCurve(fcurve)

        animation_data = camera.animation_data
        if animation_data and animation_data.action:
            for fcurve in animation_data.action.fcurves:
                if fcurve.data_path == 'location' and fcurve.array_index == 1:  # distance
                    cam_curves[8].setFCurve(fcurve)

        for frame_number, x, y, z, rx, ry, rz, fov, persp, distance in self.__allFrameKeys(
                cam_curves):
            key = vmd.CameraKeyFrameKey()
            key.frame_number = frame_number - self.__frame_start
            key.location = [
                x[0] * self.__scale, z[0] * self.__scale, y[0] * self.__scale
            ]
            key.rotation = [rx[0], rz[0], ry[0]]  # euler
            key.angle = int(0.5 + math.degrees(fov[0]))
            key.distance = distance[0] * self.__scale
            key.persp = True if persp[0] else False

            #FIXME we can only choose one interpolation from (rx, ry, rz) for camera's rotation
            ir = self.__pickRotationInterpolation([rx[1], ry[1], rz[1]])
            ix, iy, iz, iD, iF = x[1], z[1], y[1], distance[1], fov[1]
            key.interp = [
                ix[0][0],
                ix[1][0],
                ix[0][1],
                ix[1][1],
                iy[0][0],
                iy[1][0],
                iy[0][1],
                iy[1][1],
                iz[0][0],
                iz[1][0],
                iz[0][1],
                iz[1][1],
                ir[0][0],
                ir[1][0],
                ir[0][1],
                ir[1][1],
                iD[0][0],
                iD[1][0],
                iD[0][1],
                iD[1][1],
                iF[0][0],
                iF[1][0],
                iF[0][1],
                iF[1][1],
            ]

            vmd_cam_anim.append(key)
        logging.info('(camera) frames:%5d  name: %s', len(vmd_cam_anim),
                     mmd_cam.name)
        return vmd_cam_anim