Create a 3D object and add it to the object list
pos3D Vector3 optionalWorld space position
mesh Mesh optionalMesh to draw, undefined draws nothing
tileInfo TileInfo|TextureInfo optionalTexture, mesh uvs map across the tile; a whole TextureInfo becomes
the tile that covers it
color Color optionalTint
class Spinner extends EngineObject3D
{
constructor(pos) { super(pos, buildBox(), undefined, RED); }
update() { this.rotation3D.y += .02; }
}
Additive blending, in the transparent stage
Added to rotation3D each frame by the engine before update, slowed by angleDamping
Draw into the shadow map when render3D.shadows is on; sprites and cut out textures
cast their outline, an object faded below half its alpha casts nothing, a see through one casts only when
textured, and additive objects never cast
Collide as the sphere that fits size3D instead of as the size3D box, so it rolls
around corners
How much it lights itself: 0 is lit as normal, 1 is its own color with no shading, for
lamps and glowing things, between is partly self lit, and above 1 is brighter than its color, for bloom
A texture of where it glows, added on top of the lit surface so it
shows in the dark, like lit windows; read at the color texture's coordinates
Multiplies the emissive map, as glTF's emissiveFactor
What it reflects in place of render3D.environment, as a mirror captures
the scene from its own middle
The steepest slope it stands on, in radians from level, PI/4 by default: resting on
a solid within this of flat sets groundObject and holds it still, steeper it slides down
The transform from its parent, used in place of pos3D, rotation3D and
scale3D when set, for one they cannot hold like a glTF pose with shear; read every frame it is set
A normal map that bends the surface at each texel so it catches the
light like bumps and grooves, green pointing up the image as OpenGL and glTF have it; read at the color
texture's coordinates, see normalMapFromHeight to make one in code
How strongly the normal map bends the surface, 0 turns it off, as glTF's scale
Keep this object's texture pixels hard edged, for pixel art that should not blur or bleed
Position in world space, or relative to the parent while attached to an
EngineObject3D, unlike a 2D child's pos, which stays in world space; getWorldPos3D gives a child's world
position
Darkened by the shadow map when render3D.shadows is on
How much it reflects the sky, 0 none and 1 a mirror of it; the edges seen at a
glancing angle reflect more either way, as water and glass do
Draw this object over the 2D scene, undefined uses render3D.renderAfter2D
Rotation vec3(pitch, yaw, roll) in radians, relative to the parent while attached to
an EngineObject3D, like pos3D
How rough the surface is, 0 a mirror to 1 matte, as glTF and three.js's MeshStandardMaterial have it: another
way to set shininess, which is what is kept, shininess = 2 / roughness^4 - 2 and at least 1; it sets both the
highlight and how blurred a reflection is; read back it is the same up to about .9, above which shininess is 1
and it reads .9
A sprite or particle lit as a ball bulging toward the camera, bright on the side
toward each light, in place of the same all over; a normal map takes its place
Scale, relative to the parent while attached to an EngineObject3D, like pos3D
The highlight's exponent, how small and sharp it is: 4 is broad like rubber, 16 the
default, 100 sharp like polished metal; shows only with specular above 0
Size for solid collision and the collect and callback helpers, and of the sprite when
there is a tileInfo and no mesh; starts at the size of the mesh's box, or 1 with no mesh, and setMesh leaves
it as it is; the box is centered on pos3D, so center() a mesh whose origin is not its middle, like a model
standing on its feet, or set size3D; scale3D and any parent's scale grow it, so drawing and picking agree
Diameter of a soft shadow drawn under the object on render3D.softShadowHeight, 0 for
none; scale3D and a parent's scale grow it, so set it once for the unscaled object
Strength of the highlight where the sun and the Light3D objects reflect, 0 is none and
1 adds a light's full color at its brightest; shininess sets its size
Copy the 2D pos and angle into pos3D and rotation3D each frame, for 2D games with 3D
looks; set mass to use 2D physics, and pos3D.z stays yours to set or move with velocity3D.z
Draw in the transparent stage, blended and sorted far to near with depth writes off;
on for a sprite
A sprite stands on world up instead of tilting toward the camera
Added to pos3D each frame by the engine before update, like the 2D velocity, no super
call needed; damping and render3D.gravity act on it once the object has a mass
Attaches a child, its pos3D, rotation3D and scale3D taken as the offset from this one; returns child for chaining
- The 2D offset arguments do nothing for an EngineObject3D child, set its pos3D
child TlocalPos Vector2 optionallocalAngle number optional
- Returns
The child object attached
Attaches a child without moving it: its pos3D, rotation3D and scale3D become what they have to be under this
parent to keep its world transform, where addChild takes them as the offset; returns child for chaining
- A parent scaled unevenly and a child turned under it make a shear, which those three values cannot hold,
so the child comes out as close as they can get; a uniform scale is exact
child T
- Returns
The child object attached
Called by a VoxelMap to ask whether a block stops this object, a hook to let one through or react to it
type numberThe block's type, 1 to 255
cell Vector3The block's cell in the map
- Returns
- true to be stopped by it, every block stops it by default
Returns the direction the object faces, its -Z axis in the world
Returns a copy of the object's world transform, the parent's included when attached to an EngineObject3D
- The object keeps its matrix and rebuilds it only when its position, rotation or scale changed, so this is
cheap to call
Returns the object's right axis in the world
Returns the object's up axis in the world
Returns the world position
Returns the rotation in the world as vec3(pitch, yaw, roll), the parent's included on a child
- Under a parent scaled unevenly a turned child is sheared, which no rotation is exactly, so it is the nearest
Turn the object so its -Z axis points at a world space target, sets pitch and yaw and clears roll
target Vector3
Removes a child from this one, it stays where it is in the world: its pos3D, rotation3D and scale3D become
its world values, with the same shear caveat as attach; a child being destroyed is let go as it is
child EngineObject
2D rendering is skipped, the mesh is drawn by render3D during the 3D pass
Draw the object in 3D, called by the 3D pass with the draw state set from this object's flags, draws the mesh by default
Set how this object collides, the same flags as in 2D
- Solid collision happens in 3D here, against size3D boxes or spheres; a child sits it out
- The boxes turn with rotation3D; against height maps and voxel maps an object is still its upright box, and
against a MeshCollider a capsule
- A sync2D object collides in 2D instead, against the 2D size, so set that as well as size3D
collideSolidObjects boolean optional, default trueTake part in solid collision
isSolid boolean optional, default trueBlock other objects, a pair where neither one blocks passes through;
blocking needs collideSolidObjects, so isSolid on its own is not allowed
collideLevel boolean optional, default trueCollide with the level, the height maps, voxel maps and mesh colliders, or
the 2D tile layers
for a sync2D object
collideRaycast boolean optional, default falseRaycasts, 2D only; 3D has render3D.pick and engineObjectsRaycast3D
Draw a different mesh and free the GPU buffer of the one it replaces
- For a mesh built again when something changes, like a score, a rebuilt terrain or a loaded model
- A mesh another object is still drawing is left alone, since builders are often shared
- Freeing one held somewhere else only costs it an upload, the points it was built from stay
mesh Mesh optionalThe mesh to draw from now on, undefined to draw nothing
- Returns
Move the object so its world position is pos, setting pos3D, which on a child is relative to the parent
- Exact whatever the parent's turn and scale; a child with a localMatrix has the matrix moved instead
pos Vector3
Turn the object so its rotation in the world is rotation, setting rotation3D, which on a child is relative to
the parent; it stays where it is
- Exact unless the parent, or one above it, is scaled unevenly, the same limit as attach
- A child with a localMatrix has the matrix built again from its position and scale with the new turn
rotation Vector3vec3(pitch, yaw, roll) in radians
Move by the 3D velocities and push out of solids, called automatically each frame before update, like the 2D physics
- update runs once every object has moved and collided, so bounce off anything else there, it lands before the draw
- Override this and call super to change how the object moves itself
- A sync2D object runs the 2D physics as well, and collides there instead