babylon.renderingManager.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var BABYLON = BABYLON || {};
  2. (function () {
  3. BABYLON.RenderingManager = function (scene) {
  4. this._scene = scene;
  5. this._renderingGroups = [];
  6. };
  7. // Methods
  8. BABYLON.RenderingManager.prototype._renderParticles = function (index, activeMeshes) {
  9. // Particles
  10. var beforeParticlesDate = new Date();
  11. for (var particleIndex = 0; particleIndex < this._scene._activeParticleSystems.length; particleIndex++) {
  12. var particleSystem = this._scene._activeParticleSystems.data[particleIndex];
  13. if (particleSystem.renderingGroupId !== index) {
  14. continue;
  15. }
  16. if (!particleSystem.emitter.position || !activeMeshes || activeMeshes.indexOf(particleSystem.emitter) !== -1) {
  17. this._scene._activeParticles += particleSystem.render();
  18. }
  19. }
  20. this._scene._particlesDuration += new Date() - beforeParticlesDate;
  21. };
  22. BABYLON.RenderingManager.prototype.render = function (customRenderFunction, beforeTransparents, activeMeshes, renderParticles) {
  23. for (var index = 0 ; index < BABYLON.RenderingManager.MAX_RENDERINGGROUPS; index++) {
  24. var renderingGroup = this._renderingGroups[index];
  25. if (index > 0) {
  26. this._scene.getEngine().clear(0, false, true);
  27. }
  28. if (renderingGroup) {
  29. if (!renderingGroup.render(customRenderFunction, index == 0 ? beforeTransparents : null)) {
  30. this._renderingGroups.splice(index, 1);
  31. }
  32. } else if (beforeTransparents && index == 0) {
  33. beforeTransparents();
  34. }
  35. if (renderParticles) {
  36. this._renderParticles(index, activeMeshes);
  37. }
  38. }
  39. };
  40. BABYLON.RenderingManager.prototype.reset = function () {
  41. for (var index in this._renderingGroups) {
  42. var renderingGroup = this._renderingGroups[index];
  43. renderingGroup.prepare();
  44. }
  45. };
  46. BABYLON.RenderingManager.prototype.dispatch = function (subMesh) {
  47. var mesh = subMesh.getMesh();
  48. var renderingGroupId = mesh.renderingGroupId || 0;
  49. if (!this._renderingGroups[renderingGroupId]) {
  50. this._renderingGroups[renderingGroupId] = new BABYLON.RenderingGroup(renderingGroupId, this._scene);
  51. }
  52. this._renderingGroups[renderingGroupId].dispatch(subMesh);
  53. };
  54. // Statics
  55. BABYLON.RenderingManager.MAX_RENDERINGGROUPS = 4;
  56. })();