babylon.scene.ts 49 KB

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