Prefab
Base class for prefabs, scenes, and glTF.
For more information have a look at the derived types:
- Scene for Wonderland Engine activatable scenes (.bin)
- PrefabGLTF for glTF scenes
Resources
While meshes, textures, and materials are shared on the WonderlandEngine instance, a scene comes with:
- Animations: Managed using animations
- Skins: Managed using skins
Those resources are bound to the object hierarchy and are thus required to be per-scene.
Destruction
For now, destroying a scene doesn’t automatically remove the resources it references in the engine. For more information, have a look at the destroy method.
Isolation
It’s forbidden to mix objects and components from different scenes, e.g.,
- Prefab
- .animations
- .baseURL
- .children
- .childrenCount
- .engine
- .filename
- .isActive
- .isDestroyed
- .skins
- .addObject(parent) ⇒ Object3D
- .addObjects(count, parent, componentCountHint) ⇒ Object3D[]
- .assertOrigin(other) ⇒ void
- .destroy() ⇒ void
- .findByName(name, recursive) ⇒ Object3D[]
- .findByNameDirect(name) ⇒ Object3D[]
- .findByNameRecursive(name) ⇒ Object3D[]
- .getChildren(out) ⇒ Object3D[]
- .reserveObjects(objectCount, componentCountPerType) ⇒ void
- .toString() ⇒ string
- .wrap(objectId) ⇒ Object3D
.animations: ResourceManager<Animation>
Animation resources
.baseURL: string
Relative directory of the scene that was loaded.
This is used for loading any files relative to the scene.
.children: Object3D[]
1.2.0+Top-level objects of this scene.
See children for more information.
.childrenCount: number
The number of children of the root object.
.engine: WonderlandEngine
Hosting engine instance.
.filename: string
Filename used when loading the file.
If the scenes was loaded from memory and no filename was provided, this accessor will return an empty string.
.isActive: boolean
true
if the scene is active, false
otherwise.
Always false for Prefab and PrefabGLTF.
.isDestroyed: boolean
true
if the object is destroyed, false
otherwise.
If erasePrototypeOnDestroy is true
,
reading a class attribute / method will throw.
.skins: ResourceManager<Skin>
Skin resources
.addObject(parent: null | Object3D) ⇒ Object3D
Add an object to the scene.
Returns: A newly created object.
Param | Type | Description |
---|---|---|
parent | null | Object3D | Parent object or null . |
.addObjects(count: number, parent: null | Object3D, componentCountHint: number) ⇒ Object3D[]
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.
This API might change in upcoming versions.
Returns: Newly created objects
Param | Type | Description |
---|---|---|
count | number | Number of objects to add. |
parent | null | Object3D | 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 . |
.assertOrigin(other: undefined | null | Component | SceneResource | Object3D) ⇒ void
Checks that the input’s scene is the same as this instance.
It is forbidden to mix objects and components from different scenes, e.g.,
Throws: If other’s scene isn’t the same reference as this.
Param | Type | Description |
---|---|---|
other | undefined | null | Component | SceneResource | Object3D | Object / component to check. |
.destroy() ⇒ void
Destroy the scene.
For now, destroying a scene doesn’t remove the resources it references. Thus, you will need to reload a main scene to free the memory.
For more information about destruction, have a look at the destroy method.
.findByName(name: string, recursive: boolean) ⇒ Object3D[]
1.2.0+Search for objects matching the name.
See findByName for more information.
Returns: An array of Object3D matching the name.
Param | Type | Description |
---|---|---|
name | string | The name to search for. |
recursive | boolean | If true , the method will look at all the objects of this scene. If false , this method will only perform the search in root objects. |
.findByNameDirect(name: string) ⇒ Object3D[]
1.2.0+Search for all top-level objects matching the name.
See findByNameDirect for more information.
Returns: An array of Object3D matching the name.
Param | Type | Description |
---|---|---|
name | string | The name to search for. |
.findByNameRecursive(name: string) ⇒ Object3D[]
1.2.0+Search for all objects matching the name.
See findByNameRecursive for more information.
Returns: An array of Object3D matching the name.
Param | Type | Description |
---|---|---|
name | string | The name to search for. |
.getChildren(out: Object3D[]) ⇒ Object3D[]
Root object’s children.
See getChildren for more information.
Returns: The out
parameter.
Param | Type | Description |
---|---|---|
out | Object3D[] | Destination array, expected to have at least this.childrenCount elements. |
.reserveObjects(objectCount: number, componentCountPerType: Record<string, number>) ⇒ void
0.8.10+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 conservatively grow the memory in small steps.
Experimental: This API might change in upcoming versions.
Param | Type | Description |
---|---|---|
objectCount | number | Number of objects to add. |
componentCountPerType | Record<string, number> | Amount of components to allocate for addComponent, e.g. {mesh: 100, collision: 200, "my-comp": 100} . |
.toString() ⇒ string
.wrap(objectId: number) ⇒ Object3D
Wrap an object ID using Object.
Note: This method performs caching and will return the same instance on subsequent calls.
Returns: The object
Param | Type | Description |
---|---|---|
objectId | number | ID of the object to create. |