Browse Source

Add box region helper for non-cube boxes.

Entry cameras need skinny detector boxes, not cubes. This allows the
region to be exited with basically any movement.
pull/395/head
Adam Johnson 10 months ago
parent
commit
5085cf5814
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 48
      korman/exporter/utils.py
  2. 2
      korman/properties/modifiers/logic.py

48
korman/exporter/utils.py

@ -123,27 +123,53 @@ def create_camera_object(name: str) -> bpy.types.Object:
bpy.context.scene.objects.link(cam_obj) bpy.context.scene.objects.link(cam_obj)
return cam_obj return cam_obj
class CubeRegionOrigin(enum.Enum): class RegionOrigin(enum.Enum):
center = enum.auto() center = enum.auto()
bottom = enum.auto() bottom = enum.auto()
def create_cube_region(name: str, size: float, owner_object: bpy.types.Object, origin: CubeRegionOrigin = CubeRegionOrigin.center) -> bpy.types.Object: def create_cube_region(name: str, size: float, owner_object: bpy.types.Object, origin: RegionOrigin = RegionOrigin.center) -> bpy.types.Object:
"""Create a cube shaped region object""" """Create a cube shaped region object"""
# Proxy over to the generic rectangular prism implementation to
# ensure that it is well tested.
return create_box_region(name, (size, size, size), owner_object, origin)
def create_box_region(
name: str, size: Union[Tuple[float, float, float], mathutils.Vector],
owner_object: bpy.types.Object,
origin: RegionOrigin = RegionOrigin.center
) -> bpy.types.Object:
"""Create a rectangular prism region object"""
if not isinstance(size, mathutils.Vector):
size = mathutils.Vector(size)
region_object = BMeshObject(name) region_object = BMeshObject(name)
region_object.plasma_object.enabled = True region_object.plasma_object.enabled = True
region_object.plasma_object.page = owner_object.plasma_object.page region_object.plasma_object.page = owner_object.plasma_object.page
region_object.hide_render = True region_object.hide_render = True
with region_object as bm: with region_object as bm:
bmesh.ops.create_cube(bm, size=(size)) center = owner_object.matrix_world.translation
origin = owner_object.matrix_world.translation - region_object.matrix_world.translation if origin == RegionOrigin.bottom:
if origin == CubeRegionOrigin.bottom: center.z += size.z * 0.5
origin.z += size * 0.5 vert_src = [
bmesh.ops.transform( (center.x + size.x * 0.5, center.y + size.y * 0.5, center.z + size.z * 0.5),
bm, (center.x + size.x * 0.5, center.y + size.y * 0.5, center.z - size.z * 0.5),
matrix=mathutils.Matrix.Translation(origin), (center.x + size.x * 0.5, center.y - size.y * 0.5, center.z + size.z * 0.5),
space=region_object.matrix_world, verts=bm.verts (center.x + size.x * 0.5, center.y - size.y * 0.5, center.z - size.z * 0.5),
) (center.x - size.x * 0.5, center.y + size.y * 0.5, center.z + size.z * 0.5),
(center.x - size.x * 0.5, center.y + size.y * 0.5, center.z - size.z * 0.5),
(center.x - size.x * 0.5, center.y - size.y * 0.5, center.z + size.z * 0.5),
(center.x - size.x * 0.5, center.y - size.y * 0.5, center.z - size.z * 0.5),
]
verts = [bm.verts.new(i) for i in vert_src]
new_face = bm.faces.new
new_face((verts[0], verts[1], verts[3], verts[2])) # X+
new_face((verts[4], verts[5], verts[7], verts[6])) # X-
new_face((verts[0], verts[1], verts[5], verts[4])) # Y+
new_face((verts[2], verts[3], verts[7], verts[6])) # Y-
new_face((verts[0], verts[2], verts[6], verts[4])) # Z+
new_face((verts[1], verts[3], verts[7], verts[5])) # Z-
return region_object.release() return region_object.release()
@contextmanager @contextmanager

2
korman/properties/modifiers/logic.py

@ -133,7 +133,7 @@ class PlasmaSpawnPoint(PlasmaModifierProperties, PlasmaModifierLogicWiz):
if self.exit_region is None: if self.exit_region is None:
self.exit_region = yield utils.create_cube_region( self.exit_region = yield utils.create_cube_region(
f"{self.key_name}_ExitRgn", 6.0, f"{self.key_name}_ExitRgn", 6.0,
bo, utils.CubeRegionOrigin.bottom bo, utils.RegionOrigin.bottom
) )
yield self.convert_logic(bo) yield self.convert_logic(bo)

Loading…
Cancel
Save