babylon.renderingManager.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 && !renderingGroup.render(customRenderFunction, index == 0 ? beforeTransparents : null)) {
  29. this._renderingGroups.splice(index, 1);
  30. }
  31. if (renderParticles) {
  32. this._renderParticles(index, activeMeshes);
  33. }
  34. }
  35. };
  36. BABYLON.RenderingManager.prototype.reset = function () {
  37. for (var index in this._renderingGroups) {
  38. var renderingGroup = this._renderingGroups[index];
  39. renderingGroup.prepare();
  40. }
  41. };
  42. BABYLON.RenderingManager.prototype.dispatch = function (subMesh) {
  43. var mesh = subMesh.getMesh();
  44. var renderingGroupId = mesh.renderingGroupId || 0;
  45. if (!this._renderingGroups[renderingGroupId]) {
  46. this._renderingGroups[renderingGroupId] = new BABYLON.RenderingGroup(renderingGroupId, this._scene);
  47. }
  48. this._renderingGroups[renderingGroupId].dispatch(subMesh);
  49. };
  50. // Statics
  51. BABYLON.RenderingManager.MAX_RENDERINGGROUPS = 4;
  52. })();