add Apply Modifiers export property

This commit is contained in:
SleepKiller
2019-11-20 19:18:49 +13:00
parent a3a824fe9c
commit f3cbc90651
4 changed files with 19 additions and 5 deletions

View File

@@ -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'}

View File

@@ -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()

View File

@@ -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: