nanogl-gltf
Version:
72 lines (71 loc) • 2.77 kB
TypeScript
import NGLNode from 'nanogl-node';
import Skin from './Skin';
import Camera from './Camera';
import Mesh from './Mesh';
import { mat4 } from 'gl-matrix';
import Gltf2 from '../types/Gltf2';
import GltfLoader from '../io/GltfLoader';
import GltfTypes from '../types/GltfTypes';
import MeshRenderer from '../renderer/MeshRenderer';
import { IElement } from '../types/Elements';
import Gltf from '../Gltf';
/**
* The Node element is a node in the scene graph, it contains a transformation matrix or a translation/scale vectors & scale quaternion, and can be used to control a camera, a skin, a mesh, or children nodes.
*/
export default class Node extends NGLNode implements IElement {
readonly gltftype: GltfTypes.NODE;
name: undefined | string;
extras: any;
/**
* If the node is used to control a camera, this is the Camera element
*/
camera?: Camera;
/**
* If the node is used to control a skin, this is the Skin element
*/
skin?: Skin;
/**
* If the node is used to control a mesh, this is the Mesh element
*/
mesh?: Mesh;
/**
* If the node is used to control a mesh with morph targets, this is the weights array
*/
weights?: Float32Array;
/**
* If the node is used to control a mesh, this is the MeshRenderer element, used to render the mesh
*/
renderable?: MeshRenderer;
/**
* The initial transform of this node as defined in the gltf file
*/
restMatrix: mat4;
/**
* Parse the Node data, apply the transformation matrix or the translation/scale vectors & scale quaternion,
* link the camera, skin and mesh elements and weights array if needed, and add children nodes to this node.
*
* Is async as it needs to wait for all possible Camera, Skin, Mesh and children Nodes elements to be created.
* @param gltfLoader GLTFLoader to use
* @param data Data to parse
*/
parse(gltfLoader: GltfLoader, data: Gltf2.INode): Promise<void>;
/**
* Find a child Node by name.
*
* It will search only at the first level of children, not recursively. If you want to search recursively, use findDescendant.
* @param name Name of the child Node to find
*/
findChild(name: string): Node | undefined;
/**
* Find a descendant Node by name.
*
* It will search recursively in all levels of the children nodes.
* @param name Name of the descendant Node to find
*/
findDescendant(name: string): Node | undefined;
/**
* If the Node has a Mesh, creates a MeshRenderer and stores it to the renderable attribute, getting the Node ready to be rendered.
* @param gltf The Gltf object which this Node belongs to
*/
allocateGl(gltf: Gltf): void;
}