-
Notifications
You must be signed in to change notification settings - Fork 1
Simplifying Shapes
Sometimes an exact shape contains far more boxes than an outline needs. VoxLib has three helpers that trade accuracy for fewer boxes.
That trade is real: simplification fills some empty space and changes the geometry. Keep the original shape for collision, raycasting, and anything else that must be exact. Use the simplified copy only where a rougher outline is acceptable.
Reduces a shape to at most maxBoxes boxes (default 8) by filling some empty space:
import com.github.mystery2099.voxlib.combination.VoxelAssembly.simplifyForOutline
import com.github.mystery2099.voxlib.shapes.CommonShapes
val collisionShape = CommonShapes.createTable()
val outlineShape = collisionShape.simplifyForOutline(maxBoxes = 8)A common pairing keeps both:
companion object {
val COLLISION = CommonShapes.createTable()
val OUTLINE = COLLISION.simplifyForOutline()
}Collapses a shape to its bounding box in one call:
import com.github.mystery2099.voxlib.combination.VoxelAssembly.toBoundingBoxShape
val looseOutline = complexShape.toBoundingBoxShape()This is the blunt option. Use it when one loose box is good enough, such as a quick preview outline.
Builds a hollow box directly, without starting from another shape:
import com.github.mystery2099.voxlib.combination.VoxelAssembly.createOutlineShape
val hollow = createOutlineShape(
minX = 0, minY = 0, minZ = 0,
maxX = 16, maxY = 16, maxZ = 16,
thickness = 1
)The result is six thin panels forming the walls of the given volume, with the wall thickness controlled by thickness (default 1 block-unit). This shape is still assembled with vanilla VoxelShape operations; it is not intrinsically cheaper than a solid cuboid, it just has a hollow profile.
-
maxBoxesmust be at least 1. Other values throwIllegalArgumentException. - Empty input shapes are handled: bounding-box simplification of an empty shape is safe.
- Simplification is not cached the way unions and transformations are. Store simplified results in constants like any other fixed shape.
Do not use a simplified shape where exact geometry matters. In particular:
-
getShape/getCollisionShapeoverrides: use the exact shape. - Raycasting or
clipbehavior: use the exact shape. - Comparisons with vanilla shapes: use the exact shape.
The approximate result fills empty space between boxes, which changes isFull, collision responses, and outline silhouettes.