Bug fixes
- First attempt to get Chinese Characters to work, kinda working, but also not. - Small bug fixes.
This commit is contained in:
+39
-2
@@ -119,12 +119,49 @@ def get_armatures_that_are_not_selected(self, context: Context) -> List[Tuple[st
|
|||||||
return [(obj.name, obj.name, "") for obj in bpy.data.objects if ((obj.type == 'ARMATURE') and (obj.name != context.scene.selected_armature))]
|
return [(obj.name, obj.name, "") for obj in bpy.data.objects if ((obj.type == 'ARMATURE') and (obj.name != context.scene.selected_armature))]
|
||||||
|
|
||||||
def get_selected_armature(context: Context) -> Optional[Object]:
|
def get_selected_armature(context: Context) -> Optional[Object]:
|
||||||
if context.scene.selected_armature:
|
try:
|
||||||
armature = bpy.data.objects.get(context.scene.selected_armature)
|
if hasattr(context.scene, 'selected_armature'):
|
||||||
|
armature_name = context.scene.selected_armature
|
||||||
|
if isinstance(armature_name, bytes):
|
||||||
|
try:
|
||||||
|
armature_name = armature_name.decode('utf-8')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
try:
|
||||||
|
armature_name = armature_name.decode('gbk') # For Chinese characters
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
try:
|
||||||
|
armature_name = armature_name.decode('shift-jis')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
armature_name = armature_name.decode('latin1')
|
||||||
|
|
||||||
|
if armature_name:
|
||||||
|
armature = bpy.data.objects.get(str(armature_name))
|
||||||
if is_valid_armature(armature):
|
if is_valid_armature(armature):
|
||||||
return armature
|
return armature
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_merge_armature_source(context: Context) -> Optional[Object]:
|
||||||
|
try:
|
||||||
|
if hasattr(context.scene, 'merge_armature_source'):
|
||||||
|
source_name = context.scene.merge_armature_source
|
||||||
|
if isinstance(source_name, bytes):
|
||||||
|
try:
|
||||||
|
source_name = source_name.decode('utf-8')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
try:
|
||||||
|
source_name = source_name.decode('shift-jis')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
source_name = source_name.decode('latin1', errors='ignore')
|
||||||
|
|
||||||
|
if source_name:
|
||||||
|
return bpy.data.objects.get(str(source_name))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def set_selected_armature(context: Context, armature: Optional[Object]) -> None:
|
def set_selected_armature(context: Context, armature: Optional[Object]) -> None:
|
||||||
context.scene.selected_armature = armature.name if armature else ""
|
context.scene.selected_armature = armature.name if armature else ""
|
||||||
|
|
||||||
|
|||||||
+16
-4
@@ -521,6 +521,19 @@ def setup_physics(obj: bpy.types.Object, armature_obj: bpy.types.Object, rigid_b
|
|||||||
constraint.limit_ang_z_upper = joint.angular_limit_max[2]
|
constraint.limit_ang_z_upper = joint.angular_limit_max[2]
|
||||||
|
|
||||||
def create_armature(model_name: str, bones: list[PMXBone]) -> bpy.types.Object:
|
def create_armature(model_name: str, bones: list[PMXBone]) -> bpy.types.Object:
|
||||||
|
# Handle CJK characters in model name
|
||||||
|
if isinstance(model_name, bytes):
|
||||||
|
try:
|
||||||
|
model_name = model_name.decode('gbk') # Try Chinese encoding first
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
try:
|
||||||
|
model_name = model_name.decode('utf-8')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
try:
|
||||||
|
model_name = model_name.decode('shift-jis')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
model_name = model_name.decode('latin1')
|
||||||
|
|
||||||
armature = bpy.data.armatures.new(f"{model_name}_Armature")
|
armature = bpy.data.armatures.new(f"{model_name}_Armature")
|
||||||
armature_obj = bpy.data.objects.new(f"{model_name}_Armature", armature)
|
armature_obj = bpy.data.objects.new(f"{model_name}_Armature", armature)
|
||||||
bpy.context.collection.objects.link(armature_obj)
|
bpy.context.collection.objects.link(armature_obj)
|
||||||
@@ -602,7 +615,6 @@ def create_armature(model_name: str, bones: list[PMXBone]) -> bpy.types.Object:
|
|||||||
|
|
||||||
edit_bones.append(edit_bone)
|
edit_bones.append(edit_bone)
|
||||||
|
|
||||||
|
|
||||||
# Second pass: Set up hierarchy and orientations
|
# Second pass: Set up hierarchy and orientations
|
||||||
for i, bone_data in enumerate(bones):
|
for i, bone_data in enumerate(bones):
|
||||||
edit_bone = edit_bones[i]
|
edit_bone = edit_bones[i]
|
||||||
@@ -625,14 +637,14 @@ def create_armature(model_name: str, bones: list[PMXBone]) -> bpy.types.Object:
|
|||||||
y_axis = z_axis.cross(x_axis)
|
y_axis = z_axis.cross(x_axis)
|
||||||
|
|
||||||
# Create and apply orientation matrix
|
# Create and apply orientation matrix
|
||||||
matrix = Matrix((x_axis, y_axis, z_axis)).to_3x3()
|
matrix_3x3 = Matrix((x_axis, y_axis, z_axis)).to_3x3()
|
||||||
edit_bone.matrix = matrix
|
matrix_4x4 = matrix_3x3.to_4x4()
|
||||||
|
edit_bone.matrix = matrix_4x4
|
||||||
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
return armature_obj
|
return armature_obj
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def assign_vertex_weights(obj: bpy.types.Object, vertices: list[PMXVertex], bones: list[PMXBone]):
|
def assign_vertex_weights(obj: bpy.types.Object, vertices: list[PMXVertex], bones: list[PMXBone]):
|
||||||
# Pre-create vertex groups
|
# Pre-create vertex groups
|
||||||
vertex_groups = {}
|
vertex_groups = {}
|
||||||
|
|||||||
@@ -264,8 +264,8 @@ class AvatarToolkit_OT_MergeArmatures(Operator):
|
|||||||
bl_options = {'REGISTER', 'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context: Context) -> bool:
|
def poll(cls, context):
|
||||||
return (common.get_selected_armature(context) is not None) and (context.scene.merge_armature_source is not None)
|
return (common.get_selected_armature(context) is not None) and (common.get_merge_armature_source(context) is not None)
|
||||||
|
|
||||||
def make_active(self, obj: bpy.types.Object, context: Context):
|
def make_active(self, obj: bpy.types.Object, context: Context):
|
||||||
context.view_layer.objects.active = obj
|
context.view_layer.objects.active = obj
|
||||||
|
|||||||
Reference in New Issue
Block a user