From ec37d4e650a92d74ea03575720796e4fdd6cb3ce Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 25 Jun 2022 20:03:55 -0400 Subject: [PATCH 1/3] Force flat-ish convex hulls to triangle mesh. These crash the engine, so don't export them. --- korman/exporter/physics.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/korman/exporter/physics.py b/korman/exporter/physics.py index 9532009..a8e397f 100644 --- a/korman/exporter/physics.py +++ b/korman/exporter/physics.py @@ -281,6 +281,15 @@ class PhysicsConverter: # bake them to convex hulls. Specifically, Windows 32-bit w/PhysX 2.6. Everything else just # needs to have us provide some friendlier data... with bmesh_from_object(bo) as mesh: + # Don't export flat planes as convex hulls - force them to triangle meshes. + volume = mesh.calc_volume() + if volume < 0.001: + self._report.warn( + "{}: Physical wants to be a convex hull but appears to be flat (volume={}), forcing to triangle mesh...", + bo.name, volume, indent=2 + ) + self._export_trimesh(bo, physical, local_space, mat) + if local_space: physical.pos = hsVector3(*mat.to_translation()) physical.rot = utils.quaternion(mat.to_quaternion()) From a3fc2cdabf33741d7b7cf4dab53fa47c0cc4e76f Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 25 Jun 2022 20:15:55 -0400 Subject: [PATCH 2/3] Refuse to export triangle mesh regions to MOUL. --- korman/exporter/physics.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/korman/exporter/physics.py b/korman/exporter/physics.py index a8e397f..1e5e133 100644 --- a/korman/exporter/physics.py +++ b/korman/exporter/physics.py @@ -264,6 +264,17 @@ class PhysicsConverter: self._report.warn("{}: Physical memberGroup overwritten!", bo.name, indent=2) physical.memberGroup = member_group + # Sanity checking: only TPotS/Havok fully supports triangle mesh detector regions. + # ODE and PhysX 4.1 outright do not support them, and PhysX 2.6 only offers partial support, + # so warn or explode as appropriate. Note that we test against the physical itself in case + # shenanigans were performed by some of the exporters. + if physical.memberGroup == plSimDefs.kGroupDetector and physical.boundsType in (plSimDefs.kExplicitBounds, plSimDefs.kProxyBounds): + msg = f"'{bo.name}': Triangle mesh regions are poorly supported. Use a convex hull or box instead." + if ver <= pvPots: + self._report.port(msg, indent=2) + else: + raise ExportError(msg) + self._apply_props(simIface, physical, kwargs) def _export_box(self, bo, physical, local_space, mat): From 87cc4e8d1b238291d858d5969098e8ad4c39c422 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 25 Jun 2022 20:26:34 -0400 Subject: [PATCH 3/3] Alert on triangle mesh regions. This makes the bounds selection RED when a region is marked as triangle mesh. The export will succeed for TPotS but fail for Myst V and MOUL. --- korman/nodes/node_conditions.py | 4 ++++ korman/ui/modifiers/region.py | 14 +++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/korman/nodes/node_conditions.py b/korman/nodes/node_conditions.py index 5ea931f..bb178cb 100644 --- a/korman/nodes/node_conditions.py +++ b/korman/nodes/node_conditions.py @@ -174,7 +174,9 @@ class PlasmaClickableRegionNode(idprops.IDPropObjectMixin, PlasmaNodeBase, bpy.t def draw_buttons(self, context, layout): layout.prop(self, "region_object", icon="MESH_DATA") + layout.alert = self.bounds == "trimesh" layout.prop(self, "bounds") + layout.alert = False def convert_subcondition(self, exporter, parent_bo, parent_so, logicmod): # REMEMBER: parent_so doesn't have to be the actual region scene object... @@ -379,7 +381,9 @@ class PlasmaVolumeSensorNode(idprops.IDPropObjectMixin, PlasmaNodeBase, bpy.type # Okay, if they changed the name of the ObData, that's THEIR problem... layout.prop(self, "region_object", icon="MESH_DATA") + layout.alert = self.bounds == "trimesh" layout.prop(self, "bounds") + layout.alert = False def get_key(self, exporter, parent_so): bo = self.region_object diff --git a/korman/ui/modifiers/region.py b/korman/ui/modifiers/region.py index 52eb6e7..bd0be1d 100644 --- a/korman/ui/modifiers/region.py +++ b/korman/ui/modifiers/region.py @@ -16,6 +16,12 @@ import bpy from .. import ui_camera +def _draw_bounds_prop(modifier, layout, context, *, local_prop: bool = False): + prop_source = modifier if local_prop else modifier.id_data.plasma_modifiers.collision + layout.alert = prop_source.bounds == "trimesh" + layout.prop(prop_source, "bounds") + layout.alert = False + def camera_rgn(modifier, layout, context): layout.prop(modifier, "camera_type") if modifier.camera_type == "manual": @@ -35,12 +41,11 @@ def camera_rgn(modifier, layout, context): ui_camera.draw_camera_manipulation_props)) def footstep(modifier, layout, context): - layout.prop(modifier, "bounds") + _draw_bounds_prop(modifier, layout, context, local_prop=True) layout.prop(modifier, "surface") def paniclink(modifier, layout, context): - phys_mod = context.object.plasma_modifiers.collision - layout.prop(phys_mod, "bounds") + _draw_bounds_prop(modifier, layout, context) layout.prop(modifier, "play_anim") def softvolume(modifier, layout, context): @@ -61,6 +66,5 @@ def softvolume(modifier, layout, context): def subworld_rgn(modifier, layout, context): layout.prop(modifier, "subworld") - collision_mod = modifier.id_data.plasma_modifiers.collision - layout.prop(collision_mod, "bounds") + _draw_bounds_prop(modifier, layout, context) layout.prop(modifier, "transition")