Holy shit this was a pain
- Truly fixes PMX Import lol, i messed up completely - Updated MMD Tools to use Cats One
This commit is contained in:
@@ -1,42 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2014 MMD Tools authors
|
||||
# This file was originally part of the MMD Tools add-on for Blender
|
||||
# You can find MMD Tools here: https://github.com/MMD-Blender/blender_mmd_tools
|
||||
# Neoneko has modified this file to work with Avatar Toolkit and may of made changes or improvements.
|
||||
# MMD Tools is licensed under the terms of the GNU General Public License version 3 (GPLv3) same as Avatar Toolkit.
|
||||
# This file is part of MMD Tools.
|
||||
|
||||
"""Properties for rigid bodies and joints"""
|
||||
|
||||
import bpy
|
||||
from typing import Optional, Any, Set, List, Dict, Tuple, Union
|
||||
from bpy.types import Context, Object, PropertyGroup, Material
|
||||
|
||||
from .. import bpyutils
|
||||
from ..core import rigid_body
|
||||
from ..core.rigid_body import RigidBodyMaterial, FnRigidBody
|
||||
from ..core.model import FnModel
|
||||
from ..core.rigid_body import FnRigidBody, RigidBodyMaterial
|
||||
from . import patch_library_overridable
|
||||
from ....core.logging_setup import logger
|
||||
|
||||
|
||||
def _updateCollisionGroup(prop: PropertyGroup, _context: Context) -> None:
|
||||
obj: Object = prop.id_data
|
||||
materials: List[Material] = obj.data.materials
|
||||
def _updateCollisionGroup(prop, _context):
|
||||
obj = prop.id_data
|
||||
materials = obj.data.materials
|
||||
if len(materials) == 0:
|
||||
materials.append(RigidBodyMaterial.getMaterial(prop.collision_group_number))
|
||||
else:
|
||||
obj.material_slots[0].material = RigidBodyMaterial.getMaterial(prop.collision_group_number)
|
||||
|
||||
|
||||
def _updateType(prop: PropertyGroup, _context: Context) -> None:
|
||||
obj: Object = prop.id_data
|
||||
def _updateType(prop, _context):
|
||||
obj = prop.id_data
|
||||
rb = obj.rigid_body
|
||||
if rb:
|
||||
rb.kinematic = int(prop.type) == rigid_body.MODE_STATIC
|
||||
|
||||
|
||||
def _updateShape(prop: PropertyGroup, _context: Context) -> None:
|
||||
obj: Object = prop.id_data
|
||||
def _updateShape(prop, _context):
|
||||
obj = prop.id_data
|
||||
|
||||
if len(obj.data.vertices) > 0:
|
||||
size = prop.size
|
||||
@@ -47,8 +40,8 @@ def _updateShape(prop: PropertyGroup, _context: Context) -> None:
|
||||
rb.collision_shape = prop.shape
|
||||
|
||||
|
||||
def _get_bone(prop: PropertyGroup) -> str:
|
||||
obj: Object = prop.id_data
|
||||
def _get_bone(prop):
|
||||
obj = prop.id_data
|
||||
relation = obj.constraints.get("mmd_tools_rigid_parent", None)
|
||||
if relation:
|
||||
arm = relation.target
|
||||
@@ -58,9 +51,9 @@ def _get_bone(prop: PropertyGroup) -> str:
|
||||
return prop.get("bone", "")
|
||||
|
||||
|
||||
def _set_bone(prop: PropertyGroup, value: str) -> None:
|
||||
bone_name: str = value
|
||||
obj: Object = prop.id_data
|
||||
def _set_bone(prop, value):
|
||||
bone_name = value
|
||||
obj = prop.id_data
|
||||
relation = obj.constraints.get("mmd_tools_rigid_parent", None)
|
||||
if relation is None:
|
||||
relation = obj.constraints.new("CHILD_OF")
|
||||
@@ -81,21 +74,24 @@ def _set_bone(prop: PropertyGroup, value: str) -> None:
|
||||
prop["bone"] = bone_name
|
||||
|
||||
|
||||
def _get_size(prop: PropertyGroup) -> Tuple[float, float, float]:
|
||||
def _get_size(prop):
|
||||
if prop.id_data.mmd_type != "RIGID_BODY":
|
||||
return (0, 0, 0)
|
||||
return FnRigidBody.get_rigid_body_size(prop.id_data)
|
||||
|
||||
|
||||
def _set_size(prop: PropertyGroup, value: Tuple[float, float, float]) -> None:
|
||||
obj: Object = prop.id_data
|
||||
def _set_size(prop, value):
|
||||
obj = prop.id_data
|
||||
assert obj.mode == "OBJECT" # not support other mode yet
|
||||
shape: str = prop.shape
|
||||
shape = prop.shape
|
||||
|
||||
mesh = obj.data
|
||||
rb = obj.rigid_body
|
||||
|
||||
if len(mesh.vertices) == 0 or rb is None or rb.collision_shape != shape:
|
||||
current_size = FnRigidBody.get_rigid_body_size(obj)
|
||||
is_zero_size = all(abs(s) < 1e-6 for s in current_size)
|
||||
|
||||
if len(mesh.vertices) == 0 or rb is None or rb.collision_shape != shape or is_zero_size:
|
||||
if shape == "SPHERE":
|
||||
bpyutils.makeSphere(
|
||||
radius=value[0],
|
||||
@@ -149,15 +145,15 @@ def _set_size(prop: PropertyGroup, value: Tuple[float, float, float]) -> None:
|
||||
mesh.update()
|
||||
|
||||
|
||||
def _get_rigid_name(prop: PropertyGroup) -> str:
|
||||
def _get_rigid_name(prop):
|
||||
return prop.get("name", "")
|
||||
|
||||
|
||||
def _set_rigid_name(prop: PropertyGroup, value: str) -> None:
|
||||
def _set_rigid_name(prop, value):
|
||||
prop["name"] = value
|
||||
|
||||
|
||||
class MMDRigidBody(PropertyGroup):
|
||||
class MMDRigidBody(bpy.types.PropertyGroup):
|
||||
name_j: bpy.props.StringProperty(
|
||||
name="Name",
|
||||
description="Japanese Name",
|
||||
@@ -230,18 +226,16 @@ class MMDRigidBody(PropertyGroup):
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def register() -> None:
|
||||
logger.debug("Registering MMDRigidBody property")
|
||||
def register():
|
||||
bpy.types.Object.mmd_rigid = patch_library_overridable(bpy.props.PointerProperty(type=MMDRigidBody))
|
||||
|
||||
@staticmethod
|
||||
def unregister() -> None:
|
||||
logger.debug("Unregistering MMDRigidBody property")
|
||||
def unregister():
|
||||
del bpy.types.Object.mmd_rigid
|
||||
|
||||
|
||||
def _updateSpringLinear(prop: PropertyGroup, context: Context) -> None:
|
||||
obj: Object = prop.id_data
|
||||
def _updateSpringLinear(prop, context):
|
||||
obj = prop.id_data
|
||||
rbc = obj.rigid_body_constraint
|
||||
if rbc:
|
||||
rbc.spring_stiffness_x = prop.spring_linear[0]
|
||||
@@ -249,8 +243,8 @@ def _updateSpringLinear(prop: PropertyGroup, context: Context) -> None:
|
||||
rbc.spring_stiffness_z = prop.spring_linear[2]
|
||||
|
||||
|
||||
def _updateSpringAngular(prop: PropertyGroup, context: Context) -> None:
|
||||
obj: Object = prop.id_data
|
||||
def _updateSpringAngular(prop, context):
|
||||
obj = prop.id_data
|
||||
rbc = obj.rigid_body_constraint
|
||||
if rbc and hasattr(rbc, "use_spring_ang_x"):
|
||||
rbc.spring_stiffness_ang_x = prop.spring_angular[0]
|
||||
@@ -258,7 +252,7 @@ def _updateSpringAngular(prop: PropertyGroup, context: Context) -> None:
|
||||
rbc.spring_stiffness_ang_z = prop.spring_angular[2]
|
||||
|
||||
|
||||
class MMDJoint(PropertyGroup):
|
||||
class MMDJoint(bpy.types.PropertyGroup):
|
||||
name_j: bpy.props.StringProperty(
|
||||
name="Name",
|
||||
description="Japanese Name",
|
||||
@@ -292,12 +286,9 @@ class MMDJoint(PropertyGroup):
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def register() -> None:
|
||||
logger.debug("Registering MMDJoint property")
|
||||
def register():
|
||||
bpy.types.Object.mmd_joint = patch_library_overridable(bpy.props.PointerProperty(type=MMDJoint))
|
||||
|
||||
@staticmethod
|
||||
def unregister() -> None:
|
||||
logger.debug("Unregistering MMDJoint property")
|
||||
def unregister():
|
||||
del bpy.types.Object.mmd_joint
|
||||
|
||||
|
||||
Reference in New Issue
Block a user