Bug fixes

- First attempt to get Chinese Characters to work, kinda working, but also not.
- Small bug fixes.
This commit is contained in:
Yusarina
2024-11-26 01:07:51 +00:00
parent c1fa65ebdd
commit 56706c859f
3 changed files with 59 additions and 10 deletions
+16 -4
View File
@@ -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]
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_obj = bpy.data.objects.new(f"{model_name}_Armature", armature)
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)
# Second pass: Set up hierarchy and orientations
for i, bone_data in enumerate(bones):
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)
# Create and apply orientation matrix
matrix = Matrix((x_axis, y_axis, z_axis)).to_3x3()
edit_bone.matrix = matrix
matrix_3x3 = Matrix((x_axis, y_axis, z_axis)).to_3x3()
matrix_4x4 = matrix_3x3.to_4x4()
edit_bone.matrix = matrix_4x4
bpy.ops.object.mode_set(mode='OBJECT')
return armature_obj
def assign_vertex_weights(obj: bpy.types.Object, vertices: list[PMXVertex], bones: list[PMXBone]):
# Pre-create vertex groups
vertex_groups = {}