DynamicGeometryBatch.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import AssociativeArray from "../Core/AssociativeArray.js";
  2. import defined from "../Core/defined.js";
  3. import BoundingSphereState from "./BoundingSphereState.js";
  4. /**
  5. * @private
  6. */
  7. function DynamicGeometryBatch(primitives, orderedGroundPrimitives) {
  8. this._primitives = primitives;
  9. this._orderedGroundPrimitives = orderedGroundPrimitives;
  10. this._dynamicUpdaters = new AssociativeArray();
  11. }
  12. DynamicGeometryBatch.prototype.add = function (time, updater) {
  13. this._dynamicUpdaters.set(
  14. updater.id,
  15. updater.createDynamicUpdater(
  16. this._primitives,
  17. this._orderedGroundPrimitives
  18. )
  19. );
  20. };
  21. DynamicGeometryBatch.prototype.remove = function (updater) {
  22. const id = updater.id;
  23. const dynamicUpdater = this._dynamicUpdaters.get(id);
  24. if (defined(dynamicUpdater)) {
  25. this._dynamicUpdaters.remove(id);
  26. dynamicUpdater.destroy();
  27. }
  28. };
  29. DynamicGeometryBatch.prototype.update = function (time) {
  30. const geometries = this._dynamicUpdaters.values;
  31. for (let i = 0, len = geometries.length; i < len; i++) {
  32. geometries[i].update(time);
  33. }
  34. return true;
  35. };
  36. DynamicGeometryBatch.prototype.removeAllPrimitives = function () {
  37. const geometries = this._dynamicUpdaters.values;
  38. for (let i = 0, len = geometries.length; i < len; i++) {
  39. geometries[i].destroy();
  40. }
  41. this._dynamicUpdaters.removeAll();
  42. };
  43. DynamicGeometryBatch.prototype.getBoundingSphere = function (updater, result) {
  44. updater = this._dynamicUpdaters.get(updater.id);
  45. if (defined(updater) && defined(updater.getBoundingSphere)) {
  46. return updater.getBoundingSphere(result);
  47. }
  48. return BoundingSphereState.FAILED;
  49. };
  50. export default DynamicGeometryBatch;