Skip to content

Commit

Permalink
Make imports relative
Browse files Browse the repository at this point in the history
  • Loading branch information
UuuNyaa committed Jun 16, 2024
1 parent 47f4d17 commit cd39e74
Show file tree
Hide file tree
Showing 62 changed files with 349 additions and 860 deletions.
22 changes: 9 additions & 13 deletions mmd_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
bl_info = {
"name": "mmd_tools",
"author": "sugiany",
"version": (4, 2, 1),
"version": (4, 2, 2),
"blender": (4, 2, 0),
"location": "View3D > Sidebar > MMD Panel",
"description": "Utility tools for MMD model editing. (UuuNyaa's forked version)",
Expand All @@ -39,40 +39,36 @@
PACKAGE_NAME = __package__


from mmd_tools import auto_load
from . import auto_load

auto_load.init()


def register():
import bpy

import mmd_tools.handlers
import mmd_tools.operators.addon_updater
from . import handlers

mmd_tools.auto_load.register()
auto_load.register()

# pylint: disable=import-outside-toplevel
from mmd_tools.m17n import translation_dict
from .m17n import translation_dict

bpy.app.translations.register(bl_info["name"], translation_dict)

mmd_tools.operators.addon_updater.register_updater(bl_info, __file__)
mmd_tools.handlers.MMDHanders.register()
handlers.MMDHanders.register()


def unregister():
import bpy

import mmd_tools.handlers
import mmd_tools.operators.addon_updater
from . import handlers

mmd_tools.handlers.MMDHanders.unregister()
mmd_tools.operators.addon_updater.unregister_updater()
handlers.MMDHanders.unregister()

bpy.app.translations.unregister(bl_info["name"])

mmd_tools.auto_load.unregister()
auto_load.unregister()


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion mmd_tools/blender_manifest.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
schema_version = "1.0.0"

id = "mmd_tools"
version = "4.2.1"
version = "4.2.2"
name = "MMD Tools"
tagline = "Utility tools for MMD model editing"
maintainer = "UuuNyaa <[email protected]>"
Expand Down
16 changes: 8 additions & 8 deletions mmd_tools/core/bone.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import bpy
from mathutils import Vector

from mmd_tools import bpyutils
from mmd_tools.bpyutils import TransformConstraintOp
import mmd_tools.utils
from .. import bpyutils
from ..bpyutils import TransformConstraintOp
from ..utils import ItemOp

if TYPE_CHECKING:
from mmd_tools.properties.root import MMDRoot, MMDDisplayItemFrame
from mmd_tools.properties.pose_bone import MMDBone
from ..properties.root import MMDRoot, MMDDisplayItemFrame
from ..properties.pose_bone import MMDBone


def remove_constraint(constraints, name):
Expand Down Expand Up @@ -152,7 +152,7 @@ def sync_bone_collections_from_display_item_frames(armature_object: bpy.types.Ob
armature: bpy.types.Armature = armature_object.data
bone_collections = armature.collections

from mmd_tools.core.model import FnModel
from .model import FnModel

root_object: bpy.types.Object = FnModel.find_root_object(armature_object)
mmd_root: MMDRoot = root_object.mmd_root
Expand Down Expand Up @@ -196,7 +196,7 @@ def sync_display_item_frames_from_bone_collections(armature_object: bpy.types.Ob
armature: bpy.types.Armature = armature_object.data
bone_collections: bpy.types.BoneCollections = armature.collections

from mmd_tools.core.model import FnModel
from .model import FnModel

root_object: bpy.types.Object = FnModel.find_root_object(armature_object)
mmd_root: MMDRoot = root_object.mmd_root
Expand All @@ -217,7 +217,7 @@ def sync_display_item_frames_from_bone_collections(armature_object: bpy.types.Ob
display_item_frame.name_e = bone_collection_name
used_frame_index.add(display_item_frames.find(bone_collection_name))

mmd_tools.utils.ItemOp.resize(display_item_frame.data, len(bone_collection.bones))
ItemOp.resize(display_item_frame.data, len(bone_collection.bones))
for display_item, bone in zip(display_item_frame.data, bone_collection.bones):
display_item.type = "BONE"
display_item.name = bone.name
Expand Down
2 changes: 1 addition & 1 deletion mmd_tools/core/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import bpy

from mmd_tools.bpyutils import FnContext, Props
from ..bpyutils import FnContext, Props


class FnCamera:
Expand Down
2 changes: 1 addition & 1 deletion mmd_tools/core/lamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import bpy

from mmd_tools.bpyutils import FnContext, Props
from ..bpyutils import FnContext, Props


class MMDLamp:
Expand Down
9 changes: 5 additions & 4 deletions mmd_tools/core/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
import bpy
from mathutils import Vector

from mmd_tools.bpyutils import FnContext
from mmd_tools.core.exceptions import MaterialNotFoundError
from mmd_tools.core.shader import _NodeGroupUtils
from ..bpyutils import FnContext
from .exceptions import MaterialNotFoundError
from .shader import _NodeGroupUtils

if TYPE_CHECKING:
from mmd_tools.properties.material import MMDMaterial
from ..properties.material import MMDMaterial

# TODO: use enum instead of constants
SPHERE_MODE_OFF = 0
SPHERE_MODE_MULT = 1
SPHERE_MODE_ADD = 2
Expand Down
17 changes: 9 additions & 8 deletions mmd_tools/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
import rna_prop_ui
from mathutils import Vector

from mmd_tools import MMD_TOOLS_VERSION, bpyutils
from mmd_tools.bpyutils import FnContext, Props
from mmd_tools.core import rigid_body
from mmd_tools.core.morph import FnMorph
from mmd_tools.core.rigid_body import MODE_DYNAMIC, MODE_DYNAMIC_BONE, MODE_STATIC
from .. import MMD_TOOLS_VERSION, bpyutils
from ..bpyutils import FnContext, Props
from . import rigid_body
from .morph import FnMorph
from .rigid_body import MODE_DYNAMIC, MODE_DYNAMIC_BONE, MODE_STATIC

if TYPE_CHECKING:
from properties.morph import MaterialMorphData
from properties.rigid_body import MMDRigidBody
from ..properties.morph import MaterialMorphData
from ..properties.rigid_body import MMDRigidBody


class FnModel:
Expand Down Expand Up @@ -118,6 +118,7 @@ def find_bone_order_mesh_object(root_object: bpy.types.Object) -> Optional[bpy.t
@staticmethod
def find_mesh_object_by_name(root_object: bpy.types.Object, name: str) -> Optional[bpy.types.Object]:
for o in FnModel.iterate_mesh_objects(root_object):
# TODO: consider o.data.name
if o.name != name:
continue
return o
Expand Down Expand Up @@ -600,7 +601,7 @@ def create(name: str, name_e: str = "", scale: float = 1, obj_name: Optional[str
setattr(armature_object, Props.show_in_front, True)
setattr(armature_object, Props.display_type, "WIRE")

from mmd_tools.core.bone import FnBone
from .bone import FnBone

FnBone.setup_special_bone_collections(armature_object)

Expand Down
21 changes: 10 additions & 11 deletions mmd_tools/core/morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@

import bpy

import mmd_tools
from mmd_tools import bpyutils
from mmd_tools.bpyutils import FnContext, FnObject, TransformConstraintOp
from .. import bpyutils
from ..bpyutils import FnContext, FnObject, TransformConstraintOp

if TYPE_CHECKING:
import mmd_tools.core.model
from .model import Model


class FnMorph:
def __init__(self, morph, model: "mmd_tools.core.model.Model"):
def __init__(self, morph, model: "Model"):
self.__morph = morph
self.__rig = model

Expand Down Expand Up @@ -309,7 +308,7 @@ def morph_equals(l, r) -> bool:


class _MorphSlider:
def __init__(self, model: "mmd_tools.core.model.Model"):
def __init__(self, model: "Model"):
self.__rig = model

def placeholder(self, create=False, binded=False):
Expand Down Expand Up @@ -342,7 +341,7 @@ def __dummy_armature(self, obj, create=False):
arm.parent = obj
FnContext.link_object(FnContext.ensure_context(), arm)

from mmd_tools.core.bone import FnBone
from .bone import FnBone

FnBone.setup_special_bone_collections(arm)
return arm
Expand Down Expand Up @@ -435,7 +434,7 @@ def __cleanup(self, names_in_use=None):
if m.name.startswith("mmd_bind") and m.name not in names_in_use:
mesh_object.modifiers.remove(m)

from mmd_tools.core.shader import _MaterialMorph
from .shader import _MaterialMorph

for m in rig.materials():
if m and m.node_tree:
Expand Down Expand Up @@ -544,7 +543,7 @@ def bind(self):

bone_offset_map = {}
with bpyutils.edit_object(arm) as data:
from mmd_tools.core.bone import FnBone
from .bone import FnBone

edit_bones = data.edit_bones

Expand Down Expand Up @@ -675,7 +674,7 @@ def __config_bone_morph(constraints, map_type, attributes, val, val_str):
driver.expression = f"({__config_groups(variables, var.name, groups)})*{fvar.name}"

# material morphs
from mmd_tools.core.shader import _MaterialMorph
from .shader import _MaterialMorph

group_dict = material_offset_map.get("group_dict", {})

Expand Down Expand Up @@ -708,7 +707,7 @@ def __config_material_morph(mat, morph_list):
class MigrationFnMorph:
@staticmethod
def update_mmd_morph():
from mmd_tools.core.material import FnMaterial
from .material import FnMaterial

for root in bpy.data.objects:
if root.mmd_type != "ROOT":
Expand Down
6 changes: 3 additions & 3 deletions mmd_tools/core/pmd/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

import mathutils

import mmd_tools.core.pmd as pmd
import mmd_tools.core.pmx as pmx
import mmd_tools.core.pmx.importer as import_pmx
from .. import pmd
from .. import pmx
from ..pmx import importer as import_pmx


class PMDImporter:
Expand Down
18 changes: 9 additions & 9 deletions mmd_tools/core/pmx/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
import bpy
import mathutils

from mmd_tools.bpyutils import FnContext
from mmd_tools.core import pmx
from mmd_tools.core.material import FnMaterial
from mmd_tools.core.morph import FnMorph
from mmd_tools.core.sdef import FnSDEF
from mmd_tools.core.translations import FnTranslations
from mmd_tools.core.vmd.importer import BoneConverter, BoneConverterPoseMode
from mmd_tools.operators.misc import MoveObject
from mmd_tools.utils import saferelpath
from ...bpyutils import FnContext
from .. import pmx
from ..material import FnMaterial
from ..morph import FnMorph
from ..sdef import FnSDEF
from ..translations import FnTranslations
from ..vmd.importer import BoneConverter, BoneConverterPoseMode
from ...operators.misc import MoveObject
from ...utils import saferelpath


class _Vertex:
Expand Down
28 changes: 14 additions & 14 deletions mmd_tools/core/pmx/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
import bpy
from mathutils import Matrix, Vector

from mmd_tools import bpyutils, utils
from mmd_tools.bpyutils import FnContext
from mmd_tools.core import pmx
from mmd_tools.core.bone import FnBone
from mmd_tools.core.material import FnMaterial
from mmd_tools.core.model import FnModel, Model
from mmd_tools.core.morph import FnMorph
from mmd_tools.core.rigid_body import FnRigidBody
from mmd_tools.core.vmd.importer import BoneConverter
from mmd_tools.operators.misc import MoveObject
from ... import bpyutils, utils
from ...bpyutils import FnContext
from .. import pmx
from ..bone import FnBone
from ..material import FnMaterial
from ..model import FnModel, Model
from ..morph import FnMorph
from ..rigid_body import FnRigidBody
from ..vmd.importer import BoneConverter
from ...operators.misc import MoveObject

if TYPE_CHECKING:
from mmd_tools.properties.pose_bone import MMDBone
from mmd_tools.properties.root import MMDRoot
from ...properties.pose_bone import MMDBone
from ...properties.root import MMDRoot


class PMXImporter:
Expand Down Expand Up @@ -473,7 +473,7 @@ def __importBones(self):
def __importRigids(self):
start_time = time.time()
self.__rigidTable = {}
context = bpyutils.FnContext.ensure_context()
context = FnContext.ensure_context()
rigid_pool = FnRigidBody.new_rigid_body_objects(context, FnModel.ensure_rigid_group_object(context, self.__rig.rootObject()), len(self.__model.rigids))
for i, (rigid, rigid_obj) in enumerate(zip(self.__model.rigids, rigid_pool)):
loc = Vector(rigid.location).xzy * self.__scale
Expand Down Expand Up @@ -506,7 +506,7 @@ def __importRigids(self):

def __importJoints(self):
start_time = time.time()
context = bpyutils.FnContext.ensure_context()
context = FnContext.ensure_context()
joint_pool = FnRigidBody.new_joint_objects(context, FnModel.ensure_joint_group_object(context, self.__rig.rootObject()), len(self.__model.joints), FnModel.get_empty_display_size(self.__rig.rootObject()))
for i, (joint, joint_obj) in enumerate(zip(self.__model.joints, joint_pool)):
loc = Vector(joint.location).xzy * self.__scale
Expand Down
2 changes: 1 addition & 1 deletion mmd_tools/core/rigid_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import bpy
from mathutils import Euler, Vector

from mmd_tools.bpyutils import FnContext, Props
from ..bpyutils import FnContext, Props

SHAPE_SPHERE = 0
SHAPE_BOX = 1
Expand Down
2 changes: 1 addition & 1 deletion mmd_tools/core/sdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import bpy
from mathutils import Matrix, Vector

from mmd_tools.bpyutils import FnObject
from ..bpyutils import FnObject


def _hash(v):
Expand Down
12 changes: 6 additions & 6 deletions mmd_tools/core/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

import bpy

from mmd_tools.core.model import FnModel, Model
from mmd_tools.translations import DictionaryEnum
from mmd_tools.utils import convertLRToName, convertNameToLR
from ..translations import DictionaryEnum
from ..utils import convertLRToName, convertNameToLR
from .model import FnModel, Model

if TYPE_CHECKING:
from mmd_tools.properties.morph import _MorphBase
from mmd_tools.properties.root import MMDRoot
from mmd_tools.properties.translations import MMDTranslation, MMDTranslationElement, MMDTranslationElementIndex
from ..properties.morph import _MorphBase
from ..properties.root import MMDRoot
from ..properties.translations import MMDTranslation, MMDTranslationElement, MMDTranslationElementIndex


class MMDTranslationElementType(Enum):
Expand Down
Loading

0 comments on commit cd39e74

Please sign in to comment.