add "Generate Triangle Strips" option to enable faster .msh iteration
This commit is contained in:
parent
cfba9e85ce
commit
7fd46a1c2c
|
@ -60,14 +60,11 @@ from .msh_scene import create_scene
|
||||||
from .msh_scene_save import save_scene
|
from .msh_scene_save import save_scene
|
||||||
from .msh_material_properties import *
|
from .msh_material_properties import *
|
||||||
|
|
||||||
# ExportHelper is a helper class, defines filename and
|
class ExportMSH(Operator, ExportHelper):
|
||||||
# invoke() function which calls the file selector.
|
""" Export the current scene as a SWBF .msh file. """
|
||||||
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"
|
|
||||||
|
|
||||||
# ExportHelper mixin class uses this
|
bl_idname = "swbf_msh.export"
|
||||||
|
bl_label = "Export SWBF .msh File"
|
||||||
filename_ext = ".msh"
|
filename_ext = ".msh"
|
||||||
|
|
||||||
filter_glob: StringProperty(
|
filter_glob: StringProperty(
|
||||||
|
@ -76,38 +73,31 @@ class ExportSomeData(Operator, ExportHelper):
|
||||||
maxlen=255, # Max internal buffer length, longer would be clamped.
|
maxlen=255, # Max internal buffer length, longer would be clamped.
|
||||||
)
|
)
|
||||||
|
|
||||||
# List of operator properties, the attributes will be assigned
|
generate_triangle_strips: BoolProperty(
|
||||||
# to the class instance from the operator settings before calling.
|
name="Generate Triangle Strips",
|
||||||
use_setting: BoolProperty(
|
description="Triangle strip generation can be slow for meshes with thousands of faces "
|
||||||
name="Example Boolean",
|
"and is off by default to enable fast mesh iteration.\n\n"
|
||||||
description="Example Tooltip",
|
"In order to improve runtime performance and reduce munged model size you are "
|
||||||
default=True,
|
"**strongly** advised to turn it on for your 'final' export!",
|
||||||
)
|
default=False
|
||||||
|
|
||||||
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',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
with open(self.filepath, 'wb') as output_file:
|
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'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
# Only needed if you want to add into a dynamic menu
|
# Only needed if you want to add into a dynamic menu
|
||||||
def menu_func_export(self, context):
|
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():
|
def register():
|
||||||
bpy.utils.register_class(MaterialProperties)
|
bpy.utils.register_class(MaterialProperties)
|
||||||
bpy.utils.register_class(MaterialPropertiesPanel)
|
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.TOPBAR_MT_file_export.append(menu_func_export)
|
||||||
bpy.types.Material.swbf_msh = bpy.props.PointerProperty(type=MaterialProperties)
|
bpy.types.Material.swbf_msh = bpy.props.PointerProperty(type=MaterialProperties)
|
||||||
|
@ -116,11 +106,8 @@ def register():
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.utils.unregister_class(MaterialProperties)
|
bpy.utils.unregister_class(MaterialProperties)
|
||||||
bpy.utils.unregister_class(MaterialPropertiesPanel)
|
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)
|
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
register()
|
register()
|
||||||
|
|
||||||
# test call
|
|
||||||
# bpy.ops.export_test.some_data('INVOKE_DEFAULT')
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Scene:
|
||||||
materials: Dict[str, Material] = field(default_factory=dict)
|
materials: Dict[str, Material] = field(default_factory=dict)
|
||||||
models: List[Model] = field(default_factory=list)
|
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. """
|
""" Create a msh Scene from the active Blender scene. """
|
||||||
|
|
||||||
scene = Scene()
|
scene = Scene()
|
||||||
|
@ -55,7 +55,14 @@ def create_scene() -> Scene:
|
||||||
|
|
||||||
scene.models = gather_models()
|
scene.models = gather_models()
|
||||||
scene.models = sort_by_parent(scene.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):
|
if has_multiple_root_models(scene.models):
|
||||||
scene.models = reparent_model_roots(scene.models)
|
scene.models = reparent_model_roots(scene.models)
|
||||||
|
|
Loading…
Reference in New Issue