Browse Source

Use Blender's convex hull baking for hull bounds

This moves convex hull generation from the file serialization stage to
the object export stage. No longer are we dependent on spotty library
support for proper convex hulls.
pull/66/head
Adam Johnson 7 years ago
parent
commit
84f43a024c
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 32
      korman/exporter/physics.py

32
korman/exporter/physics.py

@ -37,11 +37,14 @@ class PhysicsConverter:
indices += (v[0], v[2], v[3],) indices += (v[0], v[2], v[3],)
return indices return indices
def _convert_mesh_data(self, bo, physical, indices=True): def _convert_mesh_data(self, bo, physical, indices=True, mesh_func=None):
mesh = bo.to_mesh(bpy.context.scene, True, "RENDER", calc_tessface=False) mesh = bo.to_mesh(bpy.context.scene, True, "RENDER", calc_tessface=False)
mat = bo.matrix_world mat = bo.matrix_world
with TemporaryObject(mesh, bpy.data.meshes.remove) as mesh: with TemporaryObject(mesh, bpy.data.meshes.remove):
if mesh_func is not None:
mesh_func(mesh)
# We can only use the plPhysical xforms if there is a CI... # We can only use the plPhysical xforms if there is a CI...
if self._exporter().has_coordiface(bo): if self._exporter().has_coordiface(bo):
mesh.update(calc_tessface=indices) mesh.update(calc_tessface=indices)
@ -81,7 +84,7 @@ class PhysicsConverter:
physical.sceneNode = self._mgr.get_scene_node(bl=bo) physical.sceneNode = self._mgr.get_scene_node(bl=bo)
mesh = bo.to_mesh(bpy.context.scene, True, "RENDER", calc_tessface=False) mesh = bo.to_mesh(bpy.context.scene, True, "RENDER", calc_tessface=False)
with TemporaryObject(mesh, bpy.data.meshes.remove) as mesh: with TemporaryObject(mesh, bpy.data.meshes.remove):
# We will apply all xform, seeing as how this is a special case... # We will apply all xform, seeing as how this is a special case...
mesh.transform(bo.matrix_world) mesh.transform(bo.matrix_world)
mesh.update(calc_tessface=True) mesh.update(calc_tessface=True)
@ -140,12 +143,23 @@ class PhysicsConverter:
"""Exports convex hull bounds based on the object""" """Exports convex hull bounds based on the object"""
physical.boundsType = plSimDefs.kHullBounds physical.boundsType = plSimDefs.kHullBounds
vertices = self._convert_mesh_data(bo, physical, indices=False) # Only certain builds of libHSPlasma are able to take artist generated triangle soups and
# --- TODO --- # bake them to convex hulls. Specifically, Windows 32-bit w/PhysX 2.6. Everything else just
# Until we have real convex hull processing, simply dump the verts into the physical # needs to have us provide some friendlier data...
# Note that PyPRP has always done this... PhysX will optimize this for us. So, it's not def _bake_hull(mesh):
# the end of the world (but it is evil). # The bmesh API for doing this is trash, so we will link this temporary mesh to an
physical.verts = vertices # even more temporary object so we can use the traditional operator.
# Unless you want to write some code to do this by hand...??? (not me)
bo = bpy.data.objects.new("BMeshSucks", mesh)
bpy.context.scene.objects.link(bo)
with TemporaryObject(bo, bpy.data.objects.remove):
bpy.context.scene.objects.active = bo
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.convex_hull(use_existing_faces=False)
bpy.ops.object.mode_set(mode="OBJECT")
physical.verts = self._convert_mesh_data(bo, physical, indices=False, mesh_func=_bake_hull)
def _export_sphere(self, bo, physical): def _export_sphere(self, bo, physical):
"""Exports sphere bounds based on the object""" """Exports sphere bounds based on the object"""

Loading…
Cancel
Save