Constructor
new EngineObject3D(pos3Dopt, meshopt, tileInfoopt, coloropt)
Create a 3D object and add it to the object list
| Name | Type | Attributes | Description |
|---|---|---|---|
pos3D | Vector3 | <optional> | World space position |
mesh | Mesh | <optional> | Mesh to draw, undefined draws nothing |
tileInfo | TileInfo | | <optional> | Texture, mesh uvs map across the tile; a whole TextureInfo becomes the tile that covers it |
color | Color | <optional> | Tint |
- Source
class Spinner extends EngineObject3D
{
constructor(pos) { super(pos, buildBox(), undefined, RED); }
update() { this.rotation3D.y += .02; }
}Extends
- EngineObject
Members
additive
Properties| Type | Description |
|---|---|
| boolean | Additive blending, in the transparent stage |
- Source
angleVelocity3D
Properties| Type | Description |
|---|---|
| Vector3 | Added to rotation3D each frame by the engine before update, slowed by angleDamping |
- Source
castShadow
Properties| Type | Description |
|---|---|
| boolean | 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 |
- Source
collideAsSphere3D
Properties| Type | Description |
|---|---|
| boolean | Collide as the sphere that fits size3D instead of as the size3D box, so it rolls around corners |
- Source
emissive
Properties| Type | Description |
|---|---|
| number | 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 |
- Source
emissiveMap :TextureInfo|undefined
- TextureInfo |
undefined
| Type | Description |
|---|---|
| TextureInfo | | 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 |
- Source
emissiveMapColor
Properties| Type | Description |
|---|---|
| Color | Multiplies the emissive map, as glTF's emissiveFactor |
- Source
groundAngle
Properties| Type | Description |
|---|---|
| number | 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 |
- Source
localMatrix :Matrix4|undefined
- Matrix4 |
undefined
| Type | Description |
|---|---|
| Matrix4 | | 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 |
- Source
matrixParent :EngineObject3D|undefined
- EngineObject3D |
undefined
- Source
mesh :Mesh|undefined
- Mesh |
undefined
| Type | Description |
|---|---|
| Mesh | | Mesh to draw |
- Source
normalMap :TextureInfo|undefined
- TextureInfo |
undefined
| Type | Description |
|---|---|
| TextureInfo | | 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 |
- Source
normalScale
Properties| Type | Description |
|---|---|
| number | How strongly the normal map bends the surface, 0 turns it off, as glTF's scale |
- Source
pixelated
Properties| Type | Description |
|---|---|
| boolean | Keep this object's texture pixels hard edged, for pixel art that should not blur or bleed |
- Source
pos3D
Properties| Type | Description |
|---|---|
| Vector3 | World space position, local to the parent when attached to an EngineObject3D |
- Source
receiveShadow
Properties| Type | Description |
|---|---|
| boolean | Darkened by the shadow map when render3D.shadows is on |
- Source
reflectivity
Properties| Type | Description |
|---|---|
| number | 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 |
- Source
renderAfter2D :boolean|undefined
- boolean |
undefined
| Type | Description |
|---|---|
| boolean | | Draw this object over the 2D scene, undefined uses render3D.renderAfter2D |
- Source
rotation3D
Properties| Type | Description |
|---|---|
| Vector3 | Rotation vec3(pitch, yaw, roll) in radians, local to the parent when attached to an EngineObject3D |
- Source
scale3D
Properties| Type | Description |
|---|---|
| Vector3 | Scale, local to the parent when attached to an EngineObject3D |
- Source
shininess
Properties| Type | Description |
|---|---|
| number | 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 |
- Source
softShadow
Properties| Type | Description |
|---|---|
| number | 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 |
- Source
specular
Properties| Type | Description |
|---|---|
| number | 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 |
- Source
sync2D
Properties| Type | Description |
|---|---|
| boolean | 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 |
- Source
transparent
Properties| Type | Description |
|---|---|
| boolean | Draw in the transparent stage, blended and sorted far to near with depth writes off; on for a sprite |
- Source
upright
Properties| Type | Description |
|---|---|
| boolean | A sprite stands on world up instead of tilting toward the camera |
- Source
velocity3D
Properties| Type | Description |
|---|---|
| Vector3 | 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 |
- Source
Methods
addChild(child, localPosopt, localAngleopt) → {EngineObject}
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
| Name | Type | Attributes | Description |
|---|---|---|---|
child | EngineObject | ||
localPos | Vector2 | <optional> | |
localAngle | number | <optional> |
- Source
The child object attached
- Type:
- EngineObject
attach(child) → {EngineObject}
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
| Name | Type | Description |
|---|---|---|
child | EngineObject |
- Source
The child object attached
- Type:
- EngineObject
collideWithVoxel(type, cell) → {boolean}
Called by a VoxelMap to ask whether a block stops this object, a hook to let one through or react to it
| Name | Type | Description |
|---|---|---|
type | number | The block's type, 1 to 255 |
cell | Vector3 | The block's cell in the map |
- Source
- true to be stopped by it, every block stops it by default
- Type:
- boolean
getForward3D() → {Vector3}
Returns the direction the object faces, its -Z axis in the world
- Source
- Type:
- Vector3
getMatrix() → {Matrix4}
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
- Source
- Type:
- Matrix4
getRight3D() → {Vector3}
Returns the object's right axis in the world
- Source
- Type:
- Vector3
getUp3D() → {Vector3}
Returns the object's up axis in the world
- Source
- Type:
- Vector3
getWorldPos3D() → {Vector3}
Returns the world position
- Source
- Type:
- Vector3
lookAt(target)
Turn the object so its -Z axis points at a world space target, sets pitch and yaw and clears roll
| Name | Type | Description |
|---|---|---|
target | Vector3 |
- Source
removeChild(child)
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
| Name | Type | Description |
|---|---|---|
child | EngineObject |
- Source
render()
2D rendering is skipped, the mesh is drawn by render3D during the 3D pass
- Source
render3D() → {void}
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
- Source
- Type:
- void
setCollision(collideSolidObjectsopt, isSolidopt, collideLevelopt, collideRaycastopt)
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
- A sync2D object collides in 2D instead, against the 2D size, so set that as well as size3D
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
collideSolidObjects | boolean | <optional> | true | Take part in solid collision |
isSolid | boolean | <optional> | true | Block other objects, a pair where neither one blocks passes through; blocking needs collideSolidObjects, so isSolid on its own is not allowed |
collideLevel | boolean | <optional> | true | Collide with the level, the height maps and voxel maps, or the 2D tile layers for a sync2D object |
collideRaycast | boolean | <optional> | false | Raycasts, 2D only; 3D has render3D.pick and engineObjectsRaycast3D |
- Source
setMesh(meshopt) → {Mesh|undefined}
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
| Name | Type | Attributes | Description |
|---|---|---|---|
mesh | Mesh | <optional> | The mesh to draw from now on, undefined to draw nothing |
- Source
- The mesh passed in
- Type:
- Mesh |
undefined
updatePhysics()
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
- Source
updateTransforms(updateChildrenopt)
Move a child by its own velocities, bring a sync2D object's pos3D up to its 2D pos, then update the children, called automatically each frame
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
updateChildren | boolean | <optional> | true | Also update the children's transforms |
- Source