copper3d 3.7.5 → 3.8.1

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.
Files changed (51) hide show
  1. package/dist/Controls/cameraTransitions.d.ts +87 -0
  2. package/dist/Controls/cameraTransitions.js +285 -0
  3. package/dist/Controls/cameraTransitions.js.map +1 -0
  4. package/dist/Controls/fitView.d.ts +45 -0
  5. package/dist/Controls/fitView.js +40 -0
  6. package/dist/Controls/fitView.js.map +1 -0
  7. package/dist/Controls/orbitFraming.d.ts +39 -0
  8. package/dist/Controls/orbitFraming.js +39 -0
  9. package/dist/Controls/orbitFraming.js.map +1 -1
  10. package/dist/Loader/fastSliceRepaint.d.ts +56 -0
  11. package/dist/Loader/fastSliceRepaint.js +159 -0
  12. package/dist/Loader/fastSliceRepaint.js.map +1 -0
  13. package/dist/Renderer/copperRendererOnDemond.d.ts +10 -2
  14. package/dist/Renderer/copperRendererOnDemond.js +14 -0
  15. package/dist/Renderer/copperRendererOnDemond.js.map +1 -1
  16. package/dist/Renderer/disposeScene.d.ts +47 -0
  17. package/dist/Renderer/disposeScene.js +46 -0
  18. package/dist/Renderer/disposeScene.js.map +1 -0
  19. package/dist/Renderer/sceneBudget.d.ts +40 -0
  20. package/dist/Renderer/sceneBudget.js +86 -0
  21. package/dist/Renderer/sceneBudget.js.map +1 -0
  22. package/dist/Scene/copperSceneOnDemond.d.ts +12 -0
  23. package/dist/Scene/copperSceneOnDemond.js +18 -0
  24. package/dist/Scene/copperSceneOnDemond.js.map +1 -1
  25. package/dist/Utils/dispose.d.ts +48 -0
  26. package/dist/Utils/dispose.js +60 -0
  27. package/dist/Utils/dispose.js.map +1 -0
  28. package/dist/Utils/modelCrossfade.d.ts +36 -0
  29. package/dist/Utils/modelCrossfade.js +46 -0
  30. package/dist/Utils/modelCrossfade.js.map +1 -0
  31. package/dist/Utils/volumeExposure.d.ts +32 -0
  32. package/dist/Utils/volumeExposure.js +104 -0
  33. package/dist/Utils/volumeExposure.js.map +1 -0
  34. package/dist/bundle.esm.js +31502 -10006
  35. package/dist/bundle.umd.js +31530 -10012
  36. package/dist/index.d.ts +19 -2
  37. package/dist/index.js +10 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/types/Controls/cameraTransitions.d.ts +87 -0
  40. package/dist/types/Controls/fitView.d.ts +45 -0
  41. package/dist/types/Controls/orbitFraming.d.ts +39 -0
  42. package/dist/types/Loader/fastSliceRepaint.d.ts +56 -0
  43. package/dist/types/Renderer/copperRendererOnDemond.d.ts +10 -2
  44. package/dist/types/Renderer/disposeScene.d.ts +47 -0
  45. package/dist/types/Renderer/sceneBudget.d.ts +40 -0
  46. package/dist/types/Scene/copperSceneOnDemond.d.ts +12 -0
  47. package/dist/types/Utils/dispose.d.ts +48 -0
  48. package/dist/types/Utils/modelCrossfade.d.ts +36 -0
  49. package/dist/types/Utils/volumeExposure.d.ts +32 -0
  50. package/dist/types/index.d.ts +19 -2
  51. package/package.json +7 -3
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Replaces a `VolumeSlice`'s `repaint` with an equivalent that does not
3
+ * rebuild the world on every scrub step, and can optionally lift its
4
+ * mid-tones.
5
+ *
6
+ * ## What the original does, per slice change
7
+ *
8
+ * Setting `slice.index` sets `geometryNeedsUpdate`, so the next `repaint()`
9
+ * runs `updateGeometry()` first. That method unconditionally:
10
+ *
11
+ * - assigns `canvas.width` / `canvas.height` and the same on `canvasBuffer`
12
+ * -- assigning either RESETS the whole 2D backing store even when the
13
+ * value is unchanged;
14
+ * - re-fetches both 2D contexts;
15
+ * - calls `geometry.dispose()` and builds a `new PlaneGeometry(...)`, i.e.
16
+ * deletes and recreates GPU buffers, every frame.
17
+ *
18
+ * Then `repaint()` calls `ctx.getImageData(...)`, a full canvas read-back
19
+ * that allocates a fresh `Uint8ClampedArray` -- every pixel of which is
20
+ * overwritten by the loop immediately below it, so the read is pure waste.
21
+ *
22
+ * Within one volume and one axis, `planeWidth`, `planeHeight`, `iLength` and
23
+ * `jLength` are the same for every slice; only `sliceAccess` and `matrix`
24
+ * differ. So all of the above is redundant on every scrub step but the first.
25
+ *
26
+ * Measured in a real browser while dragging a slice plane: 59 long tasks
27
+ * (>50ms) in ~2s and a p90 frame time of 61ms, against zero long tasks for
28
+ * the same drag on a scene that rotates but never repaints.
29
+ *
30
+ * `VolumeSlice` comes from three rather than from this library, and there is
31
+ * no option for any of this, so replacing the method per instance is the
32
+ * available lever.
33
+ *
34
+ * ## Fidelity
35
+ *
36
+ * The pixel loop is copied from the original, byte for byte in its
37
+ * arithmetic, threshold and window-level handling included. The differences
38
+ * are the ones above -- cached `ImageData`, geometry work skipped while the
39
+ * plane dimensions are unchanged -- plus the optional exposure LUT, which is
40
+ * the one thing here that changes what a pixel comes out as. `label` volumes
41
+ * are handed back to the original implementation.
42
+ */
43
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
44
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
45
+ return new (P || (P = Promise))(function (resolve, reject) {
46
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
47
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
48
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
49
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
50
+ });
51
+ };
52
+ const PATCHED = Symbol('fast-repaint');
53
+ /** `out = 255 * (in/255) ** exponent`, precomputed. Monotonic with both ends
54
+ * fixed, so it lifts mid-tones without clipping either end. */
55
+ function exposureLut(exponent) {
56
+ const lut = new Uint8Array(256);
57
+ for (let v = 0; v < 256; v++)
58
+ lut[v] = Math.round(255 * Math.pow((v / 255), exponent));
59
+ return lut;
60
+ }
61
+ /**
62
+ * Idempotent: patching an already-patched slice is a no-op.
63
+ *
64
+ * `exposure` is a gamma exponent, normally from `exposureExponent()`; 1
65
+ * leaves greyscale exactly as the original produced it.
66
+ *
67
+ * CALL THIS BEFORE THE FIRST PAINT. The LUT lives in the patched method, so
68
+ * painting first draws one un-lifted frame and corrects it on the reader's
69
+ * first scrub -- a visible colour change.
70
+ *
71
+ * Async only because `PlaneGeometry` is imported on demand, to keep three out
72
+ * of a consumer's initial chunk when nothing scrubs a slice.
73
+ */
74
+ export function installFastSliceRepaint(rawSlice_1) {
75
+ return __awaiter(this, arguments, void 0, function* (rawSlice, exposure = 1) {
76
+ var _a;
77
+ const slice = rawSlice;
78
+ if (!slice || slice[PATCHED])
79
+ return;
80
+ if (((_a = slice.volume) === null || _a === void 0 ? void 0 : _a.dataType) === 'label')
81
+ return;
82
+ const lut = exposure === 1 ? null : exposureLut(exposure);
83
+ const { PlaneGeometry } = yield import('three');
84
+ const original = slice.repaint;
85
+ /** Reused across repaints; re-created only when the plane resizes. */
86
+ let buffer = null;
87
+ slice.repaint = function fastRepaint() {
88
+ var _a;
89
+ if (this.volume.dataType === 'label') {
90
+ original.call(this);
91
+ return;
92
+ }
93
+ if (this.geometryNeedsUpdate) {
94
+ const e = this.volume.extractPerpendicularPlane(this.axis, this.index);
95
+ const resized = this.iLength !== e.iLength
96
+ || this.jLength !== e.jLength
97
+ || this.canvas.width !== e.planeWidth
98
+ || this.canvas.height !== e.planeHeight;
99
+ this.sliceAccess = e.sliceAccess;
100
+ this.iLength = e.iLength;
101
+ this.jLength = e.jLength;
102
+ this.matrix = e.matrix;
103
+ if (resized) {
104
+ this.canvas.width = e.planeWidth;
105
+ this.canvas.height = e.planeHeight;
106
+ this.canvasBuffer.width = e.iLength;
107
+ this.canvasBuffer.height = e.jLength;
108
+ this.ctx = this.canvas.getContext('2d');
109
+ this.ctxBuffer = this.canvasBuffer.getContext('2d');
110
+ (_a = this.geometry) === null || _a === void 0 ? void 0 : _a.dispose();
111
+ const geometry = new PlaneGeometry(e.planeWidth, e.planeHeight);
112
+ this.geometry = geometry;
113
+ if (this.mesh)
114
+ this.mesh.geometry = geometry;
115
+ buffer = null;
116
+ }
117
+ // Always: the plane's POSITION along the axis is exactly what changed.
118
+ if (this.mesh) {
119
+ this.mesh.matrix.identity();
120
+ this.mesh.applyMatrix4(this.matrix);
121
+ }
122
+ this.geometryNeedsUpdate = false;
123
+ }
124
+ const { iLength, jLength, sliceAccess, volume } = this;
125
+ if (!buffer || buffer.width !== iLength || buffer.height !== jLength) {
126
+ // `createImageData` allocates zeroed pixels without reading the canvas
127
+ // back, which is the whole point.
128
+ buffer = this.ctxBuffer.createImageData(iLength, jLength);
129
+ }
130
+ const data = buffer.data;
131
+ const volumeData = volume.data;
132
+ const { upperThreshold, lowerThreshold, windowLow, windowHigh } = volume;
133
+ const scale = 255 / (windowHigh - windowLow);
134
+ let pixelCount = 0;
135
+ for (let j = 0; j < jLength; j++) {
136
+ for (let i = 0; i < iLength; i++) {
137
+ const raw = volumeData[sliceAccess(i, j)];
138
+ const alpha = upperThreshold >= raw ? (lowerThreshold <= raw ? 0xFF : 0) : 0;
139
+ let value = Math.floor((raw - windowLow) * scale);
140
+ value = value > 255 ? 255 : (value < 0 ? 0 : value | 0);
141
+ if (lut)
142
+ value = lut[value];
143
+ const at = 4 * pixelCount;
144
+ data[at] = value;
145
+ data[at + 1] = value;
146
+ data[at + 2] = value;
147
+ data[at + 3] = alpha;
148
+ pixelCount++;
149
+ }
150
+ }
151
+ this.ctxBuffer.putImageData(buffer, 0, 0);
152
+ this.ctx.drawImage(this.canvasBuffer, 0, 0, iLength, jLength, 0, 0, this.canvas.width, this.canvas.height);
153
+ if (this.mesh)
154
+ this.mesh.material.map.needsUpdate = true;
155
+ };
156
+ slice[PATCHED] = true;
157
+ });
158
+ }
159
+ //# sourceMappingURL=fastSliceRepaint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fastSliceRepaint.js","sourceRoot":"","sources":["../../src/Loader/fastSliceRepaint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;;;;;;;;;;AAyCH,MAAM,OAAO,GAAG,MAAM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,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,GAAG,IAAI,CAAA;QAC1D,CAAC,CAAA;QAED,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;IACvB,CAAC;CAAA"}
@@ -1,10 +1,18 @@
1
1
  import { baseRenderer } from "./baseRenderer";
2
- import { ICopperRenderOpt } from "../types/types";
2
+ import { ICopperRenderOpt, SceneMapType } from "../types/types";
3
3
  import { copperSceneOnDemond } from "../Scene/copperSceneOnDemond";
4
4
  export declare class copperRendererOnDemond extends baseRenderer {
5
- private sceneMap;
5
+ /** Public so `disposeScene` can unregister an entry. Nothing else removes
6
+ * one, so a long-lived renderer otherwise accumulates every scene it has
7
+ * ever built, decoded volumes included. */
8
+ sceneMap: SceneMapType;
6
9
  constructor(container: HTMLDivElement, options?: ICopperRenderOpt);
7
10
  getSceneByName(name: string): import("..").copperScene | import("../Scene/baseScene").baseScene | import("..").copperMScene;
11
+ /**
12
+ * Unregisters a scene and frees its geometries, materials and textures.
13
+ * Returns the scene that was disposed, or undefined if there was none.
14
+ */
15
+ disposeScene(name: string): import("./disposeScene").DisposableScene | undefined;
8
16
  setCurrentScene(sceneIn: copperSceneOnDemond): void;
9
17
  createScene(name: string): copperSceneOnDemond | undefined;
10
18
  animate: () => void;
@@ -1,8 +1,12 @@
1
1
  import { baseRenderer } from "./baseRenderer";
2
2
  import { copperSceneOnDemond } from "../Scene/copperSceneOnDemond";
3
+ import { disposeScene as disposeSceneFrom } from "./disposeScene";
3
4
  export class copperRendererOnDemond extends baseRenderer {
4
5
  constructor(container, options) {
5
6
  super(container, options);
7
+ /** Public so `disposeScene` can unregister an entry. Nothing else removes
8
+ * one, so a long-lived renderer otherwise accumulates every scene it has
9
+ * ever built, decoded volumes included. */
6
10
  this.sceneMap = {};
7
11
  this.animate = () => {
8
12
  this.render();
@@ -13,6 +17,16 @@ export class copperRendererOnDemond extends baseRenderer {
13
17
  getSceneByName(name) {
14
18
  return this.sceneMap[name];
15
19
  }
20
+ /**
21
+ * Unregisters a scene and frees its geometries, materials and textures.
22
+ * Returns the scene that was disposed, or undefined if there was none.
23
+ */
24
+ disposeScene(name) {
25
+ // `SceneMapType` predates `copperSceneOnDemond` and does not list it, so
26
+ // its element type has no `controls`/`requestRenderIfNotRequested`. The
27
+ // map this renderer actually fills only ever holds `copperSceneOnDemond`.
28
+ return disposeSceneFrom(this, name);
29
+ }
16
30
  setCurrentScene(sceneIn) {
17
31
  var _a;
18
32
  if (sceneIn) {
@@ -1 +1 @@
1
- {"version":3,"file":"copperRendererOnDemond.js","sourceRoot":"","sources":["../../src/Renderer/copperRendererOnDemond.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,MAAM,OAAO,sBAAuB,SAAQ,YAAY;IAEtD,YAAY,SAAyB,EAAE,OAA0B;QAC/D,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAFpB,aAAQ,GAAiB,EAAE,CAAC;QA8BpC,YAAO,GAAG,GAAG,EAAE;YACb,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACpB,uCAAuC;QACzC,CAAC,CAAC;IA/BF,CAAC;IAED,cAAc,CAAC,IAAY;QACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,eAAe,CAAC,OAA4B;;QAC1C,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;YAC5B,IAAI,MAAA,IAAI,CAAC,OAAO,0CAAE,OAAO,EAAE,CAAC;gBAC1B,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IA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C1E,OAAO,gBAAgB,CAAC,IAAoC,EAAE,IAAI,CAAC,CAAC;IACtE,CAAC;IAED,eAAe,CAAC,OAA4B;;QAC1C,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;YAC5B,IAAI,MAAA,IAAI,CAAC,OAAO,0CAAE,OAAO,EAAE,CAAC;gBAC1B,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,SAAS,EAAE,CAAC;YACrC,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,MAAM,SAAS,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzE,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC;YAC3B,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAC3C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;YAChC,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAOD,MAAM;QACJ,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,47 @@
1
+ import type { DisposableObject3D } from '../Utils/dispose';
2
+ /**
3
+ * Removes a scene from a renderer's map and frees what it holds.
4
+ *
5
+ * There is otherwise no way out of `sceneMap` at all: nothing in copper3d
6
+ * removes an entry, so a long-lived renderer accumulates every scene it has
7
+ * ever built, decoded volumes included.
8
+ *
9
+ * Written as a free function so it can be called on a renderer instance the
10
+ * caller already has, and unit-tested against a plain object. The renderer
11
+ * class wraps it as a one-line method.
12
+ */
13
+ /** The parts of a scene this needs. Structural, so a test does not have to
14
+ * build a real one. */
15
+ export interface DisposableScene {
16
+ scene: {
17
+ children: DisposableObject3D[];
18
+ remove: (object: any) => void;
19
+ };
20
+ controls: {
21
+ enabled: boolean;
22
+ /** Narrowed to the one event this removes, so it accepts both a
23
+ * `string`-typed emitter and one already narrowed to its own events. */
24
+ removeEventListener?: (type: 'change', listener: () => void) => void;
25
+ };
26
+ requestRenderIfNotRequested: () => void;
27
+ }
28
+ export interface SceneDisposalHost<S extends DisposableScene = DisposableScene> {
29
+ sceneMap: Record<string, S>;
30
+ getSceneByName: (name: string) => S | undefined;
31
+ }
32
+ /**
33
+ * Unregisters a scene WITHOUT freeing anything, for callers re-registering it
34
+ * under a different name.
35
+ *
36
+ * Throws if the entry survives removal. `delete` on a missing property is a
37
+ * silent no-op, so restructuring `sceneMap` into a real `Map` would stop
38
+ * eviction working with no crash and no type error -- the map would grow
39
+ * without bound again, invisibly. Confirming through the host's own accessor
40
+ * fails loudly instead.
41
+ */
42
+ export declare function removeSceneFromMap(host: SceneDisposalHost<any>, name: string): void;
43
+ /**
44
+ * Unregisters a scene and frees everything in it. Returns the scene that was
45
+ * disposed, or `undefined` if there was none under that name.
46
+ */
47
+ export declare function disposeScene<S extends DisposableScene>(host: SceneDisposalHost<S>, name: string): S | undefined;
@@ -0,0 +1,46 @@
1
+ import { disposeObject3D } from '../Utils/dispose';
2
+ /**
3
+ * Unregisters a scene WITHOUT freeing anything, for callers re-registering it
4
+ * under a different name.
5
+ *
6
+ * Throws if the entry survives removal. `delete` on a missing property is a
7
+ * silent no-op, so restructuring `sceneMap` into a real `Map` would stop
8
+ * eviction working with no crash and no type error -- the map would grow
9
+ * without bound again, invisibly. Confirming through the host's own accessor
10
+ * fails loudly instead.
11
+ */
12
+ export function removeSceneFromMap(host, name) {
13
+ delete host.sceneMap[name];
14
+ if (host.getSceneByName(name)) {
15
+ throw new Error(`Scene "${name}" survived disposal: sceneMap is no longer a plain object `
16
+ + `keyed by scene name, so scenes will accumulate without bound until `
17
+ + `this is updated to match its new shape.`);
18
+ }
19
+ }
20
+ /**
21
+ * Unregisters a scene and frees everything in it. Returns the scene that was
22
+ * disposed, or `undefined` if there was none under that name.
23
+ */
24
+ export function disposeScene(host, name) {
25
+ var _a, _b;
26
+ const victim = host.getSceneByName(name);
27
+ removeSceneFromMap(host, name);
28
+ if (!victim)
29
+ return undefined;
30
+ victim.controls.enabled = false;
31
+ // Removing just the `change` listener, NOT `controls.dispose()`. Every
32
+ // scene shares one canvas, and OrbitControls' `dispose()` ends with
33
+ // `domElement.style.touchAction = ''` while only `connect()` ever sets it
34
+ // back -- so disposing one evicted scene's controls breaks touch orbiting
35
+ // for whichever scene is actually on screen, for the rest of the session.
36
+ // The listener is the reference chain that matters here anyway.
37
+ (_b = (_a = victim.controls).removeEventListener) === null || _b === void 0 ? void 0 : _b.call(_a, 'change', victim.requestRenderIfNotRequested);
38
+ // Iterating the children rather than removing objects by name: a name list
39
+ // silently misses anything added under a name nobody thought to list.
40
+ for (const object of [...victim.scene.children]) {
41
+ victim.scene.remove(object);
42
+ disposeObject3D(object);
43
+ }
44
+ return victim;
45
+ }
46
+ //# sourceMappingURL=disposeScene.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disposeScene.js","sourceRoot":"","sources":["../../src/Renderer/disposeScene.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAmClD;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAA4B,EAAE,IAAY;IAC3E,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC1B,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CACb,UAAU,IAAI,4DAA4D;cACxE,qEAAqE;cACrE,yCAAyC,CAC5C,CAAA;IACH,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,IAA0B,EAC1B,IAAY;;IAEZ,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;IACxC,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAC9B,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAA;IAE7B,MAAM,CAAC,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAA;IAC/B,uEAAuE;IACvE,oEAAoE;IACpE,0EAA0E;IAC1E,0EAA0E;IAC1E,0EAA0E;IAC1E,gEAAgE;IAChE,MAAA,MAAA,MAAM,CAAC,QAAQ,EAAC,mBAAmB,mDAAG,QAAQ,EAAE,MAAM,CAAC,2BAA2B,CAAC,CAAA;IAEnF,2EAA2E;IAC3E,sEAAsE;IACtE,KAAK,MAAM,MAAM,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC3B,eAAe,CAAC,MAAM,CAAC,CAAA;IACzB,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * How much decoded scene data may stay resident, as a byte budget with LRU
3
+ * eviction and pinning.
4
+ *
5
+ * Bytes rather than a scene count, because a count is not the thing at risk:
6
+ * an NRRD volume can be 51KB or 53MB on disk and decodes to a typed array
7
+ * larger still, so "three scenes" is anywhere from 150KB to 250MB.
8
+ *
9
+ * Whatever is on screen should be pinned and is never a victim, however far
10
+ * over the limit that puts the total. Blanking a view the reader is looking
11
+ * at is strictly worse than the memory it saves -- and with several viewports
12
+ * sharing one renderer, more than one scene is visible at a time.
13
+ */
14
+ export interface SceneBudget {
15
+ /** Records (or re-records) a resident scene's decoded size and marks it
16
+ * most-recently-used. */
17
+ register: (key: string, bytes: number) => void;
18
+ /** Marks an already-registered scene most-recently-used. No-op if absent. */
19
+ touch: (key: string) => void;
20
+ /** Protects a scene from eviction while it is on screen. */
21
+ pin: (key: string) => void;
22
+ unpin: (key: string) => void;
23
+ /** Forgets a scene entirely. Call after its GPU resources are freed. */
24
+ release: (key: string) => void;
25
+ /** Carries bytes, queue position and pin state to a new key, for callers
26
+ * that rename a scene in place. */
27
+ rename: (from: string, to: string) => void;
28
+ /** Keys to evict, least-recently-used first, never pinned. Empty when the
29
+ * total is within budget or nothing evictable is left. */
30
+ overflow: () => string[];
31
+ bytes: () => number;
32
+ }
33
+ /**
34
+ * `deviceMemory` is a Chromium-only hint in GiB, absent in Safari and every
35
+ * iOS browser. Absent must mean the SMALL budget: an iPad is both the device
36
+ * that omits the API and the one most likely to have its tab killed for using
37
+ * too much.
38
+ */
39
+ export declare function defaultBudgetBytes(deviceMemoryGiB?: number): number;
40
+ export declare function createSceneBudget(limitBytes: number): SceneBudget;
@@ -0,0 +1,86 @@
1
+ /**
2
+ * How much decoded scene data may stay resident, as a byte budget with LRU
3
+ * eviction and pinning.
4
+ *
5
+ * Bytes rather than a scene count, because a count is not the thing at risk:
6
+ * an NRRD volume can be 51KB or 53MB on disk and decodes to a typed array
7
+ * larger still, so "three scenes" is anywhere from 150KB to 250MB.
8
+ *
9
+ * Whatever is on screen should be pinned and is never a victim, however far
10
+ * over the limit that puts the total. Blanking a view the reader is looking
11
+ * at is strictly worse than the memory it saves -- and with several viewports
12
+ * sharing one renderer, more than one scene is visible at a time.
13
+ */
14
+ const MB = 1024 * 1024;
15
+ /** Roomy devices get this. */
16
+ const FULL_BUDGET = 500 * MB;
17
+ /** Low-memory devices, and any browser that will not say, get this. */
18
+ const CONSERVATIVE_BUDGET = 250 * MB;
19
+ /** `navigator.deviceMemory` in GiB, at or above which the full budget applies. */
20
+ const ROOMY_DEVICE_GIB = 8;
21
+ /**
22
+ * `deviceMemory` is a Chromium-only hint in GiB, absent in Safari and every
23
+ * iOS browser. Absent must mean the SMALL budget: an iPad is both the device
24
+ * that omits the API and the one most likely to have its tab killed for using
25
+ * too much.
26
+ */
27
+ export function defaultBudgetBytes(deviceMemoryGiB) {
28
+ return typeof deviceMemoryGiB === 'number' && deviceMemoryGiB >= ROOMY_DEVICE_GIB
29
+ ? FULL_BUDGET
30
+ : CONSERVATIVE_BUDGET;
31
+ }
32
+ export function createSceneBudget(limitBytes) {
33
+ /** Insertion order is LRU order: Map preserves it, and re-inserting a key
34
+ * after deleting it moves it to the back. */
35
+ const sizes = new Map();
36
+ const pinned = new Set();
37
+ function total() {
38
+ let sum = 0;
39
+ for (const bytes of sizes.values())
40
+ sum += bytes;
41
+ return sum;
42
+ }
43
+ return {
44
+ register(key, bytes) {
45
+ sizes.delete(key);
46
+ sizes.set(key, bytes);
47
+ },
48
+ touch(key) {
49
+ const bytes = sizes.get(key);
50
+ if (bytes === undefined)
51
+ return;
52
+ sizes.delete(key);
53
+ sizes.set(key, bytes);
54
+ },
55
+ pin(key) { pinned.add(key); },
56
+ unpin(key) { pinned.delete(key); },
57
+ release(key) {
58
+ sizes.delete(key);
59
+ pinned.delete(key);
60
+ },
61
+ rename(from, to) {
62
+ const bytes = sizes.get(from);
63
+ if (bytes === undefined)
64
+ return;
65
+ sizes.delete(from);
66
+ sizes.set(to, bytes);
67
+ if (pinned.delete(from))
68
+ pinned.add(to);
69
+ },
70
+ overflow() {
71
+ const victims = [];
72
+ let remaining = total();
73
+ for (const [key, bytes] of sizes) {
74
+ if (remaining <= limitBytes)
75
+ break;
76
+ if (pinned.has(key))
77
+ continue;
78
+ victims.push(key);
79
+ remaining -= bytes;
80
+ }
81
+ return victims;
82
+ },
83
+ bytes: total,
84
+ };
85
+ }
86
+ //# sourceMappingURL=sceneBudget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sceneBudget.js","sourceRoot":"","sources":["../../src/Renderer/sceneBudget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA;AAEtB,8BAA8B;AAC9B,MAAM,WAAW,GAAG,GAAG,GAAG,EAAE,CAAA;AAC5B,uEAAuE;AACvE,MAAM,mBAAmB,GAAG,GAAG,GAAG,EAAE,CAAA;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jB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACpB,CAAC;QACD,MAAM,CAAC,IAAI,EAAE,EAAE;YACb,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAC7B,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAM;YAC/B,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAClB,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;YACpB,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;gBAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACzC,CAAC;QACD,QAAQ;YACN,MAAM,OAAO,GAAa,EAAE,CAAA;YAC5B,IAAI,SAAS,GAAG,KAAK,EAAE,CAAA;YACvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC;gBACjC,IAAI,SAAS,IAAI,UAAU;oBAAE,MAAK;gBAClC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;oBAAE,SAAQ;gBAC7B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBACjB,SAAS,IAAI,KAAK,CAAA;YACpB,CAAC;YACD,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,KAAK,EAAE,KAAK;KACb,CAAA;AACH,CAAC"}
@@ -1,12 +1,24 @@
1
1
  import * as THREE from "three";
2
2
  import { baseScene } from "./baseScene";
3
3
  import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
4
+ import { CameraViewPoint } from "../Controls/copperControls";
5
+ import type { FitBounds } from "../Controls/orbitFraming";
4
6
  export declare class copperSceneOnDemond extends baseScene {
5
7
  controls: OrbitControls;
6
8
  renderRequested: boolean | undefined;
7
9
  isResize: boolean;
8
10
  constructor(container: HTMLDivElement, renderer: THREE.WebGLRenderer);
9
11
  loadGltf(url: string, callback?: (content: THREE.Group) => void): void;
12
+ /**
13
+ * Re-frames the camera on `bounds`, keeping the preset's view direction and
14
+ * up and replacing only its distance. Returns false when there is nothing
15
+ * to do -- an orthographic camera (no field of view to fit against), or a
16
+ * preset whose eye sits exactly on its target.
17
+ *
18
+ * Does not render: the caller decides when to draw, which matters here
19
+ * because this scene renders on demand.
20
+ */
21
+ fitView(preset: CameraViewPoint, aspect: number, bounds: FitBounds, margin?: number): boolean;
10
22
  confirmResize: () => void;
11
23
  render: () => void;
12
24
  requestRenderIfNotRequested: () => void;
@@ -2,6 +2,7 @@ import * as THREE from "three";
2
2
  import { baseScene } from "./baseScene";
3
3
  import { copperGltfLoader } from "../Loader/copperGltfLoader";
4
4
  import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
5
+ import { fitView as fitViewOn } from "../Controls/fitView";
5
6
  export class copperSceneOnDemond extends baseScene {
6
7
  constructor(container, renderer) {
7
8
  super(container, renderer);
@@ -56,5 +57,22 @@ export class copperSceneOnDemond extends baseScene {
56
57
  // console.log(error);
57
58
  });
58
59
  }
60
+ /**
61
+ * Re-frames the camera on `bounds`, keeping the preset's view direction and
62
+ * up and replacing only its distance. Returns false when there is nothing
63
+ * to do -- an orthographic camera (no field of view to fit against), or a
64
+ * preset whose eye sits exactly on its target.
65
+ *
66
+ * Does not render: the caller decides when to draw, which matters here
67
+ * because this scene renders on demand.
68
+ */
69
+ fitView(preset, aspect, bounds, margin) {
70
+ if (!this.camera.isPerspectiveCamera) {
71
+ return false;
72
+ }
73
+ // `controls` is a union of three classes; only some declare
74
+ // `handleResize`, and `fitView` already treats it as optional.
75
+ return fitViewOn(this, preset, aspect, bounds, margin);
76
+ }
59
77
  }
60
78
  //# sourceMappingURL=copperSceneOnDemond.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"copperSceneOnDemond.js","sourceRoot":"","sources":["../../src/Scene/copperSceneOnDemond.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MA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AC,MAAM,CAAC,CAAC;gBAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,YAAY,CAChC,IAAI,CAAC,MAAiC,EACtC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAC/B,CAAC;YACJ,CAAC;YAED,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC;YAC1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC,EACD,CAAC,KAAK,EAAE,EAAE;YACR,sBAAsB;QACxB,CAAC,CACF,CAAC;IACJ,CAAC;IAED;;;;;;;;OAQG;IACH,OAAO,CACL,MAAuB,EACvB,MAAc,EACd,MAAiB,EACjB,MAAe;QAEf,IAAI,CAAE,IAAI,CAAC,MAAkC,CAAC,mBAAmB,EAAE,CAAC;YAClE,OAAO,KAAK,CAAC;QACf,CAAC;QACD,4DAA4D;QAC5D,+DAA+D;QAC/D,OAAO,SAAS,CACd,IAA+B,EAC/B,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,CACP,CAAC;IACJ,CAAC;CAwBF"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Frees the GPU resources behind an object that is no longer displayed.
3
+ *
4
+ * `scene.remove()` only unlinks: three keeps the geometry's buffers and the
5
+ * material's textures uploaded until they are disposed explicitly. Nothing in
6
+ * copper3d disposes what it creates, so anything that swaps models or evicts
7
+ * scenes needs this or its footprint is unbounded.
8
+ *
9
+ * Typed structurally rather than against `THREE.Object3D` so it also accepts
10
+ * the minimal shapes callers and tests hand around; a real three object
11
+ * satisfies these interfaces.
12
+ */
13
+ interface Disposable {
14
+ dispose: () => void;
15
+ }
16
+ /** A material and the texture slots three's built-in materials use. All
17
+ * optional: any given material has only some of them. */
18
+ export interface DisposableMaterial extends Disposable {
19
+ map?: Disposable | null;
20
+ normalMap?: Disposable | null;
21
+ roughnessMap?: Disposable | null;
22
+ metalnessMap?: Disposable | null;
23
+ aoMap?: Disposable | null;
24
+ emissiveMap?: Disposable | null;
25
+ alphaMap?: Disposable | null;
26
+ bumpMap?: Disposable | null;
27
+ displacementMap?: Disposable | null;
28
+ envMap?: Disposable | null;
29
+ lightMap?: Disposable | null;
30
+ specularMap?: Disposable | null;
31
+ }
32
+ export interface DisposableObject3D {
33
+ traverse: (callback: (child: any) => void) => void;
34
+ }
35
+ /**
36
+ * `Material.dispose()` does NOT cascade into its textures, so a canvas-backed
37
+ * or image-backed map stays on the GPU without this. Handles the array form
38
+ * too: a multi-material mesh would otherwise reach `Array.prototype.dispose`,
39
+ * which does not exist.
40
+ */
41
+ export declare function disposeMaterial(material: DisposableMaterial | DisposableMaterial[] | null | undefined): void;
42
+ /**
43
+ * Works on a lone mesh as well as on a whole subtree -- `traverse` visits the
44
+ * root itself -- so a slice plane that was never added to a scene is freed by
45
+ * the same call.
46
+ */
47
+ export declare function disposeObject3D(root: DisposableObject3D): void;
48
+ export {};
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Frees the GPU resources behind an object that is no longer displayed.
3
+ *
4
+ * `scene.remove()` only unlinks: three keeps the geometry's buffers and the
5
+ * material's textures uploaded until they are disposed explicitly. Nothing in
6
+ * copper3d disposes what it creates, so anything that swaps models or evicts
7
+ * scenes needs this or its footprint is unbounded.
8
+ *
9
+ * Typed structurally rather than against `THREE.Object3D` so it also accepts
10
+ * the minimal shapes callers and tests hand around; a real three object
11
+ * satisfies these interfaces.
12
+ */
13
+ const TEXTURE_SLOTS = [
14
+ 'map',
15
+ 'normalMap',
16
+ 'roughnessMap',
17
+ 'metalnessMap',
18
+ 'aoMap',
19
+ 'emissiveMap',
20
+ 'alphaMap',
21
+ 'bumpMap',
22
+ 'displacementMap',
23
+ 'envMap',
24
+ 'lightMap',
25
+ 'specularMap',
26
+ ];
27
+ /**
28
+ * `Material.dispose()` does NOT cascade into its textures, so a canvas-backed
29
+ * or image-backed map stays on the GPU without this. Handles the array form
30
+ * too: a multi-material mesh would otherwise reach `Array.prototype.dispose`,
31
+ * which does not exist.
32
+ */
33
+ export function disposeMaterial(material) {
34
+ var _a;
35
+ if (!material)
36
+ return;
37
+ if (Array.isArray(material)) {
38
+ for (const one of material)
39
+ disposeMaterial(one);
40
+ return;
41
+ }
42
+ for (const slot of TEXTURE_SLOTS)
43
+ (_a = material[slot]) === null || _a === void 0 ? void 0 : _a.dispose();
44
+ material.dispose();
45
+ }
46
+ /**
47
+ * Works on a lone mesh as well as on a whole subtree -- `traverse` visits the
48
+ * root itself -- so a slice plane that was never added to a scene is freed by
49
+ * the same call.
50
+ */
51
+ export function disposeObject3D(root) {
52
+ root.traverse((child) => {
53
+ var _a;
54
+ if (!(child === null || child === void 0 ? void 0 : child.isMesh))
55
+ return;
56
+ (_a = child.geometry) === null || _a === void 0 ? void 0 : _a.dispose();
57
+ disposeMaterial(child.material);
58
+ });
59
+ }
60
+ //# sourceMappingURL=dispose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispose.js","sourceRoot":"","sources":["../../src/Utils/dispose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA2BH,MAAM,aAAa,GAAG;IACpB,KAAK;IACL,WAAW;IACX,cAAc;IACd,cAAc;IACd,OAAO;IACP,aAAa;IACb,UAAU;IACV,SAAS;IACT,iBAAiB;IACjB,QAAQ;IACR,UAAU;IACV,aAAa;CACL,CAAA;AAEV;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAsE;;IAEtE,IAAI,CAAC,QAAQ;QAAE,OAAM;IACrB,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,KAAK,MAAM,GAAG,IAAI,QAAQ;YAAE,eAAe,CAAC,GAAG,CAAC,CAAA;QAChD,OAAM;IACR,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,aAAa;QAAE,MAAA,QAAQ,CAAC,IAAI,CAAC,0CAAE,OAAO,EAAE,CAAA;IAC3D,QAAQ,CAAC,OAAO,EAAE,CAAA;AACpB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAwB;IACtD,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;;QACtB,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,CAAA;YAAE,OAAM;QAC1B,MAAA,KAAK,CAAC,QAAQ,0CAAE,OAAO,EAAE,CAAA;QACzB,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;AACJ,CAAC"}