def poll(cls, context): obj = context.active_object if obj is None: return False if obj.mmd_type == 'ROOT': return True if obj.mmd_type == 'NONE' and obj.type in {'MESH', 'ARMATURE'}: return True if MMDCamera.isMMDCamera(obj) or MMDLamp.isMMDLamp(obj): return True return False
def poll(cls, context): obj = context.active_object if obj is None: return False if obj.mmd_type == 'ROOT': return True if obj.mmd_type == 'NONE' and (obj.type == 'ARMATURE' or getattr(obj.data, 'shape_keys', None)): return True if MMDCamera.isMMDCamera(obj) or MMDLamp.isMMDLamp(obj): return True return False
def assign(self, obj, action_name=None): if action_name is None: action_name = os.path.splitext( os.path.basename(self.__vmdFile.filepath))[0] if MMDCamera.isMMDCamera(obj): self.__assignToCamera(obj, action_name + '_camera') elif MMDLamp.isMMDLamp(obj): self.__assignToLamp(obj, action_name + '_lamp') elif obj.type == 'MESH': self.__assignToMesh(obj, action_name + '_facial') elif obj.type == 'ARMATURE': self.__assignToArmature(obj, action_name + '_bone') elif obj.type == 'CAMERA' and self.__convert_mmd_camera: self.__assignToCamera(obj, action_name + '_camera') elif obj.type == 'LAMP' and self.__convert_mmd_lamp: self.__assignToLamp(obj, action_name + '_lamp') else: pass
def execute(self, context): params = { 'filepath': self.filepath, 'scale': self.scale, 'use_pose_mode': self.use_pose_mode, 'use_frame_range': self.use_frame_range, } obj = context.active_object if obj.mmd_type == 'ROOT': rig = mmd_model.Model(obj) params['mesh'] = rig.morph_slider.placeholder( binded=True) or rig.firstMesh() params['armature'] = rig.armature() params['model_name'] = obj.mmd_root.name or obj.name elif getattr(obj.data, 'shape_keys', None): params['mesh'] = obj params['model_name'] = obj.name elif obj.type == 'ARMATURE': params['armature'] = obj params['model_name'] = obj.name else: for i in context.selected_objects: if MMDCamera.isMMDCamera(i): params['camera'] = i elif MMDLamp.isMMDLamp(i): params['lamp'] = i try: start_time = time.time() vmd_exporter.VMDExporter().export(**params) logging.info(' Finished exporting motion in %f seconds.', time.time() - start_time) except Exception as e: err_msg = traceback.format_exc() logging.error(err_msg) self.report({'ERROR'}, err_msg) return {'FINISHED'}
def assign(self, obj, action_name=None): if obj is None: return if action_name is None: action_name = os.path.splitext(os.path.basename(self.__vmdFile.filepath))[0] if MMDCamera.isMMDCamera(obj): self.__assignToCamera(obj, action_name+'_camera') elif MMDLamp.isMMDLamp(obj): self.__assignToLamp(obj, action_name+'_lamp') elif getattr(obj.data, 'shape_keys', None): self.__assignToMesh(obj, action_name+'_facial') elif obj.type == 'ARMATURE': self.__assignToArmature(obj, action_name+'_bone') elif obj.type == 'CAMERA' and self.__convert_mmd_camera: self.__assignToCamera(obj, action_name+'_camera') elif obj.type == 'LAMP' and self.__convert_mmd_lamp: self.__assignToLamp(obj, action_name+'_lamp') elif obj.mmd_type == 'ROOT': self.__assignToRoot(obj, action_name+'_display') else: pass
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', 'Convert')
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
def poll(cls, context): obj = context.active_object return obj and (obj.type == 'CAMERA' or MMDCamera.isMMDCamera(obj))