From f426237785722a71a7b0ea36ba847a9f4706eafd Mon Sep 17 00:00:00 2001 From: Will Snyder Date: Thu, 15 Oct 2020 14:44:17 -0500 Subject: [PATCH] Rotation fix (I think) --- addons/io_scene_swbf_msh/msh_anim_gather.py | 19 ++++++++----------- addons/io_scene_swbf_msh/msh_model_gather.py | 18 +++++++++++++++--- addons/io_scene_swbf_msh/msh_scene.py | 4 +++- addons/io_scene_swbf_msh/msh_scene_save.py | 13 ++++++++----- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/addons/io_scene_swbf_msh/msh_anim_gather.py b/addons/io_scene_swbf_msh/msh_anim_gather.py index 631839f..86de953 100644 --- a/addons/io_scene_swbf_msh/msh_anim_gather.py +++ b/addons/io_scene_swbf_msh/msh_anim_gather.py @@ -33,20 +33,17 @@ def gather_animdata(armature: bpy.types.Armature) -> List[Animation]: anim_data.bone_transforms[armature.parent.name].append(ModelTransform()) #for testing for bone in armature.pose.bones: + xform = ModelTransform() - - - vt = convert_vector_space(bone.location); - - xform.translation = Vector((vt.x * -1.0, vt.y, vt.z)) + xform.translation = convert_vector_space(bone.location) + xform.translation.x *= -1.0 xform.rotation = convert_rotation_space(bone.rotation_quaternion) - - ''' - xform.translation = bone.location - xform.rotation = bone.rotation_quaternion - + xform.rotation.x *= -1.0 + xform.rotation.y *= -1.0 + xform.rotation.z *= -1.0 + anim_data.bone_transforms[bone.name].append(xform) - ''' + return [anim_data] diff --git a/addons/io_scene_swbf_msh/msh_model_gather.py b/addons/io_scene_swbf_msh/msh_model_gather.py index 7b6e7fd..dd952f4 100644 --- a/addons/io_scene_swbf_msh/msh_model_gather.py +++ b/addons/io_scene_swbf_msh/msh_model_gather.py @@ -33,6 +33,9 @@ def gather_models(apply_modifiers: bool, export_target: str) -> List[Model]: else: obj = uneval_obj + if uneval_obj.type == "ARMATURE": + continue + check_for_bad_lod_suffix(obj) local_translation, local_rotation, _ = obj.matrix_local.decompose() @@ -44,8 +47,13 @@ def gather_models(apply_modifiers: bool, export_target: str) -> List[Model]: model.transform.rotation = convert_rotation_space(local_rotation) model.transform.translation = convert_vector_space(local_translation) + print("Adding model: " + model.name) + if obj.parent is not None: if obj.parent.type == "ARMATURE": + + model.parent = "DummyRoot" + skeleton = obj.parent parent_bone_name = obj.parent_bone @@ -80,18 +88,20 @@ def gather_models(apply_modifiers: bool, export_target: str) -> List[Model]: models_list.append(model) - + for bone in skeleton.data.bones: model = Model() model.name = bone.name - model.model_type = ModelType.NULL + model.model_type = ModelType.BONE model.hidden = False local_translation, local_rotation, _ = bone.matrix_local.decompose() model.transform.rotation = convert_rotation_space(local_rotation) model.transform.translation = convert_vector_space(local_translation) + print("Adding bone: " + model.name) + parent_name = bone.parent if parent_name is not None: model.parent = parent_name @@ -102,6 +112,8 @@ def gather_models(apply_modifiers: bool, export_target: str) -> List[Model]: model.parent = None models_list.append(model) + + return models_list @@ -231,7 +243,7 @@ def create_mesh_geometry(mesh: bpy.types.Mesh, is_skinned : bool) -> List[Geomet def get_model_type(obj: bpy.types.Object) -> ModelType: """ Get the ModelType for a Blender object. """ if obj.parent_type == "ARMATURE": - return ModelType.SKIN + return ModelType.SKIN if obj.type in MESH_OBJECT_TYPES: return ModelType.STATIC diff --git a/addons/io_scene_swbf_msh/msh_scene.py b/addons/io_scene_swbf_msh/msh_scene.py index 7fa5930..f19afa2 100644 --- a/addons/io_scene_swbf_msh/msh_scene.py +++ b/addons/io_scene_swbf_msh/msh_scene.py @@ -72,6 +72,7 @@ def create_scene(generate_triangle_strips: bool, apply_modifiers: bool, export_t #now that we've collected all models, we should remap WGHT indices... + ''' names_to_indices = {} for i,model in enumerate(scene.models): names_to_indices[model.name] = i; @@ -82,11 +83,12 @@ def create_scene(generate_triangle_strips: bool, apply_modifiers: bool, export_t for i in range(len(segment.weights)): vgroup_index = segment.weights[i][0] segment.weights[i][0] = names_to_indices[model.vgroups_to_modelnames_map[vgroup_index]] + ''' scene.materials = remove_unused_materials(scene.materials, scene.models) - #scene.anims = gather_animdata(bpy.context.scene.objects["Armature"]) + scene.anims = gather_animdata(bpy.context.scene.objects["Armature"]) return scene diff --git a/addons/io_scene_swbf_msh/msh_scene_save.py b/addons/io_scene_swbf_msh/msh_scene_save.py index 2fd0945..78c786c 100644 --- a/addons/io_scene_swbf_msh/msh_scene_save.py +++ b/addons/io_scene_swbf_msh/msh_scene_save.py @@ -28,9 +28,9 @@ def save_scene(output_file, scene: Scene): with msh2.create_child("MODL") as modl: _write_modl(modl, model, index, material_index, scene) - #with hedr.create_child("ANM2") as anm2: #simple for now - # for anim in scene.anims: - # _write_anm2(anm2, anim) + with hedr.create_child("ANM2") as anm2: #simple for now + for anim in scene.anims: + _write_anm2(anm2, anim) with hedr.create_child("CL1L"): pass @@ -129,12 +129,13 @@ def _write_modl(modl: Writer, model: Model, index: int, material_index: Dict[str for segment in model.geometry: with geom.create_child("SEGM") as segm: _write_segm(segm, segment, material_index) - + ''' if model.model_type == ModelType.SKIN: with modl.create_child("ENVL") as envl: envl.write_u32(len(scene.models)) for i in range(len(scene.models)): envl.write_u32(i) + ''' if model.collisionprimitive is not None: with modl.create_child("SWCI") as swci: @@ -165,12 +166,14 @@ def _write_segm(segm: Writer, segment: GeometrySegment, material_index: Dict[str for normal in segment.normals: nrml.write_f32(normal.x, normal.y, normal.z) + ''' if segment.weights is not None: with segm.create_child("WGHT") as wght: wght.write_u32(len(segment.weights) / 4) for weight in segment.weights: wght.write_u32(weight[0]) wght.write_f32(weight[1]) + ''' if segment.colors is not None: with segm.create_child("CLRL") as clrl: @@ -217,7 +220,7 @@ def _write_anm2(anm2: Writer, anim: Animation): cycl.write_u32(1) cycl.write_string(anim.name) - for _ in range(63 - len(anim.name)): + for _ in range(64 - (len(anim.name) + 1)): cycl.write_u8(0) cycl.write_f32(10.0) #test framerate