babylon.scene.js 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658
  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. this._activeAnimatables[index]._animate(delay);
  512. }
  513. };
  514. // Matrix
  515. Scene.prototype.getViewMatrix = function () {
  516. return this._viewMatrix;
  517. };
  518. Scene.prototype.getProjectionMatrix = function () {
  519. return this._projectionMatrix;
  520. };
  521. Scene.prototype.getTransformMatrix = function () {
  522. return this._transformMatrix;
  523. };
  524. Scene.prototype.setTransformMatrix = function (view, projection) {
  525. this._viewMatrix = view;
  526. this._projectionMatrix = projection;
  527. this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);
  528. };
  529. // Methods
  530. Scene.prototype.addMesh = function (newMesh) {
  531. var position = this.meshes.push(newMesh);
  532. if (this.onNewMeshAdded) {
  533. this.onNewMeshAdded(newMesh, position, this);
  534. }
  535. };
  536. Scene.prototype.removeMesh = function (toRemove) {
  537. var index = this.meshes.indexOf(toRemove);
  538. if (index !== -1) {
  539. // Remove from the scene if mesh found
  540. this.meshes.splice(index, 1);
  541. }
  542. if (this.onMeshRemoved) {
  543. this.onMeshRemoved(toRemove);
  544. }
  545. return index;
  546. };
  547. Scene.prototype.removeLight = function (toRemove) {
  548. var index = this.lights.indexOf(toRemove);
  549. if (index !== -1) {
  550. // Remove from the scene if mesh found
  551. this.lights.splice(index, 1);
  552. }
  553. if (this.onLightRemoved) {
  554. this.onLightRemoved(toRemove);
  555. }
  556. return index;
  557. };
  558. Scene.prototype.removeCamera = function (toRemove) {
  559. var index = this.cameras.indexOf(toRemove);
  560. if (index !== -1) {
  561. // Remove from the scene if mesh found
  562. this.cameras.splice(index, 1);
  563. }
  564. if (this.onCameraRemoved) {
  565. this.onCameraRemoved(toRemove);
  566. }
  567. return index;
  568. };
  569. Scene.prototype.addLight = function (newLight) {
  570. var position = this.lights.push(newLight);
  571. if (this.onNewLightAdded) {
  572. this.onNewLightAdded(newLight, position, this);
  573. }
  574. };
  575. Scene.prototype.addCamera = function (newCamera) {
  576. var position = this.cameras.push(newCamera);
  577. if (this.onNewCameraAdded) {
  578. this.onNewCameraAdded(newCamera, position, this);
  579. }
  580. };
  581. /**
  582. * sets the active camera of the scene using its ID
  583. * @param {string} id - the camera's ID
  584. * @return {BABYLON.Camera|null} the new active camera or null if none found.
  585. * @see activeCamera
  586. */
  587. Scene.prototype.setActiveCameraByID = function (id) {
  588. var camera = this.getCameraByID(id);
  589. if (camera) {
  590. this.activeCamera = camera;
  591. return camera;
  592. }
  593. return null;
  594. };
  595. /**
  596. * sets the active camera of the scene using its name
  597. * @param {string} name - the camera's name
  598. * @return {BABYLON.Camera|null} the new active camera or null if none found.
  599. * @see activeCamera
  600. */
  601. Scene.prototype.setActiveCameraByName = function (name) {
  602. var camera = this.getCameraByName(name);
  603. if (camera) {
  604. this.activeCamera = camera;
  605. return camera;
  606. }
  607. return null;
  608. };
  609. /**
  610. * get a material using its id
  611. * @param {string} the material's ID
  612. * @return {BABYLON.Material|null} the material or null if none found.
  613. */
  614. Scene.prototype.getMaterialByID = function (id) {
  615. for (var index = 0; index < this.materials.length; index++) {
  616. if (this.materials[index].id === id) {
  617. return this.materials[index];
  618. }
  619. }
  620. return null;
  621. };
  622. /**
  623. * get a material using its name
  624. * @param {string} the material's name
  625. * @return {BABYLON.Material|null} the material or null if none found.
  626. */
  627. Scene.prototype.getMaterialByName = function (name) {
  628. for (var index = 0; index < this.materials.length; index++) {
  629. if (this.materials[index].name === name) {
  630. return this.materials[index];
  631. }
  632. }
  633. return null;
  634. };
  635. Scene.prototype.getCameraByID = function (id) {
  636. for (var index = 0; index < this.cameras.length; index++) {
  637. if (this.cameras[index].id === id) {
  638. return this.cameras[index];
  639. }
  640. }
  641. return null;
  642. };
  643. /**
  644. * get a camera using its name
  645. * @param {string} the camera's name
  646. * @return {BABYLON.Camera|null} the camera or null if none found.
  647. */
  648. Scene.prototype.getCameraByName = function (name) {
  649. for (var index = 0; index < this.cameras.length; index++) {
  650. if (this.cameras[index].name === name) {
  651. return this.cameras[index];
  652. }
  653. }
  654. return null;
  655. };
  656. /**
  657. * get a light node using its name
  658. * @param {string} the light's name
  659. * @return {BABYLON.Light|null} the light or null if none found.
  660. */
  661. Scene.prototype.getLightByName = function (name) {
  662. for (var index = 0; index < this.lights.length; index++) {
  663. if (this.lights[index].name === name) {
  664. return this.lights[index];
  665. }
  666. }
  667. return null;
  668. };
  669. /**
  670. * get a light node using its ID
  671. * @param {string} the light's id
  672. * @return {BABYLON.Light|null} the light or null if none found.
  673. */
  674. Scene.prototype.getLightByID = function (id) {
  675. for (var index = 0; index < this.lights.length; index++) {
  676. if (this.lights[index].id === id) {
  677. return this.lights[index];
  678. }
  679. }
  680. return null;
  681. };
  682. /**
  683. * get a geometry using its ID
  684. * @param {string} the geometry's id
  685. * @return {BABYLON.Geometry|null} the geometry or null if none found.
  686. */
  687. Scene.prototype.getGeometryByID = function (id) {
  688. for (var index = 0; index < this._geometries.length; index++) {
  689. if (this._geometries[index].id === id) {
  690. return this._geometries[index];
  691. }
  692. }
  693. return null;
  694. };
  695. /**
  696. * add a new geometry to this scene.
  697. * @param {BABYLON.Geometry} geometry - the geometry to be added to the scene.
  698. * @param {boolean} [force] - force addition, even if a geometry with this ID already exists
  699. * @return {boolean} was the geometry added or not
  700. */
  701. Scene.prototype.pushGeometry = function (geometry, force) {
  702. if (!force && this.getGeometryByID(geometry.id)) {
  703. return false;
  704. }
  705. this._geometries.push(geometry);
  706. return true;
  707. };
  708. Scene.prototype.getGeometries = function () {
  709. return this._geometries;
  710. };
  711. /**
  712. * Get a the first added mesh found of a given ID
  713. * @param {string} id - the id to search for
  714. * @return {BABYLON.AbstractMesh|null} the mesh found or null if not found at all.
  715. */
  716. Scene.prototype.getMeshByID = function (id) {
  717. for (var index = 0; index < this.meshes.length; index++) {
  718. if (this.meshes[index].id === id) {
  719. return this.meshes[index];
  720. }
  721. }
  722. return null;
  723. };
  724. /**
  725. * Get a the last added mesh found of a given ID
  726. * @param {string} id - the id to search for
  727. * @return {BABYLON.AbstractMesh|null} the mesh found or null if not found at all.
  728. */
  729. Scene.prototype.getLastMeshByID = function (id) {
  730. for (var index = this.meshes.length - 1; index >= 0; index--) {
  731. if (this.meshes[index].id === id) {
  732. return this.meshes[index];
  733. }
  734. }
  735. return null;
  736. };
  737. /**
  738. * Get a the last added node (Mesh, Camera, Light) found of a given ID
  739. * @param {string} id - the id to search for
  740. * @return {BABYLON.Node|null} the node found or null if not found at all.
  741. */
  742. Scene.prototype.getLastEntryByID = function (id) {
  743. for (var index = this.meshes.length - 1; index >= 0; index--) {
  744. if (this.meshes[index].id === id) {
  745. return this.meshes[index];
  746. }
  747. }
  748. for (index = this.cameras.length - 1; index >= 0; index--) {
  749. if (this.cameras[index].id === id) {
  750. return this.cameras[index];
  751. }
  752. }
  753. for (index = this.lights.length - 1; index >= 0; index--) {
  754. if (this.lights[index].id === id) {
  755. return this.lights[index];
  756. }
  757. }
  758. return null;
  759. };
  760. Scene.prototype.getNodeByName = function (name) {
  761. var mesh = this.getMeshByName(name);
  762. if (mesh) {
  763. return mesh;
  764. }
  765. var light = this.getLightByName(name);
  766. if (light) {
  767. return light;
  768. }
  769. return this.getCameraByName(name);
  770. };
  771. Scene.prototype.getMeshByName = function (name) {
  772. for (var index = 0; index < this.meshes.length; index++) {
  773. if (this.meshes[index].name === name) {
  774. return this.meshes[index];
  775. }
  776. }
  777. return null;
  778. };
  779. Scene.prototype.getSoundByName = function (name) {
  780. for (var index = 0; index < this.mainSoundTrack.soundCollection.length; index++) {
  781. if (this.mainSoundTrack.soundCollection[index].name === name) {
  782. return this.mainSoundTrack.soundCollection[index];
  783. }
  784. }
  785. for (var sdIndex = 0; sdIndex < this.soundTracks.length; sdIndex++) {
  786. for (index = 0; index < this.soundTracks[sdIndex].soundCollection.length; index++) {
  787. if (this.soundTracks[sdIndex].soundCollection[index].name === name) {
  788. return this.soundTracks[sdIndex].soundCollection[index];
  789. }
  790. }
  791. }
  792. return null;
  793. };
  794. Scene.prototype.getLastSkeletonByID = function (id) {
  795. for (var index = this.skeletons.length - 1; index >= 0; index--) {
  796. if (this.skeletons[index].id === id) {
  797. return this.skeletons[index];
  798. }
  799. }
  800. return null;
  801. };
  802. Scene.prototype.getSkeletonById = function (id) {
  803. for (var index = 0; index < this.skeletons.length; index++) {
  804. if (this.skeletons[index].id === id) {
  805. return this.skeletons[index];
  806. }
  807. }
  808. return null;
  809. };
  810. Scene.prototype.getSkeletonByName = function (name) {
  811. for (var index = 0; index < this.skeletons.length; index++) {
  812. if (this.skeletons[index].name === name) {
  813. return this.skeletons[index];
  814. }
  815. }
  816. return null;
  817. };
  818. Scene.prototype.isActiveMesh = function (mesh) {
  819. return (this._activeMeshes.indexOf(mesh) !== -1);
  820. };
  821. Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
  822. if (mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
  823. var material = subMesh.getMaterial();
  824. if (mesh.showSubMeshesBoundingBox) {
  825. this._boundingBoxRenderer.renderList.push(subMesh.getBoundingInfo().boundingBox);
  826. }
  827. if (material) {
  828. // Render targets
  829. if (material.getRenderTargetTextures) {
  830. if (this._processedMaterials.indexOf(material) === -1) {
  831. this._processedMaterials.push(material);
  832. this._renderTargets.concat(material.getRenderTargetTextures());
  833. }
  834. }
  835. // Dispatch
  836. this._activeVertices += subMesh.indexCount;
  837. this._renderingManager.dispatch(subMesh);
  838. }
  839. }
  840. };
  841. Scene.prototype._evaluateActiveMeshes = function () {
  842. this.activeCamera._activeMeshes.reset();
  843. this._activeMeshes.reset();
  844. this._renderingManager.reset();
  845. this._processedMaterials.reset();
  846. this._activeParticleSystems.reset();
  847. this._activeSkeletons.reset();
  848. this._boundingBoxRenderer.reset();
  849. if (!this._frustumPlanes) {
  850. this._frustumPlanes = BABYLON.Frustum.GetPlanes(this._transformMatrix);
  851. }
  852. else {
  853. BABYLON.Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);
  854. }
  855. // Meshes
  856. var meshes;
  857. var len;
  858. if (this._selectionOctree) {
  859. var selection = this._selectionOctree.select(this._frustumPlanes);
  860. meshes = selection.data;
  861. len = selection.length;
  862. }
  863. else {
  864. len = this.meshes.length;
  865. meshes = this.meshes;
  866. }
  867. for (var meshIndex = 0; meshIndex < len; meshIndex++) {
  868. var mesh = meshes[meshIndex];
  869. if (mesh.isBlocked) {
  870. continue;
  871. }
  872. this._totalVertices += mesh.getTotalVertices();
  873. if (!mesh.isReady()) {
  874. continue;
  875. }
  876. mesh.computeWorldMatrix();
  877. // Intersections
  878. if (mesh.actionManager && mesh.actionManager.hasSpecificTriggers([BABYLON.ActionManager.OnIntersectionEnterTrigger, BABYLON.ActionManager.OnIntersectionExitTrigger])) {
  879. this._meshesForIntersections.pushNoDuplicate(mesh);
  880. }
  881. // Switch to current LOD
  882. var meshLOD = mesh.getLOD(this.activeCamera);
  883. if (!meshLOD) {
  884. continue;
  885. }
  886. mesh._preActivate();
  887. if (mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) !== 0) && mesh.isInFrustum(this._frustumPlanes)) {
  888. this._activeMeshes.push(mesh);
  889. this.activeCamera._activeMeshes.push(mesh);
  890. mesh._activate(this._renderId);
  891. this._activeMesh(meshLOD);
  892. }
  893. }
  894. // Particle systems
  895. var beforeParticlesDate = BABYLON.Tools.Now;
  896. if (this.particlesEnabled) {
  897. BABYLON.Tools.StartPerformanceCounter("Particles", this.particleSystems.length > 0);
  898. for (var particleIndex = 0; particleIndex < this.particleSystems.length; particleIndex++) {
  899. var particleSystem = this.particleSystems[particleIndex];
  900. if (!particleSystem.isStarted()) {
  901. continue;
  902. }
  903. if (!particleSystem.emitter.position || (particleSystem.emitter && particleSystem.emitter.isEnabled())) {
  904. this._activeParticleSystems.push(particleSystem);
  905. particleSystem.animate();
  906. }
  907. }
  908. BABYLON.Tools.EndPerformanceCounter("Particles", this.particleSystems.length > 0);
  909. }
  910. this._particlesDuration += BABYLON.Tools.Now - beforeParticlesDate;
  911. };
  912. Scene.prototype._activeMesh = function (mesh) {
  913. if (mesh.skeleton && this.skeletonsEnabled) {
  914. this._activeSkeletons.pushNoDuplicate(mesh.skeleton);
  915. }
  916. if (mesh.showBoundingBox || this.forceShowBoundingBoxes) {
  917. this._boundingBoxRenderer.renderList.push(mesh.getBoundingInfo().boundingBox);
  918. }
  919. if (mesh && mesh.subMeshes) {
  920. // Submeshes Octrees
  921. var len;
  922. var subMeshes;
  923. if (mesh._submeshesOctree && mesh.useOctreeForRenderingSelection) {
  924. var intersections = mesh._submeshesOctree.select(this._frustumPlanes);
  925. len = intersections.length;
  926. subMeshes = intersections.data;
  927. }
  928. else {
  929. subMeshes = mesh.subMeshes;
  930. len = subMeshes.length;
  931. }
  932. for (var subIndex = 0; subIndex < len; subIndex++) {
  933. var subMesh = subMeshes[subIndex];
  934. this._evaluateSubMesh(subMesh, mesh);
  935. }
  936. }
  937. };
  938. Scene.prototype.updateTransformMatrix = function (force) {
  939. this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(force));
  940. };
  941. Scene.prototype._renderForCamera = function (camera) {
  942. var engine = this._engine;
  943. this.activeCamera = camera;
  944. if (!this.activeCamera)
  945. throw new Error("Active camera not set");
  946. BABYLON.Tools.StartPerformanceCounter("Rendering camera " + this.activeCamera.name);
  947. // Viewport
  948. engine.setViewport(this.activeCamera.viewport);
  949. // Camera
  950. this._renderId++;
  951. this.updateTransformMatrix();
  952. if (this.beforeCameraRender) {
  953. this.beforeCameraRender(this.activeCamera);
  954. }
  955. // Meshes
  956. var beforeEvaluateActiveMeshesDate = BABYLON.Tools.Now;
  957. BABYLON.Tools.StartPerformanceCounter("Active meshes evaluation");
  958. this._evaluateActiveMeshes();
  959. this._evaluateActiveMeshesDuration += BABYLON.Tools.Now - beforeEvaluateActiveMeshesDate;
  960. BABYLON.Tools.EndPerformanceCounter("Active meshes evaluation");
  961. for (var skeletonIndex = 0; skeletonIndex < this._activeSkeletons.length; skeletonIndex++) {
  962. var skeleton = this._activeSkeletons.data[skeletonIndex];
  963. skeleton.prepare();
  964. }
  965. // Render targets
  966. var beforeRenderTargetDate = BABYLON.Tools.Now;
  967. if (this.renderTargetsEnabled) {
  968. BABYLON.Tools.StartPerformanceCounter("Render targets", this._renderTargets.length > 0);
  969. for (var renderIndex = 0; renderIndex < this._renderTargets.length; renderIndex++) {
  970. var renderTarget = this._renderTargets.data[renderIndex];
  971. if (renderTarget._shouldRender()) {
  972. this._renderId++;
  973. var hasSpecialRenderTargetCamera = renderTarget.activeCamera && renderTarget.activeCamera !== this.activeCamera;
  974. renderTarget.render(hasSpecialRenderTargetCamera, this.dumpNextRenderTargets);
  975. }
  976. }
  977. BABYLON.Tools.EndPerformanceCounter("Render targets", this._renderTargets.length > 0);
  978. this._renderId++;
  979. }
  980. if (this._renderTargets.length > 0) {
  981. engine.restoreDefaultFramebuffer();
  982. }
  983. this._renderTargetsDuration += BABYLON.Tools.Now - beforeRenderTargetDate;
  984. // Prepare Frame
  985. this.postProcessManager._prepareFrame();
  986. var beforeRenderDate = BABYLON.Tools.Now;
  987. // Backgrounds
  988. if (this.layers.length) {
  989. engine.setDepthBuffer(false);
  990. var layerIndex;
  991. var layer;
  992. for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
  993. layer = this.layers[layerIndex];
  994. if (layer.isBackground) {
  995. layer.render();
  996. }
  997. }
  998. engine.setDepthBuffer(true);
  999. }
  1000. // Render
  1001. BABYLON.Tools.StartPerformanceCounter("Main render");
  1002. this._renderingManager.render(null, null, true, true);
  1003. BABYLON.Tools.EndPerformanceCounter("Main render");
  1004. // Bounding boxes
  1005. this._boundingBoxRenderer.render();
  1006. // Lens flares
  1007. if (this.lensFlaresEnabled) {
  1008. BABYLON.Tools.StartPerformanceCounter("Lens flares", this.lensFlareSystems.length > 0);
  1009. for (var lensFlareSystemIndex = 0; lensFlareSystemIndex < this.lensFlareSystems.length; lensFlareSystemIndex++) {
  1010. this.lensFlareSystems[lensFlareSystemIndex].render();
  1011. }
  1012. BABYLON.Tools.EndPerformanceCounter("Lens flares", this.lensFlareSystems.length > 0);
  1013. }
  1014. // Foregrounds
  1015. if (this.layers.length) {
  1016. engine.setDepthBuffer(false);
  1017. for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
  1018. layer = this.layers[layerIndex];
  1019. if (!layer.isBackground) {
  1020. layer.render();
  1021. }
  1022. }
  1023. engine.setDepthBuffer(true);
  1024. }
  1025. this._renderDuration += BABYLON.Tools.Now - beforeRenderDate;
  1026. // Finalize frame
  1027. this.postProcessManager._finalizeFrame(camera.isIntermediate);
  1028. // Update camera
  1029. this.activeCamera._updateFromScene();
  1030. // Reset some special arrays
  1031. this._renderTargets.reset();
  1032. if (this.afterCameraRender) {
  1033. this.afterCameraRender(this.activeCamera);
  1034. }
  1035. BABYLON.Tools.EndPerformanceCounter("Rendering camera " + this.activeCamera.name);
  1036. };
  1037. Scene.prototype._processSubCameras = function (camera) {
  1038. if (camera.subCameras.length === 0) {
  1039. this._renderForCamera(camera);
  1040. return;
  1041. }
  1042. for (var index = 0; index < camera.subCameras.length; index++) {
  1043. this._renderForCamera(camera.subCameras[index]);
  1044. }
  1045. this.activeCamera = camera;
  1046. this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix());
  1047. // Update camera
  1048. this.activeCamera._updateFromScene();
  1049. };
  1050. Scene.prototype._checkIntersections = function () {
  1051. for (var index = 0; index < this._meshesForIntersections.length; index++) {
  1052. var sourceMesh = this._meshesForIntersections.data[index];
  1053. for (var actionIndex = 0; actionIndex < sourceMesh.actionManager.actions.length; actionIndex++) {
  1054. var action = sourceMesh.actionManager.actions[actionIndex];
  1055. if (action.trigger === BABYLON.ActionManager.OnIntersectionEnterTrigger || action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  1056. var parameters = action.getTriggerParameter();
  1057. var otherMesh = parameters instanceof BABYLON.AbstractMesh ? parameters : parameters.mesh;
  1058. var areIntersecting = otherMesh.intersectsMesh(sourceMesh, parameters.usePreciseIntersection);
  1059. var currentIntersectionInProgress = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
  1060. if (areIntersecting && currentIntersectionInProgress === -1) {
  1061. if (action.trigger === BABYLON.ActionManager.OnIntersectionEnterTrigger) {
  1062. action._executeCurrent(BABYLON.ActionEvent.CreateNew(sourceMesh));
  1063. sourceMesh._intersectionsInProgress.push(otherMesh);
  1064. }
  1065. else if (action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  1066. sourceMesh._intersectionsInProgress.push(otherMesh);
  1067. }
  1068. }
  1069. else if (!areIntersecting && currentIntersectionInProgress > -1 && action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
  1070. action._executeCurrent(BABYLON.ActionEvent.CreateNew(sourceMesh));
  1071. var indexOfOther = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
  1072. if (indexOfOther > -1) {
  1073. sourceMesh._intersectionsInProgress.splice(indexOfOther, 1);
  1074. }
  1075. }
  1076. }
  1077. }
  1078. }
  1079. };
  1080. Scene.prototype.render = function () {
  1081. var startDate = BABYLON.Tools.Now;
  1082. this._particlesDuration = 0;
  1083. this._spritesDuration = 0;
  1084. this._activeParticles = 0;
  1085. this._renderDuration = 0;
  1086. this._renderTargetsDuration = 0;
  1087. this._evaluateActiveMeshesDuration = 0;
  1088. this._totalVertices = 0;
  1089. this._activeVertices = 0;
  1090. this._activeBones = 0;
  1091. this.getEngine().resetDrawCalls();
  1092. this._meshesForIntersections.reset();
  1093. this.resetCachedMaterial();
  1094. BABYLON.Tools.StartPerformanceCounter("Scene rendering");
  1095. // Actions
  1096. if (this.actionManager) {
  1097. this.actionManager.processTrigger(BABYLON.ActionManager.OnEveryFrameTrigger, null);
  1098. }
  1099. //Simplification Queue
  1100. if (!this.simplificationQueue.running) {
  1101. this.simplificationQueue.executeNext();
  1102. }
  1103. // Before render
  1104. if (this.beforeRender) {
  1105. this.beforeRender();
  1106. }
  1107. for (var callbackIndex = 0; callbackIndex < this._onBeforeRenderCallbacks.length; callbackIndex++) {
  1108. this._onBeforeRenderCallbacks[callbackIndex]();
  1109. }
  1110. // Animations
  1111. var deltaTime = Math.max(Scene.MinDeltaTime, Math.min(this._engine.getDeltaTime(), Scene.MaxDeltaTime));
  1112. this._animationRatio = deltaTime * (60.0 / 1000.0);
  1113. this._animate();
  1114. // Physics
  1115. if (this._physicsEngine) {
  1116. BABYLON.Tools.StartPerformanceCounter("Physics");
  1117. this._physicsEngine._runOneStep(deltaTime / 1000.0);
  1118. BABYLON.Tools.EndPerformanceCounter("Physics");
  1119. }
  1120. // Customs render targets
  1121. var beforeRenderTargetDate = BABYLON.Tools.Now;
  1122. var engine = this.getEngine();
  1123. var currentActiveCamera = this.activeCamera;
  1124. if (this.renderTargetsEnabled) {
  1125. BABYLON.Tools.StartPerformanceCounter("Custom render targets", this.customRenderTargets.length > 0);
  1126. for (var customIndex = 0; customIndex < this.customRenderTargets.length; customIndex++) {
  1127. var renderTarget = this.customRenderTargets[customIndex];
  1128. if (renderTarget._shouldRender()) {
  1129. this._renderId++;
  1130. this.activeCamera = renderTarget.activeCamera || this.activeCamera;
  1131. if (!this.activeCamera)
  1132. throw new Error("Active camera not set");
  1133. // Viewport
  1134. engine.setViewport(this.activeCamera.viewport);
  1135. // Camera
  1136. this.updateTransformMatrix();
  1137. renderTarget.render(currentActiveCamera !== this.activeCamera, this.dumpNextRenderTargets);
  1138. }
  1139. }
  1140. BABYLON.Tools.EndPerformanceCounter("Custom render targets", this.customRenderTargets.length > 0);
  1141. this._renderId++;
  1142. }
  1143. if (this.customRenderTargets.length > 0) {
  1144. engine.restoreDefaultFramebuffer();
  1145. }
  1146. this._renderTargetsDuration += BABYLON.Tools.Now - beforeRenderTargetDate;
  1147. this.activeCamera = currentActiveCamera;
  1148. // Procedural textures
  1149. if (this.proceduralTexturesEnabled) {
  1150. BABYLON.Tools.StartPerformanceCounter("Procedural textures", this._proceduralTextures.length > 0);
  1151. for (var proceduralIndex = 0; proceduralIndex < this._proceduralTextures.length; proceduralIndex++) {
  1152. var proceduralTexture = this._proceduralTextures[proceduralIndex];
  1153. if (proceduralTexture._shouldRender()) {
  1154. proceduralTexture.render();
  1155. }
  1156. }
  1157. BABYLON.Tools.EndPerformanceCounter("Procedural textures", this._proceduralTextures.length > 0);
  1158. }
  1159. // Clear
  1160. this._engine.clear(this.clearColor, this.autoClear || this.forceWireframe || this.forcePointsCloud, true);
  1161. // Shadows
  1162. if (this.shadowsEnabled) {
  1163. for (var lightIndex = 0; lightIndex < this.lights.length; lightIndex++) {
  1164. var light = this.lights[lightIndex];
  1165. var shadowGenerator = light.getShadowGenerator();
  1166. if (light.isEnabled() && shadowGenerator && shadowGenerator.getShadowMap().getScene().textures.indexOf(shadowGenerator.getShadowMap()) !== -1) {
  1167. this._renderTargets.push(shadowGenerator.getShadowMap());
  1168. }
  1169. }
  1170. }
  1171. // Depth renderer
  1172. if (this._depthRenderer) {
  1173. this._renderTargets.push(this._depthRenderer.getDepthMap());
  1174. }
  1175. // RenderPipeline
  1176. this.postProcessRenderPipelineManager.update();
  1177. // Multi-cameras?
  1178. if (this.activeCameras.length > 0) {
  1179. var currentRenderId = this._renderId;
  1180. for (var cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {
  1181. this._renderId = currentRenderId;
  1182. this._processSubCameras(this.activeCameras[cameraIndex]);
  1183. }
  1184. }
  1185. else {
  1186. if (!this.activeCamera) {
  1187. throw new Error("No camera defined");
  1188. }
  1189. this._processSubCameras(this.activeCamera);
  1190. }
  1191. // Intersection checks
  1192. this._checkIntersections();
  1193. // Update the audio listener attached to the camera
  1194. this._updateAudioParameters();
  1195. // After render
  1196. if (this.afterRender) {
  1197. this.afterRender();
  1198. }
  1199. for (callbackIndex = 0; callbackIndex < this._onAfterRenderCallbacks.length; callbackIndex++) {
  1200. this._onAfterRenderCallbacks[callbackIndex]();
  1201. }
  1202. for (var index = 0; index < this._toBeDisposed.length; index++) {
  1203. this._toBeDisposed.data[index].dispose();
  1204. this._toBeDisposed[index] = null;
  1205. }
  1206. this._toBeDisposed.reset();
  1207. if (this.dumpNextRenderTargets) {
  1208. this.dumpNextRenderTargets = false;
  1209. }
  1210. BABYLON.Tools.EndPerformanceCounter("Scene rendering");
  1211. this._lastFrameDuration = BABYLON.Tools.Now - startDate;
  1212. };
  1213. Scene.prototype._updateAudioParameters = function () {
  1214. if (!this.audioEnabled || (this.mainSoundTrack.soundCollection.length === 0 && this.soundTracks.length === 0)) {
  1215. return;
  1216. }
  1217. var listeningCamera;
  1218. var audioEngine = BABYLON.Engine.audioEngine;
  1219. if (this.activeCameras.length > 0) {
  1220. listeningCamera = this.activeCameras[0];
  1221. }
  1222. else {
  1223. listeningCamera = this.activeCamera;
  1224. }
  1225. if (listeningCamera && audioEngine.canUseWebAudio) {
  1226. audioEngine.audioContext.listener.setPosition(listeningCamera.position.x, listeningCamera.position.y, listeningCamera.position.z);
  1227. var mat = BABYLON.Matrix.Invert(listeningCamera.getViewMatrix());
  1228. var cameraDirection = BABYLON.Vector3.TransformNormal(new BABYLON.Vector3(0, 0, -1), mat);
  1229. cameraDirection.normalize();
  1230. audioEngine.audioContext.listener.setOrientation(cameraDirection.x, cameraDirection.y, cameraDirection.z, 0, 1, 0);
  1231. for (var i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  1232. var sound = this.mainSoundTrack.soundCollection[i];
  1233. if (sound.useCustomAttenuation) {
  1234. sound.updateDistanceFromListener();
  1235. }
  1236. }
  1237. for (i = 0; i < this.soundTracks.length; i++) {
  1238. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  1239. sound = this.soundTracks[i].soundCollection[j];
  1240. if (sound.useCustomAttenuation) {
  1241. sound.updateDistanceFromListener();
  1242. }
  1243. }
  1244. }
  1245. }
  1246. };
  1247. Object.defineProperty(Scene.prototype, "audioEnabled", {
  1248. // Audio
  1249. get: function () {
  1250. return this._audioEnabled;
  1251. },
  1252. set: function (value) {
  1253. this._audioEnabled = value;
  1254. if (this._audioEnabled) {
  1255. this._enableAudio();
  1256. }
  1257. else {
  1258. this._disableAudio();
  1259. }
  1260. },
  1261. enumerable: true,
  1262. configurable: true
  1263. });
  1264. Scene.prototype._disableAudio = function () {
  1265. for (var i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  1266. this.mainSoundTrack.soundCollection[i].pause();
  1267. }
  1268. for (i = 0; i < this.soundTracks.length; i++) {
  1269. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  1270. this.soundTracks[i].soundCollection[j].pause();
  1271. }
  1272. }
  1273. };
  1274. Scene.prototype._enableAudio = function () {
  1275. for (var i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
  1276. if (this.mainSoundTrack.soundCollection[i].isPaused) {
  1277. this.mainSoundTrack.soundCollection[i].play();
  1278. }
  1279. }
  1280. for (i = 0; i < this.soundTracks.length; i++) {
  1281. for (var j = 0; j < this.soundTracks[i].soundCollection.length; j++) {
  1282. if (this.soundTracks[i].soundCollection[j].isPaused) {
  1283. this.soundTracks[i].soundCollection[j].play();
  1284. }
  1285. }
  1286. }
  1287. };
  1288. Object.defineProperty(Scene.prototype, "headphone", {
  1289. get: function () {
  1290. return this._headphone;
  1291. },
  1292. set: function (value) {
  1293. this._headphone = value;
  1294. if (this._headphone) {
  1295. this._switchAudioModeForHeadphones();
  1296. }
  1297. else {
  1298. this._switchAudioModeForNormalSpeakers();
  1299. }
  1300. },
  1301. enumerable: true,
  1302. configurable: true
  1303. });
  1304. Scene.prototype._switchAudioModeForHeadphones = function () {
  1305. this.mainSoundTrack.switchPanningModelToHRTF();
  1306. for (var i = 0; i < this.soundTracks.length; i++) {
  1307. this.soundTracks[i].switchPanningModelToHRTF();
  1308. }
  1309. };
  1310. Scene.prototype._switchAudioModeForNormalSpeakers = function () {
  1311. this.mainSoundTrack.switchPanningModelToEqualPower();
  1312. for (var i = 0; i < this.soundTracks.length; i++) {
  1313. this.soundTracks[i].switchPanningModelToEqualPower();
  1314. }
  1315. };
  1316. Scene.prototype.enableDepthRenderer = function () {
  1317. if (this._depthRenderer) {
  1318. return this._depthRenderer;
  1319. }
  1320. this._depthRenderer = new BABYLON.DepthRenderer(this);
  1321. return this._depthRenderer;
  1322. };
  1323. Scene.prototype.disableDepthRenderer = function () {
  1324. if (!this._depthRenderer) {
  1325. return;
  1326. }
  1327. this._depthRenderer.dispose();
  1328. this._depthRenderer = null;
  1329. };
  1330. Scene.prototype.dispose = function () {
  1331. this.beforeRender = null;
  1332. this.afterRender = null;
  1333. this.skeletons = [];
  1334. this._boundingBoxRenderer.dispose();
  1335. if (this._depthRenderer) {
  1336. this._depthRenderer.dispose();
  1337. }
  1338. // Debug layer
  1339. this.debugLayer.hide();
  1340. // Events
  1341. if (this.onDispose) {
  1342. this.onDispose();
  1343. }
  1344. this._onBeforeRenderCallbacks = [];
  1345. this._onAfterRenderCallbacks = [];
  1346. this.detachControl();
  1347. // Release sounds & sounds tracks
  1348. this.disposeSounds();
  1349. // Detach cameras
  1350. var canvas = this._engine.getRenderingCanvas();
  1351. var index;
  1352. for (index = 0; index < this.cameras.length; index++) {
  1353. this.cameras[index].detachControl(canvas);
  1354. }
  1355. while (this.lights.length) {
  1356. this.lights[0].dispose();
  1357. }
  1358. while (this.meshes.length) {
  1359. this.meshes[0].dispose(true);
  1360. }
  1361. while (this.cameras.length) {
  1362. this.cameras[0].dispose();
  1363. }
  1364. while (this.materials.length) {
  1365. this.materials[0].dispose();
  1366. }
  1367. while (this.particleSystems.length) {
  1368. this.particleSystems[0].dispose();
  1369. }
  1370. while (this.spriteManagers.length) {
  1371. this.spriteManagers[0].dispose();
  1372. }
  1373. while (this.layers.length) {
  1374. this.layers[0].dispose();
  1375. }
  1376. while (this.textures.length) {
  1377. this.textures[0].dispose();
  1378. }
  1379. // Post-processes
  1380. this.postProcessManager.dispose();
  1381. // Physics
  1382. if (this._physicsEngine) {
  1383. this.disablePhysicsEngine();
  1384. }
  1385. // Remove from engine
  1386. index = this._engine.scenes.indexOf(this);
  1387. if (index > -1) {
  1388. this._engine.scenes.splice(index, 1);
  1389. }
  1390. this._engine.wipeCaches();
  1391. };
  1392. // Release sounds & sounds tracks
  1393. Scene.prototype.disposeSounds = function () {
  1394. this.mainSoundTrack.dispose();
  1395. for (var scIndex = 0; scIndex < this.soundTracks.length; scIndex++) {
  1396. this.soundTracks[scIndex].dispose();
  1397. }
  1398. };
  1399. // Collisions
  1400. Scene.prototype._getNewPosition = function (position, velocity, collider, maximumRetry, finalPosition, excludedMesh) {
  1401. if (excludedMesh === void 0) { excludedMesh = null; }
  1402. position.divideToRef(collider.radius, this._scaledPosition);
  1403. velocity.divideToRef(collider.radius, this._scaledVelocity);
  1404. collider.retry = 0;
  1405. collider.initialVelocity = this._scaledVelocity;
  1406. collider.initialPosition = this._scaledPosition;
  1407. this._collideWithWorld(this._scaledPosition, this._scaledVelocity, collider, maximumRetry, finalPosition, excludedMesh);
  1408. finalPosition.multiplyInPlace(collider.radius);
  1409. };
  1410. Scene.prototype._collideWithWorld = function (position, velocity, collider, maximumRetry, finalPosition, excludedMesh) {
  1411. if (excludedMesh === void 0) { excludedMesh = null; }
  1412. var closeDistance = BABYLON.Engine.CollisionsEpsilon * 10.0;
  1413. if (collider.retry >= maximumRetry) {
  1414. finalPosition.copyFrom(position);
  1415. return;
  1416. }
  1417. collider._initialize(position, velocity, closeDistance);
  1418. for (var index = 0; index < this.meshes.length; index++) {
  1419. var mesh = this.meshes[index];
  1420. if (mesh.isEnabled() && mesh.checkCollisions && mesh.subMeshes && mesh !== excludedMesh) {
  1421. mesh._checkCollision(collider);
  1422. }
  1423. }
  1424. if (!collider.collisionFound) {
  1425. position.addToRef(velocity, finalPosition);
  1426. return;
  1427. }
  1428. if (velocity.x !== 0 || velocity.y !== 0 || velocity.z !== 0) {
  1429. collider._getResponse(position, velocity);
  1430. }
  1431. if (velocity.length() <= closeDistance) {
  1432. finalPosition.copyFrom(position);
  1433. return;
  1434. }
  1435. collider.retry++;
  1436. this._collideWithWorld(position, velocity, collider, maximumRetry, finalPosition, excludedMesh);
  1437. };
  1438. // Octrees
  1439. Scene.prototype.getWorldExtends = function () {
  1440. var min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  1441. var max = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  1442. for (var index = 0; index < this.meshes.length; index++) {
  1443. var mesh = this.meshes[index];
  1444. mesh.computeWorldMatrix(true);
  1445. var minBox = mesh.getBoundingInfo().boundingBox.minimumWorld;
  1446. var maxBox = mesh.getBoundingInfo().boundingBox.maximumWorld;
  1447. BABYLON.Tools.CheckExtends(minBox, min, max);
  1448. BABYLON.Tools.CheckExtends(maxBox, min, max);
  1449. }
  1450. return {
  1451. min: min,
  1452. max: max
  1453. };
  1454. };
  1455. Scene.prototype.createOrUpdateSelectionOctree = function (maxCapacity, maxDepth) {
  1456. if (maxCapacity === void 0) { maxCapacity = 64; }
  1457. if (maxDepth === void 0) { maxDepth = 2; }
  1458. if (!this._selectionOctree) {
  1459. this._selectionOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForMeshes, maxCapacity, maxDepth);
  1460. }
  1461. var worldExtends = this.getWorldExtends();
  1462. // Update octree
  1463. this._selectionOctree.update(worldExtends.min, worldExtends.max, this.meshes);
  1464. return this._selectionOctree;
  1465. };
  1466. // Picking
  1467. Scene.prototype.createPickingRay = function (x, y, world, camera) {
  1468. var engine = this._engine;
  1469. if (!camera) {
  1470. if (!this.activeCamera)
  1471. throw new Error("Active camera not set");
  1472. camera = this.activeCamera;
  1473. }
  1474. var cameraViewport = camera.viewport;
  1475. var viewport = cameraViewport.toGlobal(engine);
  1476. // Moving coordinates to local viewport world
  1477. x = x / this._engine.getHardwareScalingLevel() - viewport.x;
  1478. y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
  1479. return BABYLON.Ray.CreateNew(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
  1480. // return BABYLON.Ray.CreateNew(x / window.devicePixelRatio, y / window.devicePixelRatio, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
  1481. };
  1482. Scene.prototype._internalPick = function (rayFunction, predicate, fastCheck) {
  1483. var pickingInfo = null;
  1484. for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {
  1485. var mesh = this.meshes[meshIndex];
  1486. if (predicate) {
  1487. if (!predicate(mesh)) {
  1488. continue;
  1489. }
  1490. }
  1491. else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
  1492. continue;
  1493. }
  1494. var world = mesh.getWorldMatrix();
  1495. var ray = rayFunction(world);
  1496. var result = mesh.intersects(ray, fastCheck);
  1497. if (!result || !result.hit)
  1498. continue;
  1499. if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance)
  1500. continue;
  1501. pickingInfo = result;
  1502. if (fastCheck) {
  1503. break;
  1504. }
  1505. }
  1506. return pickingInfo || new BABYLON.PickingInfo();
  1507. };
  1508. Scene.prototype.pick = function (x, y, predicate, fastCheck, camera) {
  1509. var _this = this;
  1510. /// <summary>Launch a ray to try to pick a mesh in the scene</summary>
  1511. /// <param name="x">X position on screen</param>
  1512. /// <param name="y">Y position on screen</param>
  1513. /// <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>
  1514. /// <param name="fastCheck">Launch a fast check only using the bounding boxes. Can be set to null.</param>
  1515. /// <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>
  1516. return this._internalPick(function (world) { return _this.createPickingRay(x, y, world, camera); }, predicate, fastCheck);
  1517. };
  1518. Scene.prototype.pickWithRay = function (ray, predicate, fastCheck) {
  1519. var _this = this;
  1520. return this._internalPick(function (world) {
  1521. if (!_this._pickWithRayInverseMatrix) {
  1522. _this._pickWithRayInverseMatrix = BABYLON.Matrix.Identity();
  1523. }
  1524. world.invertToRef(_this._pickWithRayInverseMatrix);
  1525. return BABYLON.Ray.Transform(ray, _this._pickWithRayInverseMatrix);
  1526. }, predicate, fastCheck);
  1527. };
  1528. Scene.prototype.setPointerOverMesh = function (mesh) {
  1529. if (this._pointerOverMesh === mesh) {
  1530. return;
  1531. }
  1532. if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
  1533. this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
  1534. }
  1535. this._pointerOverMesh = mesh;
  1536. if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
  1537. this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
  1538. }
  1539. };
  1540. Scene.prototype.getPointerOverMesh = function () {
  1541. return this._pointerOverMesh;
  1542. };
  1543. // Physics
  1544. Scene.prototype.getPhysicsEngine = function () {
  1545. return this._physicsEngine;
  1546. };
  1547. Scene.prototype.enablePhysics = function (gravity, plugin) {
  1548. if (this._physicsEngine) {
  1549. return true;
  1550. }
  1551. this._physicsEngine = new BABYLON.PhysicsEngine(plugin);
  1552. if (!this._physicsEngine.isSupported()) {
  1553. this._physicsEngine = null;
  1554. return false;
  1555. }
  1556. this._physicsEngine._initialize(gravity);
  1557. return true;
  1558. };
  1559. Scene.prototype.disablePhysicsEngine = function () {
  1560. if (!this._physicsEngine) {
  1561. return;
  1562. }
  1563. this._physicsEngine.dispose();
  1564. this._physicsEngine = undefined;
  1565. };
  1566. Scene.prototype.isPhysicsEnabled = function () {
  1567. return this._physicsEngine !== undefined;
  1568. };
  1569. Scene.prototype.setGravity = function (gravity) {
  1570. if (!this._physicsEngine) {
  1571. return;
  1572. }
  1573. this._physicsEngine._setGravity(gravity);
  1574. };
  1575. Scene.prototype.createCompoundImpostor = function (parts, options) {
  1576. if (parts.parts) {
  1577. options = parts;
  1578. parts = parts.parts;
  1579. }
  1580. if (!this._physicsEngine) {
  1581. return null;
  1582. }
  1583. for (var index = 0; index < parts.length; index++) {
  1584. var mesh = parts[index].mesh;
  1585. mesh._physicImpostor = parts[index].impostor;
  1586. mesh._physicsMass = options.mass / parts.length;
  1587. mesh._physicsFriction = options.friction;
  1588. mesh._physicRestitution = options.restitution;
  1589. }
  1590. return this._physicsEngine._registerMeshesAsCompound(parts, options);
  1591. };
  1592. Scene.prototype.deleteCompoundImpostor = function (compound) {
  1593. for (var index = 0; index < compound.parts.length; index++) {
  1594. var mesh = compound.parts[index].mesh;
  1595. mesh._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
  1596. this._physicsEngine._unregisterMesh(mesh);
  1597. }
  1598. };
  1599. // Misc.
  1600. Scene.prototype.createDefaultCameraOrLight = function () {
  1601. // Light
  1602. if (this.lights.length === 0) {
  1603. new BABYLON.HemisphericLight("default light", BABYLON.Vector3.Up(), this);
  1604. }
  1605. // Camera
  1606. if (!this.activeCamera) {
  1607. var camera = new BABYLON.FreeCamera("default camera", BABYLON.Vector3.Zero(), this);
  1608. // Compute position
  1609. var worldExtends = this.getWorldExtends();
  1610. var worldCenter = worldExtends.min.add(worldExtends.max.subtract(worldExtends.min).scale(0.5));
  1611. camera.position = new BABYLON.Vector3(worldCenter.x, worldCenter.y, worldExtends.min.z - (worldExtends.max.z - worldExtends.min.z));
  1612. camera.setTarget(worldCenter);
  1613. this.activeCamera = camera;
  1614. }
  1615. };
  1616. // Tags
  1617. Scene.prototype._getByTags = function (list, tagsQuery, forEach) {
  1618. if (tagsQuery === undefined) {
  1619. // returns the complete list (could be done with BABYLON.Tags.MatchesQuery but no need to have a for-loop here)
  1620. return list;
  1621. }
  1622. var listByTags = [];
  1623. forEach = forEach || (function (item) {
  1624. return;
  1625. });
  1626. for (var i in list) {
  1627. var item = list[i];
  1628. if (BABYLON.Tags.MatchesQuery(item, tagsQuery)) {
  1629. listByTags.push(item);
  1630. forEach(item);
  1631. }
  1632. }
  1633. return listByTags;
  1634. };
  1635. Scene.prototype.getMeshesByTags = function (tagsQuery, forEach) {
  1636. return this._getByTags(this.meshes, tagsQuery, forEach);
  1637. };
  1638. Scene.prototype.getCamerasByTags = function (tagsQuery, forEach) {
  1639. return this._getByTags(this.cameras, tagsQuery, forEach);
  1640. };
  1641. Scene.prototype.getLightsByTags = function (tagsQuery, forEach) {
  1642. return this._getByTags(this.lights, tagsQuery, forEach);
  1643. };
  1644. Scene.prototype.getMaterialByTags = function (tagsQuery, forEach) {
  1645. return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));
  1646. };
  1647. // Statics
  1648. Scene._FOGMODE_NONE = 0;
  1649. Scene._FOGMODE_EXP = 1;
  1650. Scene._FOGMODE_EXP2 = 2;
  1651. Scene._FOGMODE_LINEAR = 3;
  1652. Scene.MinDeltaTime = 1.0;
  1653. Scene.MaxDeltaTime = 1000.0;
  1654. return Scene;
  1655. })();
  1656. BABYLON.Scene = Scene;
  1657. })(BABYLON || (BABYLON = {}));
  1658. //# sourceMappingURL=babylon.scene.js.map