babylon.renderingManager.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var RenderingManager = (function () {
  4. function RenderingManager(scene) {
  5. this._renderingGroups = new Array();
  6. this._scene = scene;
  7. }
  8. RenderingManager.prototype._renderParticles = function (index, activeMeshes) {
  9. if (this._scene._activeParticleSystems.length === 0) {
  10. return;
  11. }
  12. // Particles
  13. var beforeParticlesDate = BABYLON.Tools.Now;
  14. for (var particleIndex = 0; particleIndex < this._scene._activeParticleSystems.length; particleIndex++) {
  15. var particleSystem = this._scene._activeParticleSystems.data[particleIndex];
  16. if (particleSystem.renderingGroupId !== index) {
  17. continue;
  18. }
  19. this._clearDepthBuffer();
  20. if (!particleSystem.emitter.position || !activeMeshes || activeMeshes.indexOf(particleSystem.emitter) !== -1) {
  21. this._scene._activeParticles += particleSystem.render();
  22. }
  23. }
  24. this._scene._particlesDuration += BABYLON.Tools.Now - beforeParticlesDate;
  25. };
  26. RenderingManager.prototype._renderSprites = function (index) {
  27. if (this._scene.spriteManagers.length === 0) {
  28. return;
  29. }
  30. // Sprites
  31. var beforeSpritessDate = BABYLON.Tools.Now;
  32. for (var id = 0; id < this._scene.spriteManagers.length; id++) {
  33. var spriteManager = this._scene.spriteManagers[id];
  34. if (spriteManager.renderingGroupId === index) {
  35. this._clearDepthBuffer();
  36. spriteManager.render();
  37. }
  38. }
  39. this._scene._spritesDuration += BABYLON.Tools.Now - beforeSpritessDate;
  40. };
  41. RenderingManager.prototype._clearDepthBuffer = function () {
  42. if (this._depthBufferAlreadyCleaned) {
  43. return;
  44. }
  45. this._scene.getEngine().clear(0, false, true);
  46. this._depthBufferAlreadyCleaned = true;
  47. };
  48. RenderingManager.prototype.render = function (customRenderFunction, activeMeshes, renderParticles, renderSprites) {
  49. for (var index = 0; index < BABYLON.RenderingManager.MAX_RENDERINGGROUPS; index++) {
  50. this._depthBufferAlreadyCleaned = false;
  51. var renderingGroup = this._renderingGroups[index];
  52. if (renderingGroup) {
  53. this._clearDepthBuffer();
  54. if (!renderingGroup.render(customRenderFunction)) {
  55. this._renderingGroups.splice(index, 1);
  56. }
  57. }
  58. this._renderSprites(index);
  59. if (renderParticles) {
  60. this._renderParticles(index, activeMeshes);
  61. }
  62. }
  63. };
  64. RenderingManager.prototype.reset = function () {
  65. for (var index in this._renderingGroups) {
  66. var renderingGroup = this._renderingGroups[index];
  67. renderingGroup.prepare();
  68. }
  69. };
  70. RenderingManager.prototype.dispatch = function (subMesh) {
  71. var mesh = subMesh.getMesh();
  72. var renderingGroupId = mesh.renderingGroupId || 0;
  73. if (!this._renderingGroups[renderingGroupId]) {
  74. this._renderingGroups[renderingGroupId] = new BABYLON.RenderingGroup(renderingGroupId, this._scene);
  75. }
  76. this._renderingGroups[renderingGroupId].dispatch(subMesh);
  77. };
  78. RenderingManager.MAX_RENDERINGGROUPS = 4;
  79. return RenderingManager;
  80. })();
  81. BABYLON.RenderingManager = RenderingManager;
  82. })(BABYLON || (BABYLON = {}));
  83. //# sourceMappingURL=babylon.renderingManager.js.map