babylon.scene.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var Scene = (function () {
  4. // Constructor
  5. function Scene(engine) {
  6. // Members
  7. this.autoClear = true;
  8. this.clearColor = new BABYLON.Color3(0.2, 0.2, 0.3);
  9. this.ambientColor = new BABYLON.Color3(0, 0, 0);
  10. this.forceWireframe = false;
  11. this.cameraToUseForPointers = null;
  12. // Fog
  13. this.fogMode = BABYLON.Scene.FOGMODE_NONE;
  14. this.fogColor = new BABYLON.Color3(0.2, 0.2, 0.3);
  15. this.fogDensity = 0.1;
  16. this.fogStart = 0;
  17. this.fogEnd = 1000.0;
  18. // Lights
  19. this.lightsEnabled = true;
  20. this.lights = new Array();
  21. // Cameras
  22. this.cameras = new Array();
  23. this.activeCameras = new Array();
  24. // Meshes
  25. this.meshes = new Array();
  26. // Geometries
  27. this._geometries = new Array();
  28. this.materials = new Array();
  29. this.multiMaterials = new Array();
  30. this.defaultMaterial = new BABYLON.StandardMaterial("default material", this);
  31. // Textures
  32. this.texturesEnabled = true;
  33. this.textures = new Array();
  34. // Particles
  35. this.particlesEnabled = true;
  36. this.particleSystems = new Array();
  37. // Sprites
  38. this.spriteManagers = new Array();
  39. // Layers
  40. this.layers = new Array();
  41. // Skeletons
  42. this.skeletons = new Array();
  43. // Lens flares
  44. this.lensFlareSystems = new Array();
  45. // Collisions
  46. this.collisionsEnabled = true;
  47. this.gravity = new BABYLON.Vector3(0, -9.0, 0);
  48. // Postprocesses
  49. this.postProcessesEnabled = true;
  50. // Customs render targets
  51. this.renderTargetsEnabled = true;
  52. this.customRenderTargets = new Array();
  53. // Imported meshes
  54. this.importedMeshesFiles = new Array();
  55. this._actionManagers = new Array();
  56. this._meshesForIntersections = new BABYLON.SmartArray(256);
  57. this._totalVertices = 0;
  58. this._activeVertices = 0;
  59. this._activeParticles = 0;
  60. this._lastFrameDuration = 0;
  61. this._evaluateActiveMeshesDuration = 0;
  62. this._renderTargetsDuration = 0;
  63. this._particlesDuration = 0;
  64. this._renderDuration = 0;
  65. this._spritesDuration = 0;
  66. this._animationRatio = 0;
  67. this._renderId = 0;
  68. this._executeWhenReadyTimeoutId = -1;
  69. this._toBeDisposed = new BABYLON.SmartArray(256);
  70. this._onReadyCallbacks = new Array();
  71. this._pendingData = [];
  72. this._onBeforeRenderCallbacks = new Array();
  73. this._activeMeshes = new BABYLON.SmartArray(256);
  74. this._processedMaterials = new BABYLON.SmartArray(256);
  75. this._renderTargets = new BABYLON.SmartArray(256);
  76. this._activeParticleSystems = new BABYLON.SmartArray(256);
  77. this._activeSkeletons = new BABYLON.SmartArray(32);
  78. this._activeAnimatables = new Array();
  79. this._transformMatrix = BABYLON.Matrix.Zero();
  80. this._scaledPosition = BABYLON.Vector3.Zero();
  81. this._scaledVelocity = BABYLON.Vector3.Zero();
  82. this._engine = engine;
  83. engine.scenes.push(this);
  84. this._renderingManager = new BABYLON.RenderingManager(this);
  85. this.postProcessManager = new BABYLON.PostProcessManager(this);
  86. this.postProcessRenderPipelineManager = new BABYLON.PostProcessRenderPipelineManager();
  87. this._boundingBoxRenderer = new BABYLON.BoundingBoxRenderer(this);
  88. this._outlineRenderer = new BABYLON.OutlineRenderer(this);
  89. this.attachControl();
  90. }
  91. Object.defineProperty(Scene.prototype, "meshUnderPointer", {
  92. // Properties
  93. get: function () {
  94. return this._meshUnderPointer;
  95. },
  96. enumerable: true,
  97. configurable: true
  98. });
  99. Object.defineProperty(Scene.prototype, "pointerX", {
  100. get: function () {
  101. return this._pointerX;
  102. },
  103. enumerable: true,
  104. configurable: true
  105. });
  106. Object.defineProperty(Scene.prototype, "pointerY", {
  107. get: function () {
  108. return this._pointerY;
  109. },
  110. enumerable: true,
  111. configurable: true
  112. });
  113. Scene.prototype.getBoundingBoxRenderer = function () {
  114. return this._boundingBoxRenderer;
  115. };
  116. Scene.prototype.getOutlineRenderer = function () {
  117. return this._outlineRenderer;
  118. };
  119. Scene.prototype.getEngine = function () {
  120. return this._engine;
  121. };
  122. Scene.prototype.getTotalVertices = function () {
  123. return this._totalVertices;
  124. };
  125. Scene.prototype.getActiveVertices = function () {
  126. return this._activeVertices;
  127. };
  128. Scene.prototype.getActiveParticles = function () {
  129. return this._activeParticles;
  130. };
  131. // Stats
  132. Scene.prototype.getLastFrameDuration = function () {
  133. return this._lastFrameDuration;
  134. };
  135. Scene.prototype.getEvaluateActiveMeshesDuration = function () {
  136. return this._evaluateActiveMeshesDuration;
  137. };
  138. Scene.prototype.getActiveMeshes = function () {
  139. return this._activeMeshes;
  140. };
  141. Scene.prototype.getRenderTargetsDuration = function () {
  142. return this._renderTargetsDuration;
  143. };
  144. Scene.prototype.getRenderDuration = function () {
  145. return this._renderDuration;
  146. };
  147. Scene.prototype.getParticlesDuration = function () {
  148. return this._particlesDuration;
  149. };
  150. Scene.prototype.getSpritesDuration = function () {
  151. return this._spritesDuration;
  152. };
  153. Scene.prototype.getAnimationRatio = function () {
  154. return this._animationRatio;
  155. };
  156. Scene.prototype.getRenderId = function () {
  157. return this._renderId;
  158. };
  159. Scene.prototype._updatePointerPosition = function (evt) {
  160. var canvasRect = this._engine.getRenderingCanvasClientRect();
  161. this._pointerX = evt.clientX - canvasRect.left;
  162. this._pointerY = evt.clientY - canvasRect.top;
  163. if (this.cameraToUseForPointers) {
  164. this._pointerX = this._pointerX - this.cameraToUseForPointers.viewport.x * this._engine.getRenderWidth();
  165. this._pointerY = this._pointerY - this.cameraToUseForPointers.viewport.y * this._engine.getRenderHeight();
  166. }
  167. };
  168. // Pointers handling
  169. Scene.prototype.attachControl = function () {
  170. var _this = this;
  171. this._onPointerMove = function (evt) {
  172. var canvas = _this._engine.getRenderingCanvas();
  173. _this._updatePointerPosition(evt);
  174. var pickResult = _this.pick(_this._pointerX, _this._pointerY, function (mesh) {
  175. return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.actionManager && mesh.actionManager.hasPointerTriggers;
  176. }, false, _this.cameraToUseForPointers);
  177. if (pickResult.hit) {
  178. _this._meshUnderPointer = pickResult.pickedMesh;
  179. _this.setPointerOverMesh(pickResult.pickedMesh);
  180. canvas.style.cursor = "pointer";
  181. } else {
  182. _this.setPointerOverMesh(null);
  183. canvas.style.cursor = "";
  184. _this._meshUnderPointer = null;
  185. }
  186. };
  187. this._onPointerDown = function (evt) {
  188. var predicate = null;
  189. if (!_this.onPointerDown) {
  190. predicate = function (mesh) {
  191. return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.actionManager && mesh.actionManager.hasPickTriggers;
  192. };
  193. }
  194. _this._updatePointerPosition(evt);
  195. var pickResult = _this.pick(_this._pointerX, _this._pointerY, predicate, false, _this.cameraToUseForPointers);
  196. if (pickResult.hit) {
  197. if (pickResult.pickedMesh.actionManager) {
  198. switch (evt.button) {
  199. case 0:
  200. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
  201. break;
  202. case 1:
  203. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
  204. break;
  205. case 2:
  206. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
  207. break;
  208. }
  209. pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
  210. }
  211. }
  212. if (_this.onPointerDown) {
  213. _this.onPointerDown(evt, pickResult);
  214. }
  215. };
  216. this._onKeyDown = function (evt) {
  217. if (_this.actionManager) {
  218. _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyDownTrigger, BABYLON.ActionEvent.CreateNewFromScene(_this, evt));
  219. }
  220. };
  221. this._onKeyUp = function (evt) {
  222. if (_this.actionManager) {
  223. _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyUpTrigger, BABYLON.ActionEvent.CreateNewFromScene(_this, evt));
  224. }
  225. };
  226. var eventPrefix = BABYLON.Tools.GetPointerPrefix();
  227. this._engine.getRenderingCanvas().addEventListener(eventPrefix + "move", this._onPointerMove, false);
  228. this._engine.getRenderingCanvas().addEventListener(eventPrefix + "down", this._onPointerDown, false);
  229. window.addEventListener("keydown", this._onKeyDown, false);
  230. window.addEventListener("keyup", this._onKeyUp, false);
  231. };
  232. Scene.prototype.detachControl = function () {
  233. var eventPrefix = BABYLON.Tools.GetPointerPrefix();
  234. this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "move", this._onPointerMove);
  235. this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "down", this._onPointerDown);
  236. window.removeEventListener("keydown", this._onKeyDown);
  237. window.removeEventListener("keyup", this._onKeyUp);
  238. };
  239. // Ready
  240. Scene.prototype.isReady = function () {
  241. if (this._pendingData.length > 0) {
  242. return false;
  243. }
  244. for (var index = 0; index < this._geometries.length; index++) {
  245. var geometry = this._geometries[index];
  246. if (geometry.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
  247. return false;
  248. }
  249. }
  250. for (index = 0; index < this.meshes.length; index++) {
  251. var mesh = this.meshes[index];
  252. if (!mesh.isReady()) {
  253. return false;
  254. }
  255. var mat = mesh.material;
  256. if (mat) {
  257. if (!mat.isReady(mesh)) {
  258. return false;
  259. }
  260. }
  261. }
  262. return true;
  263. };
  264. Scene.prototype.registerBeforeRender = function (func) {
  265. this._onBeforeRenderCallbacks.push(func);
  266. };
  267. Scene.prototype.unregisterBeforeRender = function (func) {
  268. var index = this._onBeforeRenderCallbacks.indexOf(func);
  269. if (index > -1) {
  270. this._onBeforeRenderCallbacks.splice(index, 1);
  271. }
  272. };
  273. Scene.prototype._addPendingData = function (data) {
  274. this._pendingData.push(data);
  275. };
  276. Scene.prototype._removePendingData = function (data) {
  277. var index = this._pendingData.indexOf(data);
  278. if (index !== -1) {
  279. this._pendingData.splice(index, 1);
  280. }
  281. };
  282. Scene.prototype.getWaitingItemsCount = function () {
  283. return this._pendingData.length;
  284. };
  285. Scene.prototype.executeWhenReady = function (func) {
  286. var _this = this;
  287. this._onReadyCallbacks.push(func);
  288. if (this._executeWhenReadyTimeoutId !== -1) {
  289. return;
  290. }
  291. this._executeWhenReadyTimeoutId = setTimeout(function () {
  292. _this._checkIsReady();
  293. }, 150);
  294. };
  295. Scene.prototype._checkIsReady = function () {
  296. var _this = this;
  297. if (this.isReady()) {
  298. this._onReadyCallbacks.forEach(function (func) {
  299. func();
  300. });
  301. this._onReadyCallbacks = [];
  302. this._executeWhenReadyTimeoutId = -1;
  303. return;
  304. }
  305. this._executeWhenReadyTimeoutId = setTimeout(function () {
  306. _this._checkIsReady();
  307. }, 150);
  308. };
  309. // Animations
  310. Scene.prototype.beginAnimation = function (target, from, to, loop, speedRatio, onAnimationEnd, animatable) {
  311. if (speedRatio === undefined) {
  312. speedRatio = 1.0;
  313. }
  314. this.stopAnimation(target);
  315. if (!animatable) {
  316. animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd);
  317. }
  318. // Local animations
  319. if (target.animations) {
  320. animatable.appendAnimations(target, target.animations);
  321. }
  322. // Children animations
  323. if (target.getAnimatables) {
  324. var animatables = target.getAnimatables();
  325. for (var index = 0; index < animatables.length; index++) {
  326. this.beginAnimation(animatables[index], from, to, loop, speedRatio, onAnimationEnd, animatable);
  327. }
  328. }
  329. return animatable;
  330. };
  331. Scene.prototype.beginDirectAnimation = function (target, animations, from, to, loop, speedRatio, onAnimationEnd) {
  332. if (speedRatio === undefined) {
  333. speedRatio = 1.0;
  334. }
  335. var animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, animations);
  336. return animatable;
  337. };
  338. Scene.prototype.getAnimatableByTarget = function (target) {
  339. for (var index = 0; index < this._activeAnimatables.length; index++) {
  340. if (this._activeAnimatables[index].target === target) {
  341. return this._activeAnimatables[index];
  342. }
  343. }
  344. return null;
  345. };
  346. Scene.prototype.stopAnimation = function (target) {
  347. var animatable = this.getAnimatableByTarget(target);
  348. if (animatable) {
  349. animatable.stop();
  350. }
  351. };
  352. Scene.prototype._animate = function () {
  353. if (!this._animationStartDate) {
  354. this._animationStartDate = new Date().getTime();
  355. }
  356. // Getting time
  357. var now = new Date().getTime();
  358. var delay = now - this._animationStartDate;
  359. for (var index = 0; index < this._activeAnimatables.length; index++) {
  360. if (!this._activeAnimatables[index]._animate(delay)) {
  361. this._activeAnimatables.splice(index, 1);
  362. index--;
  363. }
  364. }
  365. };
  366. // Matrix
  367. Scene.prototype.getViewMatrix = function () {
  368. return this._viewMatrix;
  369. };
  370. Scene.prototype.getProjectionMatrix = function () {
  371. return this._projectionMatrix;
  372. };
  373. Scene.prototype.getTransformMatrix = function () {
  374. return this._transformMatrix;
  375. };
  376. Scene.prototype.setTransformMatrix = function (view, projection) {
  377. this._viewMatrix = view;
  378. this._projectionMatrix = projection;
  379. this._viewMatrix.multiplyToRef(this._projectionMatrix, this._transformMatrix);
  380. };
  381. // Methods
  382. Scene.prototype.setActiveCameraByID = function (id) {
  383. var camera = this.getCameraByID(id);
  384. if (camera) {
  385. this.activeCamera = camera;
  386. return camera;
  387. }
  388. return null;
  389. };
  390. Scene.prototype.setActiveCameraByName = function (name) {
  391. var camera = this.getCameraByName(name);
  392. if (camera) {
  393. this.activeCamera = camera;
  394. return camera;
  395. }
  396. return null;
  397. };
  398. Scene.prototype.getMaterialByID = function (id) {
  399. for (var index = 0; index < this.materials.length; index++) {
  400. if (this.materials[index].id === id) {
  401. return this.materials[index];
  402. }
  403. }
  404. return null;
  405. };
  406. Scene.prototype.getMaterialByName = function (name) {
  407. for (var index = 0; index < this.materials.length; index++) {
  408. if (this.materials[index].name === name) {
  409. return this.materials[index];
  410. }
  411. }
  412. return null;
  413. };
  414. Scene.prototype.getCameraByID = function (id) {
  415. for (var index = 0; index < this.cameras.length; index++) {
  416. if (this.cameras[index].id === id) {
  417. return this.cameras[index];
  418. }
  419. }
  420. return null;
  421. };
  422. Scene.prototype.getCameraByName = function (name) {
  423. for (var index = 0; index < this.cameras.length; index++) {
  424. if (this.cameras[index].name === name) {
  425. return this.cameras[index];
  426. }
  427. }
  428. return null;
  429. };
  430. Scene.prototype.getLightByName = function (name) {
  431. for (var index = 0; index < this.lights.length; index++) {
  432. if (this.lights[index].name === name) {
  433. return this.lights[index];
  434. }
  435. }
  436. return null;
  437. };
  438. Scene.prototype.getLightByID = function (id) {
  439. for (var index = 0; index < this.lights.length; index++) {
  440. if (this.lights[index].id === id) {
  441. return this.lights[index];
  442. }
  443. }
  444. return null;
  445. };
  446. Scene.prototype.getGeometryByID = function (id) {
  447. for (var index = 0; index < this._geometries.length; index++) {
  448. if (this._geometries[index].id === id) {
  449. return this._geometries[index];
  450. }
  451. }
  452. return null;
  453. };
  454. Scene.prototype.pushGeometry = function (geometry, force) {
  455. if (!force && this.getGeometryByID(geometry.id)) {
  456. return false;
  457. }
  458. this._geometries.push(geometry);
  459. return true;
  460. };
  461. Scene.prototype.getGeometries = function () {
  462. return this._geometries;
  463. };
  464. Scene.prototype.getMeshByID = function (id) {
  465. for (var index = 0; index < this.meshes.length; index++) {
  466. if (this.meshes[index].id === id) {
  467. return this.meshes[index];
  468. }
  469. }
  470. return null;
  471. };
  472. Scene.prototype.getLastMeshByID = function (id) {
  473. for (var index = this.meshes.length - 1; index >= 0; index--) {
  474. if (this.meshes[index].id === id) {
  475. return this.meshes[index];
  476. }
  477. }
  478. return null;
  479. };
  480. Scene.prototype.getLastEntryByID = function (id) {
  481. for (var index = this.meshes.length - 1; index >= 0; index--) {
  482. if (this.meshes[index].id === id) {
  483. return this.meshes[index];
  484. }
  485. }
  486. for (index = this.cameras.length - 1; index >= 0; index--) {
  487. if (this.cameras[index].id === id) {
  488. return this.cameras[index];
  489. }
  490. }
  491. for (index = this.lights.length - 1; index >= 0; index--) {
  492. if (this.lights[index].id === id) {
  493. return this.lights[index];
  494. }
  495. }
  496. return null;
  497. };
  498. Scene.prototype.getMeshByName = function (name) {
  499. for (var index = 0; index < this.meshes.length; index++) {
  500. if (this.meshes[index].name === name) {
  501. return this.meshes[index];
  502. }
  503. }
  504. return null;
  505. };
  506. Scene.prototype.getLastSkeletonByID = function (id) {
  507. for (var index = this.skeletons.length - 1; index >= 0; index--) {
  508. if (this.skeletons[index].id === id) {
  509. return this.skeletons[index];
  510. }
  511. }
  512. return null;
  513. };
  514. Scene.prototype.getSkeletonById = function (id) {
  515. for (var index = 0; index < this.skeletons.length; index++) {
  516. if (this.skeletons[index].id === id) {
  517. return this.skeletons[index];
  518. }
  519. }
  520. return null;
  521. };
  522. Scene.prototype.getSkeletonByName = function (name) {
  523. for (var index = 0; index < this.skeletons.length; index++) {
  524. if (this.skeletons[index].name === name) {
  525. return this.skeletons[index];
  526. }
  527. }
  528. return null;
  529. };
  530. Scene.prototype.isActiveMesh = function (mesh) {
  531. return (this._activeMeshes.indexOf(mesh) !== -1);
  532. };
  533. Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
  534. if (mesh.subMeshes.length == 1 || subMesh.isInFrustum(this._frustumPlanes)) {
  535. var material = subMesh.getMaterial();
  536. if (mesh.showSubMeshesBoundingBox) {
  537. this._boundingBoxRenderer.renderList.push(subMesh.getBoundingInfo().boundingBox);
  538. }
  539. if (material) {
  540. // Render targets
  541. if (material.getRenderTargetTextures) {
  542. if (this._processedMaterials.indexOf(material) === -1) {
  543. this._processedMaterials.push(material);
  544. this._renderTargets.concat(material.getRenderTargetTextures());
  545. }
  546. }
  547. // Dispatch
  548. this._activeVertices += subMesh.verticesCount;
  549. this._renderingManager.dispatch(subMesh);
  550. }
  551. }
  552. };
  553. Scene.prototype._evaluateActiveMeshes = function () {
  554. this._activeMeshes.reset();
  555. this._renderingManager.reset();
  556. this._processedMaterials.reset();
  557. this._activeParticleSystems.reset();
  558. this._activeSkeletons.reset();
  559. this._boundingBoxRenderer.reset();
  560. if (!this._frustumPlanes) {
  561. this._frustumPlanes = BABYLON.Frustum.GetPlanes(this._transformMatrix);
  562. } else {
  563. BABYLON.Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);
  564. }
  565. // Meshes
  566. var meshes;
  567. var len;
  568. if (this._selectionOctree) {
  569. var selection = this._selectionOctree.select(this._frustumPlanes);
  570. meshes = selection.data;
  571. len = selection.length;
  572. } else {
  573. len = this.meshes.length;
  574. meshes = this.meshes;
  575. }
  576. for (var meshIndex = 0; meshIndex < len; meshIndex++) {
  577. var mesh = meshes[meshIndex];
  578. this._totalVertices += mesh.getTotalVertices();
  579. if (!mesh.isReady()) {
  580. continue;
  581. }
  582. mesh.computeWorldMatrix();
  583. mesh._preActivate();
  584. // Intersections
  585. if (mesh.actionManager && mesh.actionManager.hasSpecificTriggers([BABYLON.ActionManager.OnIntersectionEnterTrigger, BABYLON.ActionManager.OnIntersectionExitTrigger])) {
  586. this._meshesForIntersections.pushNoDuplicate(mesh);
  587. }
  588. if (mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) != 0) && mesh.isInFrustum(this._frustumPlanes)) {
  589. this._activeMeshes.push(mesh);
  590. mesh._activate(this._renderId);
  591. this._activeMesh(mesh);
  592. }
  593. }
  594. // Particle systems
  595. var beforeParticlesDate = new Date().getTime();
  596. if (this.particlesEnabled) {
  597. for (var particleIndex = 0; particleIndex < this.particleSystems.length; particleIndex++) {
  598. var particleSystem = this.particleSystems[particleIndex];
  599. if (!particleSystem.isStarted()) {
  600. continue;
  601. }
  602. if (!particleSystem.emitter.position || (particleSystem.emitter && particleSystem.emitter.isEnabled())) {
  603. this._activeParticleSystems.push(particleSystem);
  604. particleSystem.animate();
  605. }
  606. }
  607. }
  608. this._particlesDuration += new Date().getTime() - beforeParticlesDate;
  609. };
  610. Scene.prototype._activeMesh = function (mesh) {
  611. if (mesh.skeleton) {
  612. this._activeSkeletons.pushNoDuplicate(mesh.skeleton);
  613. }
  614. if (mesh.showBoundingBox) {
  615. this._boundingBoxRenderer.renderList.push(mesh.getBoundingInfo().boundingBox);
  616. }
  617. if (mesh.subMeshes) {
  618. // Submeshes Octrees
  619. var len;
  620. var subMeshes;
  621. if (mesh._submeshesOctree && mesh.useOctreeForRenderingSelection) {
  622. var intersections = mesh._submeshesOctree.select(this._frustumPlanes);
  623. len = intersections.length;
  624. subMeshes = intersections.data;
  625. } else {
  626. subMeshes = mesh.subMeshes;
  627. len = subMeshes.length;
  628. }
  629. for (var subIndex = 0; subIndex < len; subIndex++) {
  630. var subMesh = subMeshes[subIndex];
  631. this._evaluateSubMesh(subMesh, mesh);
  632. }
  633. }
  634. };
  635. Scene.prototype.updateTransformMatrix = function (force) {
  636. this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(force));
  637. };
  638. Scene.prototype._renderForCamera = function (camera) {
  639. var engine = this._engine;
  640. this.activeCamera = camera;
  641. if (!this.activeCamera)
  642. throw new Error("Active camera not set");
  643. // Viewport
  644. engine.setViewport(this.activeCamera.viewport);
  645. // Camera
  646. this._renderId++;
  647. this.updateTransformMatrix();
  648. if (this.beforeCameraRender) {
  649. this.beforeCameraRender(this.activeCamera);
  650. }
  651. // Meshes
  652. var beforeEvaluateActiveMeshesDate = new Date().getTime();
  653. this._evaluateActiveMeshes();
  654. this._evaluateActiveMeshesDuration += new Date().getTime() - beforeEvaluateActiveMeshesDate;
  655. for (var skeletonIndex = 0; skeletonIndex < this._activeSkeletons.length; skeletonIndex++) {
  656. var skeleton = this._activeSkeletons.data[skeletonIndex];
  657. skeleton.prepare();
  658. }
  659. for (var customIndex = 0; customIndex < this.customRenderTargets.length; customIndex++) {
  660. var renderTarget = this.customRenderTargets[customIndex];
  661. this._renderTargets.push(renderTarget);
  662. }
  663. // Render targets
  664. var beforeRenderTargetDate = new Date().getTime();
  665. if (this.renderTargetsEnabled) {
  666. for (var renderIndex = 0; renderIndex < this._renderTargets.length; renderIndex++) {
  667. renderTarget = this._renderTargets.data[renderIndex];
  668. if (renderTarget._shouldRender()) {
  669. this._renderId++;
  670. renderTarget.render();
  671. }
  672. }
  673. this._renderId++;
  674. }
  675. if (this._renderTargets.length > 0) {
  676. engine.restoreDefaultFramebuffer();
  677. }
  678. this._renderTargetsDuration = new Date().getTime() - beforeRenderTargetDate;
  679. // Prepare Frame
  680. this.postProcessManager._prepareFrame();
  681. var beforeRenderDate = new Date().getTime();
  682. // Backgrounds
  683. if (this.layers.length) {
  684. engine.setDepthBuffer(false);
  685. var layerIndex;
  686. var layer;
  687. for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
  688. layer = this.layers[layerIndex];
  689. if (layer.isBackground) {
  690. layer.render();
  691. }
  692. }
  693. engine.setDepthBuffer(true);
  694. }
  695. // Render
  696. this._renderingManager.render(null, null, true, true);
  697. // Bounding boxes
  698. this._boundingBoxRenderer.render();
  699. for (var lensFlareSystemIndex = 0; lensFlareSystemIndex < this.lensFlareSystems.length; lensFlareSystemIndex++) {
  700. this.lensFlareSystems[lensFlareSystemIndex].render();
  701. }
  702. // Foregrounds
  703. if (this.layers.length) {
  704. engine.setDepthBuffer(false);
  705. for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
  706. layer = this.layers[layerIndex];
  707. if (!layer.isBackground) {
  708. layer.render();
  709. }
  710. }
  711. engine.setDepthBuffer(true);
  712. }
  713. this._renderDuration += new Date().getTime() - beforeRenderDate;
  714. // Finalize frame
  715. this.postProcessManager._finalizeFrame(camera.isIntermediate);
  716. // Update camera
  717. this.activeCamera._updateFromScene();
  718. // Reset some special arrays
  719. this._renderTargets.reset();
  720. if (this.afterCameraRender) {
  721. this.afterCameraRender(this.activeCamera);
  722. }
  723. };
  724. Scene.prototype._processSubCameras = function (camera) {
  725. if (camera.subCameras.length == 0) {
  726. this._renderForCamera(camera);
  727. return;
  728. }
  729. for (var index = 0; index < camera.subCameras.length; index++) {
  730. this._renderForCamera(camera.subCameras[index]);
  731. }
  732. this.activeCamera = camera;
  733. this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix());
  734. // Update camera
  735. this.activeCamera._updateFromScene();
  736. };
  737. Scene.prototype._checkIntersections = function () {
  738. for (var index = 0; index < this._meshesForIntersections.length; index++) {
  739. var sourceMesh = this._meshesForIntersections.data[index];
  740. for (var actionIndex = 0; actionIndex < sourceMesh.actionManager.actions.length; actionIndex++) {
  741. var action = sourceMesh.actionManager.actions[actionIndex];
  742. if (action.trigger == BABYLON.ActionManager.OnIntersectionEnterTrigger || action.trigger == BABYLON.ActionManager.OnIntersectionExitTrigger) {
  743. var otherMesh = action.getTriggerParameter();
  744. var areIntersecting = otherMesh.intersectsMesh(sourceMesh, false);
  745. var currentIntersectionInProgress = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
  746. if (areIntersecting && currentIntersectionInProgress === -1 && action.trigger == BABYLON.ActionManager.OnIntersectionEnterTrigger) {
  747. sourceMesh.actionManager.processTrigger(BABYLON.ActionManager.OnIntersectionEnterTrigger, BABYLON.ActionEvent.CreateNew(sourceMesh));
  748. sourceMesh._intersectionsInProgress.push(otherMesh);
  749. } else if (!areIntersecting && currentIntersectionInProgress > -1 && action.trigger == BABYLON.ActionManager.OnIntersectionExitTrigger) {
  750. sourceMesh.actionManager.processTrigger(BABYLON.ActionManager.OnIntersectionExitTrigger, BABYLON.ActionEvent.CreateNew(sourceMesh));
  751. var indexOfOther = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
  752. if (indexOfOther > -1) {
  753. sourceMesh._intersectionsInProgress.splice(indexOfOther, 1);
  754. }
  755. }
  756. }
  757. }
  758. }
  759. };
  760. Scene.prototype.render = function () {
  761. var startDate = new Date().getTime();
  762. this._particlesDuration = 0;
  763. this._spritesDuration = 0;
  764. this._activeParticles = 0;
  765. this._renderDuration = 0;
  766. this._evaluateActiveMeshesDuration = 0;
  767. this._totalVertices = 0;
  768. this._activeVertices = 0;
  769. this._meshesForIntersections.reset();
  770. // Actions
  771. if (this.actionManager) {
  772. this.actionManager.processTrigger(BABYLON.ActionManager.OnEveryFrameTrigger, null);
  773. }
  774. // Before render
  775. if (this.beforeRender) {
  776. this.beforeRender();
  777. }
  778. for (var callbackIndex = 0; callbackIndex < this._onBeforeRenderCallbacks.length; callbackIndex++) {
  779. this._onBeforeRenderCallbacks[callbackIndex]();
  780. }
  781. // Animations
  782. var deltaTime = Math.max(Scene.MinDeltaTime, Math.min(BABYLON.Tools.GetDeltaTime(), Scene.MaxDeltaTime));
  783. this._animationRatio = deltaTime * (60.0 / 1000.0);
  784. this._animate();
  785. // Physics
  786. if (this._physicsEngine) {
  787. this._physicsEngine._runOneStep(deltaTime / 1000.0);
  788. }
  789. // Clear
  790. this._engine.clear(this.clearColor, this.autoClear || this.forceWireframe, true);
  791. for (var lightIndex = 0; lightIndex < this.lights.length; lightIndex++) {
  792. var light = this.lights[lightIndex];
  793. var shadowGenerator = light.getShadowGenerator();
  794. if (light.isEnabled() && shadowGenerator && shadowGenerator.getShadowMap().getScene().textures.indexOf(shadowGenerator.getShadowMap()) !== -1) {
  795. this._renderTargets.push(shadowGenerator.getShadowMap());
  796. }
  797. }
  798. // RenderPipeline
  799. this.postProcessRenderPipelineManager.update();
  800. // Multi-cameras?
  801. if (this.activeCameras.length > 0) {
  802. var currentRenderId = this._renderId;
  803. for (var cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {
  804. this._renderId = currentRenderId;
  805. this._processSubCameras(this.activeCameras[cameraIndex]);
  806. }
  807. } else {
  808. this._processSubCameras(this.activeCamera);
  809. }
  810. // Intersection checks
  811. this._checkIntersections();
  812. // After render
  813. if (this.afterRender) {
  814. this.afterRender();
  815. }
  816. for (var index = 0; index < this._toBeDisposed.length; index++) {
  817. this._toBeDisposed.data[index].dispose();
  818. this._toBeDisposed[index] = null;
  819. }
  820. this._toBeDisposed.reset();
  821. this._lastFrameDuration = new Date().getTime() - startDate;
  822. };
  823. Scene.prototype.dispose = function () {
  824. this.beforeRender = null;
  825. this.afterRender = null;
  826. this.skeletons = [];
  827. this._boundingBoxRenderer.dispose();
  828. // Events
  829. if (this.onDispose) {
  830. this.onDispose();
  831. }
  832. this.detachControl();
  833. // Detach cameras
  834. var canvas = this._engine.getRenderingCanvas();
  835. var index;
  836. for (index = 0; index < this.cameras.length; index++) {
  837. this.cameras[index].detachControl(canvas);
  838. }
  839. while (this.lights.length) {
  840. this.lights[0].dispose();
  841. }
  842. while (this.meshes.length) {
  843. this.meshes[0].dispose(true);
  844. }
  845. while (this.cameras.length) {
  846. this.cameras[0].dispose();
  847. }
  848. while (this.materials.length) {
  849. this.materials[0].dispose();
  850. }
  851. while (this.particleSystems.length) {
  852. this.particleSystems[0].dispose();
  853. }
  854. while (this.spriteManagers.length) {
  855. this.spriteManagers[0].dispose();
  856. }
  857. while (this.layers.length) {
  858. this.layers[0].dispose();
  859. }
  860. while (this.textures.length) {
  861. this.textures[0].dispose();
  862. }
  863. // Post-processes
  864. this.postProcessManager.dispose();
  865. // Physics
  866. if (this._physicsEngine) {
  867. this.disablePhysicsEngine();
  868. }
  869. // Remove from engine
  870. index = this._engine.scenes.indexOf(this);
  871. this._engine.scenes.splice(index, 1);
  872. this._engine.wipeCaches();
  873. };
  874. // Collisions
  875. Scene.prototype._getNewPosition = function (position, velocity, collider, maximumRetry, finalPosition, excludedMesh) {
  876. if (typeof excludedMesh === "undefined") { excludedMesh = null; }
  877. position.divideToRef(collider.radius, this._scaledPosition);
  878. velocity.divideToRef(collider.radius, this._scaledVelocity);
  879. collider.retry = 0;
  880. collider.initialVelocity = this._scaledVelocity;
  881. collider.initialPosition = this._scaledPosition;
  882. this._collideWithWorld(this._scaledPosition, this._scaledVelocity, collider, maximumRetry, finalPosition, excludedMesh);
  883. finalPosition.multiplyInPlace(collider.radius);
  884. };
  885. Scene.prototype._collideWithWorld = function (position, velocity, collider, maximumRetry, finalPosition, excludedMesh) {
  886. if (typeof excludedMesh === "undefined") { excludedMesh = null; }
  887. var closeDistance = BABYLON.Engine.CollisionsEpsilon * 10.0;
  888. if (collider.retry >= maximumRetry) {
  889. finalPosition.copyFrom(position);
  890. return;
  891. }
  892. collider._initialize(position, velocity, closeDistance);
  893. for (var index = 0; index < this.meshes.length; index++) {
  894. var mesh = this.meshes[index];
  895. if (mesh.isEnabled() && mesh.checkCollisions && mesh.subMeshes && mesh !== excludedMesh) {
  896. mesh._checkCollision(collider);
  897. }
  898. }
  899. if (!collider.collisionFound) {
  900. position.addToRef(velocity, finalPosition);
  901. return;
  902. }
  903. if (velocity.x != 0 || velocity.y != 0 || velocity.z != 0) {
  904. collider._getResponse(position, velocity);
  905. }
  906. if (velocity.length() <= closeDistance) {
  907. finalPosition.copyFrom(position);
  908. return;
  909. }
  910. collider.retry++;
  911. this._collideWithWorld(position, velocity, collider, maximumRetry, finalPosition, excludedMesh);
  912. };
  913. // Octrees
  914. Scene.prototype.createOrUpdateSelectionOctree = function (maxCapacity, maxDepth) {
  915. if (typeof maxCapacity === "undefined") { maxCapacity = 64; }
  916. if (typeof maxDepth === "undefined") { maxDepth = 2; }
  917. if (!this._selectionOctree) {
  918. this._selectionOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForMeshes, maxCapacity, maxDepth);
  919. }
  920. var min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  921. var max = new BABYLON.Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  922. for (var index = 0; index < this.meshes.length; index++) {
  923. var mesh = this.meshes[index];
  924. mesh.computeWorldMatrix(true);
  925. var minBox = mesh.getBoundingInfo().boundingBox.minimumWorld;
  926. var maxBox = mesh.getBoundingInfo().boundingBox.maximumWorld;
  927. BABYLON.Tools.CheckExtends(minBox, min, max);
  928. BABYLON.Tools.CheckExtends(maxBox, min, max);
  929. }
  930. // Update octree
  931. this._selectionOctree.update(min, max, this.meshes);
  932. return this._selectionOctree;
  933. };
  934. // Picking
  935. Scene.prototype.createPickingRay = function (x, y, world, camera) {
  936. var engine = this._engine;
  937. if (!camera) {
  938. if (!this.activeCamera)
  939. throw new Error("Active camera not set");
  940. camera = this.activeCamera;
  941. }
  942. var cameraViewport = camera.viewport;
  943. var viewport = cameraViewport.toGlobal(engine);
  944. // Moving coordinates to local viewport world
  945. x = x / this._engine.getHardwareScalingLevel() - viewport.x;
  946. y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);
  947. return BABYLON.Ray.CreateNew(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
  948. // return BABYLON.Ray.CreateNew(x / window.devicePixelRatio, y / window.devicePixelRatio, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), camera.getViewMatrix(), camera.getProjectionMatrix());
  949. };
  950. Scene.prototype._internalPick = function (rayFunction, predicate, fastCheck) {
  951. var pickingInfo = null;
  952. for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {
  953. var mesh = this.meshes[meshIndex];
  954. if (predicate) {
  955. if (!predicate(mesh)) {
  956. continue;
  957. }
  958. } else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
  959. continue;
  960. }
  961. var world = mesh.getWorldMatrix();
  962. var ray = rayFunction(world);
  963. var result = mesh.intersects(ray, fastCheck);
  964. if (!result || !result.hit)
  965. continue;
  966. if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance)
  967. continue;
  968. pickingInfo = result;
  969. if (fastCheck) {
  970. break;
  971. }
  972. }
  973. return pickingInfo || new BABYLON.PickingInfo();
  974. };
  975. Scene.prototype.pick = function (x, y, predicate, fastCheck, camera) {
  976. var _this = this;
  977. /// <summary>Launch a ray to try to pick a mesh in the scene</summary>
  978. /// <param name="x">X position on screen</param>
  979. /// <param name="y">Y position on screen</param>
  980. /// <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>
  981. /// <param name="fastCheck">Launch a fast check only using the bounding boxes. Can be set to null.</param>
  982. /// <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>
  983. return this._internalPick(function (world) {
  984. return _this.createPickingRay(x, y, world, camera);
  985. }, predicate, fastCheck);
  986. };
  987. Scene.prototype.pickWithRay = function (ray, predicate, fastCheck) {
  988. var _this = this;
  989. return this._internalPick(function (world) {
  990. if (!_this._pickWithRayInverseMatrix) {
  991. _this._pickWithRayInverseMatrix = BABYLON.Matrix.Identity();
  992. }
  993. world.invertToRef(_this._pickWithRayInverseMatrix);
  994. return BABYLON.Ray.Transform(ray, _this._pickWithRayInverseMatrix);
  995. }, predicate, fastCheck);
  996. };
  997. Scene.prototype.setPointerOverMesh = function (mesh) {
  998. if (this._pointerOverMesh === mesh) {
  999. return;
  1000. }
  1001. if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
  1002. this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
  1003. }
  1004. this._pointerOverMesh = mesh;
  1005. if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
  1006. this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
  1007. }
  1008. };
  1009. Scene.prototype.getPointerOverMesh = function () {
  1010. return this._pointerOverMesh;
  1011. };
  1012. // Physics
  1013. Scene.prototype.getPhysicsEngine = function () {
  1014. return this._physicsEngine;
  1015. };
  1016. Scene.prototype.enablePhysics = function (gravity, plugin) {
  1017. if (this._physicsEngine) {
  1018. return true;
  1019. }
  1020. this._physicsEngine = new BABYLON.PhysicsEngine(plugin);
  1021. if (!this._physicsEngine.isSupported()) {
  1022. this._physicsEngine = null;
  1023. return false;
  1024. }
  1025. this._physicsEngine._initialize(gravity);
  1026. return true;
  1027. };
  1028. Scene.prototype.disablePhysicsEngine = function () {
  1029. if (!this._physicsEngine) {
  1030. return;
  1031. }
  1032. this._physicsEngine.dispose();
  1033. this._physicsEngine = undefined;
  1034. };
  1035. Scene.prototype.isPhysicsEnabled = function () {
  1036. return this._physicsEngine !== undefined;
  1037. };
  1038. Scene.prototype.setGravity = function (gravity) {
  1039. if (!this._physicsEngine) {
  1040. return;
  1041. }
  1042. this._physicsEngine._setGravity(gravity);
  1043. };
  1044. Scene.prototype.createCompoundImpostor = function (parts, options) {
  1045. if (parts.parts) {
  1046. options = parts;
  1047. parts = parts.parts;
  1048. }
  1049. if (!this._physicsEngine) {
  1050. return null;
  1051. }
  1052. for (var index = 0; index < parts.length; index++) {
  1053. var mesh = parts[index].mesh;
  1054. mesh._physicImpostor = parts[index].impostor;
  1055. mesh._physicsMass = options.mass / parts.length;
  1056. mesh._physicsFriction = options.friction;
  1057. mesh._physicRestitution = options.restitution;
  1058. }
  1059. return this._physicsEngine._registerMeshesAsCompound(parts, options);
  1060. };
  1061. //ANY
  1062. Scene.prototype.deleteCompoundImpostor = function (compound) {
  1063. for (var index = 0; index < compound.parts.length; index++) {
  1064. var mesh = compound.parts[index].mesh;
  1065. mesh._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
  1066. this._physicsEngine._unregisterMesh(mesh);
  1067. }
  1068. };
  1069. // Tags
  1070. Scene.prototype._getByTags = function (list, tagsQuery) {
  1071. if (tagsQuery === undefined) {
  1072. // returns the complete list (could be done with BABYLON.Tags.MatchesQuery but no need to have a for-loop here)
  1073. return list;
  1074. }
  1075. var listByTags = [];
  1076. for (var i in list) {
  1077. var item = list[i];
  1078. if (BABYLON.Tags.MatchesQuery(item, tagsQuery)) {
  1079. listByTags.push(item);
  1080. }
  1081. }
  1082. return listByTags;
  1083. };
  1084. Scene.prototype.getMeshesByTags = function (tagsQuery) {
  1085. return this._getByTags(this.meshes, tagsQuery);
  1086. };
  1087. Scene.prototype.getCamerasByTags = function (tagsQuery) {
  1088. return this._getByTags(this.cameras, tagsQuery);
  1089. };
  1090. Scene.prototype.getLightsByTags = function (tagsQuery) {
  1091. return this._getByTags(this.lights, tagsQuery);
  1092. };
  1093. Scene.prototype.getMaterialByTags = function (tagsQuery) {
  1094. return this._getByTags(this.materials, tagsQuery).concat(this._getByTags(this.multiMaterials, tagsQuery));
  1095. };
  1096. Scene.FOGMODE_NONE = 0;
  1097. Scene.FOGMODE_EXP = 1;
  1098. Scene.FOGMODE_EXP2 = 2;
  1099. Scene.FOGMODE_LINEAR = 3;
  1100. Scene.MinDeltaTime = 1.0;
  1101. Scene.MaxDeltaTime = 1000.0;
  1102. return Scene;
  1103. })();
  1104. BABYLON.Scene = Scene;
  1105. })(BABYLON || (BABYLON = {}));
  1106. //# sourceMappingURL=babylon.scene.js.map