From 7fd46a1c2cccf5e3a4c111d953dd22aad9a5edcc Mon Sep 17 00:00:00 2001 From: SleepKiller Date: Wed, 20 Nov 2019 15:17:25 +1300 Subject: [PATCH] add "Generate Triangle Strips" option to enable faster .msh iteration --- addons/io_scene_swbf_msh/__init__.py | 47 ++++++++++----------------- addons/io_scene_swbf_msh/msh_scene.py | 11 +++++-- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/addons/io_scene_swbf_msh/__init__.py b/addons/io_scene_swbf_msh/__init__.py index 2ad9fe7..3d28326 100644 --- a/addons/io_scene_swbf_msh/__init__.py +++ b/addons/io_scene_swbf_msh/__init__.py @@ -60,14 +60,11 @@ from .msh_scene import create_scene from .msh_scene_save import save_scene from .msh_material_properties import * -# ExportHelper is a helper class, defines filename and -# invoke() function which calls the file selector. -class ExportSomeData(Operator, ExportHelper): - """This appears in the tooltip of the operator and in the generated docs""" - bl_idname = "export_test.some_data" # important since its how bpy.ops.import_test.some_data is constructed - bl_label = "Export Some Data" +class ExportMSH(Operator, ExportHelper): + """ Export the current scene as a SWBF .msh file. """ - # ExportHelper mixin class uses this + bl_idname = "swbf_msh.export" + bl_label = "Export SWBF .msh File" filename_ext = ".msh" filter_glob: StringProperty( @@ -76,38 +73,31 @@ class ExportSomeData(Operator, ExportHelper): maxlen=255, # Max internal buffer length, longer would be clamped. ) - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - use_setting: BoolProperty( - name="Example Boolean", - description="Example Tooltip", - default=True, - ) - - type: EnumProperty( - name="Example Enum", - description="Choose between two items", - items=( - ('OPT_A', "First Option", "Description one"), - ('OPT_B', "Second Option", "Description two"), - ), - default='OPT_A', + generate_triangle_strips: BoolProperty( + name="Generate Triangle Strips", + description="Triangle strip generation can be slow for meshes with thousands of faces " + "and is off by default to enable fast mesh iteration.\n\n" + "In order to improve runtime performance and reduce munged model size you are " + "**strongly** advised to turn it on for your 'final' export!", + default=False ) def execute(self, context): with open(self.filepath, 'wb') as output_file: - save_scene(output_file, create_scene()) + save_scene( + output_file=output_file, + scene=create_scene(generate_triangle_strips=self.generate_triangle_strips)) return {'FINISHED'} # Only needed if you want to add into a dynamic menu def menu_func_export(self, context): - self.layout.operator(ExportSomeData.bl_idname, text="SWBF msh (.msh)") + self.layout.operator(ExportMSH.bl_idname, text="SWBF msh (.msh)") def register(): bpy.utils.register_class(MaterialProperties) bpy.utils.register_class(MaterialPropertiesPanel) - bpy.utils.register_class(ExportSomeData) + bpy.utils.register_class(ExportMSH) bpy.types.TOPBAR_MT_file_export.append(menu_func_export) bpy.types.Material.swbf_msh = bpy.props.PointerProperty(type=MaterialProperties) @@ -116,11 +106,8 @@ def register(): def unregister(): bpy.utils.unregister_class(MaterialProperties) bpy.utils.unregister_class(MaterialPropertiesPanel) - bpy.utils.unregister_class(ExportSomeData) + bpy.utils.unregister_class(ExportMSH) bpy.types.TOPBAR_MT_file_export.remove(menu_func_export) if __name__ == "__main__": register() - - # test call - # bpy.ops.export_test.some_data('INVOKE_DEFAULT') diff --git a/addons/io_scene_swbf_msh/msh_scene.py b/addons/io_scene_swbf_msh/msh_scene.py index 0046854..7d711c2 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() -> Scene: +def create_scene(generate_triangle_strips: bool) -> Scene: """ Create a msh Scene from the active Blender scene. """ scene = Scene() @@ -55,7 +55,14 @@ def create_scene() -> Scene: scene.models = gather_models() scene.models = sort_by_parent(scene.models) - scene.models = create_models_triangle_strips(scene.models) + + if generate_triangle_strips: + scene.models = create_models_triangle_strips(scene.models) + else: + for model in scene.models: + if model.geometry: + for segment in model.geometry: + segment.triangle_strips = segment.triangles if has_multiple_root_models(scene.models): scene.models = reparent_model_roots(scene.models)