PrefabGLTF
1.2.0+
glTF scene.
At the opposite of Scene, glTF scenes can be instantiated in other scenes but can’t:
- Be activated
- Be the destination of an instantiation
Usage
const prefab = await engine.loadGLTF('Zombie.glb');
const scene = engine.scene;
for (let i = 0; i < 100; ++i) {
scene.instantiate(prefab);
}
Since this class inherits from Prefab, you can use the shared API to modify the glTF before an instantiation:
const prefab = await engine.loadGLTF('Zombie.glb');
const zombie = prefab.findByName('Zombie')[0];
// The mesh is too small, we scale the root
zombie.setScalingWorld([2, 2, 2]);
// Add a custom js 'health' component to the root
zombie.addComponent('health', {value: 100});
// 'Zombie' is wrapped in a new root added during instantiation
const {root} = engine.scene.instantiate(prefab);
const instanceZombie = root.children[0];
console.log(instanceZombie.getScalingWorld()); // Prints '[2, 2, 2]'
Properties
Properties
.extensions: null | GLTFExtensions
Raw extensions read from the glTF file.
The extensions will be mapped to the hierarchy upon instantiation. For more information, have a look at the InstantiateGltfResult type.
Note: The glTF must be loaded with extensions enabled. If not, this
field will be set to null. For more information, have a look at the
GLTFOptions type.