From f3cbc90651069dd31674d36d140292cea1846020 Mon Sep 17 00:00:00 2001 From: SleepKiller Date: Wed, 20 Nov 2019 19:18:49 +1300 Subject: [PATCH] add Apply Modifiers export property --- addons/io_scene_swbf_msh/__init__.py | 10 +++++++++- addons/io_scene_swbf_msh/msh_model_gather.py | 7 +++++-- addons/io_scene_swbf_msh/msh_scene.py | 4 ++-- docs/reference_manual.md | 3 +++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/addons/io_scene_swbf_msh/__init__.py b/addons/io_scene_swbf_msh/__init__.py index 3d28326..97c8e70 100644 --- a/addons/io_scene_swbf_msh/__init__.py +++ b/addons/io_scene_swbf_msh/__init__.py @@ -82,11 +82,19 @@ class ExportMSH(Operator, ExportHelper): default=False ) + apply_modifiers: BoolProperty( + name="Apply Modifiers", + description="Whether to apply Modifiers during export or not.", + default=True + ) + def execute(self, context): with open(self.filepath, 'wb') as output_file: save_scene( output_file=output_file, - scene=create_scene(generate_triangle_strips=self.generate_triangle_strips)) + scene=create_scene( + generate_triangle_strips=self.generate_triangle_strips, + apply_modifiers=self.apply_modifiers)) return {'FINISHED'} diff --git a/addons/io_scene_swbf_msh/msh_model_gather.py b/addons/io_scene_swbf_msh/msh_model_gather.py index 8e20634..dc67270 100644 --- a/addons/io_scene_swbf_msh/msh_model_gather.py +++ b/addons/io_scene_swbf_msh/msh_model_gather.py @@ -13,7 +13,7 @@ SKIPPED_OBJECT_TYPES = {"LATTICE", "CAMERA", "LIGHT", "SPEAKER", "LIGHT_PROBE"} MESH_OBJECT_TYPES = {"MESH", "CURVE", "SURFACE", "META", "FONT", "GPENCIL"} MAX_MSH_VERTEX_COUNT = 32767 -def gather_models() -> List[Model]: +def gather_models(apply_modifiers: bool) -> List[Model]: """ Gathers the Blender objects from the current scene and returns them as a list of Model objects. """ @@ -26,7 +26,10 @@ def gather_models() -> List[Model]: if uneval_obj.type in SKIPPED_OBJECT_TYPES and uneval_obj.name not in parents: continue - obj = uneval_obj.evaluated_get(depsgraph) + if apply_modifiers: + obj = uneval_obj.evaluated_get(depsgraph) + else: + obj = uneval_obj local_translation, local_rotation, _ = obj.matrix_local.decompose() diff --git a/addons/io_scene_swbf_msh/msh_scene.py b/addons/io_scene_swbf_msh/msh_scene.py index 7d711c2..64c7770 100644 --- a/addons/io_scene_swbf_msh/msh_scene.py +++ b/addons/io_scene_swbf_msh/msh_scene.py @@ -44,7 +44,7 @@ class Scene: materials: Dict[str, Material] = field(default_factory=dict) models: List[Model] = field(default_factory=list) -def create_scene(generate_triangle_strips: bool) -> Scene: +def create_scene(generate_triangle_strips: bool, apply_modifiers: bool) -> Scene: """ Create a msh Scene from the active Blender scene. """ scene = Scene() @@ -53,7 +53,7 @@ def create_scene(generate_triangle_strips: bool) -> Scene: scene.materials = gather_materials() - scene.models = gather_models() + scene.models = gather_models(apply_modifiers=apply_modifiers) scene.models = sort_by_parent(scene.models) if generate_triangle_strips: diff --git a/docs/reference_manual.md b/docs/reference_manual.md index 8f27911..ee0fcea 100644 --- a/docs/reference_manual.md +++ b/docs/reference_manual.md @@ -14,6 +14,9 @@ In order to improve runtime performance and reduce munged model size you are **s For very complex scenes with meshes that have tens of thousands (or more) faces Blender may freeze up for a couple minutes while triangle strips are generated. Either minimize it and do something else on your PC while you wait and it'll eventually finish. +#### Apply Modifiers +Whether to apply [Modifiers](https://docs.blender.org/manual/en/latest/modeling/modifiers/index.html) during export or not. + ### Export Failures There should be few things that can cause an export to fail. Should you encounter one you can consult the list below for how to remedy the situation. If you're error isn't on the list then feel free to [Open an issue](https://github.com/SleepKiller/SWBF-msh-Blender-Export/issues/new), remember to attach a .blend file that reproduces the issue.