Example #1
0
    def draw(self, context):
        obj = context.active_object

        layout = self.layout

        if MMDLamp.isMMDLamp(obj):
            mmd_lamp = MMDLamp(obj)
            empty = mmd_lamp.object()
            lamp = mmd_lamp.lamp()

            c = layout.column()
            c.prop(lamp.data, 'color')
            c.prop(lamp, 'location', text='Light Source')
        else:
            layout.operator('mmd_tools.convert_to_mmd_lamp', text='Convert')
Example #2
0
    def __assignToLamp(self, lampObj, action_name=None):
        mmdLampInstance = MMDLamp.convertToMMDLamp(lampObj, self.__scale)
        mmdLamp = mmdLampInstance.object()
        lampObj = mmdLampInstance.lamp()

        lampAnim = self.__vmdFile.lampAnimation
        logging.info('(lamp) frames:%5d  name: %s', len(lampAnim),
                     mmdLamp.name)
        if len(lampAnim) < 1:
            return

        action_name = action_name or mmdLamp.name
        color_action = bpy.data.actions.new(name=action_name + '_color')
        location_action = bpy.data.actions.new(name=action_name + '_loc')
        lampObj.data.animation_data_create().action = color_action
        lampObj.animation_data_create().action = location_action

        for keyFrame in lampAnim:
            frame = keyFrame.frame_number + self.__frame_margin
            lampObj.data.color = Vector(keyFrame.color)
            lampObj.location = Vector(keyFrame.direction).xzy * -1
            lampObj.data.keyframe_insert(data_path='color', frame=frame)
            lampObj.keyframe_insert(data_path='location', frame=frame)

        for fcurve in lampObj.animation_data.action.fcurves:
            self.detectLampChange(fcurve)
Example #3
0
    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
Example #4
0
    def __exportLampAnimation(self, lampObj):
        if lampObj is None:
            return None
        if not MMDLamp.isMMDLamp(lampObj):
            logging.warning('[WARNING] lamp "%s" is not MMDLamp', lampObj.name)
            return None

        lamp_rig = MMDLamp(lampObj)
        mmd_lamp = lamp_rig.object()
        lamp = lamp_rig.lamp()

        vmd_lamp_anim = vmd.LampAnimation()

        data = list(lamp.data.color) + list(lamp.location)
        lamp_curves = [_FCurve(i) for i in data]  # r, g, b, x, y, z

        animation_data = lamp.data.animation_data
        if animation_data and animation_data.action:
            for fcurve in animation_data.action.fcurves:
                if fcurve.data_path == 'color':  # r, g, b
                    lamp_curves[fcurve.array_index].setFCurve(fcurve)

        animation_data = lamp.animation_data
        if animation_data and animation_data.action:
            for fcurve in animation_data.action.fcurves:
                if fcurve.data_path == 'location':  # x, y, z
                    lamp_curves[3 + fcurve.array_index].setFCurve(fcurve)

        for frame_number, r, g, b, x, y, z in self.__allFrameKeys(lamp_curves):
            key = vmd.LampKeyFrameKey()
            key.frame_number = frame_number - self.__frame_start
            key.color = [r[0], g[0], b[0]]
            key.direction = [-x[0], -z[0], -y[0]]
            vmd_lamp_anim.append(key)
        logging.info('(lamp) frames:%5d  name: %s', len(vmd_lamp_anim),
                     mmd_lamp.name)
        return vmd_lamp_anim
Example #5
0
    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')
        else:
            pass
Example #6
0
    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.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'}
Example #7
0
 def execute(self, context):
     MMDLamp.convertToMMDLamp(context.active_object, self.scale)
     return {'FINISHED'}
Example #8
0
 def poll(cls, context):
     return MMDLamp.isLamp(context.active_object)
Example #9
0
 def poll(cls, context):
     obj = context.active_object
     return obj and (MMDLamp.isLamp(obj) or MMDLamp.isMMDLamp(obj))