babylon.scene.js 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083
  1. var BABYLON;
  2. (function (BABYLON) {
  3. /**
  4. * Represents a scene to be rendered by the engine.
  5. * @see http://doc.babylonjs.com/page.php?p=21911
  6. */
  7. var Scene = (function () {
  8. /**
  9. * @constructor
  10. * @param {BABYLON.Engine} engine - the engine to be used to render this scene.
  11. */
  12. function Scene(engine) {
  13. // Members
  14. this.autoClear = true;
  15. this.clearColor = new BABYLON.Color3(0.2, 0.2, 0.3);
  16. this.ambientColor = new BABYLON.Color3(0, 0, 0);
  17. this.forceWireframe = false;
  18. this.forcePointsCloud = false;
  19. this.forceShowBoundingBoxes = false;
  20. this.animationsEnabled = true;
  21. this.constantlyUpdateMeshUnderPointer = false;
  22. this.cameraToUseForPointers = null; // Define this parameter if you are using multiple cameras and you want to specify which one should be used for pointer position
  23. this._startingPointerPosition = new BABYLON.Vector2(0, 0);
  24. this._startingPointerTime = 0;
  25. // Fog
  26. /**
  27. * is fog enabled on this scene.
  28. * @type {boolean}
  29. */
  30. this.fogEnabled = true;
  31. this.fogMode = Scene.FOGMODE_NONE;
  32. this.fogColor = new BABYLON.Color3(0.2, 0.2, 0.3);
  33. this.fogDensity = 0.1;
  34. this.fogStart = 0;
  35. this.fogEnd = 1000.0;
  36. // Lights
  37. /**
  38. * is shadow enabled on this scene.
  39. * @type {boolean}
  40. */
  41. this.shadowsEnabled = true;
  42. /**
  43. * is light enabled on this scene.
  44. * @type {boolean}
  45. */
  46. this.lightsEnabled = true;
  47. /**
  48. * All of the lights added to this scene.
  49. * @see BABYLON.Light
  50. * @type {BABYLON.Light[]}
  51. */
  52. this.lights = new Array();
  53. // Cameras
  54. /**
  55. * All of the cameras added to this scene.
  56. * @see BABYLON.Camera
  57. * @type {BABYLON.Camera[]}
  58. */
  59. this.cameras = new Array();
  60. this.activeCameras = new Array();
  61. // Meshes
  62. /**
  63. * All of the (abstract) meshes added to this scene.
  64. * @see BABYLON.AbstractMesh
  65. * @type {BABYLON.AbstractMesh[]}
  66. */
  67. this.meshes = new Array();
  68. // Geometries
  69. this._geometries = new Array();
  70. this.materials = new Array();
  71. this.multiMaterials = new Array();
  72. this.defaultMaterial = new BABYLON.StandardMaterial("default material", this);
  73. // Textures
  74. this.texturesEnabled = true;
  75. this.textures = new Array();
  76. // Particles
  77. this.particlesEnabled = true;
  78. this.particleSystems = new Array();
  79. // Sprites
  80. this.spritesEnabled = true;
  81. this.spriteManagers = new Array();
  82. // Layers
  83. this.layers = new Array();
  84. // Skeletons
  85. this.skeletonsEnabled = true;
  86. this.skeletons = new Array();
  87. // Lens flares
  88. this.lensFlaresEnabled = true;
  89. this.lensFlareSystems = new Array();
  90. // Collisions
  91. this.collisionsEnabled = true;
  92. this.gravity = new BABYLON.Vector3(0, -9.807, 0);
  93. // Postprocesses
  94. this.postProcessesEnabled = true;
  95. // Customs render targets
  96. this.renderTargetsEnabled = true;
  97. this.dumpNextRenderTargets = false;
  98. this.customRenderTargets = new Array();
  99. // Imported meshes
  100. this.importedMeshesFiles = new Array();
  101. // Probes
  102. this.probesEnabled = true;
  103. this.reflectionProbes = new Array();
  104. this._actionManagers = new Array();
  105. this._meshesForIntersections = new BABYLON.SmartArray(256);
  106. // Procedural textures
  107. this.proceduralTexturesEnabled = true;
  108. this._proceduralTextures = new Array();
  109. this.soundTracks = new Array();
  110. this._audioEnabled = true;
  111. this._headphone = false;
  112. this._totalVertices = 0;
  113. this._activeIndices = 0;
  114. this._activeParticles = 0;
  115. this._lastFrameDuration = 0;
  116. this._evaluateActiveMeshesDuration = 0;
  117. this._renderTargetsDuration = 0;
  118. this._particlesDuration = 0;
  119. this._renderDuration = 0;
  120. this._spritesDuration = 0;
  121. this._animationRatio = 0;
  122. this._renderId = 0;
  123. this._executeWhenReadyTimeoutId = -1;
  124. this._toBeDisposed = new BABYLON.SmartArray(256);
  125. this._onReadyCallbacks = new Array();
  126. this._pendingData = []; //ANY
  127. this._onBeforeRenderCallbacks = new Array();
  128. this._onAfterRenderCallbacks = new Array();
  129. this._activeMeshes = new BABYLON.SmartArray(256);
  130. this._processedMaterials = new BABYLON.SmartArray(256);
  131. this._renderTargets = new BABYLON.SmartArray(256);
  132. this._activeParticleSystems = new BABYLON.SmartArray(256);
  133. this._activeSkeletons = new BABYLON.SmartArray(32);
  134. this._softwareSkinnedMeshes = new BABYLON.SmartArray(32);
  135. this._activeBones = 0;
  136. this._activeAnimatables = new Array();
  137. this._transformMatrix = BABYLON.Matrix.Zero();
  138. this._edgesRenderers = new BABYLON.SmartArray(16);
  139. this._uniqueIdCounter = 0;
  140. this._engine = engine;
  141. engine.scenes.push(this);
  142. this._renderingManager = new BABYLON.RenderingManager(this);
  143. this.postProcessManager = new BABYLON.PostProcessManager(this);
  144. this.postProcessRenderPipelineManager = new BABYLON.PostProcessRenderPipelineManager();
  145. this._boundingBoxRenderer = new BABYLON.BoundingBoxRenderer(this);
  146. if (BABYLON.OutlineRenderer) {
  147. this._outlineRenderer = new BABYLON.OutlineRenderer(this);
  148. }
  149. this.attachControl();
  150. this._debugLayer = new BABYLON.DebugLayer(this);
  151. if (BABYLON.SoundTrack) {
  152. this.mainSoundTrack = new BABYLON.SoundTrack(this, { mainTrack: true });
  153. }
  154. //simplification queue
  155. if (BABYLON.SimplificationQueue) {
  156. this.simplificationQueue = new BABYLON.SimplificationQueue();
  157. }
  158. //collision coordinator initialization. For now legacy per default.
  159. this.workerCollisions = false; //(!!Worker && (!!BABYLON.CollisionWorker || BABYLON.WorkerIncluded));
  160. }
  161. Object.defineProperty(Scene, "FOGMODE_NONE", {
  162. get: function () {
  163. return Scene._FOGMODE_NONE;
  164. },
  165. enumerable: true,
  166. configurable: true
  167. });
  168. Object.defineProperty(Scene, "FOGMODE_EXP", {
  169. get: function () {
  170. return Scene._FOGMODE_EXP;
  171. },
  172. enumerable: true,
  173. configurable: true
  174. });
  175. Object.defineProperty(Scene, "FOGMODE_EXP2", {
  176. get: function () {
  177. return Scene._FOGMODE_EXP2;
  178. },
  179. enumerable: true,
  180. configurable: true
  181. });
  182. Object.defineProperty(Scene, "FOGMODE_LINEAR", {
  183. get: function () {
  184. return Scene._FOGMODE_LINEAR;
  185. },
  186. enumerable: true,
  187. configurable: true
  188. });
  189. Object.defineProperty(Scene.prototype, "debugLayer", {
  190. // Properties
  191. get: function () {
  192. return this._debugLayer;
  193. },
  194. enumerable: true,
  195. configurable: true
  196. });
  197. Object.defineProperty(Scene.prototype, "workerCollisions", {
  198. get: function () {
  199. return this._workerCollisions;
  200. },
  201. set: function (enabled) {
  202. enabled = (enabled && !!Worker);
  203. this._workerCollisions = enabled;
  204. if (this.collisionCoordinator) {
  205. this.collisionCoordinator.destroy();
  206. }
  207. this.collisionCoordinator = enabled ? new BABYLON.CollisionCoordinatorWorker() : new BABYLON.CollisionCoordinatorLegacy();
  208. this.collisionCoordinator.init(this);
  209. },
  210. enumerable: true,
  211. configurable: true
  212. });
  213. Object.defineProperty(Scene.prototype, "SelectionOctree", {
  214. get: function () {
  215. return this._selectionOctree;
  216. },
  217. enumerable: true,
  218. configurable: true
  219. });
  220. Object.defineProperty(Scene.prototype, "meshUnderPointer", {
  221. /**
  222. * The mesh that is currently under the pointer.
  223. * @return {BABYLON.AbstractMesh} mesh under the pointer/mouse cursor or null if none.
  224. */
  225. get: function () {
  226. return this._meshUnderPointer;
  227. },
  228. enumerable: true,
  229. configurable: true
  230. });
  231. Object.defineProperty(Scene.prototype, "pointerX", {
  232. /**
  233. * Current on-screen X position of the pointer
  234. * @return {number} X position of the pointer
  235. */
  236. get: function () {
  237. return this._pointerX;
  238. },
  239. enumerable: true,
  240. configurable: true
  241. });
  242. Object.defineProperty(Scene.prototype, "pointerY", {
  243. /**
  244. * Current on-screen Y position of the pointer
  245. * @return {number} Y position of the pointer
  246. */
  247. get: function () {
  248. return this._pointerY;
  249. },
  250. enumerable: true,
  251. configurable: true
  252. });
  253. Scene.prototype.getCachedMaterial = function () {
  254. return this._cachedMaterial;
  255. };
  256. Scene.prototype.getBoundingBoxRenderer = function () {
  257. return this._boundingBoxRenderer;
  258. };
  259. Scene.prototype.getOutlineRenderer = function () {
  260. return this._outlineRenderer;
  261. };
  262. Scene.prototype.getEngine = function () {
  263. return this._engine;
  264. };
  265. Scene.prototype.getTotalVertices = function () {
  266. return this._totalVertices;
  267. };
  268. Scene.prototype.getActiveIndices = function () {
  269. return this._activeIndices;
  270. };
  271. Scene.prototype.getActiveParticles = function () {
  272. return this._activeParticles;
  273. };
  274. Scene.prototype.getActiveBones = function () {
  275. return this._activeBones;
  276. };
  277. // Stats
  278. Scene.prototype.getLastFrameDuration = function () {
  279. return this._lastFrameDuration;
  280. };
  281. Scene.prototype.getEvaluateActiveMeshesDuration = function () {
  282. return this._evaluateActiveMeshesDuration;
  283. };
  284. Scene.prototype.getActiveMeshes = function () {
  285. return this._activeMeshes;
  286. };
  287. Scene.prototype.getRenderTargetsDuration = function () {
  288. return this._renderTargetsDuration;
  289. };
  290. Scene.prototype.getRenderDuration = function () {
  291. return this._renderDuration;
  292. };
  293. Scene.prototype.getParticlesDuration = function () {
  294. return this._particlesDuration;
  295. };
  296. Scene.prototype.getSpritesDuration = function () {
  297. return this._spritesDuration;
  298. };
  299. Scene.prototype.getAnimationRatio = function () {
  300. return this._animationRatio;
  301. };
  302. Scene.prototype.getRenderId = function () {
  303. return this._renderId;
  304. };
  305. Scene.prototype.incrementRenderId = function () {
  306. this._renderId++;
  307. };
  308. Scene.prototype._updatePointerPosition = function (evt) {
  309. var canvasRect = this._engine.getRenderingCanvasClientRect();
  310. this._pointerX = evt.clientX - canvasRect.left;
  311. this._pointerY = evt.clientY - canvasRect.top;
  312. if (this.cameraToUseForPointers) {
  313. this._pointerX = this._pointerX - this.cameraToUseForPointers.viewport.x * this._engine.getRenderWidth();
  314. this._pointerY = this._pointerY - this.cameraToUseForPointers.viewport.y * this._engine.getRenderHeight();
  315. }
  316. };
  317. // Pointers handling
  318. Scene.prototype.attachControl = function () {
  319. var _this = this;
  320. var spritePredicate = function (sprite) {
  321. return sprite.isPickable && sprite.actionManager && sprite.actionManager.hasPickTriggers;
  322. };
  323. this._onPointerMove = function (evt) {
  324. if (!_this.cameraToUseForPointers && !_this.activeCamera) {
  325. return;
  326. }
  327. var canvas = _this._engine.getRenderingCanvas();
  328. _this._updatePointerPosition(evt);
  329. // Meshes
  330. var pickResult = _this.pick(_this._pointerX, _this._pointerY, function (mesh) { return mesh.isPickable && mesh.isVisible && mesh.isReady() && (_this.constantlyUpdateMeshUnderPointer || mesh.actionManager !== null && mesh.actionManager !== undefined); }, false, _this.cameraToUseForPointers);
  331. if (pickResult.hit && pickResult.pickedMesh) {
  332. _this._meshUnderPointer = pickResult.pickedMesh;
  333. _this.setPointerOverMesh(pickResult.pickedMesh);
  334. if (_this._meshUnderPointer.actionManager && _this._meshUnderPointer.actionManager.hasPointerTriggers) {
  335. canvas.style.cursor = "pointer";
  336. }
  337. else {
  338. canvas.style.cursor = "";
  339. }
  340. }
  341. else {
  342. // Sprites
  343. pickResult = _this.pickSprite(_this._pointerX, _this._pointerY, spritePredicate, false, _this.cameraToUseForPointers);
  344. if (pickResult.hit && pickResult.pickedSprite) {
  345. canvas.style.cursor = "pointer";
  346. }
  347. else {
  348. // Restore pointer
  349. _this.setPointerOverMesh(null);
  350. canvas.style.cursor = "";
  351. _this._meshUnderPointer = null;
  352. }
  353. }
  354. if (_this.onPointerMove) {
  355. _this.onPointerMove(evt, pickResult);
  356. }
  357. };
  358. this._onPointerDown = function (evt) {
  359. if (!_this.cameraToUseForPointers && !_this.activeCamera) {
  360. return;
  361. }
  362. _this._updatePointerPosition(evt);
  363. _this._startingPointerPosition.x = _this._pointerX;
  364. _this._startingPointerPosition.y = _this._pointerY;
  365. _this._startingPointerTime = new Date().getTime();
  366. var predicate = null;
  367. // Meshes
  368. _this._pickedDownMesh = null;
  369. if (!_this.onPointerDown && !_this.onPointerPick) {
  370. predicate = function (mesh) {
  371. return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.actionManager && mesh.actionManager.hasPointerTriggers;
  372. };
  373. }
  374. var pickResult = _this.pick(_this._pointerX, _this._pointerY, predicate, false, _this.cameraToUseForPointers);
  375. if (pickResult.hit && pickResult.pickedMesh) {
  376. if (pickResult.pickedMesh.actionManager) {
  377. _this._pickedDownMesh = pickResult.pickedMesh;
  378. if (pickResult.pickedMesh.actionManager.hasPickTriggers) {
  379. switch (evt.button) {
  380. case 0:
  381. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  382. break;
  383. case 1:
  384. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  385. break;
  386. case 2:
  387. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  388. break;
  389. }
  390. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickDownTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  391. }
  392. if (pickResult.pickedMesh.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnLongPressTrigger)) {
  393. var that = _this;
  394. window.setTimeout(function () {
  395. var pickResult = that.pick(that._pointerX, that._pointerY, function (mesh) { return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.actionManager && mesh.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnLongPressTrigger); }, false, that.cameraToUseForPointers);
  396. if (pickResult.hit && pickResult.pickedMesh) {
  397. if (pickResult.pickedMesh.actionManager) {
  398. if (that._startingPointerTime !== 0 && ((new Date().getTime() - that._startingPointerTime) > BABYLON.ActionManager.LongPressDelay) && (Math.abs(that._startingPointerPosition.x - that._pointerX) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(that._startingPointerPosition.y - that._pointerY) < BABYLON.ActionManager.DragMovementThreshold)) {
  399. that._startingPointerTime = 0;
  400. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  401. }
  402. }
  403. }
  404. }, BABYLON.ActionManager.LongPressDelay);
  405. }
  406. }
  407. }
  408. if (_this.onPointerDown) {
  409. _this.onPointerDown(evt, pickResult);
  410. }
  411. // Sprites
  412. _this._pickedDownSprite = null;
  413. if (_this.spriteManagers.length > 0) {
  414. pickResult = _this.pickSprite(_this._pointerX, _this._pointerY, spritePredicate, false, _this.cameraToUseForPointers);
  415. if (pickResult.hit && pickResult.pickedSprite) {
  416. if (pickResult.pickedSprite.actionManager) {
  417. _this._pickedDownSprite = pickResult.pickedSprite;
  418. switch (evt.button) {
  419. case 0:
  420. pickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, BABYLON.ActionEvent.CreateNewFromSprite(pickResult.pickedSprite, _this, evt));
  421. break;
  422. case 1:
  423. pickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, BABYLON.ActionEvent.CreateNewFromSprite(pickResult.pickedSprite, _this, evt));
  424. break;
  425. case 2:
  426. pickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, BABYLON.ActionEvent.CreateNewFromSprite(pickResult.pickedSprite, _this, evt));
  427. break;
  428. }
  429. pickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnPickDownTrigger, BABYLON.ActionEvent.CreateNewFromSprite(pickResult.pickedSprite, _this, evt));
  430. }
  431. }
  432. }
  433. };
  434. this._onPointerUp = function (evt) {
  435. if (!_this.cameraToUseForPointers && !_this.activeCamera) {
  436. return;
  437. }
  438. var predicate = null;
  439. _this._updatePointerPosition(evt);
  440. if (!_this.onPointerUp && !_this.onPointerPick) {
  441. predicate = function (mesh) {
  442. return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.actionManager && (mesh.actionManager.hasPickTriggers || mesh.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnLongPressTrigger));
  443. };
  444. }
  445. // Meshes
  446. var pickResult = _this.pick(_this._pointerX, _this._pointerY, predicate, false, _this.cameraToUseForPointers);
  447. if (pickResult.hit && pickResult.pickedMesh) {
  448. if (_this.onPointerPick && _this._pickedDownMesh != null && pickResult.pickedMesh == _this._pickedDownMesh) {
  449. _this.onPointerPick(evt, pickResult);
  450. }
  451. if (pickResult.pickedMesh.actionManager) {
  452. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickUpTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  453. if (Math.abs(_this._startingPointerPosition.x - _this._pointerX) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(_this._startingPointerPosition.y - _this._pointerY) < BABYLON.ActionManager.DragMovementThreshold) {
  454. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  455. }
  456. }
  457. }
  458. if (_this._pickedDownMesh && _this._pickedDownMesh !== pickResult.pickedMesh) {
  459. _this._pickedDownMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickOutTrigger, BABYLON.ActionEvent.CreateNew(_this._pickedDownMesh, evt));
  460. }
  461. if (_this.onPointerUp) {
  462. _this.onPointerUp(evt, pickResult);
  463. }
  464. _this._startingPointerTime = 0;
  465. // Sprites
  466. if (_this.spriteManagers.length > 0) {
  467. pickResult = _this.pickSprite(_this._pointerX, _this._pointerY, spritePredicate, false, _this.cameraToUseForPointers);
  468. if (pickResult.hit && pickResult.pickedSprite) {
  469. if (pickResult.pickedSprite.actionManager) {
  470. pickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnPickUpTrigger, BABYLON.ActionEvent.CreateNewFromSprite(pickResult.pickedSprite, _this, evt));
  471. if (Math.abs(_this._startingPointerPosition.x - _this._pointerX) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(_this._startingPointerPosition.y - _this._pointerY) < BABYLON.ActionManager.DragMovementThreshold) {
  472. pickResult.pickedSprite.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionEvent.CreateNewFromSprite(pickResult.pickedSprite, _this, evt));
  473. }
  474. }
  475. }
  476. if (_this._pickedDownSprite && _this._pickedDownSprite !== pickResult.pickedSprite) {
  477. _this._pickedDownSprite.actionManager.processTrigger(BABYLON.ActionManager.OnPickOutTrigger, BABYLON.ActionEvent.CreateNewFromSprite(_this._pickedDownSprite, _this, evt));
  478. }
  479. }
  480. };
  481. this._onKeyDown = function (evt) {
  482. if (_this.actionManager) {
  483. _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyDownTrigger, BABYLON.ActionEvent.CreateNewFromScene(_this, evt));
  484. }
  485. };
  486. this._onKeyUp = function (evt) {
  487. if (_this.actionManager) {
  488. _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyUpTrigger, BABYLON.ActionEvent.CreateNewFromScene(_this, evt));
  489. }
  490. };
  491. var eventPrefix = BABYLON.Tools.GetPointerPrefix();
  492. this._engine.getRenderingCanvas().addEventListener(eventPrefix + "move", this._onPointerMove, false);
  493. this._engine.getRenderingCanvas().addEventListener(eventPrefix + "down", this._onPointerDown, false);
  494. this._engine.getRenderingCanvas().addEventListener(eventPrefix + "up", this._onPointerUp, false);
  495. // Wheel
  496. this._engine.getRenderingCanvas().addEventListener('mousewheel', this._onPointerMove, false);
  497. this._engine.getRenderingCanvas().addEventListener('DOMMouseScroll', this._onPointerMove, false);
  498. BABYLON.Tools.RegisterTopRootEvents([
  499. { name: "keydown", handler: this._onKeyDown },
  500. { name: "keyup", handler: this._onKeyUp }
  501. ]);
  502. };
  503. Scene.prototype.detachControl = function () {
  504. var eventPrefix = BABYLON.Tools.GetPointerPrefix();
  505. this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "move", this._onPointerMove);
  506. this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "down", this._onPointerDown);
  507. this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "up", this._onPointerUp);
  508. // Wheel
  509. this._engine.getRenderingCanvas().removeEventListener('mousewheel', this._onPointerMove);
  510. this._engine.getRenderingCanvas().removeEventListener('DOMMouseScroll', this._onPointerMove);
  511. BABYLON.Tools.UnregisterTopRootEvents([
  512. { name: "keydown", handler: this._onKeyDown },
  513. { name: "keyup", handler: this._onKeyUp }
  514. ]);
  515. };
  516. // Ready
  517. Scene.prototype.isReady = function () {
  518. if (this._pendingData.length > 0) {
  519. return false;
  520. }
  521. var index;
  522. for (index = 0; index < this._geometries.length; index++) {
  523. var geometry = this._geometries[index];
  524. if (geometry.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
  525. return false;
  526. }
  527. }
  528. for (index = 0; index < this.meshes.length; index++) {
  529. var mesh = this.meshes[index];
  530. if (!mesh.isReady()) {
  531. return false;
  532. }
  533. var mat = mesh.material;
  534. if (mat) {
  535. if (!mat.isReady(mesh)) {
  536. return false;
  537. }
  538. }
  539. }
  540. return true;
  541. };
  542. Scene.prototype.resetCachedMaterial = function () {
  543. this._cachedMaterial = null;
  544. };
  545. Scene.prototype.registerBeforeRender = function (func) {
  546. this._onBeforeRenderCallbacks.push(func);
  547. };
  548. Scene.prototype.unregisterBeforeRender = function (func) {
  549. var index = this._onBeforeRenderCallbacks.indexOf(func);
  550. if (index > -1) {
  551. this._onBeforeRenderCallbacks.splice(index, 1);
  552. }
  553. };
  554. Scene.prototype.registerAfterRender = function (func) {
  555. this._onAfterRenderCallbacks.push(func);
  556. };
  557. Scene.prototype.unregisterAfterRender = function (func) {
  558. var index = this._onAfterRenderCallbacks.indexOf(func);
  559. if (index > -1) {
  560. this._onAfterRenderCallbacks.splice(index, 1);
  561. }
  562. };
  563. Scene.prototype._addPendingData = function (data) {
  564. this._pendingData.push(data);
  565. };
  566. Scene.prototype._removePendingData = function (data) {
  567. var index = this._pendingData.indexOf(data);
  568. if (index !== -1) {
  569. this._pendingData.splice(index, 1);
  570. }
  571. };
  572. Scene.prototype.getWaitingItemsCount = function () {
  573. return this._pendingData.length;
  574. };
  575. /**
  576. * Registers a function to be executed when the scene is ready.
  577. * @param {Function} func - the function to be executed.
  578. */
  579. Scene.prototype.executeWhenReady = function (func) {
  580. var _this = this;
  581. this._onReadyCallbacks.push(func);
  582. if (this._executeWhenReadyTimeoutId !== -1) {
  583. return;
  584. }
  585. this._executeWhenReadyTimeoutId = setTimeout(function () {
  586. _this._checkIsReady();
  587. }, 150);
  588. };
  589. Scene.prototype._checkIsReady = function () {
  590. var _this = this;
  591. if (this.isReady()) {
  592. this._onReadyCallbacks.forEach(function (func) {
  593. func();
  594. });
  595. this._onReadyCallbacks = [];
  596. this._executeWhenReadyTimeoutId = -1;
  597. return;
  598. }
  599. this._executeWhenReadyTimeoutId = setTimeout(function () {
  600. _this._checkIsReady();
  601. }, 150);
  602. };
  603. // Animations
  604. /**
  605. * Will start the animation sequence of a given target
  606. * @param target - the target
  607. * @param {number} from - from which frame should animation start
  608. * @param {number} to - till which frame should animation run.
  609. * @param {boolean} [loop] - should the animation loop
  610. * @param {number} [speedRatio] - the speed in which to run the animation
  611. * @param {Function} [onAnimationEnd] function to be executed when the animation ended.
  612. * @param {BABYLON.Animatable} [animatable] an animatable object. If not provided a new one will be created from the given params.
  613. * @return {BABYLON.Animatable} the animatable object created for this animation
  614. * @see BABYLON.Animatable
  615. * @see http://doc.babylonjs.com/page.php?p=22081
  616. */
  617. Scene.prototype.beginAnimation = function (target, from, to, loop, speedRatio, onAnimationEnd, animatable) {
  618. if (speedRatio === void 0) { speedRatio = 1.0; }
  619. this.stopAnimation(target);
  620. if (!animatable) {
  621. animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd);
  622. }
  623. // Local animations
  624. if (target.animations) {
  625. animatable.appendAnimations(target, target.animations);
  626. }
  627. // Children animations
  628. if (target.getAnimatables) {
  629. var animatables = target.getAnimatables();
  630. for (var index = 0; index < animatables.length; index++) {
  631. this.beginAnimation(animatables[index], from, to, loop, speedRatio, onAnimationEnd, animatable);
  632. }
  633. }
  634. return animatable;
  635. };
  636. Scene.prototype.beginDirectAnimation = function (target, animations, from, to, loop, speedRatio, onAnimationEnd) {
  637. if (speedRatio === undefined) {
  638. speedRatio = 1.0;
  639. }
  640. var animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, animations);
  641. return animatable;
  642. };
  643. Scene.prototype.getAnimatableByTarget = function (target) {
  644. for (var index = 0; index < this._activeAnimatables.length; index++) {
  645. if (this._activeAnimatables[index].target === target) {
  646. return this._activeAnimatables[index];
  647. }
  648. }
  649. return null;
  650. };
  651. Object.defineProperty(Scene.prototype, "Animatables", {
  652. get: function () {
  653. return this._activeAnimatables;
  654. },
  655. enumerable: true,
  656. configurable: true
  657. });
  658. /**
  659. * Will stop the animation of the given target
  660. * @param target - the target
  661. * @see beginAnimation
  662. */
  663. Scene.prototype.stopAnimation = function (target) {
  664. var animatable = this.getAnimatableByTarget(target);
  665. if (animatable) {
  666. animatable.stop();
  667. }
  668. };
  669. Scene.prototype._animate = function () {
  670. if (!this.animationsEnabled || this._activeAnimatables.length === 0) {
  671. return;
  672. }
  673. if (!this._animationStartDate) {
  674. if (this._pendingData.length > 0) {
  675. return;
  676. }
  677. this._animationStartDate = BABYLON.Tools.Now;
  678. }
  679. // Getting time
  680. var now = BABYLON.Tools.Now;
  681. var delay = now - this._animationStartDate;
  682. for (var index = 0; index < this._activeAnimatables.length; index++) {
  683. this._activeAnimatables[index]._animate(delay);
  684. }
  685. };
  686. // Matrix
  687. Scene.prototype.getViewMatrix = function () {
  688. return this._viewMatrix;
  689. };
  690. Scene.prototype.getProjectionMatrix = function () {
  691. return this._projectionMatrix;
  692. };
  693. Scene.prototype.getTransformMatrix = function () {
  694. return this._transformMatrix;
  695. };
  696. Scene.prototype.setTransformMatrix = function (view, projection) {
  697. this._viewMatrix = view;
  698. this._projectionMatrix = projection;
  699. this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);
  700. };
  701. // Methods
  702. Scene.prototype.addMesh = function (newMesh) {
  703. newMesh.uniqueId = this._uniqueIdCounter++;
  704. var position = this.meshes.push(newMesh);
  705. //notify the collision coordinator
  706. this.collisionCoordinator.onMeshAdded(newMesh);
  707. if (this.onNewMeshAdded) {
  708. this.onNewMeshAdded(newMesh, position, this);
  709. }
  710. };
  711. Scene.prototype.removeMesh = function (toRemove) {
  712. var index = this.meshes.indexOf(toRemove);
  713. if (index !== -1) {
  714. // Remove from the scene if mesh found
  715. this.meshes.splice(index, 1);
  716. }
  717. //notify the collision coordinator
  718. this.collisionCoordinator.onMeshRemoved(toRemove);
  719. if (this.onMeshRemoved) {
  720. this.onMeshRemoved(toRemove);
  721. }
  722. return index;
  723. };
  724. Scene.prototype.removeSkeleton = function (toRemove) {
  725. var index = this.skeletons.indexOf(toRemove);
  726. if (index !== -1) {
  727. // Remove from the scene if mesh found
  728. this.skeletons.splice(index, 1);
  729. }
  730. return index;
  731. };
  732. Scene.prototype.removeLight = function (toRemove) {
  733. var index = this.lights.indexOf(toRemove);
  734. if (index !== -1) {
  735. // Remove from the scene if mesh found
  736. this.lights.splice(index, 1);
  737. }
  738. if (this.onLightRemoved) {
  739. this.onLightRemoved(toRemove);
  740. }
  741. return index;
  742. };
  743. Scene.prototype.removeCamera = function (toRemove) {
  744. var index = this.cameras.indexOf(toRemove);
  745. if (index !== -1) {
  746. // Remove from the scene if mesh found
  747. this.cameras.splice(index, 1);
  748. }
  749. // Remove from activeCameras
  750. var index2 = this.activeCameras.indexOf(toRemove);
  751. if (index2 !== -1) {
  752. // Remove from the scene if mesh found
  753. this.activeCameras.splice(index2, 1);
  754. }
  755. // Reset the activeCamera
  756. if (this.activeCamera === toRemove) {
  757. if (this.cameras.length > 0) {
  758. this.activeCamera = this.cameras[0];
  759. }
  760. else {
  761. this.activeCamera = null;
  762. }
  763. }
  764. if (this.onCameraRemoved) {
  765. this.onCameraRemoved(toRemove);
  766. }
  767. return index;
  768. };
  769. Scene.prototype.addLight = function (newLight) {
  770. newLight.uniqueId = this._uniqueIdCounter++;
  771. var position = this.lights.push(newLight);
  772. if (this.onNewLightAdded) {
  773. this.onNewLightAdded(newLight, position, this);
  774. }
  775. };
  776. Scene.prototype.addCamera = function (newCamera) {
  777. newCamera.uniqueId = this._uniqueIdCounter++;
  778. var position = this.cameras.push(newCamera);
  779. if (this.onNewCameraAdded) {
  780. this.onNewCameraAdded(newCamera, position, this);
  781. }
  782. };
  783. /**
  784. * Switch active camera
  785. * @param {Camera} newCamera - new active camera
  786. * @param {boolean} attachControl - call attachControl for the new active camera (default: true)
  787. */
  788. Scene.prototype.swithActiveCamera = function (newCamera, attachControl) {
  789. if (attachControl === void 0) { attachControl = true; }
  790. var canvas = this._engine.getRenderingCanvas();
  791. this.activeCamera.detachControl(canvas);
  792. this.activeCamera = newCamera;
  793. if (attachControl) {
  794. newCamera.attachControl(canvas);
  795. }
  796. };
  797. /**
  798. * sets the active camera of the scene using its ID
  799. * @param {string} id - the camera's ID
  800. * @return {BABYLON.Camera|null} the new active camera or null if none found.
  801. * @see activeCamera
  802. */
  803. Scene.prototype.setActiveCameraByID = function (id) {
  804. var camera = this.getCameraByID(id);
  805. if (camera) {
  806. this.activeCamera = camera;
  807. return camera;
  808. }
  809. return null;
  810. };
  811. /**
  812. * sets the active camera of the scene using its name
  813. * @param {string} name - the camera's name
  814. * @return {BABYLON.Camera|null} the new active camera or null if none found.
  815. * @see activeCamera
  816. */
  817. Scene.prototype.setActiveCameraByName = function (name) {
  818. var camera = this.getCameraByName(name);
  819. if (camera) {
  820. this.activeCamera = camera;
  821. return camera;
  822. }
  823. return null;
  824. };
  825. /**
  826. * get a material using its id
  827. * @param {string} the material's ID
  828. * @return {BABYLON.Material|null} the material or null if none found.
  829. */
  830. Scene.prototype.getMaterialByID = function (id) {
  831. for (var index = 0; index < this.materials.length; index++) {
  832. if (this.materials[index].id === id) {
  833. return this.materials[index];
  834. }
  835. }
  836. return null;
  837. };
  838. /**
  839. * get a material using its name
  840. * @param {string} the material's name
  841. * @return {BABYLON.Material|null} the material or null if none found.
  842. */
  843. Scene.prototype.getMaterialByName = function (name) {
  844. for (var index = 0; index < this.materials.length; index++) {
  845. if (this.materials[index].name === name) {
  846. return this.materials[index];
  847. }
  848. }
  849. return null;
  850. };
  851. Scene.prototype.getLensFlareSystemByName = function (name) {
  852. for (var index = 0; index < this.lensFlareSystems.length; index++) {
  853. if (this.lensFlareSystems[index].name === name) {
  854. return this.lensFlareSystems[index];
  855. }
  856. }
  857. return null;
  858. };
  859. Scene.prototype.getCameraByID = function (id) {
  860. for (var index = 0; index < this.cameras.length; index++) {
  861. if (this.cameras[index].id === id) {
  862. return this.cameras[index];
  863. }
  864. }
  865. return null;
  866. };
  867. Scene.prototype.getCameraByUniqueID = function (uniqueId) {
  868. for (var index = 0; index < this.cameras.length; index++) {
  869. if (this.cameras[index].uniqueId === uniqueId) {
  870. return this.cameras[index];
  871. }
  872. }
  873. return null;
  874. };
  875. /**
  876. * get a camera using its name
  877. * @param {string} the camera's name
  878. * @return {BABYLON.Camera|null} the camera or null if none found.
  879. */
  880. Scene.prototype.getCameraByName = function (name) {
  881. for (var index = 0; index < this.cameras.length; index++) {
  882. if (this.cameras[index].name === name) {
  883. return this.cameras[index];
  884. }
  885. }
  886. return null;
  887. };
  888. /**
  889. * get a bone using its id
  890. * @param {string} the bone's id
  891. * @return {BABYLON.Bone|null} the bone or null if not found
  892. */
  893. Scene.prototype.getBoneByID = function (id) {
  894. for (var skeletonIndex = 0; skeletonIndex < this.skeletons.length; skeletonIndex++) {
  895. var skeleton = this.skeletons[skeletonIndex];
  896. for (var boneIndex = 0; boneIndex < skeleton.bones.length; boneIndex++) {
  897. if (skeleton.bones[boneIndex].id === id) {
  898. return skeleton.bones[boneIndex];
  899. }
  900. }
  901. }
  902. return null;
  903. };
  904. /**
  905. * get a bone using its id
  906. * @param {string} the bone's name
  907. * @return {BABYLON.Bone|null} the bone or null if not found
  908. */
  909. Scene.prototype.getBoneByName = function (name) {
  910. for (var skeletonIndex = 0; skeletonIndex < this.skeletons.length; skeletonIndex++) {
  911. var skeleton = this.skeletons[skeletonIndex];
  912. for (var boneIndex = 0; boneIndex < skeleton.bones.length; boneIndex++) {
  913. if (skeleton.bones[boneIndex].name === name) {
  914. return skeleton.bones[boneIndex];
  915. }
  916. }
  917. }
  918. return null;
  919. };
  920. /**
  921. * get a light node using its name
  922. * @param {string} the light's name
  923. * @return {BABYLON.Light|null} the light or null if none found.
  924. */
  925. Scene.prototype.getLightByName = function (name) {
  926. for (var index = 0; index < this.lights.length; index++) {
  927. if (this.lights[index].name === name) {
  928. return this.lights[index];
  929. }
  930. }
  931. return null;
  932. };
  933. /**
  934. * get a light node using its ID
  935. * @param {string} the light's id
  936. * @return {BABYLON.Light|null} the light or null if none found.
  937. */
  938. Scene.prototype.getLightByID = function (id) {
  939. for (var index = 0; index < this.lights.length; index++) {
  940. if (this.lights[index].id === id) {
  941. return this.lights[index];
  942. }
  943. }
  944. return null;
  945. };
  946. /**
  947. * get a light node using its scene-generated unique ID
  948. * @param {number} the light's unique id
  949. * @return {BABYLON.Light|null} the light or null if none found.
  950. */
  951. Scene.prototype.getLightByUniqueID = function (uniqueId) {
  952. for (var index = 0; index < this.lights.length; index++) {
  953. if (this.lights[index].uniqueId === uniqueId) {
  954. return this.lights[index];
  955. }
  956. }
  957. return null;
  958. };
  959. /**
  960. * get a particle system by id
  961. * @param id {number} the particle system id
  962. * @return {BABYLON.ParticleSystem|null} the corresponding system or null if none found.
  963. */
  964. Scene.prototype.getParticleSystemByID = function (id) {
  965. for (var index = 0; index < this.particleSystems.length; index++) {
  966. if (this.particleSystems[index].id === id) {
  967. return this.particleSystems[index];
  968. }
  969. }
  970. return null;
  971. };
  972. /**
  973. * get a geometry using its ID
  974. * @param {string} the geometry's id
  975. * @return {BABYLON.Geometry|null} the geometry or null if none found.
  976. */
  977. Scene.prototype.getGeometryByID = function (id) {
  978. for (var index = 0; index < this._geometries.length; index++) {
  979. if (this._geometries[index].id === id) {
  980. return this._geometries[index];
  981. }
  982. }
  983. return null;
  984. };
  985. /**
  986. * add a new geometry to this scene.
  987. * @param {BABYLON.Geometry} geometry - the geometry to be added to the scene.
  988. * @param {boolean} [force] - force addition, even if a geometry with this ID already exists
  989. * @return {boolean} was the geometry added or not
  990. */
  991. Scene.prototype.pushGeometry = function (geometry, force) {
  992. if (!force && this.getGeometryByID(geometry.id)) {
  993. return false;
  994. }
  995. this._geometries.push(geometry);
  996. //notify the collision coordinator
  997. this.collisionCoordinator.onGeometryAdded(geometry);
  998. if (this.onGeometryAdded) {
  999. this.onGeometryAdded(geometry);
  1000. }
  1001. return true;
  1002. };
  1003. /**
  1004. * Removes an existing geometry
  1005. * @param {BABYLON.Geometry} geometry - the geometry to be removed from the scene.
  1006. * @return {boolean} was the geometry removed or not
  1007. */
  1008. Scene.prototype.removeGeometry = function (geometry) {
  1009. var index = this._geometries.indexOf(geometry);
  1010. if (index > -1) {
  1011. this._geometries.splice(index, 1);
  1012. //notify the collision coordinator
  1013. this.collisionCoordinator.onGeometryDeleted(geometry);
  1014. if (this.onGeometryRemoved) {
  1015. this.onGeometryRemoved(geometry);
  1016. }
  1017. return true;
  1018. }
  1019. return false;
  1020. };
  1021. Scene.prototype.getGeometries = function () {
  1022. return this._geometries;
  1023. };
  1024. /**
  1025. * Get the first added mesh found of a given ID
  1026. * @param {string} id - the id to search for
  1027. * @return {BABYLON.AbstractMesh|null} the mesh found or null if not found at all.
  1028. */
  1029. Scene.prototype.getMeshByID = function (id) {
  1030. for (var index = 0; index < this.meshes.length; index++) {
  1031. if (this.meshes[index].id === id) {
  1032. return this.meshes[index];
  1033. }
  1034. }
  1035. return null;
  1036. };
  1037. /**
  1038. * Get a mesh with its auto-generated unique id
  1039. * @param {number} uniqueId - the unique id to search for
  1040. * @return {BABYLON.AbstractMesh|null} the mesh found or null if not found at all.
  1041. */
  1042. Scene.prototype.getMeshByUniqueID = function (uniqueId) {
  1043. for (var index = 0; index < this.meshes.length; index++) {
  1044. if (this.meshes[index].uniqueId === uniqueId) {
  1045. return this.meshes[index];
  1046. }
  1047. }
  1048. return null;
  1049. };
  1050. /**
  1051. * Get a the last added mesh found of a given ID
  1052. * @param {string} id - the id to search for
  1053. * @return {BABYLON.AbstractMesh|null} the mesh found or null if not found at all.
  1054. */
  1055. Scene.prototype.getLastMeshByID = function (id) {
  1056. for (var index = this.meshes.length - 1; index >= 0; index--) {
  1057. if (this.meshes[index].id === id) {
  1058. return this.meshes[index];
  1059. }
  1060. }
  1061. return null;
  1062. };
  1063. /**
  1064. * Get a the last added node (Mesh, Camera, Light) found of a given ID
  1065. * @param {string} id - the id to search for
  1066. * @return {BABYLON.Node|null} the node found or null if not found at all.
  1067. */
  1068. Scene.prototype.getLastEntryByID = function (id) {
  1069. var index;
  1070. for (index = this.meshes.length - 1; index >= 0; index--) {
  1071. if (this.meshes[index].id === id) {
  1072. return this.meshes[index];
  1073. }
  1074. }
  1075. for (index = this.cameras.length - 1; index >= 0; index--) {
  1076. if (this.cameras[index].id === id) {
  1077. return this.cameras[index];
  1078. }
  1079. }
  1080. for (index = this.lights.length - 1; index >= 0; index--) {
  1081. if (this.lights[index].id === id) {
  1082. return this.lights[index];
  1083. }
  1084. }
  1085. return null;
  1086. };
  1087. Scene.prototype.getNodeByID = function (id) {
  1088. var mesh = this.getMeshByID(id);
  1089. if (mesh) {
  1090. return mesh;
  1091. }
  1092. var light = this.getLightByID(id);
  1093. if (light) {
  1094. return light;
  1095. }
  1096. var camera = this.getCameraByID(id);
  1097. if (camera) {
  1098. return camera;
  1099. }
  1100. var bone = this.getBoneByID(id);
  1101. return bone;
  1102. };
  1103. Scene.prototype.getNodeByName = function (name) {
  1104. var mesh = this.getMeshByName(name);
  1105. if (mesh) {
  1106. return mesh;
  1107. }
  1108. var light = this.getLightByName(name);
  1109. if (light) {
  1110. return light;
  1111. }
  1112. var camera = this.getCameraByName(name);
  1113. if (camera) {
  1114. return camera;
  1115. }
  1116. var bone = this.getBoneByName(name);
  1117. return bone;
  1118. };
  1119. Scene.prototype.getMeshByName = function (name) {
  1120. for (var index = 0; index < this.meshes.length; index++) {
  1121. if (this.meshes[index].name === name) {
  1122. return this.meshes[index];
  1123. }
  1124. }
  1125. return null;
  1126. };
  1127. Scene.prototype.getSoundByName = function (name) {
  1128. var index;
  1129. if (BABYLON.AudioEngine) {
  1130. for (index = 0; index < this.mainSoundTrack.soundCollection.length; index++) {
  1131. if (this.mainSoundTrack.soundCollection[index].name === name) {
  1132. return this.mainSoundTrack.soundCollection[index];
  1133. }
  1134. }
  1135. for (var sdIndex = 0; sdIndex < this.soundTracks.length; sdIndex++) {
  1136. for (index = 0; index < this.soundTracks[sdIndex].soundCollection.length; index++) {
  1137. if (this.soundTracks[sdIndex].soundCollection[index].name === name) {
  1138. return this.soundTracks[sdIndex].soundCollection[index];
  1139. }
  1140. }
  1141. }
  1142. }
  1143. return null;
  1144. };
  1145. Scene.prototype.getLastSkeletonByID = function (id) {
  1146. for (var index = this.skeletons.length - 1; index >= 0; index--) {
  1147. if (this.skeletons[index].id === id) {
  1148. return this.skeletons[index];
  1149. }
  1150. }
  1151. return null;
  1152. };
  1153. Scene.prototype.getSkeletonById = function (id) {
  1154. for (var index = 0; index < this.skeletons.length; index++) {
  1155. if (this.skeletons[index].id === id) {
  1156. return this.skeletons[index];
  1157. }
  1158. }
  1159. return null;
  1160. };
  1161. Scene.prototype.getSkeletonByName = function (name) {
  1162. for (var index = 0; index < this.skeletons.length; index++) {
  1163. if (this.skeletons[index].name === name) {
  1164. return this.skeletons[index];
  1165. }
  1166. }
  1167. return null;
  1168. };
  1169. Scene.prototype.isActiveMesh = function (mesh) {
  1170. return (this._activeMeshes.indexOf(mesh) !== -1);
  1171. };
  1172. Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
  1173. if (mesh.alwaysSelectAsActiveMesh || mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
  1174. var material = subMesh.getMaterial();
  1175. if (mesh.showSubMeshesBoundingBox) {
  1176. this._boundingBoxRenderer.renderList.push(subMesh.getBoundingInfo().boundingBox);
  1177. }
  1178. if (material) {
  1179. // Render targets
  1180. if (material.getRenderTargetTextures) {
  1181. if (this._processedMaterials.indexOf(material) === -1) {
  1182. this._processedMaterials.push(material);
  1183. this._renderTargets.concatWithNoDuplicate(material.getRenderTargetTextures());
  1184. }
  1185. }
  1186. // Dispatch
  1187. this._activeIndices += subMesh.indexCount;
  1188. this._renderingManager.dispatch(subMesh);
  1189. }
  1190. }
  1191. };
  1192. Scene.prototype._evaluateActiveMeshes = function () {
  1193. this.activeCamera._activeMeshes.reset();
  1194. this._activeMeshes.reset();
  1195. this._renderingManager.reset();
  1196. this._processedMaterials.reset();
  1197. this._activeParticleSystems.reset();
  1198. this._activeSkeletons.reset();
  1199. this._softwareSkinnedMeshes.reset();
  1200. this._boundingBoxRenderer.reset();
  1201. this._edgesRenderers.reset();
  1202. if (!this._frustumPlanes) {
  1203. this._frustumPlanes = BABYLON.Frustum.GetPlanes(this._transformMatrix);
  1204. }
  1205. else {
  1206. BABYLON.Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);
  1207. }
  1208. // Meshes
  1209. var meshes;
  1210. var len;
  1211. if (this._selectionOctree) {
  1212. var selection = this._selectionOctree.select(this._frustumPlanes);
  1213. meshes = selection.data;
  1214. len = selection.length;
  1215. }
  1216. else {
  1217. len = this.meshes.length;
  1218. meshes = this.meshes;
  1219. }
  1220. for (var meshIndex = 0; meshIndex < len; meshIndex++) {
  1221. var mesh = meshes[meshIndex];
  1222. if (mesh.isBlocked) {
  1223. continue;
  1224. }
  1225. this._totalVertices += mesh.getTotalVertices();
  1226. if (!mesh.isReady() || !mesh.isEnabled()) {
  1227. continue;
  1228. }
  1229. mesh.computeWorldMatrix();
  1230. // Intersections
  1231. if (mesh.actionManager && mesh.actionManager.hasSpecificTriggers([BABYLON.ActionManager.OnIntersectionEnterTrigger, BABYLON.ActionManager.OnIntersectionExitTrigger])) {
  1232. this._meshesForIntersections.pushNoDuplicate(mesh);
  1233. }
  1234. // Switch to current LOD
  1235. var meshLOD = mesh.getLOD(this.activeCamera);
  1236. if (!meshLOD) {
  1237. continue;
  1238. }
  1239. mesh._preActivate();
  1240. if (mesh.alwaysSelectAsActiveMesh || mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) !== 0) && mesh.isInFrustum(this._frustumPlanes)) {
  1241. this._activeMeshes.push(mesh);
  1242. this.activeCamera._activeMeshes.push(mesh);
  1243. mesh._activate(this._renderId);
  1244. this._activeMesh(meshLOD);
  1245. }
  1246. }
  1247. // Particle systems
  1248. var beforeParticlesDate = BABYLON.Tools.Now;
  1249. if (this.particlesEnabled) {
  1250. BABYLON.Tools.StartPerformanceCounter("Particles", this.particleSystems.length > 0);
  1251. for (var particleIndex = 0; particleIndex < this.particleSystems.length; particleIndex++) {
  1252. var particleSystem = this.particleSystems[particleIndex];
  1253. if (!particleSystem.isStarted()) {
  1254. continue;
  1255. }
  1256. if (!particleSystem.emitter.position || (particleSystem.emitter && particleSystem.emitter.isEnabled())) {
  1257. this._activeParticleSystems.push(particleSystem);
  1258. particleSystem.animate();
  1259. }
  1260. }
  1261. BABYLON.Tools.EndPerformanceCounter("Particles", this.particleSystems.length > 0);
  1262. }
  1263. this._particlesDuration += BABYLON.Tools.Now - beforeParticlesDate;
  1264. };
  1265. Scene.prototype._activeMesh = function (mesh) {
  1266. if (mesh.skeleton && this.skeletonsEnabled) {
  1267. this._activeSkeletons.pushNoDuplicate(mesh.skeleton);
  1268. if (!mesh.computeBonesUsingShaders) {
  1269. this._softwareSkinnedMeshes.pushNoDuplicate(mesh);
  1270. }
  1271. }
  1272. if (mesh.showBoundingBox || this.forceShowBoundingBoxes) {
  1273. this._boundingBoxRenderer.renderList.push(mesh.getBoundingInfo().boundingBox);
  1274. }
  1275. if (mesh._edgesRenderer) {
  1276. this._edgesRenderers.push(mesh._edgesRenderer);
  1277. }
  1278. if (mesh && mesh.subMeshes) {
  1279. // Submeshes Octrees
  1280. var len;
  1281. var subMeshes;
  1282. if (mesh._submeshesOctree && mesh.useOctreeForRenderingSelection) {
  1283. var intersections = mesh._submeshesOctree.select(this._frustumPlanes);
  1284. len = intersections.length;
  1285. subMeshes = intersections.data;
  1286. }
  1287. else {
  1288. subMeshes = mesh.subMeshes;
  1289. len = subMeshes.length;
  1290. }
  1291. for (var subIndex = 0; subIndex < len; subIndex++) {
  1292. var subMesh = subMeshes[subIndex];
  1293. this._evaluateSubMesh(subMesh, mesh);
  1294. }
  1295. }
  1296. };
  1297. Scene.prototype.updateTransformMatrix = function (force) {
  1298. this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(force));
  1299. };
  1300. Scene.prototype._renderForCamera = function (camera) {
  1301. var engine = this._engine;
  1302. this.activeCamera = camera;
  1303. if (!this.activeCamera)
  1304. throw new Error("Active camera not set");
  1305. BABYLON.Tools.StartPerformanceCounter("Rendering camera " + this.activeCamera.name);
  1306. // Viewport
  1307. engine.setViewport(this.activeCamera.viewport);
  1308. // Camera
  1309. this.resetCachedMaterial();
  1310. this._renderId++;
  1311. this.updateTransformMatrix();
  1312. if (this.beforeCameraRender) {
  1313. this.beforeCameraRender(this.activeCamera);
  1314. }
  1315. // Meshes
  1316. var beforeEvaluateActiveMeshesDate = BABYLON.Tools.Now;
  1317. BABYLON.Tools.StartPerformanceCounter("Active meshes evaluation");
  1318. this._evaluateActiveMeshes();
  1319. this._evaluateActiveMeshesDuration += BABYLON.Tools.Now - beforeEvaluateActiveMeshesDate;
  1320. BABYLON.Tools.EndPerformanceCounter("Active meshes evaluation");
  1321. // Skeletons
  1322. for (var skeletonIndex = 0; skeletonIndex < this._activeSkeletons.length; skeletonIndex++) {
  1323. var skeleton = this._activeSkeletons.data[skeletonIndex];
  1324. skeleton.prepare();
  1325. }
  1326. // Software skinning
  1327. for (var softwareSkinnedMeshIndex = 0; softwareSkinnedMeshIndex < this._softwareSkinnedMeshes.length; softwareSkinnedMeshIndex++) {
  1328. var mesh = this._softwareSkinnedMeshes.data[softwareSkinnedMeshIndex];
  1329. mesh.applySkeleton(mesh.skeleton);
  1330. }
  1331. // Render targets
  1332. var beforeRenderTargetDate = BABYLON.Tools.Now;
  1333. if (this.renderTargetsEnabled && this._renderTargets.length > 0) {
  1334. BABYLON.Tools.StartPerformanceCounter("Render targets", this._renderTargets.length > 0);
  1335. for (var renderIndex = 0; renderIndex < this._renderTargets.length; renderIndex++) {
  1336. var renderTarget = this._renderTargets.data[renderIndex];
  1337. if (renderTarget._shouldRender()) {
  1338. this._renderId++;
  1339. var hasSpecialRenderTargetCamera = renderTarget.activeCamera && renderTarget.activeCamera !== this.activeCamera;
  1340. renderTarget.render(hasSpecialRenderTargetCamera, this.dumpNextRenderTargets);
  1341. }
  1342. }
  1343. BABYLON.Tools.EndPerformanceCounter("Render targets", this._renderTargets.length > 0);
  1344. this._renderId++;
  1345. engine.restoreDefaultFramebuffer(); // Restore back buffer
  1346. }
  1347. this._renderTargetsDuration += BABYLON.Tools.Now - beforeRenderTargetDate;
  1348. // Prepare Frame
  1349. this.postProcessManager._prepareFrame();
  1350. var beforeRenderDate = BABYLON.Tools.Now;
  1351. // Backgrounds
  1352. var layerIndex;
  1353. var layer;
  1354. if (this.layers.length) {
  1355. engine.setDepthBuffer(false);
  1356. for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
  1357. layer = this.layers[layerIndex];
  1358. if (layer.isBackground) {
  1359. layer.render();
  1360. }
  1361. }
  1362. engine.setDepthBuffer(true);
  1363. }
  1364. // Render
  1365. BABYLON.Tools.StartPerformanceCounter("Main render");
  1366. this._renderingManager.render(null, null, true, true);
  1367. BABYLON.Tools.EndPerformanceCounter("Main render");
  1368. // Bounding boxes
  1369. this._boundingBoxRenderer.render();
  1370. // Edges
  1371. for (var edgesRendererIndex = 0; edgesRendererIndex < this._edgesRenderers.length; edgesRendererIndex++) {
  1372. this._edgesRenderers.data[edgesRendererIndex].render();
  1373. }
  1374. // Lens flares
  1375. if (this.lensFlaresEnabled) {
  1376. BABYLON.Tools.StartPerformanceCounter("Lens flares", this.lensFlareSystems.length > 0);
  1377. for (var lensFlareSystemIndex = 0; lensFlareSystemIndex < this.lensFlareSystems.length; lensFlareSystemIndex++) {
  1378. var lensFlareSystem = this.lensFlareSystems[lensFlareSystemIndex];
  1379. if ((camera.layerMask & lensFlareSystem.layerMask) !== 0) {
  1380. lensFlareSystem.render();
  1381. }
  1382. }
  1383. BABYLON.Tools.EndPerformanceCounter("Lens flares", this.lensFlareSystems.length > 0);
  1384. }
  1385. // Foregrounds
  1386. if (this.layers.length) {
  1387. engine.setDepthBuffer(false);
  1388. for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
  1389. layer = this.layers[layerIndex];
  1390. if (!layer.isBackground) {
  1391. layer.render();
  1392. }
  1393. }
  1394. engine.setDepthBuffer(true);
  1395. }
  1396. this._renderDuration += BABYLON.Tools.Now - beforeRenderDate;
  1397. // Finalize frame
  1398. this.postProcessManager._finalizeFrame(camera.isIntermediate);
  1399. // Update camera
  1400. this.activeCamera._updateFromScene();
  1401. // Reset some special arrays
  1402. this._renderTargets.reset();
  1403. if (this.afterCameraRender) {
  1404. this.afterCameraRender(this.activeCamera);
  1405. }
  1406. BABYLON.Tools.EndPerformanceCounter("Rendering camera " + this.activeCamera.name);
  1407. };
  1408. Scene.prototype._processSubCameras = function (camera) {
  1409. if (camera.cameraRigMode === BABYLON.Camera.RIG_MODE_NONE) {
  1410. this._renderForCamera(camera);
  1411. return;
  1412. }
  1413. // rig cameras
  1414. for (var index = 0; index < camera._rigCameras.length; index++) {
  1415. this._renderForCamera(camera._rigCameras[index]);
  1416. }
  1417. this.activeCamera = camera;
  1418. this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix());
  1419. // Update camera
  1420. this.activeCamera._updateFromScene();
  1421. };
  1422. Scene.prototype._checkIntersections = function () {
  1423. for (var index = 0; index < this._meshesForIntersections.length; index++) {
  1424. var sourceMesh = this._meshesForIntersections.data[index];
  1425. for (var actionIndex = 0; actionIndex < sourceMesh.actionManager.actions.length; actionIndex++) {
  1426. var action = sourceMesh.actionManager.actions[actionIndex];
  1427. if (action.trigger === BABYLON.ActionManager.OnIntersectionEnterTrigger || action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  1428. var parameters = action.getTriggerParameter();
  1429. var otherMesh = parameters instanceof BABYLON.AbstractMesh ? parameters : parameters.mesh;
  1430. var areIntersecting = otherMesh.intersectsMesh(sourceMesh, parameters.usePreciseIntersection);
  1431. var currentIntersectionInProgress = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
  1432. if (areIntersecting && currentIntersectionInProgress === -1) {
  1433. if (action.trigger === BABYLON.ActionManager.OnIntersectionEnterTrigger) {
  1434. action._executeCurrent(BABYLON.ActionEvent.CreateNew(sourceMesh, null, otherMesh));
  1435. sourceMesh._intersectionsInProgress.push(otherMesh);
  1436. }
  1437. else if (action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  1438. sourceMesh._intersectionsInProgress.push(otherMesh);
  1439. }
  1440. }
  1441. else if (!areIntersecting && currentIntersectionInProgress > -1) {
  1442. //They intersected, and now they don't.
  1443. //is this trigger an exit trigger? execute an event.
  1444. if (action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  1445. action._executeCurrent(BABYLON.ActionEvent.CreateNew(sourceMesh, null, otherMesh));
  1446. }
  1447. //if this is an exit trigger, or no exit trigger exists, remove the id from the intersection in progress array.
  1448. if (!sourceMesh.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnIntersectionExitTrigger) || action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  1449. sourceMesh._intersectionsInProgress.splice(currentIntersectionInProgress, 1);
  1450. }
  1451. }
  1452. }
  1453. }
  1454. }
  1455. };
  1456. Scene.prototype.render = function () {
  1457. var startDate = BABYLON.Tools.Now;
  1458. this._particlesDuration = 0;
  1459. this._spritesDuration = 0;
  1460. this._activeParticles = 0;
  1461. this._renderDuration = 0;
  1462. this._renderTargetsDuration = 0;
  1463. this._evaluateActiveMeshesDuration = 0;
  1464. this._totalVertices = 0;
  1465. this._activeIndices = 0;
  1466. this._activeBones = 0;
  1467. this.getEngine().resetDrawCalls();
  1468. this._meshesForIntersections.reset();
  1469. this.resetCachedMaterial();
  1470. BABYLON.Tools.StartPerformanceCounter("Scene rendering");
  1471. // Actions
  1472. if (this.actionManager) {
  1473. this.actionManager.processTrigger(BABYLON.ActionManager.OnEveryFrameTrigger, null);
  1474. }
  1475. //Simplification Queue
  1476. if (this.simplificationQueue && !this.simplificationQueue.running) {
  1477. this.simplificationQueue.executeNext();
  1478. }
  1479. // Animations
  1480. var deltaTime = Math.max(Scene.MinDeltaTime, Math.min(this._engine.getDeltaTime(), Scene.MaxDeltaTime));
  1481. this._animationRatio = deltaTime * (60.0 / 1000.0);
  1482. this._animate();
  1483. // Physics
  1484. if (this._physicsEngine) {
  1485. BABYLON.Tools.StartPerformanceCounter("Physics");
  1486. this._physicsEngine._runOneStep(deltaTime / 1000.0);
  1487. BABYLON.Tools.EndPerformanceCounter("Physics");
  1488. }
  1489. // Before render
  1490. if (this.beforeRender) {
  1491. this.beforeRender();
  1492. }
  1493. var callbackIndex;
  1494. for (callbackIndex = 0; callbackIndex < this._onBeforeRenderCallbacks.length; callbackIndex++) {
  1495. this._onBeforeRenderCallbacks[callbackIndex]();
  1496. }
  1497. // Customs render targets
  1498. var beforeRenderTargetDate = BABYLON.Tools.Now;
  1499. var engine = this.getEngine();
  1500. var currentActiveCamera = this.activeCamera;
  1501. if (this.renderTargetsEnabled) {
  1502. BABYLON.Tools.StartPerformanceCounter("Custom render targets", this.customRenderTargets.length > 0);
  1503. for (var customIndex = 0; customIndex < this.customRenderTargets.length; customIndex++) {
  1504. var renderTarget = this.customRenderTargets[customIndex];
  1505. if (renderTarget._shouldRender()) {
  1506. this._renderId++;
  1507. this.activeCamera = renderTarget.activeCamera || this.activeCamera;
  1508. if (!this.activeCamera)
  1509. throw new Error("Active camera not set");
  1510. // Viewport
  1511. engine.setViewport(this.activeCamera.viewport);
  1512. // Camera
  1513. this.updateTransformMatrix();
  1514. renderTarget.render(currentActiveCamera !== this.activeCamera, this.dumpNextRenderTargets);
  1515. }
  1516. }
  1517. BABYLON.Tools.EndPerformanceCounter("Custom render targets", this.customRenderTargets.length > 0);
  1518. this._renderId++;
  1519. }
  1520. if (this.customRenderTargets.length > 0) {
  1521. engine.restoreDefaultFramebuffer();
  1522. }
  1523. this._renderTargetsDuration += BABYLON.Tools.Now - beforeRenderTargetDate;
  1524. this.activeCamera = currentActiveCamera;
  1525. // Procedural textures
  1526. if (this.proceduralTexturesEnabled) {
  1527. BABYLON.Tools.StartPerformanceCounter("Procedural textures", this._proceduralTextures.length > 0);
  1528. for (var proceduralIndex = 0; proceduralIndex < this._proceduralTextures.length; proceduralIndex++) {
  1529. var proceduralTexture = this._proceduralTextures[proceduralIndex];
  1530. if (proceduralTexture._shouldRender()) {
  1531. proceduralTexture.render();
  1532. }
  1533. }
  1534. BABYLON.Tools.EndPerformanceCounter("Procedural textures", this._proceduralTextures.length > 0);
  1535. }
  1536. // Clear
  1537. this._engine.clear(this.clearColor, this.autoClear || this.forceWireframe || this.forcePointsCloud, true);
  1538. // Shadows
  1539. if (this.shadowsEnabled) {
  1540. for (var lightIndex = 0; lightIndex < this.lights.length; lightIndex++) {
  1541. var light = this.lights[lightIndex];
  1542. var shadowGenerator = light.getShadowGenerator();
  1543. if (light.isEnabled() && shadowGenerator && shadowGenerator.getShadowMap().getScene().textures.indexOf(shadowGenerator.getShadowMap()) !== -1) {
  1544. this._renderTargets.push(shadowGenerator.getShadowMap());
  1545. }
  1546. }
  1547. }
  1548. // Depth renderer
  1549. if (this._depthRenderer) {
  1550. this._renderTargets.push(this._depthRenderer.getDepthMap());
  1551. }
  1552. // RenderPipeline
  1553. this.postProcessRenderPipelineManager.update();
  1554. // Multi-cameras?
  1555. if (this.activeCameras.length > 0) {
  1556. var currentRenderId = this._renderId;
  1557. for (var cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {
  1558. this._renderId = currentRenderId;
  1559. if (cameraIndex > 0) {
  1560. this._engine.clear(0, false, true);
  1561. }
  1562. this._processSubCameras(this.activeCameras[cameraIndex]);
  1563. }
  1564. }
  1565. else {
  1566. if (!this.activeCamera) {
  1567. throw new Error("No camera defined");
  1568. }
  1569. this._processSubCameras(this.activeCamera);
  1570. }
  1571. // Intersection checks
  1572. this._checkIntersections();
  1573. // Update the audio listener attached to the camera
  1574. if (BABYLON.AudioEngine) {
  1575. this._updateAudioParameters();
  1576. }
  1577. // After render
  1578. if (this.afterRender) {
  1579. this.afterRender();
  1580. }
  1581. for (callbackIndex = 0; callbackIndex < this._onAfterRenderCallbacks.length; callbackIndex++) {
  1582. this._onAfterRenderCallbacks[callbackIndex]();
  1583. }
  1584. // Cleaning
  1585. for (var index = 0; index < this._toBeDisposed.length; index++) {
  1586. this._toBeDisposed.data[index].dispose();
  1587. this._toBeDisposed[index] = null;
  1588. }
  1589. this._toBeDisposed.reset();
  1590. if (this.dumpNextRenderTargets) {
  1591. this.dumpNextRenderTargets = false;
  1592. }
  1593. BABYLON.Tools.EndPerformanceCounter("Scene rendering");
  1594. this._lastFrameDuration = BABYLON.Tools.Now - startDate;
  1595. };
  1596. Scene.prototype._updateAudioParameters = function () {
  1597. if (!this.audioEnabled || (this.mainSoundTrack.soundCollection.length === 0 && this.soundTracks.length === 1)) {
  1598. return;
  1599. }
  1600. var listeningCamera;
  1601. var audioEngine = BABYLON.Engine.audioEngine;
  1602. if (this.activeCameras.length > 0) {
  1603. listeningCamera = this.activeCameras[0];
  1604. }
  1605. else {
  1606. listeningCamera = this.activeCamera;
  1607. }
  1608. if (listeningCamera && audioEngine.canUseWebAudio) {
  1609. audioEngine.audioContext.listener.setPosition(listeningCamera.position.x, listeningCamera.position.y, listeningCamera.position.z);
  1610. var mat = BABYLON.Matrix.Invert(listeningCamera.getViewMatrix());
  1611. var cameraDirection = BABYLON.Vector3.TransformNormal(new BABYLON.Vector3(0, 0, -1), mat);
  1612. cameraDirection.normalize();
  1613. audioEngine.audioContext.listener.setOrientation(cameraDirection.x, cameraDirection.y, cameraDirection.z, 0, 1, 0);
  1614. var i;
  1615. for (i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  1616. var sound = this.mainSoundTrack.soundCollection[i];
  1617. if (sound.useCustomAttenuation) {
  1618. sound.updateDistanceFromListener();
  1619. }
  1620. }
  1621. for (i = 0; i < this.soundTracks.length; i++) {
  1622. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  1623. sound = this.soundTracks[i].soundCollection[j];
  1624. if (sound.useCustomAttenuation) {
  1625. sound.updateDistanceFromListener();
  1626. }
  1627. }
  1628. }
  1629. }
  1630. };
  1631. Object.defineProperty(Scene.prototype, "audioEnabled", {
  1632. // Audio
  1633. get: function () {
  1634. return this._audioEnabled;
  1635. },
  1636. set: function (value) {
  1637. this._audioEnabled = value;
  1638. if (BABYLON.AudioEngine) {
  1639. if (this._audioEnabled) {
  1640. this._enableAudio();
  1641. }
  1642. else {
  1643. this._disableAudio();
  1644. }
  1645. }
  1646. },
  1647. enumerable: true,
  1648. configurable: true
  1649. });
  1650. Scene.prototype._disableAudio = function () {
  1651. var i;
  1652. for (i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  1653. this.mainSoundTrack.soundCollection[i].pause();
  1654. }
  1655. for (i = 0; i < this.soundTracks.length; i++) {
  1656. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  1657. this.soundTracks[i].soundCollection[j].pause();
  1658. }
  1659. }
  1660. };
  1661. Scene.prototype._enableAudio = function () {
  1662. var i;
  1663. for (i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  1664. if (this.mainSoundTrack.soundCollection[i].isPaused) {
  1665. this.mainSoundTrack.soundCollection[i].play();
  1666. }
  1667. }
  1668. for (i = 0; i < this.soundTracks.length; i++) {
  1669. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  1670. if (this.soundTracks[i].soundCollection[j].isPaused) {
  1671. this.soundTracks[i].soundCollection[j].play();
  1672. }
  1673. }
  1674. }
  1675. };
  1676. Object.defineProperty(Scene.prototype, "headphone", {
  1677. get: function () {
  1678. return this._headphone;
  1679. },
  1680. set: function (value) {
  1681. this._headphone = value;
  1682. if (BABYLON.AudioEngine) {
  1683. if (this._headphone) {
  1684. this._switchAudioModeForHeadphones();
  1685. }
  1686. else {
  1687. this._switchAudioModeForNormalSpeakers();
  1688. }
  1689. }
  1690. },
  1691. enumerable: true,
  1692. configurable: true
  1693. });
  1694. Scene.prototype._switchAudioModeForHeadphones = function () {
  1695. this.mainSoundTrack.switchPanningModelToHRTF();
  1696. for (var i = 0; i < this.soundTracks.length; i++) {
  1697. this.soundTracks[i].switchPanningModelToHRTF();
  1698. }
  1699. };
  1700. Scene.prototype._switchAudioModeForNormalSpeakers = function () {
  1701. this.mainSoundTrack.switchPanningModelToEqualPower();
  1702. for (var i = 0; i < this.soundTracks.length; i++) {
  1703. this.soundTracks[i].switchPanningModelToEqualPower();
  1704. }
  1705. };
  1706. Scene.prototype.enableDepthRenderer = function () {
  1707. if (this._depthRenderer) {
  1708. return this._depthRenderer;
  1709. }
  1710. this._depthRenderer = new BABYLON.DepthRenderer(this);
  1711. return this._depthRenderer;
  1712. };
  1713. Scene.prototype.disableDepthRenderer = function () {
  1714. if (!this._depthRenderer) {
  1715. return;
  1716. }
  1717. this._depthRenderer.dispose();
  1718. this._depthRenderer = null;
  1719. };
  1720. Scene.prototype.freezeMaterials = function () {
  1721. for (var i = 0; i < this.materials.length; i++) {
  1722. this.materials[i].freeze();
  1723. }
  1724. };
  1725. Scene.prototype.unfreezeMaterials = function () {
  1726. for (var i = 0; i < this.materials.length; i++) {
  1727. this.materials[i].unfreeze();
  1728. }
  1729. };
  1730. Scene.prototype.dispose = function () {
  1731. this.beforeRender = null;
  1732. this.afterRender = null;
  1733. this.skeletons = [];
  1734. this._boundingBoxRenderer.dispose();
  1735. if (this._depthRenderer) {
  1736. this._depthRenderer.dispose();
  1737. }
  1738. // Debug layer
  1739. this.debugLayer.hide();
  1740. // Events
  1741. if (this.onDispose) {
  1742. this.onDispose();
  1743. }
  1744. this._onBeforeRenderCallbacks = [];
  1745. this._onAfterRenderCallbacks = [];
  1746. this.detachControl();
  1747. // Release sounds & sounds tracks
  1748. if (BABYLON.AudioEngine) {
  1749. this.disposeSounds();
  1750. }
  1751. // Detach cameras
  1752. var canvas = this._engine.getRenderingCanvas();
  1753. var index;
  1754. for (index = 0; index < this.cameras.length; index++) {
  1755. this.cameras[index].detachControl(canvas);
  1756. }
  1757. // Release lights
  1758. while (this.lights.length) {
  1759. this.lights[0].dispose();
  1760. }
  1761. // Release meshes
  1762. while (this.meshes.length) {
  1763. this.meshes[0].dispose(true);
  1764. }
  1765. // Release cameras
  1766. while (this.cameras.length) {
  1767. this.cameras[0].dispose();
  1768. }
  1769. // Release materials
  1770. while (this.materials.length) {
  1771. this.materials[0].dispose();
  1772. }
  1773. // Release particles
  1774. while (this.particleSystems.length) {
  1775. this.particleSystems[0].dispose();
  1776. }
  1777. // Release sprites
  1778. while (this.spriteManagers.length) {
  1779. this.spriteManagers[0].dispose();
  1780. }
  1781. // Release layers
  1782. while (this.layers.length) {
  1783. this.layers[0].dispose();
  1784. }
  1785. // Release textures
  1786. while (this.textures.length) {
  1787. this.textures[0].dispose();
  1788. }
  1789. // Post-processes
  1790. this.postProcessManager.dispose();
  1791. // Physics
  1792. if (this._physicsEngine) {
  1793. this.disablePhysicsEngine();
  1794. }
  1795. // Remove from engine
  1796. index = this._engine.scenes.indexOf(this);
  1797. if (index > -1) {
  1798. this._engine.scenes.splice(index, 1);
  1799. }
  1800. this._engine.wipeCaches();
  1801. };
  1802. // Release sounds & sounds tracks
  1803. Scene.prototype.disposeSounds = function () {
  1804. this.mainSoundTrack.dispose();
  1805. for (var scIndex = 0; scIndex < this.soundTracks.length; scIndex++) {
  1806. this.soundTracks[scIndex].dispose();
  1807. }
  1808. };
  1809. // Octrees
  1810. Scene.prototype.getWorldExtends = function () {
  1811. var min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  1812. var max = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  1813. for (var index = 0; index < this.meshes.length; index++) {
  1814. var mesh = this.meshes[index];
  1815. mesh.computeWorldMatrix(true);
  1816. var minBox = mesh.getBoundingInfo().boundingBox.minimumWorld;
  1817. var maxBox = mesh.getBoundingInfo().boundingBox.maximumWorld;
  1818. BABYLON.Tools.CheckExtends(minBox, min, max);
  1819. BABYLON.Tools.CheckExtends(maxBox, min, max);
  1820. }
  1821. return {
  1822. min: min,
  1823. max: max
  1824. };
  1825. };
  1826. Scene.prototype.createOrUpdateSelectionOctree = function (maxCapacity, maxDepth) {
  1827. if (maxCapacity === void 0) { maxCapacity = 64; }
  1828. if (maxDepth === void 0) { maxDepth = 2; }
  1829. if (!this._selectionOctree) {
  1830. this._selectionOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForMeshes, maxCapacity, maxDepth);
  1831. }
  1832. var worldExtends = this.getWorldExtends();
  1833. // Update octree
  1834. this._selectionOctree.update(worldExtends.min, worldExtends.max, this.meshes);
  1835. return this._selectionOctree;
  1836. };
  1837. // Picking
  1838. Scene.prototype.createPickingRay = function (x, y, world, camera, cameraViewSpace) {
  1839. if (cameraViewSpace === void 0) { cameraViewSpace = false; }
  1840. var engine = this._engine;
  1841. if (!camera) {
  1842. if (!this.activeCamera)
  1843. throw new Error("Active camera not set");
  1844. camera = this.activeCamera;
  1845. }
  1846. var cameraViewport = camera.viewport;
  1847. var viewport = cameraViewport.toGlobal(engine);
  1848. // Moving coordinates to local viewport world
  1849. x = x / this._engine.getHardwareScalingLevel() - viewport.x;
  1850. y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
  1851. return BABYLON.Ray.CreateNew(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), cameraViewSpace ? BABYLON.Matrix.Identity() : camera.getViewMatrix(), camera.getProjectionMatrix());
  1852. // return BABYLON.Ray.CreateNew(x / window.devicePixelRatio, y / window.devicePixelRatio, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
  1853. };
  1854. Scene.prototype.createPickingRayInCameraSpace = function (x, y, camera) {
  1855. var engine = this._engine;
  1856. if (!camera) {
  1857. if (!this.activeCamera)
  1858. throw new Error("Active camera not set");
  1859. camera = this.activeCamera;
  1860. }
  1861. var cameraViewport = camera.viewport;
  1862. var viewport = cameraViewport.toGlobal(engine);
  1863. var identity = BABYLON.Matrix.Identity();
  1864. // Moving coordinates to local viewport world
  1865. x = x / this._engine.getHardwareScalingLevel() - viewport.x;
  1866. y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
  1867. return BABYLON.Ray.CreateNew(x, y, viewport.width, viewport.height, identity, identity, camera.getProjectionMatrix());
  1868. };
  1869. Scene.prototype._internalPick = function (rayFunction, predicate, fastCheck) {
  1870. var pickingInfo = null;
  1871. for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {
  1872. var mesh = this.meshes[meshIndex];
  1873. if (predicate) {
  1874. if (!predicate(mesh)) {
  1875. continue;
  1876. }
  1877. }
  1878. else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
  1879. continue;
  1880. }
  1881. var world = mesh.getWorldMatrix();
  1882. var ray = rayFunction(world);
  1883. var result = mesh.intersects(ray, fastCheck);
  1884. if (!result || !result.hit)
  1885. continue;
  1886. if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance)
  1887. continue;
  1888. pickingInfo = result;
  1889. if (fastCheck) {
  1890. break;
  1891. }
  1892. }
  1893. return pickingInfo || new BABYLON.PickingInfo();
  1894. };
  1895. Scene.prototype._internalPickSprites = function (ray, predicate, fastCheck, camera) {
  1896. var pickingInfo = null;
  1897. camera = camera || this.activeCamera;
  1898. if (this.spriteManagers.length > 0) {
  1899. for (var spriteIndex = 0; spriteIndex < this.spriteManagers.length; spriteIndex++) {
  1900. var spriteManager = this.spriteManagers[spriteIndex];
  1901. if (!spriteManager.isPickable) {
  1902. continue;
  1903. }
  1904. var result = spriteManager.intersects(ray, camera, predicate, fastCheck);
  1905. if (!result || !result.hit)
  1906. continue;
  1907. if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance)
  1908. continue;
  1909. pickingInfo = result;
  1910. if (fastCheck) {
  1911. break;
  1912. }
  1913. }
  1914. }
  1915. return pickingInfo || new BABYLON.PickingInfo();
  1916. };
  1917. Scene.prototype.pick = function (x, y, predicate, fastCheck, camera) {
  1918. var _this = this;
  1919. /// <summary>Launch a ray to try to pick a mesh in the scene</summary>
  1920. /// <param name="x">X position on screen</param>
  1921. /// <param name="y">Y position on screen</param>
  1922. /// <param name="predicate">Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true</param>
  1923. /// <param name="fastCheck">Launch a fast check only using the bounding boxes. Can be set to null.</param>
  1924. /// <param name="camera">camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used</param>
  1925. return this._internalPick(function (world) { return _this.createPickingRay(x, y, world, camera); }, predicate, fastCheck);
  1926. };
  1927. Scene.prototype.pickSprite = function (x, y, predicate, fastCheck, camera) {
  1928. /// <summary>Launch a ray to try to pick a mesh in the scene</summary>
  1929. /// <param name="x">X position on screen</param>
  1930. /// <param name="y">Y position on screen</param>
  1931. /// <param name="predicate">Predicate function used to determine eligible sprites. Can be set to null. In this case, a sprite must have isPickable set to true</param>
  1932. /// <param name="fastCheck">Launch a fast check only using the bounding boxes. Can be set to null.</param>
  1933. /// <param name="camera">camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used</param>
  1934. return this._internalPickSprites(this.createPickingRayInCameraSpace(x, y, camera), predicate, fastCheck, camera);
  1935. };
  1936. Scene.prototype.pickWithRay = function (ray, predicate, fastCheck) {
  1937. var _this = this;
  1938. return this._internalPick(function (world) {
  1939. if (!_this._pickWithRayInverseMatrix) {
  1940. _this._pickWithRayInverseMatrix = BABYLON.Matrix.Identity();
  1941. }
  1942. world.invertToRef(_this._pickWithRayInverseMatrix);
  1943. return BABYLON.Ray.Transform(ray, _this._pickWithRayInverseMatrix);
  1944. }, predicate, fastCheck);
  1945. };
  1946. Scene.prototype.setPointerOverMesh = function (mesh) {
  1947. if (this._pointerOverMesh === mesh) {
  1948. return;
  1949. }
  1950. if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
  1951. this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
  1952. }
  1953. this._pointerOverMesh = mesh;
  1954. if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
  1955. this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
  1956. }
  1957. };
  1958. Scene.prototype.getPointerOverMesh = function () {
  1959. return this._pointerOverMesh;
  1960. };
  1961. // Physics
  1962. Scene.prototype.getPhysicsEngine = function () {
  1963. return this._physicsEngine;
  1964. };
  1965. /**
  1966. * Enables physics to the current scene
  1967. * @param {BABYLON.Vector3} [gravity] - the scene's gravity for the physics engine
  1968. * @param {BABYLON.IPhysicsEnginePlugin} [plugin] - The physics engine to be used. defaults to OimoJS.
  1969. * @return {boolean} was the physics engine initialized
  1970. */
  1971. Scene.prototype.enablePhysics = function (gravity, plugin) {
  1972. if (this._physicsEngine) {
  1973. return true;
  1974. }
  1975. this._physicsEngine = new BABYLON.PhysicsEngine(plugin);
  1976. if (!this._physicsEngine.isSupported()) {
  1977. this._physicsEngine = null;
  1978. return false;
  1979. }
  1980. this._physicsEngine._initialize(gravity);
  1981. return true;
  1982. };
  1983. Scene.prototype.disablePhysicsEngine = function () {
  1984. if (!this._physicsEngine) {
  1985. return;
  1986. }
  1987. this._physicsEngine.dispose();
  1988. this._physicsEngine = undefined;
  1989. };
  1990. Scene.prototype.isPhysicsEnabled = function () {
  1991. return this._physicsEngine !== undefined;
  1992. };
  1993. /**
  1994. * Sets the gravity of the physics engine (and NOT of the scene)
  1995. * @param {BABYLON.Vector3} [gravity] - the new gravity to be used
  1996. */
  1997. Scene.prototype.setGravity = function (gravity) {
  1998. if (!this._physicsEngine) {
  1999. return;
  2000. }
  2001. this._physicsEngine._setGravity(gravity);
  2002. };
  2003. Scene.prototype.createCompoundImpostor = function (parts, options) {
  2004. if (parts.parts) {
  2005. options = parts;
  2006. parts = parts.parts;
  2007. }
  2008. if (!this._physicsEngine) {
  2009. return null;
  2010. }
  2011. for (var index = 0; index < parts.length; index++) {
  2012. var mesh = parts[index].mesh;
  2013. mesh._physicImpostor = parts[index].impostor;
  2014. mesh._physicsMass = options.mass / parts.length;
  2015. mesh._physicsFriction = options.friction;
  2016. mesh._physicRestitution = options.restitution;
  2017. }
  2018. return this._physicsEngine._registerMeshesAsCompound(parts, options);
  2019. };
  2020. Scene.prototype.deleteCompoundImpostor = function (compound) {
  2021. for (var index = 0; index < compound.parts.length; index++) {
  2022. var mesh = compound.parts[index].mesh;
  2023. mesh._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
  2024. this._physicsEngine._unregisterMesh(mesh);
  2025. }
  2026. };
  2027. // Misc.
  2028. Scene.prototype.createDefaultCameraOrLight = function () {
  2029. // Light
  2030. if (this.lights.length === 0) {
  2031. new BABYLON.HemisphericLight("default light", BABYLON.Vector3.Up(), this);
  2032. }
  2033. // Camera
  2034. if (!this.activeCamera) {
  2035. var camera = new BABYLON.FreeCamera("default camera", BABYLON.Vector3.Zero(), this);
  2036. // Compute position
  2037. var worldExtends = this.getWorldExtends();
  2038. var worldCenter = worldExtends.min.add(worldExtends.max.subtract(worldExtends.min).scale(0.5));
  2039. camera.position = new BABYLON.Vector3(worldCenter.x, worldCenter.y, worldExtends.min.z - (worldExtends.max.z - worldExtends.min.z));
  2040. camera.setTarget(worldCenter);
  2041. this.activeCamera = camera;
  2042. }
  2043. };
  2044. // Tags
  2045. Scene.prototype._getByTags = function (list, tagsQuery, forEach) {
  2046. if (tagsQuery === undefined) {
  2047. // returns the complete list (could be done with BABYLON.Tags.MatchesQuery but no need to have a for-loop here)
  2048. return list;
  2049. }
  2050. var listByTags = [];
  2051. forEach = forEach || (function (item) { return; });
  2052. for (var i in list) {
  2053. var item = list[i];
  2054. if (BABYLON.Tags.MatchesQuery(item, tagsQuery)) {
  2055. listByTags.push(item);
  2056. forEach(item);
  2057. }
  2058. }
  2059. return listByTags;
  2060. };
  2061. Scene.prototype.getMeshesByTags = function (tagsQuery, forEach) {
  2062. return this._getByTags(this.meshes, tagsQuery, forEach);
  2063. };
  2064. Scene.prototype.getCamerasByTags = function (tagsQuery, forEach) {
  2065. return this._getByTags(this.cameras, tagsQuery, forEach);
  2066. };
  2067. Scene.prototype.getLightsByTags = function (tagsQuery, forEach) {
  2068. return this._getByTags(this.lights, tagsQuery, forEach);
  2069. };
  2070. Scene.prototype.getMaterialByTags = function (tagsQuery, forEach) {
  2071. return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));
  2072. };
  2073. // Statics
  2074. Scene._FOGMODE_NONE = 0;
  2075. Scene._FOGMODE_EXP = 1;
  2076. Scene._FOGMODE_EXP2 = 2;
  2077. Scene._FOGMODE_LINEAR = 3;
  2078. Scene.MinDeltaTime = 1.0;
  2079. Scene.MaxDeltaTime = 1000.0;
  2080. return Scene;
  2081. })();
  2082. BABYLON.Scene = Scene;
  2083. })(BABYLON || (BABYLON = {}));