Browse Source

Merge pull request #336 from Hoikas/collider_fixes

A batch of collider usability improvements.
pull/346/head
Adam Johnson 2 years ago committed by GitHub
parent
commit
81d8918657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      korman/exporter/physics.py
  2. 4
      korman/nodes/node_conditions.py
  3. 14
      korman/ui/modifiers/region.py

20
korman/exporter/physics.py

@ -264,6 +264,17 @@ class PhysicsConverter:
self._report.warn("{}: Physical memberGroup overwritten!", bo.name, indent=2) self._report.warn("{}: Physical memberGroup overwritten!", bo.name, indent=2)
physical.memberGroup = member_group 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) self._apply_props(simIface, physical, kwargs)
def _export_box(self, bo, physical, local_space, mat): def _export_box(self, bo, physical, local_space, mat):
@ -281,6 +292,15 @@ class PhysicsConverter:
# bake them to convex hulls. Specifically, Windows 32-bit w/PhysX 2.6. Everything else just # bake them to convex hulls. Specifically, Windows 32-bit w/PhysX 2.6. Everything else just
# needs to have us provide some friendlier data... # needs to have us provide some friendlier data...
with bmesh_from_object(bo) as mesh: 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: if local_space:
physical.pos = hsVector3(*mat.to_translation()) physical.pos = hsVector3(*mat.to_translation())
physical.rot = utils.quaternion(mat.to_quaternion()) physical.rot = utils.quaternion(mat.to_quaternion())

4
korman/nodes/node_conditions.py

@ -174,7 +174,9 @@ class PlasmaClickableRegionNode(idprops.IDPropObjectMixin, PlasmaNodeBase, bpy.t
def draw_buttons(self, context, layout): def draw_buttons(self, context, layout):
layout.prop(self, "region_object", icon="MESH_DATA") layout.prop(self, "region_object", icon="MESH_DATA")
layout.alert = self.bounds == "trimesh"
layout.prop(self, "bounds") layout.prop(self, "bounds")
layout.alert = False
def convert_subcondition(self, exporter, parent_bo, parent_so, logicmod): def convert_subcondition(self, exporter, parent_bo, parent_so, logicmod):
# REMEMBER: parent_so doesn't have to be the actual region scene object... # 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... # Okay, if they changed the name of the ObData, that's THEIR problem...
layout.prop(self, "region_object", icon="MESH_DATA") layout.prop(self, "region_object", icon="MESH_DATA")
layout.alert = self.bounds == "trimesh"
layout.prop(self, "bounds") layout.prop(self, "bounds")
layout.alert = False
def get_key(self, exporter, parent_so): def get_key(self, exporter, parent_so):
bo = self.region_object bo = self.region_object

14
korman/ui/modifiers/region.py

@ -16,6 +16,12 @@
import bpy import bpy
from .. import ui_camera 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): def camera_rgn(modifier, layout, context):
layout.prop(modifier, "camera_type") layout.prop(modifier, "camera_type")
if modifier.camera_type == "manual": if modifier.camera_type == "manual":
@ -35,12 +41,11 @@ def camera_rgn(modifier, layout, context):
ui_camera.draw_camera_manipulation_props)) ui_camera.draw_camera_manipulation_props))
def footstep(modifier, layout, context): def footstep(modifier, layout, context):
layout.prop(modifier, "bounds") _draw_bounds_prop(modifier, layout, context, local_prop=True)
layout.prop(modifier, "surface") layout.prop(modifier, "surface")
def paniclink(modifier, layout, context): def paniclink(modifier, layout, context):
phys_mod = context.object.plasma_modifiers.collision _draw_bounds_prop(modifier, layout, context)
layout.prop(phys_mod, "bounds")
layout.prop(modifier, "play_anim") layout.prop(modifier, "play_anim")
def softvolume(modifier, layout, context): def softvolume(modifier, layout, context):
@ -61,6 +66,5 @@ def softvolume(modifier, layout, context):
def subworld_rgn(modifier, layout, context): def subworld_rgn(modifier, layout, context):
layout.prop(modifier, "subworld") layout.prop(modifier, "subworld")
collision_mod = modifier.id_data.plasma_modifiers.collision _draw_bounds_prop(modifier, layout, context)
layout.prop(collision_mod, "bounds")
layout.prop(modifier, "transition") layout.prop(modifier, "transition")

Loading…
Cancel
Save