@adatechnology/game-vegetation-three 0.2.6 → 0.2.7

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.
@@ -1557,6 +1557,90 @@ var GameVegetationThree = (() => {
1557
1557
  shims.add(result);
1558
1558
  return result;
1559
1559
  }
1560
+ var isTexture = (v) => !!v && typeof v === "object" && v.isTexture === true;
1561
+ function texturesOf(material, out) {
1562
+ for (const value of Object.values(material)) if (isTexture(value)) out.add(value);
1563
+ const uniforms = material.uniforms;
1564
+ if (uniforms) {
1565
+ for (const u of Object.values(uniforms)) if (isTexture(u?.value)) out.add(u.value);
1566
+ }
1567
+ }
1568
+ function collect(roots) {
1569
+ const geometries = /* @__PURE__ */ new Set();
1570
+ const materials = /* @__PURE__ */ new Set();
1571
+ const textures = /* @__PURE__ */ new Set();
1572
+ const skeletons = /* @__PURE__ */ new Set();
1573
+ for (const root of roots) {
1574
+ root.traverse((object2) => {
1575
+ const o = object2;
1576
+ if (o.geometry && typeof o.geometry.dispose === "function") geometries.add(o.geometry);
1577
+ if (o.skeleton && typeof o.skeleton.dispose === "function") skeletons.add(o.skeleton);
1578
+ const list2 = Array.isArray(o.material) ? o.material : o.material ? [o.material] : [];
1579
+ for (const m of list2) {
1580
+ if (!m || typeof m.dispose !== "function") continue;
1581
+ materials.add(m);
1582
+ texturesOf(m, textures);
1583
+ }
1584
+ });
1585
+ }
1586
+ return { geometries, materials, textures, skeletons };
1587
+ }
1588
+ var marked = /* @__PURE__ */ new WeakSet();
1589
+ var shared = (r) => r.userData?.shared === true || marked.has(r);
1590
+ function releaseObject3D(roots, options = {}) {
1591
+ const list2 = Array.isArray(roots) ? roots : [roots];
1592
+ const report = { geometries: 0, materials: 0, textures: 0 };
1593
+ if (list2.length === 0) return report;
1594
+ const found = collect(list2);
1595
+ const keepRoots = options.keep === void 0 ? [] : Array.isArray(options.keep) ? options.keep : [options.keep];
1596
+ const releasing = new Set(list2);
1597
+ for (const keep of keepRoots) {
1598
+ const walk = (o) => {
1599
+ if (releasing.has(o)) return;
1600
+ const owner = o;
1601
+ if (owner.geometry) found.geometries.delete(owner.geometry);
1602
+ if (owner.skeleton) found.skeletons.delete(owner.skeleton);
1603
+ const mats = Array.isArray(owner.material) ? owner.material : owner.material ? [owner.material] : [];
1604
+ for (const m of mats) {
1605
+ if (!m) continue;
1606
+ found.materials.delete(m);
1607
+ const t = /* @__PURE__ */ new Set();
1608
+ texturesOf(m, t);
1609
+ for (const x of t) found.textures.delete(x);
1610
+ }
1611
+ for (const c of o.children) walk(c);
1612
+ };
1613
+ walk(keep);
1614
+ }
1615
+ for (const g of found.geometries) {
1616
+ if (shared(g)) continue;
1617
+ g.dispose();
1618
+ report.geometries++;
1619
+ }
1620
+ for (const m of found.materials) {
1621
+ if (shared(m)) continue;
1622
+ m.dispose();
1623
+ report.materials++;
1624
+ }
1625
+ for (const t of found.textures) {
1626
+ if (shared(t)) continue;
1627
+ t.dispose();
1628
+ report.textures++;
1629
+ }
1630
+ for (const s of found.skeletons) s.dispose();
1631
+ return report;
1632
+ }
1633
+ function discardObject3D(objects, options = {}) {
1634
+ const list2 = Array.isArray(objects) ? objects : [objects];
1635
+ const keep = options.keep === void 0 ? [] : Array.isArray(options.keep) ? [...options.keep] : [options.keep];
1636
+ for (const object2 of list2) {
1637
+ let top = object2;
1638
+ while (top.parent) top = top.parent;
1639
+ object2.removeFromParent();
1640
+ if (top !== object2 && !keep.includes(top)) keep.push(top);
1641
+ }
1642
+ return releaseObject3D(list2, { keep });
1643
+ }
1560
1644
 
1561
1645
  // ../game-vegetation/dist/index.js
1562
1646
  var dist_exports = {};
@@ -10335,7 +10419,7 @@ gl_Position = projectionMatrix * mvPosition;
10335
10419
  });
10336
10420
  const clearHelpers = () => {
10337
10421
  for (const entry of placed.values()) {
10338
- for (const helper of entry.helpers) helper.parent?.remove(helper);
10422
+ discardObject3D(entry.helpers);
10339
10423
  entry.helpers = [];
10340
10424
  }
10341
10425
  helpersShown = "";