nanogl-gltf
Version:
34 lines (33 loc) • 1.1 kB
JavaScript
import GltfTypes from '../types/GltfTypes';
/**
* The Scene element is the root of the scene graph, it contains all the root nodes of the scene, which in turn contains all the children nodes and cover the whole scene to render.
*/
export default class Scene {
constructor() {
this.gltftype = GltfTypes.SCENE;
}
/**
* Parse the Scene data, fill the nodes array with the Nodes elements created by the GLTFLoader.
*
* Is async as it needs to wait for all the Nodes to be created.
* @param gltfLoader GLTFLoader to use
* @param data Data to parse
*/
async parse(gltfLoader, data) {
if (data.nodes !== undefined) {
const nodePromises = data.nodes.map(idx => gltfLoader.getElement(GltfTypes.NODE, idx));
this.nodes = await Promise.all(nodePromises);
}
else {
this.nodes = [];
}
}
/*
* Update world matrices of all scene nodes
*/
updateNodes() {
for (let i = 0; i < this.nodes.length; i++) {
this.nodes[i].updateWorldMatrix();
}
}
}