abstractScene.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**
  2. * Base class of the scene acting as a container for the different elements composing a scene.
  3. * This class is dynamically extended by the different components of the scene increasing
  4. * flexibility and reducing coupling
  5. */
  6. export class AbstractScene {
  7. constructor() {
  8. /**
  9. * Gets the list of root nodes (ie. nodes with no parent)
  10. */
  11. this.rootNodes = [];
  12. /** All of the cameras added to this scene
  13. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras
  14. */
  15. this.cameras = [];
  16. /**
  17. * All of the lights added to this scene
  18. * @see https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction
  19. */
  20. this.lights = [];
  21. /**
  22. * All of the (abstract) meshes added to this scene
  23. */
  24. this.meshes = [];
  25. /**
  26. * The list of skeletons added to the scene
  27. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/bonesSkeletons
  28. */
  29. this.skeletons = [];
  30. /**
  31. * All of the particle systems added to this scene
  32. * @see https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/particle_system_intro
  33. */
  34. this.particleSystems = [];
  35. /**
  36. * Gets a list of Animations associated with the scene
  37. */
  38. this.animations = [];
  39. /**
  40. * All of the animation groups added to this scene
  41. * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/groupAnimations
  42. */
  43. this.animationGroups = [];
  44. /**
  45. * All of the multi-materials added to this scene
  46. * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/multiMaterials
  47. */
  48. this.multiMaterials = [];
  49. /**
  50. * All of the materials added to this scene
  51. * In the context of a Scene, it is not supposed to be modified manually.
  52. * Any addition or removal should be done using the addMaterial and removeMaterial Scene methods.
  53. * Note also that the order of the Material within the array is not significant and might change.
  54. * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction
  55. */
  56. this.materials = [];
  57. /**
  58. * The list of morph target managers added to the scene
  59. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/dynamicMeshMorph
  60. */
  61. this.morphTargetManagers = [];
  62. /**
  63. * The list of geometries used in the scene.
  64. */
  65. this.geometries = [];
  66. /**
  67. * All of the transform nodes added to this scene
  68. * In the context of a Scene, it is not supposed to be modified manually.
  69. * Any addition or removal should be done using the addTransformNode and removeTransformNode Scene methods.
  70. * Note also that the order of the TransformNode within the array is not significant and might change.
  71. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/transform_node
  72. */
  73. this.transformNodes = [];
  74. /**
  75. * ActionManagers available on the scene.
  76. * @deprecated
  77. */
  78. this.actionManagers = [];
  79. /**
  80. * Textures to keep.
  81. */
  82. this.textures = [];
  83. /** @internal */
  84. this._environmentTexture = null;
  85. /**
  86. * The list of postprocesses added to the scene
  87. */
  88. this.postProcesses = [];
  89. }
  90. /**
  91. * Adds a parser in the list of available ones
  92. * @param name Defines the name of the parser
  93. * @param parser Defines the parser to add
  94. */
  95. static AddParser(name, parser) {
  96. this._BabylonFileParsers[name] = parser;
  97. }
  98. /**
  99. * Gets a general parser from the list of available ones
  100. * @param name Defines the name of the parser
  101. * @returns the requested parser or null
  102. */
  103. static GetParser(name) {
  104. if (this._BabylonFileParsers[name]) {
  105. return this._BabylonFileParsers[name];
  106. }
  107. return null;
  108. }
  109. /**
  110. * Adds n individual parser in the list of available ones
  111. * @param name Defines the name of the parser
  112. * @param parser Defines the parser to add
  113. */
  114. static AddIndividualParser(name, parser) {
  115. this._IndividualBabylonFileParsers[name] = parser;
  116. }
  117. /**
  118. * Gets an individual parser from the list of available ones
  119. * @param name Defines the name of the parser
  120. * @returns the requested parser or null
  121. */
  122. static GetIndividualParser(name) {
  123. if (this._IndividualBabylonFileParsers[name]) {
  124. return this._IndividualBabylonFileParsers[name];
  125. }
  126. return null;
  127. }
  128. /**
  129. * Parser json data and populate both a scene and its associated container object
  130. * @param jsonData Defines the data to parse
  131. * @param scene Defines the scene to parse the data for
  132. * @param container Defines the container attached to the parsing sequence
  133. * @param rootUrl Defines the root url of the data
  134. */
  135. static Parse(jsonData, scene, container, rootUrl) {
  136. for (const parserName in this._BabylonFileParsers) {
  137. if (Object.prototype.hasOwnProperty.call(this._BabylonFileParsers, parserName)) {
  138. this._BabylonFileParsers[parserName](jsonData, scene, container, rootUrl);
  139. }
  140. }
  141. }
  142. /**
  143. * Texture used in all pbr material as the reflection texture.
  144. * As in the majority of the scene they are the same (exception for multi room and so on),
  145. * this is easier to reference from here than from all the materials.
  146. */
  147. get environmentTexture() {
  148. return this._environmentTexture;
  149. }
  150. set environmentTexture(value) {
  151. this._environmentTexture = value;
  152. }
  153. /**
  154. * @returns all meshes, lights, cameras, transformNodes and bones
  155. */
  156. getNodes() {
  157. let nodes = [];
  158. nodes = nodes.concat(this.meshes);
  159. nodes = nodes.concat(this.lights);
  160. nodes = nodes.concat(this.cameras);
  161. nodes = nodes.concat(this.transformNodes); // dummies
  162. this.skeletons.forEach((skeleton) => (nodes = nodes.concat(skeleton.bones)));
  163. return nodes;
  164. }
  165. }
  166. /**
  167. * Stores the list of available parsers in the application.
  168. */
  169. AbstractScene._BabylonFileParsers = {};
  170. /**
  171. * Stores the list of available individual parsers in the application.
  172. */
  173. AbstractScene._IndividualBabylonFileParsers = {};
  174. //# sourceMappingURL=abstractScene.js.map