babylon.scene.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  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.cameraToUseForPointers = null; // Define this parameter if you are using multiple cameras and you want to specify which one should be used for pointer position
  22. // Fog
  23. /**
  24. * is fog enabled on this scene.
  25. * @type {boolean}
  26. */
  27. this.fogEnabled = true;
  28. this.fogMode = Scene.FOGMODE_NONE;
  29. this.fogColor = new BABYLON.Color3(0.2, 0.2, 0.3);
  30. this.fogDensity = 0.1;
  31. this.fogStart = 0;
  32. this.fogEnd = 1000.0;
  33. // Lights
  34. /**
  35. * is shadow enabled on this scene.
  36. * @type {boolean}
  37. */
  38. this.shadowsEnabled = true;
  39. /**
  40. * is light enabled on this scene.
  41. * @type {boolean}
  42. */
  43. this.lightsEnabled = true;
  44. /**
  45. * All of the lights added to this scene.
  46. * @see BABYLON.Light
  47. * @type {BABYLON.Light[]}
  48. */
  49. this.lights = new Array();
  50. // Cameras
  51. /**
  52. * All of the cameras added to this scene.
  53. * @see BABYLON.Camera
  54. * @type {BABYLON.Camera[]}
  55. */
  56. this.cameras = new Array();
  57. this.activeCameras = new Array();
  58. // Meshes
  59. /**
  60. * All of the (abstract) meshes added to this scene.
  61. * @see BABYLON.AbstractMesh
  62. * @type {BABYLON.AbstractMesh[]}
  63. */
  64. this.meshes = new Array();
  65. // Geometries
  66. this._geometries = new Array();
  67. this.materials = new Array();
  68. this.multiMaterials = new Array();
  69. this.defaultMaterial = new BABYLON.StandardMaterial("default material", this);
  70. // Textures
  71. this.texturesEnabled = true;
  72. this.textures = new Array();
  73. // Particles
  74. this.particlesEnabled = true;
  75. this.particleSystems = new Array();
  76. // Sprites
  77. this.spritesEnabled = true;
  78. this.spriteManagers = new Array();
  79. // Layers
  80. this.layers = new Array();
  81. // Skeletons
  82. this.skeletonsEnabled = true;
  83. this.skeletons = new Array();
  84. // Lens flares
  85. this.lensFlaresEnabled = true;
  86. this.lensFlareSystems = new Array();
  87. // Collisions
  88. this.collisionsEnabled = true;
  89. this.gravity = new BABYLON.Vector3(0, -9.0, 0);
  90. // Postprocesses
  91. this.postProcessesEnabled = true;
  92. // Customs render targets
  93. this.renderTargetsEnabled = true;
  94. this.dumpNextRenderTargets = false;
  95. this.customRenderTargets = new Array();
  96. // Imported meshes
  97. this.importedMeshesFiles = new Array();
  98. this._actionManagers = new Array();
  99. this._meshesForIntersections = new BABYLON.SmartArray(256);
  100. // Procedural textures
  101. this.proceduralTexturesEnabled = true;
  102. this._proceduralTextures = new Array();
  103. this.soundTracks = new Array();
  104. this._audioEnabled = true;
  105. this._headphone = false;
  106. this._totalVertices = 0;
  107. this._activeVertices = 0;
  108. this._activeParticles = 0;
  109. this._lastFrameDuration = 0;
  110. this._evaluateActiveMeshesDuration = 0;
  111. this._renderTargetsDuration = 0;
  112. this._particlesDuration = 0;
  113. this._renderDuration = 0;
  114. this._spritesDuration = 0;
  115. this._animationRatio = 0;
  116. this._renderId = 0;
  117. this._executeWhenReadyTimeoutId = -1;
  118. this._toBeDisposed = new BABYLON.SmartArray(256);
  119. this._onReadyCallbacks = new Array();
  120. this._pendingData = []; //ANY
  121. this._onBeforeRenderCallbacks = new Array();
  122. this._onAfterRenderCallbacks = new Array();
  123. this._activeMeshes = new BABYLON.SmartArray(256);
  124. this._processedMaterials = new BABYLON.SmartArray(256);
  125. this._renderTargets = new BABYLON.SmartArray(256);
  126. this._activeParticleSystems = new BABYLON.SmartArray(256);
  127. this._activeSkeletons = new BABYLON.SmartArray(32);
  128. this._activeBones = 0;
  129. this._activeAnimatables = new Array();
  130. this._transformMatrix = BABYLON.Matrix.Zero();
  131. this._scaledPosition = BABYLON.Vector3.Zero();
  132. this._scaledVelocity = BABYLON.Vector3.Zero();
  133. this._engine = engine;
  134. engine.scenes.push(this);
  135. this._renderingManager = new BABYLON.RenderingManager(this);
  136. this.postProcessManager = new BABYLON.PostProcessManager(this);
  137. this.postProcessRenderPipelineManager = new BABYLON.PostProcessRenderPipelineManager();
  138. this._boundingBoxRenderer = new BABYLON.BoundingBoxRenderer(this);
  139. this._outlineRenderer = new BABYLON.OutlineRenderer(this);
  140. this.attachControl();
  141. this._debugLayer = new BABYLON.DebugLayer(this);
  142. this.mainSoundTrack = new BABYLON.SoundTrack(this, { mainTrack: true });
  143. //simplification queue
  144. this.simplificationQueue = new BABYLON.SimplificationQueue();
  145. }
  146. Object.defineProperty(Scene, "FOGMODE_NONE", {
  147. get: function () {
  148. return Scene._FOGMODE_NONE;
  149. },
  150. enumerable: true,
  151. configurable: true
  152. });
  153. Object.defineProperty(Scene, "FOGMODE_EXP", {
  154. get: function () {
  155. return Scene._FOGMODE_EXP;
  156. },
  157. enumerable: true,
  158. configurable: true
  159. });
  160. Object.defineProperty(Scene, "FOGMODE_EXP2", {
  161. get: function () {
  162. return Scene._FOGMODE_EXP2;
  163. },
  164. enumerable: true,
  165. configurable: true
  166. });
  167. Object.defineProperty(Scene, "FOGMODE_LINEAR", {
  168. get: function () {
  169. return Scene._FOGMODE_LINEAR;
  170. },
  171. enumerable: true,
  172. configurable: true
  173. });
  174. Object.defineProperty(Scene.prototype, "debugLayer", {
  175. // Properties
  176. get: function () {
  177. return this._debugLayer;
  178. },
  179. enumerable: true,
  180. configurable: true
  181. });
  182. Object.defineProperty(Scene.prototype, "meshUnderPointer", {
  183. /**
  184. * The mesh that is currently under the pointer.
  185. * @return {BABYLON.AbstractMesh} mesh under the pointer/mouse cursor or null if none.
  186. */
  187. get: function () {
  188. return this._meshUnderPointer;
  189. },
  190. enumerable: true,
  191. configurable: true
  192. });
  193. Object.defineProperty(Scene.prototype, "pointerX", {
  194. /**
  195. * Current on-screen X position of the pointer
  196. * @return {number} X position of the pointer
  197. */
  198. get: function () {
  199. return this._pointerX;
  200. },
  201. enumerable: true,
  202. configurable: true
  203. });
  204. Object.defineProperty(Scene.prototype, "pointerY", {
  205. /**
  206. * Current on-screen Y position of the pointer
  207. * @return {number} Y position of the pointer
  208. */
  209. get: function () {
  210. return this._pointerY;
  211. },
  212. enumerable: true,
  213. configurable: true
  214. });
  215. Scene.prototype.getCachedMaterial = function () {
  216. return this._cachedMaterial;
  217. };
  218. Scene.prototype.getBoundingBoxRenderer = function () {
  219. return this._boundingBoxRenderer;
  220. };
  221. Scene.prototype.getOutlineRenderer = function () {
  222. return this._outlineRenderer;
  223. };
  224. Scene.prototype.getEngine = function () {
  225. return this._engine;
  226. };
  227. Scene.prototype.getTotalVertices = function () {
  228. return this._totalVertices;
  229. };
  230. Scene.prototype.getActiveVertices = function () {
  231. return this._activeVertices;
  232. };
  233. Scene.prototype.getActiveParticles = function () {
  234. return this._activeParticles;
  235. };
  236. Scene.prototype.getActiveBones = function () {
  237. return this._activeBones;
  238. };
  239. // Stats
  240. Scene.prototype.getLastFrameDuration = function () {
  241. return this._lastFrameDuration;
  242. };
  243. Scene.prototype.getEvaluateActiveMeshesDuration = function () {
  244. return this._evaluateActiveMeshesDuration;
  245. };
  246. Scene.prototype.getActiveMeshes = function () {
  247. return this._activeMeshes;
  248. };
  249. Scene.prototype.getRenderTargetsDuration = function () {
  250. return this._renderTargetsDuration;
  251. };
  252. Scene.prototype.getRenderDuration = function () {
  253. return this._renderDuration;
  254. };
  255. Scene.prototype.getParticlesDuration = function () {
  256. return this._particlesDuration;
  257. };
  258. Scene.prototype.getSpritesDuration = function () {
  259. return this._spritesDuration;
  260. };
  261. Scene.prototype.getAnimationRatio = function () {
  262. return this._animationRatio;
  263. };
  264. Scene.prototype.getRenderId = function () {
  265. return this._renderId;
  266. };
  267. Scene.prototype.incrementRenderId = function () {
  268. this._renderId++;
  269. };
  270. Scene.prototype._updatePointerPosition = function (evt) {
  271. var canvasRect = this._engine.getRenderingCanvasClientRect();
  272. this._pointerX = evt.clientX - canvasRect.left;
  273. this._pointerY = evt.clientY - canvasRect.top;
  274. if (this.cameraToUseForPointers) {
  275. this._pointerX = this._pointerX - this.cameraToUseForPointers.viewport.x * this._engine.getRenderWidth();
  276. this._pointerY = this._pointerY - this.cameraToUseForPointers.viewport.y * this._engine.getRenderHeight();
  277. }
  278. };
  279. // Pointers handling
  280. Scene.prototype.attachControl = function () {
  281. var _this = this;
  282. this._onPointerMove = function (evt) {
  283. var canvas = _this._engine.getRenderingCanvas();
  284. _this._updatePointerPosition(evt);
  285. var pickResult = _this.pick(_this._pointerX, _this._pointerY, function (mesh) { return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.actionManager && mesh.actionManager.hasPointerTriggers; }, false, _this.cameraToUseForPointers);
  286. if (pickResult.hit) {
  287. _this._meshUnderPointer = pickResult.pickedMesh;
  288. _this.setPointerOverMesh(pickResult.pickedMesh);
  289. canvas.style.cursor = "pointer";
  290. }
  291. else {
  292. _this.setPointerOverMesh(null);
  293. canvas.style.cursor = "";
  294. _this._meshUnderPointer = null;
  295. }
  296. };
  297. this._onPointerDown = function (evt) {
  298. var predicate = null;
  299. if (!_this.onPointerDown) {
  300. predicate = function (mesh) {
  301. return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.actionManager && mesh.actionManager.hasPickTriggers;
  302. };
  303. }
  304. _this._updatePointerPosition(evt);
  305. var pickResult = _this.pick(_this._pointerX, _this._pointerY, predicate, false, _this.cameraToUseForPointers);
  306. if (pickResult.hit) {
  307. if (pickResult.pickedMesh.actionManager) {
  308. switch (evt.button) {
  309. case 0:
  310. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  311. break;
  312. case 1:
  313. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  314. break;
  315. case 2:
  316. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  317. break;
  318. }
  319. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
  320. }
  321. }
  322. if (_this.onPointerDown) {
  323. _this.onPointerDown(evt, pickResult);
  324. }
  325. };
  326. this._onKeyDown = function (evt) {
  327. if (_this.actionManager) {
  328. _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyDownTrigger, BABYLON.ActionEvent.CreateNewFromScene(_this, evt));
  329. }
  330. };
  331. this._onKeyUp = function (evt) {
  332. if (_this.actionManager) {
  333. _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyUpTrigger, BABYLON.ActionEvent.CreateNewFromScene(_this, evt));
  334. }
  335. };
  336. var eventPrefix = BABYLON.Tools.GetPointerPrefix();
  337. this._engine.getRenderingCanvas().addEventListener(eventPrefix + "move", this._onPointerMove, false);
  338. this._engine.getRenderingCanvas().addEventListener(eventPrefix + "down", this._onPointerDown, false);
  339. BABYLON.Tools.RegisterTopRootEvents([
  340. { name: "keydown", handler: this._onKeyDown },
  341. { name: "keyup", handler: this._onKeyUp }
  342. ]);
  343. };
  344. Scene.prototype.detachControl = function () {
  345. var eventPrefix = BABYLON.Tools.GetPointerPrefix();
  346. this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "move", this._onPointerMove);
  347. this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "down", this._onPointerDown);
  348. BABYLON.Tools.UnregisterTopRootEvents([
  349. { name: "keydown", handler: this._onKeyDown },
  350. { name: "keyup", handler: this._onKeyUp }
  351. ]);
  352. };
  353. // Ready
  354. Scene.prototype.isReady = function () {
  355. if (this._pendingData.length > 0) {
  356. return false;
  357. }
  358. for (var index = 0; index < this._geometries.length; index++) {
  359. var geometry = this._geometries[index];
  360. if (geometry.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
  361. return false;
  362. }
  363. }
  364. for (index = 0; index < this.meshes.length; index++) {
  365. var mesh = this.meshes[index];
  366. if (!mesh.isReady()) {
  367. return false;
  368. }
  369. var mat = mesh.material;
  370. if (mat) {
  371. if (!mat.isReady(mesh)) {
  372. return false;
  373. }
  374. }
  375. }
  376. return true;
  377. };
  378. Scene.prototype.resetCachedMaterial = function () {
  379. this._cachedMaterial = null;
  380. };
  381. Scene.prototype.registerBeforeRender = function (func) {
  382. this._onBeforeRenderCallbacks.push(func);
  383. };
  384. Scene.prototype.unregisterBeforeRender = function (func) {
  385. var index = this._onBeforeRenderCallbacks.indexOf(func);
  386. if (index > -1) {
  387. this._onBeforeRenderCallbacks.splice(index, 1);
  388. }
  389. };
  390. Scene.prototype.registerAfterRender = function (func) {
  391. this._onAfterRenderCallbacks.push(func);
  392. };
  393. Scene.prototype.unregisterAfterRender = function (func) {
  394. var index = this._onAfterRenderCallbacks.indexOf(func);
  395. if (index > -1) {
  396. this._onAfterRenderCallbacks.splice(index, 1);
  397. }
  398. };
  399. Scene.prototype._addPendingData = function (data) {
  400. this._pendingData.push(data);
  401. };
  402. Scene.prototype._removePendingData = function (data) {
  403. var index = this._pendingData.indexOf(data);
  404. if (index !== -1) {
  405. this._pendingData.splice(index, 1);
  406. }
  407. };
  408. Scene.prototype.getWaitingItemsCount = function () {
  409. return this._pendingData.length;
  410. };
  411. /**
  412. * Registers a function to be executed when the scene is ready.
  413. * @param {Function} func - the function to be executed.
  414. */
  415. Scene.prototype.executeWhenReady = function (func) {
  416. var _this = this;
  417. this._onReadyCallbacks.push(func);
  418. if (this._executeWhenReadyTimeoutId !== -1) {
  419. return;
  420. }
  421. this._executeWhenReadyTimeoutId = setTimeout(function () {
  422. _this._checkIsReady();
  423. }, 150);
  424. };
  425. Scene.prototype._checkIsReady = function () {
  426. var _this = this;
  427. if (this.isReady()) {
  428. this._onReadyCallbacks.forEach(function (func) {
  429. func();
  430. });
  431. this._onReadyCallbacks = [];
  432. this._executeWhenReadyTimeoutId = -1;
  433. return;
  434. }
  435. this._executeWhenReadyTimeoutId = setTimeout(function () {
  436. _this._checkIsReady();
  437. }, 150);
  438. };
  439. // Animations
  440. /**
  441. * Will start the animation sequence of a given target
  442. * @param target - the target
  443. * @param {number} from - from which frame should animation start
  444. * @param {number} to - till which frame should animation run.
  445. * @param {boolean} [loop] - should the animation loop
  446. * @param {number} [speedRatio] - the speed in which to run the animation
  447. * @param {Function} [onAnimationEnd] function to be executed when the animation ended.
  448. * @param {BABYLON.Animatable} [animatable] an animatable object. If not provided a new one will be created from the given params.
  449. * @return {BABYLON.Animatable} the animatable object created for this animation
  450. * @see BABYLON.Animatable
  451. * @see http://doc.babylonjs.com/page.php?p=22081
  452. */
  453. Scene.prototype.beginAnimation = function (target, from, to, loop, speedRatio, onAnimationEnd, animatable) {
  454. if (speedRatio === undefined) {
  455. speedRatio = 1.0;
  456. }
  457. this.stopAnimation(target);
  458. if (!animatable) {
  459. animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd);
  460. }
  461. // Local animations
  462. if (target.animations) {
  463. animatable.appendAnimations(target, target.animations);
  464. }
  465. // Children animations
  466. if (target.getAnimatables) {
  467. var animatables = target.getAnimatables();
  468. for (var index = 0; index < animatables.length; index++) {
  469. this.beginAnimation(animatables[index], from, to, loop, speedRatio, onAnimationEnd, animatable);
  470. }
  471. }
  472. return animatable;
  473. };
  474. Scene.prototype.beginDirectAnimation = function (target, animations, from, to, loop, speedRatio, onAnimationEnd) {
  475. if (speedRatio === undefined) {
  476. speedRatio = 1.0;
  477. }
  478. var animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, animations);
  479. return animatable;
  480. };
  481. Scene.prototype.getAnimatableByTarget = function (target) {
  482. for (var index = 0; index < this._activeAnimatables.length; index++) {
  483. if (this._activeAnimatables[index].target === target) {
  484. return this._activeAnimatables[index];
  485. }
  486. }
  487. return null;
  488. };
  489. /**
  490. * Will stop the animation of the given target
  491. * @param target - the target
  492. * @see beginAnimation
  493. */
  494. Scene.prototype.stopAnimation = function (target) {
  495. var animatable = this.getAnimatableByTarget(target);
  496. if (animatable) {
  497. animatable.stop();
  498. }
  499. };
  500. Scene.prototype._animate = function () {
  501. if (!this.animationsEnabled) {
  502. return;
  503. }
  504. if (!this._animationStartDate) {
  505. this._animationStartDate = BABYLON.Tools.Now;
  506. }
  507. // Getting time
  508. var now = BABYLON.Tools.Now;
  509. var delay = now - this._animationStartDate;
  510. for (var index = 0; index < this._activeAnimatables.length; index++) {
  511. if (!this._activeAnimatables[index]._animate(delay)) {
  512. this._activeAnimatables.splice(index, 1);
  513. index--;
  514. }
  515. }
  516. };
  517. // Matrix
  518. Scene.prototype.getViewMatrix = function () {
  519. return this._viewMatrix;
  520. };
  521. Scene.prototype.getProjectionMatrix = function () {
  522. return this._projectionMatrix;
  523. };
  524. Scene.prototype.getTransformMatrix = function () {
  525. return this._transformMatrix;
  526. };
  527. Scene.prototype.setTransformMatrix = function (view, projection) {
  528. this._viewMatrix = view;
  529. this._projectionMatrix = projection;
  530. this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);
  531. };
  532. // Methods
  533. Scene.prototype.addMesh = function (newMesh) {
  534. var position = this.meshes.push(newMesh);
  535. if (this.onNewMeshAdded) {
  536. this.onNewMeshAdded(newMesh, position, this);
  537. }
  538. };
  539. Scene.prototype.removeMesh = function (toRemove) {
  540. var index = this.meshes.indexOf(toRemove);
  541. if (index != -1) {
  542. // Remove from the scene if mesh found
  543. this.meshes.splice(index, 1);
  544. }
  545. if (this.onMeshRemoved) {
  546. this.onMeshRemoved(toRemove);
  547. }
  548. return index;
  549. };
  550. Scene.prototype.removeLight = function (toRemove) {
  551. var index = this.lights.indexOf(toRemove);
  552. if (index != -1) {
  553. // Remove from the scene if mesh found
  554. this.lights.splice(index, 1);
  555. }
  556. if (this.onLightRemoved) {
  557. this.onLightRemoved(toRemove);
  558. }
  559. return index;
  560. };
  561. Scene.prototype.removeCamera = function (toRemove) {
  562. var index = this.cameras.indexOf(toRemove);
  563. if (index != -1) {
  564. // Remove from the scene if mesh found
  565. this.cameras.splice(index, 1);
  566. }
  567. if (this.onCameraRemoved) {
  568. this.onCameraRemoved(toRemove);
  569. }
  570. return index;
  571. };
  572. Scene.prototype.addLight = function (newLight) {
  573. var position = this.lights.push(newLight);
  574. if (this.onNewLightAdded) {
  575. this.onNewLightAdded(newLight, position, this);
  576. }
  577. };
  578. Scene.prototype.addCamera = function (newCamera) {
  579. var position = this.cameras.push(newCamera);
  580. if (this.onNewCameraAdded) {
  581. this.onNewCameraAdded(newCamera, position, this);
  582. }
  583. };
  584. /**
  585. * sets the active camera of the scene using its ID
  586. * @param {string} id - the camera's ID
  587. * @return {BABYLON.Camera|null} the new active camera or null if none found.
  588. * @see activeCamera
  589. */
  590. Scene.prototype.setActiveCameraByID = function (id) {
  591. var camera = this.getCameraByID(id);
  592. if (camera) {
  593. this.activeCamera = camera;
  594. return camera;
  595. }
  596. return null;
  597. };
  598. /**
  599. * sets the active camera of the scene using its name
  600. * @param {string} name - the camera's name
  601. * @return {BABYLON.Camera|null} the new active camera or null if none found.
  602. * @see activeCamera
  603. */
  604. Scene.prototype.setActiveCameraByName = function (name) {
  605. var camera = this.getCameraByName(name);
  606. if (camera) {
  607. this.activeCamera = camera;
  608. return camera;
  609. }
  610. return null;
  611. };
  612. /**
  613. * get a material using its id
  614. * @param {string} the material's ID
  615. * @return {BABYLON.Material|null} the material or null if none found.
  616. */
  617. Scene.prototype.getMaterialByID = function (id) {
  618. for (var index = 0; index < this.materials.length; index++) {
  619. if (this.materials[index].id === id) {
  620. return this.materials[index];
  621. }
  622. }
  623. return null;
  624. };
  625. /**
  626. * get a material using its name
  627. * @param {string} the material's name
  628. * @return {BABYLON.Material|null} the material or null if none found.
  629. */
  630. Scene.prototype.getMaterialByName = function (name) {
  631. for (var index = 0; index < this.materials.length; index++) {
  632. if (this.materials[index].name === name) {
  633. return this.materials[index];
  634. }
  635. }
  636. return null;
  637. };
  638. Scene.prototype.getCameraByID = function (id) {
  639. for (var index = 0; index < this.cameras.length; index++) {
  640. if (this.cameras[index].id === id) {
  641. return this.cameras[index];
  642. }
  643. }
  644. return null;
  645. };
  646. /**
  647. * get a camera using its name
  648. * @param {string} the camera's name
  649. * @return {BABYLON.Camera|null} the camera or null if none found.
  650. */
  651. Scene.prototype.getCameraByName = function (name) {
  652. for (var index = 0; index < this.cameras.length; index++) {
  653. if (this.cameras[index].name === name) {
  654. return this.cameras[index];
  655. }
  656. }
  657. return null;
  658. };
  659. /**
  660. * get a light node using its name
  661. * @param {string} the light's name
  662. * @return {BABYLON.Light|null} the light or null if none found.
  663. */
  664. Scene.prototype.getLightByName = function (name) {
  665. for (var index = 0; index < this.lights.length; index++) {
  666. if (this.lights[index].name === name) {
  667. return this.lights[index];
  668. }
  669. }
  670. return null;
  671. };
  672. /**
  673. * get a light node using its ID
  674. * @param {string} the light's id
  675. * @return {BABYLON.Light|null} the light or null if none found.
  676. */
  677. Scene.prototype.getLightByID = function (id) {
  678. for (var index = 0; index < this.lights.length; index++) {
  679. if (this.lights[index].id === id) {
  680. return this.lights[index];
  681. }
  682. }
  683. return null;
  684. };
  685. /**
  686. * get a geometry using its ID
  687. * @param {string} the geometry's id
  688. * @return {BABYLON.Geometry|null} the geometry or null if none found.
  689. */
  690. Scene.prototype.getGeometryByID = function (id) {
  691. for (var index = 0; index < this._geometries.length; index++) {
  692. if (this._geometries[index].id === id) {
  693. return this._geometries[index];
  694. }
  695. }
  696. return null;
  697. };
  698. /**
  699. * add a new geometry to this scene.
  700. * @param {BABYLON.Geometry} geometry - the geometry to be added to the scene.
  701. * @param {boolean} [force] - force addition, even if a geometry with this ID already exists
  702. * @return {boolean} was the geometry added or not
  703. */
  704. Scene.prototype.pushGeometry = function (geometry, force) {
  705. if (!force && this.getGeometryByID(geometry.id)) {
  706. return false;
  707. }
  708. this._geometries.push(geometry);
  709. return true;
  710. };
  711. Scene.prototype.getGeometries = function () {
  712. return this._geometries;
  713. };
  714. /**
  715. * Get a the first added mesh found of a given ID
  716. * @param {string} id - the id to search for
  717. * @return {BABYLON.AbstractMesh|null} the mesh found or null if not found at all.
  718. */
  719. Scene.prototype.getMeshByID = function (id) {
  720. for (var index = 0; index < this.meshes.length; index++) {
  721. if (this.meshes[index].id === id) {
  722. return this.meshes[index];
  723. }
  724. }
  725. return null;
  726. };
  727. /**
  728. * Get a the last added mesh found of a given ID
  729. * @param {string} id - the id to search for
  730. * @return {BABYLON.AbstractMesh|null} the mesh found or null if not found at all.
  731. */
  732. Scene.prototype.getLastMeshByID = function (id) {
  733. for (var index = this.meshes.length - 1; index >= 0; index--) {
  734. if (this.meshes[index].id === id) {
  735. return this.meshes[index];
  736. }
  737. }
  738. return null;
  739. };
  740. /**
  741. * Get a the last added node (Mesh, Camera, Light) found of a given ID
  742. * @param {string} id - the id to search for
  743. * @return {BABYLON.Node|null} the node found or null if not found at all.
  744. */
  745. Scene.prototype.getLastEntryByID = function (id) {
  746. for (var index = this.meshes.length - 1; index >= 0; index--) {
  747. if (this.meshes[index].id === id) {
  748. return this.meshes[index];
  749. }
  750. }
  751. for (index = this.cameras.length - 1; index >= 0; index--) {
  752. if (this.cameras[index].id === id) {
  753. return this.cameras[index];
  754. }
  755. }
  756. for (index = this.lights.length - 1; index >= 0; index--) {
  757. if (this.lights[index].id === id) {
  758. return this.lights[index];
  759. }
  760. }
  761. return null;
  762. };
  763. Scene.prototype.getNodeByName = function (name) {
  764. var mesh = this.getMeshByName(name);
  765. if (mesh) {
  766. return mesh;
  767. }
  768. var light = this.getLightByName(name);
  769. if (light) {
  770. return light;
  771. }
  772. return this.getCameraByName(name);
  773. };
  774. Scene.prototype.getMeshByName = function (name) {
  775. for (var index = 0; index < this.meshes.length; index++) {
  776. if (this.meshes[index].name === name) {
  777. return this.meshes[index];
  778. }
  779. }
  780. return null;
  781. };
  782. Scene.prototype.getSoundByName = function (name) {
  783. for (var index = 0; index < this.mainSoundTrack.soundCollection.length; index++) {
  784. if (this.mainSoundTrack.soundCollection[index].name === name) {
  785. return this.mainSoundTrack.soundCollection[index];
  786. }
  787. }
  788. for (var sdIndex = 0; sdIndex < this.soundTracks.length; sdIndex++) {
  789. for (index = 0; index < this.soundTracks[sdIndex].soundCollection.length; index++) {
  790. if (this.soundTracks[sdIndex].soundCollection[index].name === name) {
  791. return this.soundTracks[sdIndex].soundCollection[index];
  792. }
  793. }
  794. }
  795. return null;
  796. };
  797. Scene.prototype.getLastSkeletonByID = function (id) {
  798. for (var index = this.skeletons.length - 1; index >= 0; index--) {
  799. if (this.skeletons[index].id === id) {
  800. return this.skeletons[index];
  801. }
  802. }
  803. return null;
  804. };
  805. Scene.prototype.getSkeletonById = function (id) {
  806. for (var index = 0; index < this.skeletons.length; index++) {
  807. if (this.skeletons[index].id === id) {
  808. return this.skeletons[index];
  809. }
  810. }
  811. return null;
  812. };
  813. Scene.prototype.getSkeletonByName = function (name) {
  814. for (var index = 0; index < this.skeletons.length; index++) {
  815. if (this.skeletons[index].name === name) {
  816. return this.skeletons[index];
  817. }
  818. }
  819. return null;
  820. };
  821. Scene.prototype.isActiveMesh = function (mesh) {
  822. return (this._activeMeshes.indexOf(mesh) !== -1);
  823. };
  824. Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
  825. if (mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
  826. var material = subMesh.getMaterial();
  827. if (mesh.showSubMeshesBoundingBox) {
  828. this._boundingBoxRenderer.renderList.push(subMesh.getBoundingInfo().boundingBox);
  829. }
  830. if (material) {
  831. // Render targets
  832. if (material.getRenderTargetTextures) {
  833. if (this._processedMaterials.indexOf(material) === -1) {
  834. this._processedMaterials.push(material);
  835. this._renderTargets.concat(material.getRenderTargetTextures());
  836. }
  837. }
  838. // Dispatch
  839. this._activeVertices += subMesh.indexCount;
  840. this._renderingManager.dispatch(subMesh);
  841. }
  842. }
  843. };
  844. Scene.prototype._evaluateActiveMeshes = function () {
  845. this.activeCamera._activeMeshes.reset();
  846. this._activeMeshes.reset();
  847. this._renderingManager.reset();
  848. this._processedMaterials.reset();
  849. this._activeParticleSystems.reset();
  850. this._activeSkeletons.reset();
  851. this._boundingBoxRenderer.reset();
  852. if (!this._frustumPlanes) {
  853. this._frustumPlanes = BABYLON.Frustum.GetPlanes(this._transformMatrix);
  854. }
  855. else {
  856. BABYLON.Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);
  857. }
  858. // Meshes
  859. var meshes;
  860. var len;
  861. if (this._selectionOctree) {
  862. var selection = this._selectionOctree.select(this._frustumPlanes);
  863. meshes = selection.data;
  864. len = selection.length;
  865. }
  866. else {
  867. len = this.meshes.length;
  868. meshes = this.meshes;
  869. }
  870. for (var meshIndex = 0; meshIndex < len; meshIndex++) {
  871. var mesh = meshes[meshIndex];
  872. if (mesh.isBlocked) {
  873. continue;
  874. }
  875. this._totalVertices += mesh.getTotalVertices();
  876. if (!mesh.isReady()) {
  877. continue;
  878. }
  879. mesh.computeWorldMatrix();
  880. // Intersections
  881. if (mesh.actionManager && mesh.actionManager.hasSpecificTriggers([BABYLON.ActionManager.OnIntersectionEnterTrigger, BABYLON.ActionManager.OnIntersectionExitTrigger])) {
  882. this._meshesForIntersections.pushNoDuplicate(mesh);
  883. }
  884. // Switch to current LOD
  885. var meshLOD = mesh.getLOD(this.activeCamera);
  886. if (!meshLOD) {
  887. continue;
  888. }
  889. mesh._preActivate();
  890. if (mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) !== 0) && mesh.isInFrustum(this._frustumPlanes)) {
  891. this._activeMeshes.push(mesh);
  892. this.activeCamera._activeMeshes.push(mesh);
  893. mesh._activate(this._renderId);
  894. this._activeMesh(meshLOD);
  895. }
  896. }
  897. // Particle systems
  898. var beforeParticlesDate = BABYLON.Tools.Now;
  899. if (this.particlesEnabled) {
  900. BABYLON.Tools.StartPerformanceCounter("Particles", this.particleSystems.length > 0);
  901. for (var particleIndex = 0; particleIndex < this.particleSystems.length; particleIndex++) {
  902. var particleSystem = this.particleSystems[particleIndex];
  903. if (!particleSystem.isStarted()) {
  904. continue;
  905. }
  906. if (!particleSystem.emitter.position || (particleSystem.emitter && particleSystem.emitter.isEnabled())) {
  907. this._activeParticleSystems.push(particleSystem);
  908. particleSystem.animate();
  909. }
  910. }
  911. BABYLON.Tools.EndPerformanceCounter("Particles", this.particleSystems.length > 0);
  912. }
  913. this._particlesDuration += BABYLON.Tools.Now - beforeParticlesDate;
  914. };
  915. Scene.prototype._activeMesh = function (mesh) {
  916. if (mesh.skeleton && this.skeletonsEnabled) {
  917. this._activeSkeletons.pushNoDuplicate(mesh.skeleton);
  918. }
  919. if (mesh.showBoundingBox || this.forceShowBoundingBoxes) {
  920. this._boundingBoxRenderer.renderList.push(mesh.getBoundingInfo().boundingBox);
  921. }
  922. if (mesh && mesh.subMeshes) {
  923. // Submeshes Octrees
  924. var len;
  925. var subMeshes;
  926. if (mesh._submeshesOctree && mesh.useOctreeForRenderingSelection) {
  927. var intersections = mesh._submeshesOctree.select(this._frustumPlanes);
  928. len = intersections.length;
  929. subMeshes = intersections.data;
  930. }
  931. else {
  932. subMeshes = mesh.subMeshes;
  933. len = subMeshes.length;
  934. }
  935. for (var subIndex = 0; subIndex < len; subIndex++) {
  936. var subMesh = subMeshes[subIndex];
  937. this._evaluateSubMesh(subMesh, mesh);
  938. }
  939. }
  940. };
  941. Scene.prototype.updateTransformMatrix = function (force) {
  942. this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(force));
  943. };
  944. Scene.prototype._renderForCamera = function (camera) {
  945. var engine = this._engine;
  946. this.activeCamera = camera;
  947. if (!this.activeCamera)
  948. throw new Error("Active camera not set");
  949. BABYLON.Tools.StartPerformanceCounter("Rendering camera " + this.activeCamera.name);
  950. // Viewport
  951. engine.setViewport(this.activeCamera.viewport);
  952. // Camera
  953. this._renderId++;
  954. this.updateTransformMatrix();
  955. if (this.beforeCameraRender) {
  956. this.beforeCameraRender(this.activeCamera);
  957. }
  958. // Meshes
  959. var beforeEvaluateActiveMeshesDate = BABYLON.Tools.Now;
  960. BABYLON.Tools.StartPerformanceCounter("Active meshes evaluation");
  961. this._evaluateActiveMeshes();
  962. this._evaluateActiveMeshesDuration += BABYLON.Tools.Now - beforeEvaluateActiveMeshesDate;
  963. BABYLON.Tools.EndPerformanceCounter("Active meshes evaluation");
  964. for (var skeletonIndex = 0; skeletonIndex < this._activeSkeletons.length; skeletonIndex++) {
  965. var skeleton = this._activeSkeletons.data[skeletonIndex];
  966. skeleton.prepare();
  967. }
  968. // Render targets
  969. var beforeRenderTargetDate = BABYLON.Tools.Now;
  970. if (this.renderTargetsEnabled) {
  971. BABYLON.Tools.StartPerformanceCounter("Render targets", this._renderTargets.length > 0);
  972. for (var renderIndex = 0; renderIndex < this._renderTargets.length; renderIndex++) {
  973. var renderTarget = this._renderTargets.data[renderIndex];
  974. if (renderTarget._shouldRender()) {
  975. this._renderId++;
  976. renderTarget.render(false, this.dumpNextRenderTargets);
  977. }
  978. }
  979. BABYLON.Tools.EndPerformanceCounter("Render targets", this._renderTargets.length > 0);
  980. this._renderId++;
  981. }
  982. if (this._renderTargets.length > 0) {
  983. engine.restoreDefaultFramebuffer();
  984. }
  985. this._renderTargetsDuration += BABYLON.Tools.Now - beforeRenderTargetDate;
  986. // Prepare Frame
  987. this.postProcessManager._prepareFrame();
  988. var beforeRenderDate = BABYLON.Tools.Now;
  989. // Backgrounds
  990. if (this.layers.length) {
  991. engine.setDepthBuffer(false);
  992. var layerIndex;
  993. var layer;
  994. for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
  995. layer = this.layers[layerIndex];
  996. if (layer.isBackground) {
  997. layer.render();
  998. }
  999. }
  1000. engine.setDepthBuffer(true);
  1001. }
  1002. // Render
  1003. BABYLON.Tools.StartPerformanceCounter("Main render");
  1004. this._renderingManager.render(null, null, true, true);
  1005. BABYLON.Tools.EndPerformanceCounter("Main render");
  1006. // Bounding boxes
  1007. this._boundingBoxRenderer.render();
  1008. // Lens flares
  1009. if (this.lensFlaresEnabled) {
  1010. BABYLON.Tools.StartPerformanceCounter("Lens flares", this.lensFlareSystems.length > 0);
  1011. for (var lensFlareSystemIndex = 0; lensFlareSystemIndex < this.lensFlareSystems.length; lensFlareSystemIndex++) {
  1012. this.lensFlareSystems[lensFlareSystemIndex].render();
  1013. }
  1014. BABYLON.Tools.EndPerformanceCounter("Lens flares", this.lensFlareSystems.length > 0);
  1015. }
  1016. // Foregrounds
  1017. if (this.layers.length) {
  1018. engine.setDepthBuffer(false);
  1019. for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
  1020. layer = this.layers[layerIndex];
  1021. if (!layer.isBackground) {
  1022. layer.render();
  1023. }
  1024. }
  1025. engine.setDepthBuffer(true);
  1026. }
  1027. this._renderDuration += BABYLON.Tools.Now - beforeRenderDate;
  1028. // Finalize frame
  1029. this.postProcessManager._finalizeFrame(camera.isIntermediate);
  1030. // Update camera
  1031. this.activeCamera._updateFromScene();
  1032. // Reset some special arrays
  1033. this._renderTargets.reset();
  1034. if (this.afterCameraRender) {
  1035. this.afterCameraRender(this.activeCamera);
  1036. }
  1037. BABYLON.Tools.EndPerformanceCounter("Rendering camera " + this.activeCamera.name);
  1038. };
  1039. Scene.prototype._processSubCameras = function (camera) {
  1040. if (camera.subCameras.length === 0) {
  1041. this._renderForCamera(camera);
  1042. return;
  1043. }
  1044. for (var index = 0; index < camera.subCameras.length; index++) {
  1045. this._renderForCamera(camera.subCameras[index]);
  1046. }
  1047. this.activeCamera = camera;
  1048. this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix());
  1049. // Update camera
  1050. this.activeCamera._updateFromScene();
  1051. };
  1052. Scene.prototype._checkIntersections = function () {
  1053. for (var index = 0; index < this._meshesForIntersections.length; index++) {
  1054. var sourceMesh = this._meshesForIntersections.data[index];
  1055. for (var actionIndex = 0; actionIndex < sourceMesh.actionManager.actions.length; actionIndex++) {
  1056. var action = sourceMesh.actionManager.actions[actionIndex];
  1057. if (action.trigger === BABYLON.ActionManager.OnIntersectionEnterTrigger || action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  1058. var parameters = action.getTriggerParameter();
  1059. var otherMesh = parameters instanceof BABYLON.AbstractMesh ? parameters : parameters.mesh;
  1060. var areIntersecting = otherMesh.intersectsMesh(sourceMesh, parameters.usePreciseIntersection);
  1061. var currentIntersectionInProgress = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
  1062. if (areIntersecting && currentIntersectionInProgress === -1) {
  1063. if (action.trigger === BABYLON.ActionManager.OnIntersectionEnterTrigger) {
  1064. action._executeCurrent(BABYLON.ActionEvent.CreateNew(sourceMesh));
  1065. sourceMesh._intersectionsInProgress.push(otherMesh);
  1066. }
  1067. else if (action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  1068. sourceMesh._intersectionsInProgress.push(otherMesh);
  1069. }
  1070. }
  1071. else if (!areIntersecting && currentIntersectionInProgress > -1 && action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  1072. action._executeCurrent(BABYLON.ActionEvent.CreateNew(sourceMesh));
  1073. var indexOfOther = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
  1074. if (indexOfOther > -1) {
  1075. sourceMesh._intersectionsInProgress.splice(indexOfOther, 1);
  1076. }
  1077. }
  1078. }
  1079. }
  1080. }
  1081. };
  1082. Scene.prototype.render = function () {
  1083. var startDate = BABYLON.Tools.Now;
  1084. this._particlesDuration = 0;
  1085. this._spritesDuration = 0;
  1086. this._activeParticles = 0;
  1087. this._renderDuration = 0;
  1088. this._renderTargetsDuration = 0;
  1089. this._evaluateActiveMeshesDuration = 0;
  1090. this._totalVertices = 0;
  1091. this._activeVertices = 0;
  1092. this._activeBones = 0;
  1093. this.getEngine().resetDrawCalls();
  1094. this._meshesForIntersections.reset();
  1095. this.resetCachedMaterial();
  1096. BABYLON.Tools.StartPerformanceCounter("Scene rendering");
  1097. // Actions
  1098. if (this.actionManager) {
  1099. this.actionManager.processTrigger(BABYLON.ActionManager.OnEveryFrameTrigger, null);
  1100. }
  1101. //Simplification Queue
  1102. if (!this.simplificationQueue.running) {
  1103. this.simplificationQueue.executeNext();
  1104. }
  1105. // Before render
  1106. if (this.beforeRender) {
  1107. this.beforeRender();
  1108. }
  1109. for (var callbackIndex = 0; callbackIndex < this._onBeforeRenderCallbacks.length; callbackIndex++) {
  1110. this._onBeforeRenderCallbacks[callbackIndex]();
  1111. }
  1112. // Animations
  1113. var deltaTime = Math.max(Scene.MinDeltaTime, Math.min(this._engine.getDeltaTime(), Scene.MaxDeltaTime));
  1114. this._animationRatio = deltaTime * (60.0 / 1000.0);
  1115. this._animate();
  1116. // Physics
  1117. if (this._physicsEngine) {
  1118. BABYLON.Tools.StartPerformanceCounter("Physics");
  1119. this._physicsEngine._runOneStep(deltaTime / 1000.0);
  1120. BABYLON.Tools.EndPerformanceCounter("Physics");
  1121. }
  1122. // Customs render targets
  1123. var beforeRenderTargetDate = BABYLON.Tools.Now;
  1124. var engine = this.getEngine();
  1125. var currentActiveCamera = this.activeCamera;
  1126. if (this.renderTargetsEnabled) {
  1127. BABYLON.Tools.StartPerformanceCounter("Custom render targets", this.customRenderTargets.length > 0);
  1128. for (var customIndex = 0; customIndex < this.customRenderTargets.length; customIndex++) {
  1129. var renderTarget = this.customRenderTargets[customIndex];
  1130. if (renderTarget._shouldRender()) {
  1131. this._renderId++;
  1132. this.activeCamera = renderTarget.activeCamera || this.activeCamera;
  1133. if (!this.activeCamera)
  1134. throw new Error("Active camera not set");
  1135. // Viewport
  1136. engine.setViewport(this.activeCamera.viewport);
  1137. // Camera
  1138. this.updateTransformMatrix();
  1139. renderTarget.render(false, this.dumpNextRenderTargets);
  1140. }
  1141. }
  1142. BABYLON.Tools.EndPerformanceCounter("Custom render targets", this.customRenderTargets.length > 0);
  1143. this._renderId++;
  1144. }
  1145. if (this.customRenderTargets.length > 0) {
  1146. engine.restoreDefaultFramebuffer();
  1147. }
  1148. this._renderTargetsDuration += BABYLON.Tools.Now - beforeRenderTargetDate;
  1149. this.activeCamera = currentActiveCamera;
  1150. // Procedural textures
  1151. if (this.proceduralTexturesEnabled) {
  1152. BABYLON.Tools.StartPerformanceCounter("Procedural textures", this._proceduralTextures.length > 0);
  1153. for (var proceduralIndex = 0; proceduralIndex < this._proceduralTextures.length; proceduralIndex++) {
  1154. var proceduralTexture = this._proceduralTextures[proceduralIndex];
  1155. if (proceduralTexture._shouldRender()) {
  1156. proceduralTexture.render();
  1157. }
  1158. }
  1159. BABYLON.Tools.EndPerformanceCounter("Procedural textures", this._proceduralTextures.length > 0);
  1160. }
  1161. // Clear
  1162. this._engine.clear(this.clearColor, this.autoClear || this.forceWireframe || this.forcePointsCloud, true);
  1163. // Shadows
  1164. if (this.shadowsEnabled) {
  1165. for (var lightIndex = 0; lightIndex < this.lights.length; lightIndex++) {
  1166. var light = this.lights[lightIndex];
  1167. var shadowGenerator = light.getShadowGenerator();
  1168. if (light.isEnabled() && shadowGenerator && shadowGenerator.getShadowMap().getScene().textures.indexOf(shadowGenerator.getShadowMap()) !== -1) {
  1169. this._renderTargets.push(shadowGenerator.getShadowMap());
  1170. }
  1171. }
  1172. }
  1173. // Depth renderer
  1174. if (this._depthRenderer) {
  1175. this._renderTargets.push(this._depthRenderer.getDepthMap());
  1176. }
  1177. // RenderPipeline
  1178. this.postProcessRenderPipelineManager.update();
  1179. // Multi-cameras?
  1180. if (this.activeCameras.length > 0) {
  1181. var currentRenderId = this._renderId;
  1182. for (var cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {
  1183. this._renderId = currentRenderId;
  1184. this._processSubCameras(this.activeCameras[cameraIndex]);
  1185. }
  1186. }
  1187. else {
  1188. if (!this.activeCamera) {
  1189. throw new Error("No camera defined");
  1190. }
  1191. this._processSubCameras(this.activeCamera);
  1192. }
  1193. // Intersection checks
  1194. this._checkIntersections();
  1195. // Update the audio listener attached to the camera
  1196. this._updateAudioParameters();
  1197. // After render
  1198. if (this.afterRender) {
  1199. this.afterRender();
  1200. }
  1201. for (callbackIndex = 0; callbackIndex < this._onAfterRenderCallbacks.length; callbackIndex++) {
  1202. this._onAfterRenderCallbacks[callbackIndex]();
  1203. }
  1204. for (var index = 0; index < this._toBeDisposed.length; index++) {
  1205. this._toBeDisposed.data[index].dispose();
  1206. this._toBeDisposed[index] = null;
  1207. }
  1208. this._toBeDisposed.reset();
  1209. if (this.dumpNextRenderTargets) {
  1210. this.dumpNextRenderTargets = false;
  1211. }
  1212. BABYLON.Tools.EndPerformanceCounter("Scene rendering");
  1213. this._lastFrameDuration = BABYLON.Tools.Now - startDate;
  1214. };
  1215. Scene.prototype._updateAudioParameters = function () {
  1216. if (!this.audioEnabled || (this.mainSoundTrack.soundCollection.length === 0 && this.soundTracks.length === 0)) {
  1217. return;
  1218. }
  1219. var listeningCamera;
  1220. var audioEngine = BABYLON.Engine.audioEngine;
  1221. if (this.activeCameras.length > 0) {
  1222. listeningCamera = this.activeCameras[0];
  1223. }
  1224. else {
  1225. listeningCamera = this.activeCamera;
  1226. }
  1227. if (listeningCamera && audioEngine.canUseWebAudio) {
  1228. audioEngine.audioContext.listener.setPosition(listeningCamera.position.x, listeningCamera.position.y, listeningCamera.position.z);
  1229. var mat = BABYLON.Matrix.Invert(listeningCamera.getViewMatrix());
  1230. var cameraDirection = BABYLON.Vector3.TransformNormal(new BABYLON.Vector3(0, 0, -1), mat);
  1231. cameraDirection.normalize();
  1232. audioEngine.audioContext.listener.setOrientation(cameraDirection.x, cameraDirection.y, cameraDirection.z, 0, 1, 0);
  1233. for (var i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  1234. var sound = this.mainSoundTrack.soundCollection[i];
  1235. if (sound.useCustomAttenuation) {
  1236. sound.updateDistanceFromListener();
  1237. }
  1238. }
  1239. for (i = 0; i < this.soundTracks.length; i++) {
  1240. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  1241. sound = this.soundTracks[i].soundCollection[j];
  1242. if (sound.useCustomAttenuation) {
  1243. sound.updateDistanceFromListener();
  1244. }
  1245. }
  1246. }
  1247. }
  1248. };
  1249. Object.defineProperty(Scene.prototype, "audioEnabled", {
  1250. // Audio
  1251. get: function () {
  1252. return this._audioEnabled;
  1253. },
  1254. set: function (value) {
  1255. this._audioEnabled = value;
  1256. if (this._audioEnabled) {
  1257. this._enableAudio();
  1258. }
  1259. else {
  1260. this._disableAudio();
  1261. }
  1262. },
  1263. enumerable: true,
  1264. configurable: true
  1265. });
  1266. Scene.prototype._disableAudio = function () {
  1267. for (var i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  1268. this.mainSoundTrack.soundCollection[i].pause();
  1269. }
  1270. for (i = 0; i < this.soundTracks.length; i++) {
  1271. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  1272. this.soundTracks[i].soundCollection[j].pause();
  1273. }
  1274. }
  1275. };
  1276. Scene.prototype._enableAudio = function () {
  1277. for (var i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  1278. if (this.mainSoundTrack.soundCollection[i].isPaused) {
  1279. this.mainSoundTrack.soundCollection[i].play();
  1280. }
  1281. }
  1282. for (i = 0; i < this.soundTracks.length; i++) {
  1283. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  1284. if (this.soundTracks[i].soundCollection[j].isPaused) {
  1285. this.soundTracks[i].soundCollection[j].play();
  1286. }
  1287. }
  1288. }
  1289. };
  1290. Object.defineProperty(Scene.prototype, "headphone", {
  1291. get: function () {
  1292. return this._headphone;
  1293. },
  1294. set: function (value) {
  1295. this._headphone = value;
  1296. if (this._headphone) {
  1297. this._switchAudioModeForHeadphones();
  1298. }
  1299. else {
  1300. this._switchAudioModeForNormalSpeakers();
  1301. }
  1302. },
  1303. enumerable: true,
  1304. configurable: true
  1305. });
  1306. Scene.prototype._switchAudioModeForHeadphones = function () {
  1307. this.mainSoundTrack.switchPanningModelToHRTF();
  1308. for (var i = 0; i < this.soundTracks.length; i++) {
  1309. this.soundTracks[i].switchPanningModelToHRTF();
  1310. }
  1311. };
  1312. Scene.prototype._switchAudioModeForNormalSpeakers = function () {
  1313. this.mainSoundTrack.switchPanningModelToEqualPower();
  1314. for (var i = 0; i < this.soundTracks.length; i++) {
  1315. this.soundTracks[i].switchPanningModelToEqualPower();
  1316. }
  1317. };
  1318. Scene.prototype.enableDepthRenderer = function () {
  1319. if (this._depthRenderer) {
  1320. return this._depthRenderer;
  1321. }
  1322. this._depthRenderer = new BABYLON.DepthRenderer(this);
  1323. return this._depthRenderer;
  1324. };
  1325. Scene.prototype.disableDepthRenderer = function () {
  1326. if (!this._depthRenderer) {
  1327. return;
  1328. }
  1329. this._depthRenderer.dispose();
  1330. this._depthRenderer = null;
  1331. };
  1332. Scene.prototype.dispose = function () {
  1333. this.beforeRender = null;
  1334. this.afterRender = null;
  1335. this.skeletons = [];
  1336. this._boundingBoxRenderer.dispose();
  1337. if (this._depthRenderer) {
  1338. this._depthRenderer.dispose();
  1339. }
  1340. // Debug layer
  1341. this.debugLayer.hide();
  1342. // Events
  1343. if (this.onDispose) {
  1344. this.onDispose();
  1345. }
  1346. this._onBeforeRenderCallbacks = [];
  1347. this._onAfterRenderCallbacks = [];
  1348. this.detachControl();
  1349. // Release sounds & sounds tracks
  1350. this.disposeSounds();
  1351. // Detach cameras
  1352. var canvas = this._engine.getRenderingCanvas();
  1353. var index;
  1354. for (index = 0; index < this.cameras.length; index++) {
  1355. this.cameras[index].detachControl(canvas);
  1356. }
  1357. while (this.lights.length) {
  1358. this.lights[0].dispose();
  1359. }
  1360. while (this.meshes.length) {
  1361. this.meshes[0].dispose(true);
  1362. }
  1363. while (this.cameras.length) {
  1364. this.cameras[0].dispose();
  1365. }
  1366. while (this.materials.length) {
  1367. this.materials[0].dispose();
  1368. }
  1369. while (this.particleSystems.length) {
  1370. this.particleSystems[0].dispose();
  1371. }
  1372. while (this.spriteManagers.length) {
  1373. this.spriteManagers[0].dispose();
  1374. }
  1375. while (this.layers.length) {
  1376. this.layers[0].dispose();
  1377. }
  1378. while (this.textures.length) {
  1379. this.textures[0].dispose();
  1380. }
  1381. // Post-processes
  1382. this.postProcessManager.dispose();
  1383. // Physics
  1384. if (this._physicsEngine) {
  1385. this.disablePhysicsEngine();
  1386. }
  1387. // Remove from engine
  1388. index = this._engine.scenes.indexOf(this);
  1389. if (index > -1) {
  1390. this._engine.scenes.splice(index, 1);
  1391. }
  1392. this._engine.wipeCaches();
  1393. };
  1394. // Release sounds & sounds tracks
  1395. Scene.prototype.disposeSounds = function () {
  1396. this.mainSoundTrack.dispose();
  1397. for (var scIndex = 0; scIndex < this.soundTracks.length; scIndex++) {
  1398. this.soundTracks[scIndex].dispose();
  1399. }
  1400. };
  1401. // Collisions
  1402. Scene.prototype._getNewPosition = function (position, velocity, collider, maximumRetry, finalPosition, excludedMesh) {
  1403. if (excludedMesh === void 0) { excludedMesh = null; }
  1404. position.divideToRef(collider.radius, this._scaledPosition);
  1405. velocity.divideToRef(collider.radius, this._scaledVelocity);
  1406. collider.retry = 0;
  1407. collider.initialVelocity = this._scaledVelocity;
  1408. collider.initialPosition = this._scaledPosition;
  1409. this._collideWithWorld(this._scaledPosition, this._scaledVelocity, collider, maximumRetry, finalPosition, excludedMesh);
  1410. finalPosition.multiplyInPlace(collider.radius);
  1411. };
  1412. Scene.prototype._collideWithWorld = function (position, velocity, collider, maximumRetry, finalPosition, excludedMesh) {
  1413. if (excludedMesh === void 0) { excludedMesh = null; }
  1414. var closeDistance = BABYLON.Engine.CollisionsEpsilon * 10.0;
  1415. if (collider.retry >= maximumRetry) {
  1416. finalPosition.copyFrom(position);
  1417. return;
  1418. }
  1419. collider._initialize(position, velocity, closeDistance);
  1420. for (var index = 0; index < this.meshes.length; index++) {
  1421. var mesh = this.meshes[index];
  1422. if (mesh.isEnabled() && mesh.checkCollisions && mesh.subMeshes && mesh !== excludedMesh) {
  1423. mesh._checkCollision(collider);
  1424. }
  1425. }
  1426. if (!collider.collisionFound) {
  1427. position.addToRef(velocity, finalPosition);
  1428. return;
  1429. }
  1430. if (velocity.x !== 0 || velocity.y !== 0 || velocity.z !== 0) {
  1431. collider._getResponse(position, velocity);
  1432. }
  1433. if (velocity.length() <= closeDistance) {
  1434. finalPosition.copyFrom(position);
  1435. return;
  1436. }
  1437. collider.retry++;
  1438. this._collideWithWorld(position, velocity, collider, maximumRetry, finalPosition, excludedMesh);
  1439. };
  1440. // Octrees
  1441. Scene.prototype.getWorldExtends = function () {
  1442. var min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  1443. var max = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  1444. for (var index = 0; index < this.meshes.length; index++) {
  1445. var mesh = this.meshes[index];
  1446. mesh.computeWorldMatrix(true);
  1447. var minBox = mesh.getBoundingInfo().boundingBox.minimumWorld;
  1448. var maxBox = mesh.getBoundingInfo().boundingBox.maximumWorld;
  1449. BABYLON.Tools.CheckExtends(minBox, min, max);
  1450. BABYLON.Tools.CheckExtends(maxBox, min, max);
  1451. }
  1452. return {
  1453. min: min,
  1454. max: max
  1455. };
  1456. };
  1457. Scene.prototype.createOrUpdateSelectionOctree = function (maxCapacity, maxDepth) {
  1458. if (maxCapacity === void 0) { maxCapacity = 64; }
  1459. if (maxDepth === void 0) { maxDepth = 2; }
  1460. if (!this._selectionOctree) {
  1461. this._selectionOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForMeshes, maxCapacity, maxDepth);
  1462. }
  1463. var worldExtends = this.getWorldExtends();
  1464. // Update octree
  1465. this._selectionOctree.update(worldExtends.min, worldExtends.max, this.meshes);
  1466. return this._selectionOctree;
  1467. };
  1468. // Picking
  1469. Scene.prototype.createPickingRay = function (x, y, world, camera) {
  1470. var engine = this._engine;
  1471. if (!camera) {
  1472. if (!this.activeCamera)
  1473. throw new Error("Active camera not set");
  1474. camera = this.activeCamera;
  1475. }
  1476. var cameraViewport = camera.viewport;
  1477. var viewport = cameraViewport.toGlobal(engine);
  1478. // Moving coordinates to local viewport world
  1479. x = x / this._engine.getHardwareScalingLevel() - viewport.x;
  1480. y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
  1481. return BABYLON.Ray.CreateNew(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
  1482. // return BABYLON.Ray.CreateNew(x / window.devicePixelRatio, y / window.devicePixelRatio, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
  1483. };
  1484. Scene.prototype._internalPick = function (rayFunction, predicate, fastCheck) {
  1485. var pickingInfo = null;
  1486. for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {
  1487. var mesh = this.meshes[meshIndex];
  1488. if (predicate) {
  1489. if (!predicate(mesh)) {
  1490. continue;
  1491. }
  1492. }
  1493. else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
  1494. continue;
  1495. }
  1496. var world = mesh.getWorldMatrix();
  1497. var ray = rayFunction(world);
  1498. var result = mesh.intersects(ray, fastCheck);
  1499. if (!result || !result.hit)
  1500. continue;
  1501. if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance)
  1502. continue;
  1503. pickingInfo = result;
  1504. if (fastCheck) {
  1505. break;
  1506. }
  1507. }
  1508. return pickingInfo || new BABYLON.PickingInfo();
  1509. };
  1510. Scene.prototype.pick = function (x, y, predicate, fastCheck, camera) {
  1511. var _this = this;
  1512. /// <summary>Launch a ray to try to pick a mesh in the scene</summary>
  1513. /// <param name="x">X position on screen</param>
  1514. /// <param name="y">Y position on screen</param>
  1515. /// <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>
  1516. /// <param name="fastCheck">Launch a fast check only using the bounding boxes. Can be set to null.</param>
  1517. /// <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>
  1518. return this._internalPick(function (world) { return _this.createPickingRay(x, y, world, camera); }, predicate, fastCheck);
  1519. };
  1520. Scene.prototype.pickWithRay = function (ray, predicate, fastCheck) {
  1521. var _this = this;
  1522. return this._internalPick(function (world) {
  1523. if (!_this._pickWithRayInverseMatrix) {
  1524. _this._pickWithRayInverseMatrix = BABYLON.Matrix.Identity();
  1525. }
  1526. world.invertToRef(_this._pickWithRayInverseMatrix);
  1527. return BABYLON.Ray.Transform(ray, _this._pickWithRayInverseMatrix);
  1528. }, predicate, fastCheck);
  1529. };
  1530. Scene.prototype.setPointerOverMesh = function (mesh) {
  1531. if (this._pointerOverMesh === mesh) {
  1532. return;
  1533. }
  1534. if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
  1535. this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
  1536. }
  1537. this._pointerOverMesh = mesh;
  1538. if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
  1539. this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
  1540. }
  1541. };
  1542. Scene.prototype.getPointerOverMesh = function () {
  1543. return this._pointerOverMesh;
  1544. };
  1545. // Physics
  1546. Scene.prototype.getPhysicsEngine = function () {
  1547. return this._physicsEngine;
  1548. };
  1549. Scene.prototype.enablePhysics = function (gravity, plugin) {
  1550. if (this._physicsEngine) {
  1551. return true;
  1552. }
  1553. this._physicsEngine = new BABYLON.PhysicsEngine(plugin);
  1554. if (!this._physicsEngine.isSupported()) {
  1555. this._physicsEngine = null;
  1556. return false;
  1557. }
  1558. this._physicsEngine._initialize(gravity);
  1559. return true;
  1560. };
  1561. Scene.prototype.disablePhysicsEngine = function () {
  1562. if (!this._physicsEngine) {
  1563. return;
  1564. }
  1565. this._physicsEngine.dispose();
  1566. this._physicsEngine = undefined;
  1567. };
  1568. Scene.prototype.isPhysicsEnabled = function () {
  1569. return this._physicsEngine !== undefined;
  1570. };
  1571. Scene.prototype.setGravity = function (gravity) {
  1572. if (!this._physicsEngine) {
  1573. return;
  1574. }
  1575. this._physicsEngine._setGravity(gravity);
  1576. };
  1577. Scene.prototype.createCompoundImpostor = function (parts, options) {
  1578. if (parts.parts) {
  1579. options = parts;
  1580. parts = parts.parts;
  1581. }
  1582. if (!this._physicsEngine) {
  1583. return null;
  1584. }
  1585. for (var index = 0; index < parts.length; index++) {
  1586. var mesh = parts[index].mesh;
  1587. mesh._physicImpostor = parts[index].impostor;
  1588. mesh._physicsMass = options.mass / parts.length;
  1589. mesh._physicsFriction = options.friction;
  1590. mesh._physicRestitution = options.restitution;
  1591. }
  1592. return this._physicsEngine._registerMeshesAsCompound(parts, options);
  1593. };
  1594. Scene.prototype.deleteCompoundImpostor = function (compound) {
  1595. for (var index = 0; index < compound.parts.length; index++) {
  1596. var mesh = compound.parts[index].mesh;
  1597. mesh._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
  1598. this._physicsEngine._unregisterMesh(mesh);
  1599. }
  1600. };
  1601. // Misc.
  1602. Scene.prototype.createDefaultCameraOrLight = function () {
  1603. // Light
  1604. if (this.lights.length === 0) {
  1605. new BABYLON.HemisphericLight("default light", BABYLON.Vector3.Up(), this);
  1606. }
  1607. // Camera
  1608. if (!this.activeCamera) {
  1609. var camera = new BABYLON.FreeCamera("default camera", BABYLON.Vector3.Zero(), this);
  1610. // Compute position
  1611. var worldExtends = this.getWorldExtends();
  1612. var worldCenter = worldExtends.min.add(worldExtends.max.subtract(worldExtends.min).scale(0.5));
  1613. camera.position = new BABYLON.Vector3(worldCenter.x, worldCenter.y, worldExtends.min.z - (worldExtends.max.z - worldExtends.min.z));
  1614. camera.setTarget(worldCenter);
  1615. this.activeCamera = camera;
  1616. }
  1617. };
  1618. // Tags
  1619. Scene.prototype._getByTags = function (list, tagsQuery, forEach) {
  1620. if (tagsQuery === undefined) {
  1621. // returns the complete list (could be done with BABYLON.Tags.MatchesQuery but no need to have a for-loop here)
  1622. return list;
  1623. }
  1624. var listByTags = [];
  1625. forEach = forEach || (function (item) {
  1626. return;
  1627. });
  1628. for (var i in list) {
  1629. var item = list[i];
  1630. if (BABYLON.Tags.MatchesQuery(item, tagsQuery)) {
  1631. listByTags.push(item);
  1632. forEach(item);
  1633. }
  1634. }
  1635. return listByTags;
  1636. };
  1637. Scene.prototype.getMeshesByTags = function (tagsQuery, forEach) {
  1638. return this._getByTags(this.meshes, tagsQuery, forEach);
  1639. };
  1640. Scene.prototype.getCamerasByTags = function (tagsQuery, forEach) {
  1641. return this._getByTags(this.cameras, tagsQuery, forEach);
  1642. };
  1643. Scene.prototype.getLightsByTags = function (tagsQuery, forEach) {
  1644. return this._getByTags(this.lights, tagsQuery, forEach);
  1645. };
  1646. Scene.prototype.getMaterialByTags = function (tagsQuery, forEach) {
  1647. return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));
  1648. };
  1649. // Statics
  1650. Scene._FOGMODE_NONE = 0;
  1651. Scene._FOGMODE_EXP = 1;
  1652. Scene._FOGMODE_EXP2 = 2;
  1653. Scene._FOGMODE_LINEAR = 3;
  1654. Scene.MinDeltaTime = 1.0;
  1655. Scene.MaxDeltaTime = 1000.0;
  1656. return Scene;
  1657. })();
  1658. BABYLON.Scene = Scene;
  1659. })(BABYLON || (BABYLON = {}));
  1660. //# sourceMappingURL=babylon.scene.js.map