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, angleDamping is 2D only |
- Source
castShadow
Properties| Type | Description |
|---|---|
| boolean | Draw into the shadow map when render3D.shadows is on; sprites and cut out textures cast their outline, 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
cullBackFaces
Properties| Type | Description |
|---|---|
| boolean | Skip faces that point away from the camera, faster for closed meshes |
- 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
mesh :Mesh|undefined
- Mesh |
undefined
| Type | Description |
|---|---|
| Mesh | | Mesh to draw |
- 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
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
size3D
Properties| Type | Description |
|---|---|
| Vector3 | Size for the collect and callback helpers, and of the sprite when there is a tileInfo and no mesh; scale3D and any parent's scale grow it, so drawing and picking agree |
- 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 directional light reflects, 0 is none and 1 adds the light's full color at its brightest; its size is fixed |
- 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
getForward3D() → {Vector3}
Returns the direction the object faces, its -Z axis in the world
- Source
- Type:
- Vector3
getMatrix() → {Matrix4}
Returns the object's world transform, relative to the parent's when attached to an EngineObject3D
- 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
render()
2D rendering is skipped, the mesh is drawn by render3D during the 3D pass
- Source
render3D()
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
setCollision(collideSolidObjectsopt, isSolidopt, collideTilesopt, 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
- 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 |
collideTiles | boolean | <optional> | false | Tile collision, 2D only so it needs sync2D |
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()
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
- Source