Reference Source

src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsRenderers.js

  1. import {VBOBatchingPointsColorRenderer} from "./VBOBatchingPointsColorRenderer.js";
  2. import {VBOBatchingPointsSilhouetteRenderer} from "./VBOBatchingPointsSilhouetteRenderer.js";
  3. import {VBOBatchingPointsPickMeshRenderer} from "./VBOBatchingPointsPickMeshRenderer.js";
  4. import {VBOBatchingPointsPickDepthRenderer} from "./VBOBatchingPointsPickDepthRenderer.js";
  5. import {VBOBatchingPointsOcclusionRenderer} from "./VBOBatchingPointsOcclusionRenderer.js";
  6. import {VBOBatchingPointsSnapInitRenderer} from "./VBOBatchingPointsSnapInitRenderer.js";
  7. import {VBOBatchingPointsSnapRenderer} from "./VBOBatchingPointsSnapRenderer.js";
  8.  
  9. /**
  10. * @private
  11. */
  12. class VBOBatchingPointsRenderers {
  13.  
  14. constructor(scene) {
  15. this._scene = scene;
  16. }
  17.  
  18. _compile() {
  19. if (this._colorRenderer && (!this._colorRenderer.getValid())) {
  20. this._colorRenderer.destroy();
  21. this._colorRenderer = null;
  22. }
  23. if (this._silhouetteRenderer && (!this._silhouetteRenderer.getValid())) {
  24. this._silhouetteRenderer.destroy();
  25. this._silhouetteRenderer = null;
  26. }
  27. if (this._pickMeshRenderer && (!this._pickMeshRenderer.getValid())) {
  28. this._pickMeshRenderer.destroy();
  29. this._pickMeshRenderer = null;
  30. }
  31. if (this._pickDepthRenderer && (!this._pickDepthRenderer.getValid())) {
  32. this._pickDepthRenderer.destroy();
  33. this._pickDepthRenderer = null;
  34. }
  35. if (this._occlusionRenderer && this._occlusionRenderer.getValid() === false) {
  36. this._occlusionRenderer.destroy();
  37. this._occlusionRenderer = null;
  38. }
  39. if (this._snapInitRenderer && (!this._snapInitRenderer.getValid())) {
  40. this._snapInitRenderer.destroy();
  41. this._snapInitRenderer = null;
  42. }
  43. if (this._snapRenderer && (!this._snapRenderer.getValid())) {
  44. this._snapRenderer.destroy();
  45. this._snapRenderer = null;
  46. }
  47. }
  48.  
  49. get colorRenderer() {
  50. if (!this._colorRenderer) {
  51. this._colorRenderer = new VBOBatchingPointsColorRenderer(this._scene);
  52. }
  53. return this._colorRenderer;
  54. }
  55.  
  56. get silhouetteRenderer() {
  57. if (!this._silhouetteRenderer) {
  58. this._silhouetteRenderer = new VBOBatchingPointsSilhouetteRenderer(this._scene);
  59. }
  60. return this._silhouetteRenderer;
  61. }
  62.  
  63. get pickMeshRenderer() {
  64. if (!this._pickMeshRenderer) {
  65. this._pickMeshRenderer = new VBOBatchingPointsPickMeshRenderer(this._scene);
  66. }
  67. return this._pickMeshRenderer;
  68. }
  69.  
  70. get pickDepthRenderer() {
  71. if (!this._pickDepthRenderer) {
  72. this._pickDepthRenderer = new VBOBatchingPointsPickDepthRenderer(this._scene);
  73. }
  74. return this._pickDepthRenderer;
  75. }
  76.  
  77. get occlusionRenderer() {
  78. if (!this._occlusionRenderer) {
  79. this._occlusionRenderer = new VBOBatchingPointsOcclusionRenderer(this._scene);
  80. }
  81. return this._occlusionRenderer;
  82. }
  83.  
  84. get snapInitRenderer() {
  85. if (!this._snapInitRenderer) {
  86. this._snapInitRenderer = new VBOBatchingPointsSnapInitRenderer(this._scene, false);
  87. }
  88. return this._snapInitRenderer;
  89. }
  90.  
  91. get snapRenderer() {
  92. if (!this._snapRenderer) {
  93. this._snapRenderer = new VBOBatchingPointsSnapRenderer(this._scene);
  94. }
  95. return this._snapRenderer;
  96. }
  97.  
  98. _destroy() {
  99. if (this._colorRenderer) {
  100. this._colorRenderer.destroy();
  101. }
  102. if (this._silhouetteRenderer) {
  103. this._silhouetteRenderer.destroy();
  104. }
  105. if (this._pickMeshRenderer) {
  106. this._pickMeshRenderer.destroy();
  107. }
  108. if (this._pickDepthRenderer) {
  109. this._pickDepthRenderer.destroy();
  110. }
  111. if (this._occlusionRenderer) {
  112. this._occlusionRenderer.destroy();
  113. }
  114. if (this._snapInitRenderer) {
  115. this._snapInitRenderer.destroy();
  116. }
  117. if (this._snapRenderer) {
  118. this._snapRenderer.destroy();
  119. }
  120. }
  121. }
  122.  
  123. const cachedRenderers = {};
  124.  
  125. /**
  126. * @private
  127. */
  128. export function getRenderers(scene) {
  129. const sceneId = scene.id;
  130. let renderers = cachedRenderers[sceneId];
  131. if (!renderers) {
  132. renderers = new VBOBatchingPointsRenderers(scene);
  133. cachedRenderers[sceneId] = renderers;
  134. renderers._compile();
  135. scene.on("compile", () => {
  136. renderers._compile();
  137. });
  138. scene.on("destroyed", () => {
  139. delete cachedRenderers[sceneId];
  140. renderers._destroy();
  141. });
  142. }
  143. return renderers;
  144. }