Skip to content

Commit

Permalink
#78 Add mmd_tools version to root object
Browse files Browse the repository at this point in the history
  • Loading branch information
UuuNyaa committed Oct 24, 2022
1 parent b3d366c commit 2677cc2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 3 additions & 1 deletion mmd_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"category": "Object",
}

MMD_TOOLS_VERSION = '.'.join(map(str,bl_info['version']))

import bpy

from mmd_tools import auto_load
Expand All @@ -22,7 +24,6 @@
from mmd_tools import operators
from mmd_tools import properties


def menu_func_import(self, _context):
self.layout.operator(operators.fileio.ImportPmx.bl_idname, text='MikuMikuDance Model (.pmd, .pmx)', icon='OUTLINER_OB_ARMATURE')
self.layout.operator(operators.fileio.ImportVmd.bl_idname, text='MikuMikuDance Motion (.vmd)', icon='ANIM')
Expand Down Expand Up @@ -78,6 +79,7 @@ def load_handler(_dummy):

from mmd_tools.core.model import MigrationFnModel
MigrationFnModel.update_mmd_ik_loop_factor()
MigrationFnModel.update_mmd_tools_version()

@bpy.app.handlers.persistent
def save_pre_handler(_dummy):
Expand Down
27 changes: 23 additions & 4 deletions mmd_tools/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import idprop
import mathutils
import rna_prop_ui
from mmd_tools import bpyutils
from mmd_tools import MMD_TOOLS_VERSION, bpyutils
from mmd_tools.bpyutils import Props, SceneOp, matmul
from mmd_tools.core import rigid_body
from mmd_tools.core.bone import FnBone, MigrationFnBone
Expand Down Expand Up @@ -97,13 +97,13 @@ class FnModel:
def copy_mmd_root(destination_root_object: bpy.types.Object, source_root_object: bpy.types.Object, overwrite: bool = True, replace_name2values: Dict[str,Dict[Any,Any]] = dict()):
_copy_property(destination_root_object.mmd_root, source_root_object.mmd_root, overwrite=overwrite, replace_name2values=replace_name2values)

@classmethod
def find_root(cls, obj: bpy.types.Object) -> Optional[bpy.types.Object]:
@staticmethod
def find_root(obj: bpy.types.Object) -> Optional[bpy.types.Object]:
if not obj:
return None
if obj.mmd_type == 'ROOT':
return obj
return cls.find_root(obj.parent)
return FnModel.find_root(obj.parent)

@staticmethod
def find_armature(root) -> Optional[bpy.types.Object]:
Expand Down Expand Up @@ -150,6 +150,10 @@ def filtered_children(cls, filter, obj: bpy.types.Object) -> Iterable[bpy.types.
def child_meshes(cls, obj: bpy.types.Object) -> Iterable[bpy.types.Object]:
return cls.filtered_children(lambda x: x.type == 'MESH' and x.mmd_type == 'NONE', obj)

@staticmethod
def is_root_object(obj):
return obj and obj.mmd_type == 'ROOT'

@staticmethod
def is_rigid_body_object(obj):
return obj and obj.mmd_type == 'RIGID_BODY'
Expand Down Expand Up @@ -360,6 +364,20 @@ def update_mmd_ik_loop_factor(cls):
FnModel.find_root(armature_object).mmd_root.ik_loop_factor = max(armature_object['mmd_ik_loop_factor'], 1)
del armature_object['mmd_ik_loop_factor']

@staticmethod
def update_mmd_tools_version():
for root_object in bpy.data.objects:
if root_object.type != 'EMPTY':
continue

if not FnModel.is_root_object(root_object):
continue

if 'mmd_tools_version' in root_object:
continue

root_object['mmd_tools_version'] = '2.8.0'


# SUPPORT_UNTIL: 4.3 LTS
def isRigidBodyObject(obj):
Expand Down Expand Up @@ -398,6 +416,7 @@ def create(name, name_e='', scale=1, obj_name=None, armature=None, add_root_bone
root.mmd_type = 'ROOT'
root.mmd_root.name = name
root.mmd_root.name_e = name_e
root['mmd_tools_version'] = MMD_TOOLS_VERSION
setattr(root, Props.empty_display_size, scale/0.2)
scene.link_object(root)

Expand Down

0 comments on commit 2677cc2

Please sign in to comment.