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.
@@ -1729,6 +1729,11 @@ function addWireframeToMesh(geo, mesh, color = 16777215, w = 2) {
1729
1729
  mesh.add(wireframe);
1730
1730
  let axes = new AxesHelper(1);
1731
1731
  mesh.add(axes);
1732
+ return () => {
1733
+ wireGeo.dispose();
1734
+ wireMat.dispose();
1735
+ axes.dispose();
1736
+ };
1732
1737
  }
1733
1738
  var init_model = __esm({
1734
1739
  "src/util/model.ts"() {
@@ -5139,12 +5144,16 @@ var _EntityObject = class _EntityObject extends SceneObject {
5139
5144
  this.entity = entity;
5140
5145
  this.isEntityObject = true;
5141
5146
  this.meshesCreated = false;
5147
+ this.geometries = /* @__PURE__ */ new Set();
5148
+ this.disposeWireframes = [];
5142
5149
  /** Scrolling materials are owned: their texture offset follows this entity's age. */
5143
5150
  this.scrollMaterials = [];
5144
5151
  /** Entity age in ticks, as vanilla's `ageInTicks`; drives the scrolling render modes. */
5145
5152
  this.age = 0;
5146
5153
  this.animationPlayer = new EntityAnimationPlayer();
5147
5154
  this.options = (0, import_ts_deepmerge4.default)({}, _EntityObject.DEFAULT_OPTIONS, options ?? {});
5155
+ this.addEventListener("added", () => this.updateScrollSubscription());
5156
+ this.addEventListener("removed", () => this.updateScrollSubscription());
5148
5157
  }
5149
5158
  async init() {
5150
5159
  this.createMeshes();
@@ -5155,6 +5164,9 @@ var _EntityObject = class _EntityObject extends SceneObject {
5155
5164
  }
5156
5165
  disposeAndRemoveAllChildren() {
5157
5166
  this.clearScrollMaterials();
5167
+ for (const geometry of this.geometries) geometry.dispose();
5168
+ this.geometries.clear();
5169
+ for (const dispose of this.disposeWireframes.splice(0)) dispose();
5158
5170
  this.animationPlayer.clear();
5159
5171
  super.disposeAndRemoveAllChildren();
5160
5172
  }
@@ -5166,6 +5178,19 @@ var _EntityObject = class _EntityObject extends SceneObject {
5166
5178
  material.dispose();
5167
5179
  }
5168
5180
  }
5181
+ updateScrollSubscription() {
5182
+ if (this.parent && this.scrollMaterials.length) {
5183
+ if (this.scrollTicker === void 0) {
5184
+ this.scrollTicker = Ticker.add(() => {
5185
+ this.age++;
5186
+ this.updateScroll();
5187
+ });
5188
+ }
5189
+ } else {
5190
+ Ticker.remove(this.scrollTicker);
5191
+ this.scrollTicker = void 0;
5192
+ }
5193
+ }
5169
5194
  /** Applies the entity age to the scrolling materials; the ticker calls this 20 times per second. */
5170
5195
  updateScroll() {
5171
5196
  for (const { offset, speed } of this.scrollMaterials) {
@@ -5276,6 +5301,7 @@ var _EntityObject = class _EntityObject extends SceneObject {
5276
5301
  depth + growZ * 2,
5277
5302
  uv
5278
5303
  ).clone();
5304
+ this.geometries.add(geometry);
5279
5305
  geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
5280
5306
  if (inward && Math.min(width + growX * 2, height + growY * 2, depth + growZ * 2) > 0) {
5281
5307
  const index = Array.from(geometry.getIndex().array);
@@ -5284,7 +5310,7 @@ var _EntityObject = class _EntityObject extends SceneObject {
5284
5310
  const mesh = this.createMesh(name, geometry, material);
5285
5311
  mesh.renderOrder = renderOrder;
5286
5312
  anchor.add(mesh);
5287
- if (this.options.wireframe) addWireframeToMesh(geometry, mesh);
5313
+ if (this.options.wireframe) this.disposeWireframes.push(addWireframeToMesh(geometry, mesh));
5288
5314
  }
5289
5315
  for (const [childName, child] of Object.entries(part.children)) {
5290
5316
  this.createPart(childName, child, anchor, size, material, renderOrder, inward);
@@ -5318,11 +5344,8 @@ var _EntityObject = class _EntityObject extends SceneObject {
5318
5344
  this.clearScrollMaterials();
5319
5345
  } else if (this.scrollMaterials.length) {
5320
5346
  this.updateScroll();
5321
- this.scrollTicker = Ticker.add(() => {
5322
- this.age++;
5323
- this.updateScroll();
5324
- });
5325
5347
  }
5348
+ this.updateScrollSubscription();
5326
5349
  this.notifyDirty();
5327
5350
  }
5328
5351
  };