minerender 2.1.0-alpha.55 → 2.1.0-alpha.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -691,7 +691,7 @@ declare function applyElementRotation(rotation: ElementRotation, geometry: Buffe
691
691
  declare function applyGenericRotation(axis: Axis, rotation: number, obj: Object3D): void;
692
692
  declare function addBox3WireframeToObject(box: Box3, obj: Object3D, color?: number, w?: number): void;
693
693
  declare function addWireframeToObject(obj: Object3D, color?: number, w?: number): void;
694
- declare function addWireframeToMesh(geo: BufferGeometry, mesh: Mesh, color?: number, w?: number): void;
694
+ declare function addWireframeToMesh(geo: BufferGeometry, mesh: Mesh, color?: number, w?: number): () => void;
695
695
 
696
696
  declare function captureException(e: any, ...extra: any[]): void;
697
697
  declare function timingStart(marker: string): void;
@@ -1180,6 +1180,8 @@ declare class EntityObject extends SceneObject {
1180
1180
  static readonly DEFAULT_OPTIONS: EntityObjectOptions;
1181
1181
  readonly options: EntityObjectOptions;
1182
1182
  private meshesCreated;
1183
+ private readonly geometries;
1184
+ private readonly disposeWireframes;
1183
1185
  /** Scrolling materials are owned: their texture offset follows this entity's age. */
1184
1186
  private readonly scrollMaterials;
1185
1187
  private scrollTicker;
@@ -1191,6 +1193,7 @@ declare class EntityObject extends SceneObject {
1191
1193
  dispose(): void;
1192
1194
  disposeAndRemoveAllChildren(): void;
1193
1195
  private clearScrollMaterials;
1196
+ private updateScrollSubscription;
1194
1197
  /** Applies the entity age to the scrolling materials; the ticker calls this 20 times per second. */
1195
1198
  private updateScroll;
1196
1199
  /** The animation started by {@link playAnimation}, until {@link stopAnimation} or disposal. */
@@ -691,7 +691,7 @@ declare function applyElementRotation(rotation: ElementRotation, geometry: Buffe
691
691
  declare function applyGenericRotation(axis: Axis, rotation: number, obj: Object3D): void;
692
692
  declare function addBox3WireframeToObject(box: Box3, obj: Object3D, color?: number, w?: number): void;
693
693
  declare function addWireframeToObject(obj: Object3D, color?: number, w?: number): void;
694
- declare function addWireframeToMesh(geo: BufferGeometry, mesh: Mesh, color?: number, w?: number): void;
694
+ declare function addWireframeToMesh(geo: BufferGeometry, mesh: Mesh, color?: number, w?: number): () => void;
695
695
 
696
696
  declare function captureException(e: any, ...extra: any[]): void;
697
697
  declare function timingStart(marker: string): void;
@@ -1180,6 +1180,8 @@ declare class EntityObject extends SceneObject {
1180
1180
  static readonly DEFAULT_OPTIONS: EntityObjectOptions;
1181
1181
  readonly options: EntityObjectOptions;
1182
1182
  private meshesCreated;
1183
+ private readonly geometries;
1184
+ private readonly disposeWireframes;
1183
1185
  /** Scrolling materials are owned: their texture offset follows this entity's age. */
1184
1186
  private readonly scrollMaterials;
1185
1187
  private scrollTicker;
@@ -1191,6 +1193,7 @@ declare class EntityObject extends SceneObject {
1191
1193
  dispose(): void;
1192
1194
  disposeAndRemoveAllChildren(): void;
1193
1195
  private clearScrollMaterials;
1196
+ private updateScrollSubscription;
1194
1197
  /** Applies the entity age to the scrolling materials; the ticker calls this 20 times per second. */
1195
1198
  private updateScroll;
1196
1199
  /** The animation started by {@link playAnimation}, until {@link stopAnimation} or disposal. */
@@ -1778,6 +1778,11 @@ function addWireframeToMesh(geo, mesh, color = 16777215, w = 2) {
1778
1778
  mesh.add(wireframe);
1779
1779
  let axes = new import_three8.AxesHelper(1);
1780
1780
  mesh.add(axes);
1781
+ return () => {
1782
+ wireGeo.dispose();
1783
+ wireMat.dispose();
1784
+ axes.dispose();
1785
+ };
1781
1786
  }
1782
1787
  var import_three8;
1783
1788
  var init_model = __esm({
@@ -5356,12 +5361,16 @@ var EntityObject = class _EntityObject extends SceneObject {
5356
5361
  this.entity = entity;
5357
5362
  this.isEntityObject = true;
5358
5363
  this.meshesCreated = false;
5364
+ this.geometries = /* @__PURE__ */ new Set();
5365
+ this.disposeWireframes = [];
5359
5366
  /** Scrolling materials are owned: their texture offset follows this entity's age. */
5360
5367
  this.scrollMaterials = [];
5361
5368
  /** Entity age in ticks, as vanilla's `ageInTicks`; drives the scrolling render modes. */
5362
5369
  this.age = 0;
5363
5370
  this.animationPlayer = new EntityAnimationPlayer();
5364
5371
  this.options = (0, import_ts_deepmerge4.default)({}, _EntityObject.DEFAULT_OPTIONS, options ?? {});
5372
+ this.addEventListener("added", () => this.updateScrollSubscription());
5373
+ this.addEventListener("removed", () => this.updateScrollSubscription());
5365
5374
  }
5366
5375
  static {
5367
5376
  this.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS);
@@ -5375,6 +5384,9 @@ var EntityObject = class _EntityObject extends SceneObject {
5375
5384
  }
5376
5385
  disposeAndRemoveAllChildren() {
5377
5386
  this.clearScrollMaterials();
5387
+ for (const geometry of this.geometries) geometry.dispose();
5388
+ this.geometries.clear();
5389
+ for (const dispose of this.disposeWireframes.splice(0)) dispose();
5378
5390
  this.animationPlayer.clear();
5379
5391
  super.disposeAndRemoveAllChildren();
5380
5392
  }
@@ -5386,6 +5398,19 @@ var EntityObject = class _EntityObject extends SceneObject {
5386
5398
  material.dispose();
5387
5399
  }
5388
5400
  }
5401
+ updateScrollSubscription() {
5402
+ if (this.parent && this.scrollMaterials.length) {
5403
+ if (this.scrollTicker === void 0) {
5404
+ this.scrollTicker = Ticker.add(() => {
5405
+ this.age++;
5406
+ this.updateScroll();
5407
+ });
5408
+ }
5409
+ } else {
5410
+ Ticker.remove(this.scrollTicker);
5411
+ this.scrollTicker = void 0;
5412
+ }
5413
+ }
5389
5414
  /** Applies the entity age to the scrolling materials; the ticker calls this 20 times per second. */
5390
5415
  updateScroll() {
5391
5416
  for (const { offset, speed } of this.scrollMaterials) {
@@ -5496,6 +5521,7 @@ var EntityObject = class _EntityObject extends SceneObject {
5496
5521
  depth + growZ * 2,
5497
5522
  uv
5498
5523
  ).clone();
5524
+ this.geometries.add(geometry);
5499
5525
  geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
5500
5526
  if (inward && Math.min(width + growX * 2, height + growY * 2, depth + growZ * 2) > 0) {
5501
5527
  const index = Array.from(geometry.getIndex().array);
@@ -5504,7 +5530,7 @@ var EntityObject = class _EntityObject extends SceneObject {
5504
5530
  const mesh = this.createMesh(name, geometry, material);
5505
5531
  mesh.renderOrder = renderOrder;
5506
5532
  anchor.add(mesh);
5507
- if (this.options.wireframe) addWireframeToMesh(geometry, mesh);
5533
+ if (this.options.wireframe) this.disposeWireframes.push(addWireframeToMesh(geometry, mesh));
5508
5534
  }
5509
5535
  for (const [childName, child] of Object.entries(part.children)) {
5510
5536
  this.createPart(childName, child, anchor, size, material, renderOrder, inward);
@@ -5538,11 +5564,8 @@ var EntityObject = class _EntityObject extends SceneObject {
5538
5564
  this.clearScrollMaterials();
5539
5565
  } else if (this.scrollMaterials.length) {
5540
5566
  this.updateScroll();
5541
- this.scrollTicker = Ticker.add(() => {
5542
- this.age++;
5543
- this.updateScroll();
5544
- });
5545
5567
  }
5568
+ this.updateScrollSubscription();
5546
5569
  this.notifyDirty();
5547
5570
  }
5548
5571
  };