meshSimplificationSceneComponent.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Scene } from "../scene.js";
  2. import { Mesh } from "./mesh.js";
  3. import { SimplificationQueue, SimplificationType } from "./meshSimplification.js";
  4. import { SceneComponentConstants } from "../sceneComponent.js";
  5. Object.defineProperty(Scene.prototype, "simplificationQueue", {
  6. get: function () {
  7. if (!this._simplificationQueue) {
  8. this._simplificationQueue = new SimplificationQueue();
  9. let component = this._getComponent(SceneComponentConstants.NAME_SIMPLIFICATIONQUEUE);
  10. if (!component) {
  11. component = new SimplicationQueueSceneComponent(this);
  12. this._addComponent(component);
  13. }
  14. }
  15. return this._simplificationQueue;
  16. },
  17. set: function (value) {
  18. this._simplificationQueue = value;
  19. },
  20. enumerable: true,
  21. configurable: true,
  22. });
  23. Mesh.prototype.simplify = function (settings, parallelProcessing = true, simplificationType = SimplificationType.QUADRATIC, successCallback) {
  24. this.getScene().simplificationQueue.addTask({
  25. settings: settings,
  26. parallelProcessing: parallelProcessing,
  27. mesh: this,
  28. simplificationType: simplificationType,
  29. successCallback: successCallback,
  30. });
  31. return this;
  32. };
  33. /**
  34. * Defines the simplification queue scene component responsible to help scheduling the various simplification task
  35. * created in a scene
  36. */
  37. export class SimplicationQueueSceneComponent {
  38. /**
  39. * Creates a new instance of the component for the given scene
  40. * @param scene Defines the scene to register the component in
  41. */
  42. constructor(scene) {
  43. /**
  44. * The component name helpfull to identify the component in the list of scene components.
  45. */
  46. this.name = SceneComponentConstants.NAME_SIMPLIFICATIONQUEUE;
  47. this.scene = scene;
  48. }
  49. /**
  50. * Registers the component in a given scene
  51. */
  52. register() {
  53. this.scene._beforeCameraUpdateStage.registerStep(SceneComponentConstants.STEP_BEFORECAMERAUPDATE_SIMPLIFICATIONQUEUE, this, this._beforeCameraUpdate);
  54. }
  55. /**
  56. * Rebuilds the elements related to this component in case of
  57. * context lost for instance.
  58. */
  59. rebuild() {
  60. // Nothing to do for this component
  61. }
  62. /**
  63. * Disposes the component and the associated resources
  64. */
  65. dispose() {
  66. // Nothing to do for this component
  67. }
  68. _beforeCameraUpdate() {
  69. if (this.scene._simplificationQueue && !this.scene._simplificationQueue.running) {
  70. this.scene._simplificationQueue.executeNext();
  71. }
  72. }
  73. }
  74. //# sourceMappingURL=meshSimplificationSceneComponent.js.map