From aa18f5c2b78de67071db052882d0c11d114101f8 Mon Sep 17 00:00:00 2001 From: SleepKiller Date: Wed, 20 Nov 2019 03:33:01 +1300 Subject: [PATCH] raise an error when an object creates a .msh segment with too many vertices --- README.md | 4 ++-- addons/io_scene_swbf_msh/msh_model_gather.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09bf295..04f953b 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,10 @@ Can't imagine this coming up much (Maybe if you're model is just for collisions This shouldn't be relevant as any mesh that you haven't assigned a material to is likely to just be collision geometry or shadow geometry. ### Work to be done -- [ ] Raise an error when a .msh segment has more than 32767 vertices. +- [x] Raise an error when a .msh segment has more than 32767 vertices. - [x] Convert from Blender's coordinate space to .msh cooordinate space. - [x] Add support for exporting materials. Blender's materials are all based around it's own renderers, so possibly going to need custom UI and properties in order to provide something useful for .msh files. -- [ ] Add support for collision primitives. Blender doesn't seam to support having basic boxes, cylinders or spheres so it's likely some wacky rules and conventions will need to be used by the modeler. "Add a 1m mesh primitive, have "sphere/box/cylinder" in the name and control the size with the object's scale." Less intuitive than I'd like but it might be the best course of action. +- [x] Add support for collision primitives. Blender doesn't seam to support having basic boxes, cylinders or spheres so it's likely some wacky rules and conventions will need to be used by the modeler. "Add a 1m mesh primitive, have "sphere/box/cylinder" in the name and control the size with the object's scale." Less intuitive than I'd like but it might be the best course of action. - [ ] Investigate and add support for exporting bones and vertex weights. - [ ] Investigate and add support for exporting animations. - [ ] Investigate if anything special needs to be done for lod/lowres exporting. diff --git a/addons/io_scene_swbf_msh/msh_model_gather.py b/addons/io_scene_swbf_msh/msh_model_gather.py index 37ac6a5..4ec5c66 100644 --- a/addons/io_scene_swbf_msh/msh_model_gather.py +++ b/addons/io_scene_swbf_msh/msh_model_gather.py @@ -11,6 +11,7 @@ from .msh_utilities import * 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]: """ Gathers the Blender objects from the current scene and returns them as a list of @@ -47,6 +48,12 @@ def gather_models() -> List[Model]: _, _, world_scale = obj.matrix_world.decompose() world_scale = convert_scale_space(world_scale) scale_segments(world_scale, model.geometry) + + for segment in model.geometry: + if len(segment.positions) > MAX_MSH_VERTEX_COUNT: + raise RuntimeError(f"Object '{obj.name}' has resulted in a .msh geometry segment that has " + f"more than {MAX_MSH_VERTEX_COUNT} vertices! Split the object's mesh up " + f"and try again!") if get_is_collision_primitive(obj): model.collisionprimitive = get_collision_primitive(obj)