babylon.abstractScene.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. module BABYLON {
  2. /**
  3. * Defines how the parser contract is defined.
  4. * These parsers are used to parse a list of specific assets (like particle systems, etc..)
  5. */
  6. export type BabylonFileParser = (parsedData: any, scene: Scene, container: AssetContainer, rootUrl: string) => void;
  7. /**
  8. * Defines how the individual parser contract is defined.
  9. * These parser can parse an individual asset
  10. */
  11. export type IndividualBabylonFileParser = (parsedData: any, scene: Scene, rootUrl: string) => any;
  12. /**
  13. * Base class of the scene acting as a container for the different elements composing a scene.
  14. * This class is dynamically extended by the different components of the scene increasing
  15. * flexibility and reducing coupling
  16. */
  17. export abstract class AbstractScene {
  18. /**
  19. * Stores the list of available parsers in the application.
  20. */
  21. private static _BabylonFileParsers: { [key: string]: BabylonFileParser } = { };
  22. /**
  23. * Stores the list of available individual parsers in the application.
  24. */
  25. private static _IndividualBabylonFileParsers: { [key: string]: IndividualBabylonFileParser } = { };
  26. /**
  27. * Adds a parser in the list of available ones
  28. * @param name Defines the name of the parser
  29. * @param parser Defines the parser to add
  30. */
  31. public static AddParser(name: string, parser: BabylonFileParser): void {
  32. this._BabylonFileParsers[name] = parser;
  33. }
  34. /**
  35. * Gets a general parser from the list of avaialble ones
  36. * @param name Defines the name of the parser
  37. * @returns the requested parser or null
  38. */
  39. public static GetParser(name: string): Nullable<BabylonFileParser> {
  40. if (this._BabylonFileParsers[name]) {
  41. return this._BabylonFileParsers[name];
  42. }
  43. return null;
  44. }
  45. /**
  46. * Adds n individual parser in the list of available ones
  47. * @param name Defines the name of the parser
  48. * @param parser Defines the parser to add
  49. */
  50. public static AddIndividualParser(name: string, parser: IndividualBabylonFileParser): void {
  51. this._IndividualBabylonFileParsers[name] = parser;
  52. }
  53. /**
  54. * Gets an individual parser from the list of avaialble ones
  55. * @param name Defines the name of the parser
  56. * @returns the requested parser or null
  57. */
  58. public static GetIndividualParser(name: string): Nullable<IndividualBabylonFileParser> {
  59. if (this._IndividualBabylonFileParsers[name]) {
  60. return this._IndividualBabylonFileParsers[name];
  61. }
  62. return null;
  63. }
  64. /**
  65. * Parser json data and populate both a scene and its associated container object
  66. * @param jsonData Defines the data to parse
  67. * @param scene Defines the scene to parse the data for
  68. * @param container Defines the container attached to the parsing sequence
  69. * @param rootUrl Defines the root url of the data
  70. */
  71. public static Parse(jsonData: any, scene: Scene, container: AssetContainer, rootUrl: string): void {
  72. for (let parserName in this._BabylonFileParsers) {
  73. if (this._BabylonFileParsers.hasOwnProperty(parserName)) {
  74. this._BabylonFileParsers[parserName](jsonData, scene, container, rootUrl);
  75. }
  76. }
  77. }
  78. /**
  79. * Gets the list of root nodes (ie. nodes with no parent)
  80. */
  81. public rootNodes = new Array<Node>();
  82. /** All of the cameras added to this scene
  83. * @see http://doc.babylonjs.com/babylon101/cameras
  84. */
  85. public cameras = new Array<Camera>();
  86. /**
  87. * All of the lights added to this scene
  88. * @see http://doc.babylonjs.com/babylon101/lights
  89. */
  90. public lights = new Array<Light>();
  91. /**
  92. * All of the (abstract) meshes added to this scene
  93. */
  94. public meshes = new Array<AbstractMesh>();
  95. /**
  96. * The list of skeletons added to the scene
  97. * @see http://doc.babylonjs.com/how_to/how_to_use_bones_and_skeletons
  98. */
  99. public skeletons = new Array<Skeleton>();
  100. /**
  101. * All of the particle systems added to this scene
  102. * @see http://doc.babylonjs.com/babylon101/particles
  103. */
  104. public particleSystems = new Array<IParticleSystem>();
  105. /**
  106. * Gets a list of Animations associated with the scene
  107. */
  108. public animations: Animation[] = [];
  109. /**
  110. * All of the animation groups added to this scene
  111. * @see http://doc.babylonjs.com/how_to/group
  112. */
  113. public animationGroups = new Array<AnimationGroup>();
  114. /**
  115. * All of the multi-materials added to this scene
  116. * @see http://doc.babylonjs.com/how_to/multi_materials
  117. */
  118. public multiMaterials = new Array<MultiMaterial>();
  119. /**
  120. * All of the materials added to this scene
  121. * @see http://doc.babylonjs.com/babylon101/materials
  122. */
  123. public materials = new Array<Material>();
  124. /**
  125. * The list of morph target managers added to the scene
  126. * @see http://doc.babylonjs.com/how_to/how_to_dynamically_morph_a_mesh
  127. */
  128. public morphTargetManagers = new Array<MorphTargetManager>();
  129. /**
  130. * The list of geometries used in the scene.
  131. */
  132. public geometries = new Array<Geometry>();
  133. /**
  134. * All of the tranform nodes added to this scene
  135. * @see http://doc.babylonjs.com/how_to/transformnode
  136. */
  137. public transformNodes = new Array<TransformNode>();
  138. /**
  139. * ActionManagers available on the scene.
  140. */
  141. public actionManagers = new Array<ActionManager>();
  142. /**
  143. * Textures to keep.
  144. */
  145. public textures = new Array<BaseTexture>();
  146. }
  147. }