123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- import { Scene } from "./scene";
- import { Nullable } from "./types";
- import { AbstractMesh } from "./Meshes/abstractMesh";
- import { TransformNode } from "./Meshes/transformNode";
- import { Geometry } from "./Meshes/geometry";
- import { Skeleton } from "./Bones/skeleton";
- import { MorphTargetManager } from "./Morph/morphTargetManager";
- import { AssetContainer } from "./assetContainer";
- import { IParticleSystem } from "./Particles/IParticleSystem";
- import { AnimationGroup } from "./Animations/animationGroup";
- import { BaseTexture } from "./Materials/Textures/baseTexture";
- import { Material } from "./Materials/material";
- import { MultiMaterial } from "./Materials/multiMaterial";
- import { AbstractActionManager } from "./Actions/abstractActionManager";
- import { Camera } from "./Cameras/camera";
- import { Light } from "./Lights/light";
- import { Node } from "./node";
- declare type Animation = import("./Animations/animation").Animation;
- /**
- * Defines how the parser contract is defined.
- * These parsers are used to parse a list of specific assets (like particle systems, etc..)
- */
- export type BabylonFileParser = (parsedData: any, scene: Scene, container: AssetContainer, rootUrl: string) => void;
- /**
- * Defines how the individual parser contract is defined.
- * These parser can parse an individual asset
- */
- export type IndividualBabylonFileParser = (parsedData: any, scene: Scene, rootUrl: string) => any;
- /**
- * Base class of the scene acting as a container for the different elements composing a scene.
- * This class is dynamically extended by the different components of the scene increasing
- * flexibility and reducing coupling
- */
- export abstract class AbstractScene {
- /**
- * Stores the list of available parsers in the application.
- */
- private static _BabylonFileParsers: { [key: string]: BabylonFileParser } = {};
- /**
- * Stores the list of available individual parsers in the application.
- */
- private static _IndividualBabylonFileParsers: { [key: string]: IndividualBabylonFileParser } = {};
- /**
- * Adds a parser in the list of available ones
- * @param name Defines the name of the parser
- * @param parser Defines the parser to add
- */
- public static AddParser(name: string, parser: BabylonFileParser): void {
- this._BabylonFileParsers[name] = parser;
- }
- /**
- * Gets a general parser from the list of avaialble ones
- * @param name Defines the name of the parser
- * @returns the requested parser or null
- */
- public static GetParser(name: string): Nullable<BabylonFileParser> {
- if (this._BabylonFileParsers[name]) {
- return this._BabylonFileParsers[name];
- }
- return null;
- }
- /**
- * Adds n individual parser in the list of available ones
- * @param name Defines the name of the parser
- * @param parser Defines the parser to add
- */
- public static AddIndividualParser(name: string, parser: IndividualBabylonFileParser): void {
- this._IndividualBabylonFileParsers[name] = parser;
- }
- /**
- * Gets an individual parser from the list of avaialble ones
- * @param name Defines the name of the parser
- * @returns the requested parser or null
- */
- public static GetIndividualParser(name: string): Nullable<IndividualBabylonFileParser> {
- if (this._IndividualBabylonFileParsers[name]) {
- return this._IndividualBabylonFileParsers[name];
- }
- return null;
- }
- /**
- * Parser json data and populate both a scene and its associated container object
- * @param jsonData Defines the data to parse
- * @param scene Defines the scene to parse the data for
- * @param container Defines the container attached to the parsing sequence
- * @param rootUrl Defines the root url of the data
- */
- public static Parse(jsonData: any, scene: Scene, container: AssetContainer, rootUrl: string): void {
- for (let parserName in this._BabylonFileParsers) {
- if (this._BabylonFileParsers.hasOwnProperty(parserName)) {
- this._BabylonFileParsers[parserName](jsonData, scene, container, rootUrl);
- }
- }
- }
- /**
- * Gets the list of root nodes (ie. nodes with no parent)
- */
- public rootNodes = new Array<Node>();
- /** All of the cameras added to this scene
- * @see http://doc.babylonjs.com/babylon101/cameras
- */
- public cameras = new Array<Camera>();
- /**
- * All of the lights added to this scene
- * @see http://doc.babylonjs.com/babylon101/lights
- */
- public lights = new Array<Light>();
- /**
- * All of the (abstract) meshes added to this scene
- */
- public meshes = new Array<AbstractMesh>();
- /**
- * The list of skeletons added to the scene
- * @see http://doc.babylonjs.com/how_to/how_to_use_bones_and_skeletons
- */
- public skeletons = new Array<Skeleton>();
- /**
- * All of the particle systems added to this scene
- * @see http://doc.babylonjs.com/babylon101/particles
- */
- public particleSystems = new Array<IParticleSystem>();
- /**
- * Gets a list of Animations associated with the scene
- */
- public animations: Animation[] = [];
- /**
- * All of the animation groups added to this scene
- * @see http://doc.babylonjs.com/how_to/group
- */
- public animationGroups = new Array<AnimationGroup>();
- /**
- * All of the multi-materials added to this scene
- * @see http://doc.babylonjs.com/how_to/multi_materials
- */
- public multiMaterials = new Array<MultiMaterial>();
- /**
- * All of the materials added to this scene
- * In the context of a Scene, it is not supposed to be modified manually.
- * Any addition or removal should be done using the addMaterial and removeMaterial Scene methods.
- * Note also that the order of the Material within the array is not significant and might change.
- * @see http://doc.babylonjs.com/babylon101/materials
- */
- public materials = new Array<Material>();
- /**
- * The list of morph target managers added to the scene
- * @see http://doc.babylonjs.com/how_to/how_to_dynamically_morph_a_mesh
- */
- public morphTargetManagers = new Array<MorphTargetManager>();
- /**
- * The list of geometries used in the scene.
- */
- public geometries = new Array<Geometry>();
- /**
- * All of the tranform nodes added to this scene
- * In the context of a Scene, it is not supposed to be modified manually.
- * Any addition or removal should be done using the addTransformNode and removeTransformNode Scene methods.
- * Note also that the order of the TransformNode wihin the array is not significant and might change.
- * @see http://doc.babylonjs.com/how_to/transformnode
- */
- public transformNodes = new Array<TransformNode>();
- /**
- * ActionManagers available on the scene.
- */
- public actionManagers = new Array<AbstractActionManager>();
- /**
- * Textures to keep.
- */
- public textures = new Array<BaseTexture>();
- /**
- * Environment texture for the scene
- */
- public environmentTexture: Nullable<BaseTexture> = null;
- /**
- * @returns all meshes, lights, cameras, transformNodes and bones
- */
- public getNodes(): Array<Node> {
- let nodes = new Array<Node>();
- nodes = nodes.concat(this.meshes);
- nodes = nodes.concat(this.lights);
- nodes = nodes.concat(this.cameras);
- nodes = nodes.concat(this.transformNodes); // dummies
- this.skeletons.forEach((skeleton) => nodes = nodes.concat(skeleton.bones));
- return nodes;
- }
- }
|