@selvajs/visualization 1.7.0 → 1.7.1-beta.0

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.
package/dist/parse.d.cts CHANGED
@@ -4,6 +4,7 @@ import * as THREE from "three";
4
4
  export declare const meshPolicy: {
5
5
  clone(meshes: THREE.Object3D[]): THREE.Object3D[];
6
6
  release(meshes: THREE.Object3D[]): void;
7
+ byteSize(meshes: THREE.Object3D[]): number;
7
8
  };
8
9
  /**
9
10
  * Declared structurally rather than imported from `@selvajs/compute` — this package converts
package/dist/parse.d.ts CHANGED
@@ -4,6 +4,7 @@ import * as THREE from "three";
4
4
  export declare const meshPolicy: {
5
5
  clone(meshes: THREE.Object3D[]): THREE.Object3D[];
6
6
  release(meshes: THREE.Object3D[]): void;
7
+ byteSize(meshes: THREE.Object3D[]): number;
7
8
  };
8
9
  /**
9
10
  * Declared structurally rather than imported from `@selvajs/compute` — this package converts
package/dist/parse.js CHANGED
@@ -73,10 +73,24 @@ function cloneSceneObjects(meshes) {
73
73
  function releaseSceneObjects(meshes) {
74
74
  meshes.forEach((root) => disposeObjectTree(root, { materials: false }));
75
75
  }
76
+ /** Geometry bytes only: the memo's copies share materials and textures with the live scene. */
77
+ function sceneObjectsByteSize(meshes) {
78
+ let bytes = 0;
79
+ const seen = /* @__PURE__ */ new Set();
80
+ for (const root of meshes) root.traverse((child) => {
81
+ const geometry = child.geometry;
82
+ if (!geometry || seen.has(geometry)) return;
83
+ seen.add(geometry);
84
+ for (const attribute of Object.values(geometry.attributes)) bytes += attribute.array.byteLength;
85
+ if (geometry.index) bytes += geometry.index.array.byteLength;
86
+ });
87
+ return bytes;
88
+ }
76
89
  /** Structurally, not nominally, typed as `@selvajs/solve/client`'s `MeshPolicy<THREE.Object3D>` — avoids a dependency on solve. */
77
90
  const meshPolicy = {
78
91
  clone: cloneSceneObjects,
79
- release: releaseSceneObjects
92
+ release: releaseSceneObjects,
93
+ byteSize: sceneObjectsByteSize
80
94
  };
81
95
  /** Opacity < 1 flips `transparent` on. */
82
96
  function materialParams(color, opacity) {