Armature offset bug fix
This commit is contained in:
parent
f88b62c986
commit
f69ed3f143
|
@ -60,6 +60,7 @@ def required_skeleton_to_armature(required_skeleton : List[Model], model_map : D
|
||||||
|
|
||||||
armature = bpy.data.armatures.new("skeleton")
|
armature = bpy.data.armatures.new("skeleton")
|
||||||
armature_obj = bpy.data.objects.new("skeleton", armature)
|
armature_obj = bpy.data.objects.new("skeleton", armature)
|
||||||
|
armature_obj.matrix_world = Matrix.Identity(4)
|
||||||
bpy.context.view_layer.active_layer_collection.collection.objects.link(armature_obj)
|
bpy.context.view_layer.active_layer_collection.collection.objects.link(armature_obj)
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,6 +84,7 @@ def required_skeleton_to_armature(required_skeleton : List[Model], model_map : D
|
||||||
'''
|
'''
|
||||||
bone_obj = model_map[bone.name]
|
bone_obj = model_map[bone.name]
|
||||||
|
|
||||||
|
# TODO: This will lead to mistranslated bones when armature is reparented!
|
||||||
edit_bone.matrix = bone_obj.matrix_world
|
edit_bone.matrix = bone_obj.matrix_world
|
||||||
edit_bone.tail = bone_obj.matrix_world @ Vector((0.0,1.0,0.0))
|
edit_bone.tail = bone_obj.matrix_world @ Vector((0.0,1.0,0.0))
|
||||||
|
|
||||||
|
@ -209,3 +211,4 @@ def extract_required_skeleton(scene: Scene) -> List[Model]:
|
||||||
#stacked_transform = model_transform_to_matrix(curr_ancestor.transform) @ stacked_transform
|
#stacked_transform = model_transform_to_matrix(curr_ancestor.transform) @ stacked_transform
|
||||||
|
|
||||||
return required_skeleton_models
|
return required_skeleton_models
|
||||||
|
|
||||||
|
|
|
@ -178,6 +178,8 @@ def extract_materials(folder_path: str, scene: Scene) -> Dict[str, bpy.types.Mat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def extract_scene(filepath: str, scene: Scene):
|
def extract_scene(filepath: str, scene: Scene):
|
||||||
|
|
||||||
folder = os.path.join(os.path.dirname(filepath),"")
|
folder = os.path.join(os.path.dirname(filepath),"")
|
||||||
|
@ -225,8 +227,10 @@ def extract_scene(filepath: str, scene: Scene):
|
||||||
|
|
||||||
has_skin = True
|
has_skin = True
|
||||||
|
|
||||||
|
worldmat = curr_obj.matrix_world
|
||||||
curr_obj.parent = armature
|
curr_obj.parent = armature
|
||||||
curr_obj.parent_type = 'ARMATURE'
|
curr_obj.parent_type = 'ARMATURE'
|
||||||
|
curr_obj.matrix_world = worldmat
|
||||||
|
|
||||||
# Parent the object to a bone if necessary
|
# Parent the object to a bone if necessary
|
||||||
else:
|
else:
|
||||||
|
@ -262,7 +266,11 @@ def extract_scene(filepath: str, scene: Scene):
|
||||||
|
|
||||||
# Now we reparent the armature to the node (armature_reparent_obj) we just found
|
# Now we reparent the armature to the node (armature_reparent_obj) we just found
|
||||||
if armature_reparent_obj is not None and armature.name != armature_reparent_obj.name:
|
if armature_reparent_obj is not None and armature.name != armature_reparent_obj.name:
|
||||||
|
world_tx = armature.matrix_world
|
||||||
armature.parent = armature_reparent_obj
|
armature.parent = armature_reparent_obj
|
||||||
|
armature.matrix_basis = Matrix()
|
||||||
|
armature.matrix_parent_inverse = Matrix()
|
||||||
|
armature.matrix_world = Matrix.Identity(4)
|
||||||
|
|
||||||
|
|
||||||
# If an bone exists in the armature, delete its
|
# If an bone exists in the armature, delete its
|
||||||
|
@ -273,6 +281,8 @@ def extract_scene(filepath: str, scene: Scene):
|
||||||
bpy.data.objects.remove(model_to_remove, do_unlink=True)
|
bpy.data.objects.remove(model_to_remove, do_unlink=True)
|
||||||
model_map.pop(bone.name)
|
model_map.pop(bone.name)
|
||||||
|
|
||||||
|
armature.matrix_world = Matrix.Identity(4)
|
||||||
|
|
||||||
|
|
||||||
# Lastly, hide all that is hidden in the msh scene
|
# Lastly, hide all that is hidden in the msh scene
|
||||||
for model in scene.models:
|
for model in scene.models:
|
||||||
|
@ -280,3 +290,4 @@ def extract_scene(filepath: str, scene: Scene):
|
||||||
obj = model_map[model.name]
|
obj = model_map[model.name]
|
||||||
if get_is_model_hidden(obj) and len(obj.children) == 0:
|
if get_is_model_hidden(obj) and len(obj.children) == 0:
|
||||||
obj.hide_set(True)
|
obj.hide_set(True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue