Scene
Scene
Provides global scene functionality like raycasting.
Kind: global class
- Scene
- .activeViews ⇒ Array.<ViewComponent>
- .clearColor
- .colorClearEnabled
- .rayCast(o, d, group)
- .addObject(parent) ⇒ Object
- .addObjects(count, parent, componentCountHint) ⇒ Array.<Object>
- .reserveObjects(objectCount, componentCountPerType)
- .load(filename)
- .append(filename, options) ⇒ Promise.<Object> | Promise.<Object>
- ._unmarshallGltfExtensions(data) ⇒ Object
- .reset()
.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) |
.colorClearEnabled
Set whether to clear the color framebuffer before drawing.
This function is useful if an external framework (e.g. an AR tracking framework) is responsible for drawing a camera frame before Wonderland Engine draws the scene on top of it.
Kind: instance property of Scene
0.9.4+
Param | Type | Description |
---|---|---|
b | boolean | Whether to enable color clear. |
.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 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, options) ⇒ Promise.<Object> | Promise.<Object>
Load an 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> | Promise.<Object> - Root of the loaded scene
Param | Description |
---|---|
filename | Path to the .gltf or .glb file |
options | Additional options for loading |
Example
Example
|
|
._unmarshallGltfExtensions (data) ⇒ Object
Unmarshalls the GltfExtensions from an Uint32Array
Kind: instance method of Scene
Param | Type | Description |
---|---|---|
data | Uint32Array | Array containing the gltf extension data |
.reset ()
Reset the scene
This method deletes all used and allocated objects, and components.
Kind: instance method of Scene