Prefab

1.2.0+

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:

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.,

1const objA = sceneA.addObject();
2const objB = sceneB.addObject();
3objA.parent = objB; // Throws

.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.

ParamTypeDescription
parentnull | Object3DParent 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

ParamTypeDescription
countnumberNumber of objects to add.
parentnull | Object3DParent object or null, default null.
componentCountHintnumberHint 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.,

1const objA = sceneA.addObject();
2const objB = sceneA.addObject();
3objA.parent = objB; // Throws

Throws: If other’s scene isn’t the same reference as this.

ParamTypeDescription
otherundefined | null | Component | SceneResource | Object3DObject / 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.

ParamTypeDescription
namestringThe name to search for.
recursivebooleanIf 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.

ParamTypeDescription
namestringThe 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.

ParamTypeDescription
namestringThe name to search for.

.getChildren(out: Object3D[]) ⇒ Object3D[] 

Root object’s children.

See getChildren for more information.

Returns: The out parameter.

ParamTypeDescription
outObject3D[]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.

ParamTypeDescription
objectCountnumberNumber of objects to add.
componentCountPerTypeRecord<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

ParamTypeDescription
objectIdnumberID of the object to create.