center of the box on the horizontal axis
center of the box on the vertical axis
center of the box on the depth axis
width of the box
height of the box
depth of the box
OptionalcollisionOptionalcollisionOptional per-shape collision settings, honoured by Body#addShape
and defaulted there. Declared rather than initialized: the body writes
them when the shape joins it, so a class field here would emit an
undefined own property on every shape ever built. See addShape for
the table of defaults and what each one does.
half the box size on each axis. Always non-negative; a negative extent passed to Box3d#setShape is stored as its magnitude, since a box with a mirrored axis has no meaning to the narrowphase.
Optionalisfalse takes this shape out of collision without removing it
Optionalistrue reports contacts but skips the position correction
the center of the box, as an offset from the owning body's position
the shape type (used internally)
depth of the box
height of the box
width of the box
true if this box contains the given point
point x, or a vector carrying the whole point
Optionaly: number = 0
point y
Optionalz: number = 0
point z
the 2D XY footprint of this box.
Deliberately 2D: this is the Renderable#getBounds contract that Body and the broadphase pre-gate already speak. For the depth extent use Box3d#getBounds3d.
the XY footprint
set new position and size for this box
center of the box on the horizontal axis
center of the box on the vertical axis
center of the box on the depth axis
width of the box
height of the box
depth of the box
this box, for chaining
An axis-aligned 3D box, usable as a Body collision shape.
One of the two shapes that let a body collide along Z as well as X and Y, the other being Sphere. The planar shapes (Polygon, Rect, RoundRect, Ellipse) are resolved by the 2D SAT narrowphase, which can only ever produce a 2D pushback — see ResponseObject#overlapV. A
Box3dpair is instead resolved by an AABB-vs-AABB narrowphase that also fills ResponseObject#overlapZ.A
Box3dis world-axis-aligned and cannot be oriented, which makes it the shape for walls, floors and crates, and the wrong one for anything that turns. Reach for aSpherethere.Coordinate convention matches the rest of melonJS 3D code (see Camera3d): Y-down, +Z forward / away from the camera.
Position is the CENTER
Unlike Rect (top-left) and like Ellipse (center),
posis the box center. That matches how 3D objects are placed everywhere else in the engine — Mesh, Sprite3d and the ground-shadow footprint all work from a center plus half-extents — and it keeps the narrowphase free of corner/center conversions on the hot path.Mixing with 2D shapes
A
Box3dcan collide with a planar shape. The planar shape is treated as unbounded along Z (an infinitely extruded prism of its own outline), so the pair degrades to the ordinary 2D test on the XY footprint and the box's z never causes it to miss. This keeps an existing 2D game working unchanged when a singleBox3dbody is introduced: its world shapes go on colliding exactly as before. UsecollisionType/collisionMaskto opt specific shapes out of a 3D body.Example