Example #1
0
    def execute(self, context):
        try:
            self.__translator = DictionaryEnum.get_translator(self.dictionary)
        except Exception as e:
            self.report({'ERROR'}, 'Failed to load dictionary: %s' % e)
            return {'CANCELLED'}

        obj = context.active_object
        root = mmd_model.Model.findRoot(obj)
        rig = mmd_model.Model(root)

        if 'MMD' in self.modes:
            for i in self.types:
                getattr(self, 'translate_%s' % i.lower())(rig)

        if 'BLENDER' in self.modes:
            self.translate_blender_names(rig)

        translator = self.__translator
        txt = translator.save_fails()
        if translator.fails:
            self.report(
                {'WARNING'},
                "Failed to translate %d names, see '%s' in text editor" %
                (len(translator.fails), txt.name))
        return {'FINISHED'}
Example #2
0
    def execute(self, context):
        selected_objects = set(context.selected_objects)
        for i in frozenset(selected_objects):
            root = mmd_model.Model.findRoot(i)
            if root == i:
                rig = mmd_model.Model(root)
                selected_objects.add(rig.armature())
                selected_objects.add(rig.morph_slider.placeholder())
                selected_objects |= set(rig.meshes())

        bone_mapper = None
        if self.bone_mapper == 'PMX':
            bone_mapper = makePmxBoneMap
        elif self.bone_mapper == 'RENAMED_BONES':
            bone_mapper = vmd_importer.RenamedBoneMapper(
                rename_LR_bones=self.rename_bones,
                use_underscore=self.use_underscore,
                translator=DictionaryEnum.get_translator(self.dictionary),
            ).init

        for f in self.files:
            importer = vpd_importer.VPDImporter(
                filepath=os.path.join(self.directory, f.name),
                scale=self.scale,
                bone_mapper=bone_mapper,
                use_pose_mode=self.use_pose_mode,
            )
            for i in selected_objects:
                importer.assign(i)
        return {'FINISHED'}
Example #3
0
 def execute(self, context):
     try:
         self.__translator = DictionaryEnum.get_translator(self.dictionary)
         if self.directory:
             for f in self.files:
                 self.filepath = os.path.join(self.directory, f.name)
                 self._do_execute(context)
         elif self.filepath:
             self._do_execute(context)
     except Exception as e:
         err_msg = traceback.format_exc()
         self.report({'ERROR'}, err_msg)
     return {'FINISHED'}
Example #4
0
def translate_bones(dictionary):
    armature = tools.common.get_armature().data
    translator = DictionaryEnum.get_translator(dictionary)
    regex = u'[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf]+'  # Regex to look for japanese chars

    google_input = []
    google_output = []

    count = [0, 0]

    # Translate with the local mmd_tools dictionary
    for bone in armature.bones:
        translated_name = utils.convertNameToLR(bone.name, True)
        translated_name = translator.translate(translated_name)
        bone.name = translated_name
        count[0] += 1

        # Check if name contains untranslated chars and add them to the list
        match = re.findall(regex, translated_name)
        if match is not None:
            for name in match:
                if name not in google_input:
                    google_input.append(name)

    # Translate the list with google translate
    try:
        translator = Translator()
        translations = translator.translate(google_input)
    except:
        return count

    for translation in translations:
        google_output.append(translation.text.capitalize())

    # Replace all untranslated parts in the bones with translations
    for bone in armature.bones:
        bone_name = bone.name
        match = re.findall(regex, bone_name)
        if match and len(match) > 0:
            for index, name in enumerate(google_input):
                if name in match:
                    bone_name = bone_name.replace(name, google_output[index])
            bone.name = bone_name
            count[1] += 1

    return count
Example #5
0
    def execute(self, context):
        selected_objects = list(context.selected_objects)
        for i in selected_objects:
            root = mmd_model.Model.findRoot(i)
            if root == i:
                rig = mmd_model.Model(root)
                arm = rig.armature()
                if arm not in selected_objects:
                    selected_objects.append(arm)
                for m in rig.meshes():
                    if m not in selected_objects:
                        selected_objects.append(m)

        bone_mapper = None
        if self.bone_mapper == 'PMX':
            bone_mapper = makePmxBoneMap
        elif self.bone_mapper == 'RENAMED_BONES':
            bone_mapper = vmd_importer.RenamedBoneMapper(
                rename_LR_bones=self.rename_bones,
                use_underscore=self.use_underscore,
                translator=DictionaryEnum.get_translator(self.dictionary),
            ).init

        start_time = time.time()
        importer = vmd_importer.VMDImporter(
            filepath=self.filepath,
            scale=self.scale,
            bone_mapper=bone_mapper,
            use_pose_mode=self.use_pose_mode,
            frame_margin=self.margin,
        )

        for i in selected_objects:
            importer.assign(i)
        logging.info(' Finished importing motion in %f seconds.',
                     time.time() - start_time)

        if self.update_scene_settings:
            auto_scene_setup.setupFrameRanges()
            auto_scene_setup.setupFps()
        context.scene.frame_set(context.scene.frame_current)
        return {'FINISHED'}