Scene
Scene
Provides global scene functionality like raycasting.
Kind: global class
.activeViews ⇒ Array.<ViewComponent>
Kind: instance property of Scene
Returns: Array.<ViewComponent> - currently active view components
.clearColor
Set the background clear color
Kind: instance property of Scene
0.8.5+
Param | Type | Description |
---|---|---|
color | Array.<number> | new clear color (RGBA) |
.rayCast (o, d, group)
Cast a ray through the scene and find intersecting objects.
The resulting ray hit will contain up to 4 closest ray hits, sorted by increasing distance.
Kind: instance method of Scene
Note: The returned RayHit object is owned by the Scene instance and
will be reused with the next rayCast call.
Param | Type | Description |
---|---|---|
o | Array.<number> | Ray origin |
d | Array.<number> | Ray direction |
group | number | Collision group to filter by: only objects that are part of given group are considered for raycast. |
.addObject (parent) ⇒ Object
Add object to the scene
Kind: instance method of Scene
Returns: Object - newly created object
Param | Type | Description |
---|---|---|
parent | Object | Parent object or null |
.addObjects (count, parent, componentCountHint) ⇒ Array.<Object>
Batch-add objects to the scene
Will provide better performance for adding multiple objects (e.g. > 16) than calling addObject repeatedly in a loop.
By providing upfront information of how many objects will be required, the engine is able to batch-allocate the required memory rather than convervatively grow the memory in small steps.
Experimental: This API might change in upcoming versions.
Kind: instance method of Scene
Returns: Array.<Object> - newly created objects
Param | Type | Description |
---|---|---|
count | number | Number of objects to add |
parent | Object | Parent object or null, default null |
componentCountHint | number | Hint for how many components in total will be added to the created objects afterwards, default 0 . |
.reserveObjects (objectCount, componentCountPerType)
Pre-allocate memory for a given amount of objects and components
Will provide better performance for adding objects later with addObject and addObjects
By providing upfront information of how many objects will be required, the engine is able to batch-allocate the required memory rather than convervatively grow the memory in small steps.
Experimental: This API might change in upcoming versions.
Kind: instance method of Scene
0.8.10+
Param | Type | Description |
---|---|---|
objectCount | number | Number of objects to add |
componentCountPerType | Object.<string, number> | Amount of components to allocate for Object.addComponent(), e.g. {mesh: 100, collision: 200, "my-comp": 100} |
.load (filename)
Load a scene file (.bin)
Will replace the currently active scene with the one loaded from given file. It is assumed that JavaScript components required by the new scene were registered in advance.
Kind: instance method of Scene
Param | Description |
---|---|
filename | Path to the .bin file |
.append (filename) ⇒ Promise.<Object>
Load a external 3D file (.gltf, .glb)
Loads and parses the gltf file and its images and appends the result to scene.
Kind: instance method of Scene
Returns: Promise.<Object> - Root of the loaded scene
Param | Description |
---|---|
filename | Path to the .gltf or .glb file |