copper3d 3.7.5 → 3.9.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.
Files changed (91) hide show
  1. package/dist/Controls/Copper3dTrackballControls.d.ts +25 -1
  2. package/dist/Controls/Copper3dTrackballControls.js +20 -0
  3. package/dist/Controls/Copper3dTrackballControls.js.map +1 -1
  4. package/dist/Controls/cameraTransitions.d.ts +87 -0
  5. package/dist/Controls/cameraTransitions.js +285 -0
  6. package/dist/Controls/cameraTransitions.js.map +1 -0
  7. package/dist/Controls/controlsAxes.d.ts +31 -0
  8. package/dist/Controls/controlsAxes.js +63 -0
  9. package/dist/Controls/controlsAxes.js.map +1 -0
  10. package/dist/Controls/fitView.d.ts +45 -0
  11. package/dist/Controls/fitView.js +40 -0
  12. package/dist/Controls/fitView.js.map +1 -0
  13. package/dist/Controls/gestureGate.d.ts +48 -0
  14. package/dist/Controls/gestureGate.js +67 -0
  15. package/dist/Controls/gestureGate.js.map +1 -0
  16. package/dist/Controls/orbitFraming.d.ts +39 -0
  17. package/dist/Controls/orbitFraming.js +39 -0
  18. package/dist/Controls/orbitFraming.js.map +1 -1
  19. package/dist/Controls/setCameraPose.d.ts +50 -0
  20. package/dist/Controls/setCameraPose.js +20 -0
  21. package/dist/Controls/setCameraPose.js.map +1 -0
  22. package/dist/Loader/copperGltfLoader.d.ts +35 -0
  23. package/dist/Loader/copperGltfLoader.js +43 -2
  24. package/dist/Loader/copperGltfLoader.js.map +1 -1
  25. package/dist/Loader/copperNrrdLoader.d.ts +47 -0
  26. package/dist/Loader/copperNrrdLoader.js +88 -42
  27. package/dist/Loader/copperNrrdLoader.js.map +1 -1
  28. package/dist/Loader/fastSliceRepaint.d.ts +56 -0
  29. package/dist/Loader/fastSliceRepaint.js +159 -0
  30. package/dist/Loader/fastSliceRepaint.js.map +1 -0
  31. package/dist/Loader/volumeBoundingBox.d.ts +44 -0
  32. package/dist/Loader/volumeBoundingBox.js +32 -0
  33. package/dist/Loader/volumeBoundingBox.js.map +1 -0
  34. package/dist/Renderer/copperRendererOnDemond.d.ts +21 -3
  35. package/dist/Renderer/copperRendererOnDemond.js +26 -2
  36. package/dist/Renderer/copperRendererOnDemond.js.map +1 -1
  37. package/dist/Renderer/disposeScene.d.ts +51 -0
  38. package/dist/Renderer/disposeScene.js +51 -0
  39. package/dist/Renderer/disposeScene.js.map +1 -0
  40. package/dist/Renderer/sceneBudget.d.ts +40 -0
  41. package/dist/Renderer/sceneBudget.js +86 -0
  42. package/dist/Renderer/sceneBudget.js.map +1 -0
  43. package/dist/Scene/copperMScene.d.ts +2 -1
  44. package/dist/Scene/copperMScene.js +4 -4
  45. package/dist/Scene/copperMScene.js.map +1 -1
  46. package/dist/Scene/copperScene.d.ts +2 -1
  47. package/dist/Scene/copperScene.js +6 -4
  48. package/dist/Scene/copperScene.js.map +1 -1
  49. package/dist/Scene/copperSceneOnDemond.d.ts +66 -3
  50. package/dist/Scene/copperSceneOnDemond.js +103 -7
  51. package/dist/Scene/copperSceneOnDemond.js.map +1 -1
  52. package/dist/Utils/dispose.d.ts +48 -0
  53. package/dist/Utils/dispose.js +60 -0
  54. package/dist/Utils/dispose.js.map +1 -0
  55. package/dist/Utils/kiwrious/configKiwrious.d.ts +23 -1
  56. package/dist/Utils/kiwrious/configKiwrious.js +154 -42
  57. package/dist/Utils/kiwrious/configKiwrious.js.map +1 -1
  58. package/dist/Utils/modelCrossfade.d.ts +36 -0
  59. package/dist/Utils/modelCrossfade.js +46 -0
  60. package/dist/Utils/modelCrossfade.js.map +1 -0
  61. package/dist/Utils/volumeExposure.d.ts +32 -0
  62. package/dist/Utils/volumeExposure.js +104 -0
  63. package/dist/Utils/volumeExposure.js.map +1 -0
  64. package/dist/bundle.esm.js +63653 -51923
  65. package/dist/bundle.umd.js +63701 -51933
  66. package/dist/index.d.ts +32 -3
  67. package/dist/index.js +17 -2
  68. package/dist/index.js.map +1 -1
  69. package/dist/types/Controls/Copper3dTrackballControls.d.ts +25 -1
  70. package/dist/types/Controls/cameraTransitions.d.ts +87 -0
  71. package/dist/types/Controls/controlsAxes.d.ts +31 -0
  72. package/dist/types/Controls/fitView.d.ts +45 -0
  73. package/dist/types/Controls/gestureGate.d.ts +48 -0
  74. package/dist/types/Controls/orbitFraming.d.ts +39 -0
  75. package/dist/types/Controls/setCameraPose.d.ts +50 -0
  76. package/dist/types/Loader/copperGltfLoader.d.ts +35 -0
  77. package/dist/types/Loader/copperNrrdLoader.d.ts +47 -0
  78. package/dist/types/Loader/fastSliceRepaint.d.ts +56 -0
  79. package/dist/types/Loader/volumeBoundingBox.d.ts +44 -0
  80. package/dist/types/Renderer/copperRendererOnDemond.d.ts +21 -3
  81. package/dist/types/Renderer/disposeScene.d.ts +51 -0
  82. package/dist/types/Renderer/sceneBudget.d.ts +40 -0
  83. package/dist/types/Scene/copperMScene.d.ts +2 -1
  84. package/dist/types/Scene/copperScene.d.ts +2 -1
  85. package/dist/types/Scene/copperSceneOnDemond.d.ts +66 -3
  86. package/dist/types/Utils/dispose.d.ts +48 -0
  87. package/dist/types/Utils/kiwrious/configKiwrious.d.ts +23 -1
  88. package/dist/types/Utils/modelCrossfade.d.ts +36 -0
  89. package/dist/types/Utils/volumeExposure.d.ts +32 -0
  90. package/dist/types/index.d.ts +32 -3
  91. package/package.json +7 -3
@@ -0,0 +1,63 @@
1
+ /**
2
+ * One way to ask about, and set, whether a controls instance may rotate, pan
3
+ * or zoom.
4
+ *
5
+ * There are two spellings in play and they are opposites. `OrbitControls` (and
6
+ * `Copper3dOrbitControls`) use positive `enableRotate` / `enablePan` /
7
+ * `enableZoom`; `TrackballControls` and `Copper3dTrackballControls` use
8
+ * negative `noRotate` / `noPan` / `noZoom`. Neither class complains about the
9
+ * other's property name -- it lands as an unread extra field -- so writing the
10
+ * wrong one is a SILENT no-op, and code that has to work with whatever
11
+ * controls a scene happens to be carrying gets it wrong sooner or later.
12
+ *
13
+ * Deliberately structural and free of `three`: a caller holding a controls
14
+ * instance out of a published bundle can still pass it here.
15
+ */
16
+ function read(controls, axis) {
17
+ const negative = controls[`no${axis}`];
18
+ if (typeof negative === "boolean")
19
+ return !negative;
20
+ const positive = controls[`enable${axis}`];
21
+ if (typeof positive === "boolean")
22
+ return positive;
23
+ // Neither spelling present: nothing is gating the axis, so it is on.
24
+ return true;
25
+ }
26
+ function write(controls, axis, enabled) {
27
+ const target = controls;
28
+ // Whichever spellings exist, all of them -- an instance carrying both (a
29
+ // wrapper, or a caller who already wrote the wrong one once) must not be
30
+ // left disagreeing with itself.
31
+ let written = false;
32
+ if (typeof target[`no${axis}`] === "boolean") {
33
+ target[`no${axis}`] = !enabled;
34
+ written = true;
35
+ }
36
+ if (typeof target[`enable${axis}`] === "boolean") {
37
+ target[`enable${axis}`] = enabled;
38
+ written = true;
39
+ }
40
+ // Nothing to write to means the controls class does not gate this axis;
41
+ // inventing the property would be a lie the class never reads.
42
+ if (!written)
43
+ return;
44
+ }
45
+ export function isRotateEnabled(controls) {
46
+ return read(controls, "Rotate");
47
+ }
48
+ export function setRotateEnabled(controls, enabled) {
49
+ write(controls, "Rotate", enabled);
50
+ }
51
+ export function isPanEnabled(controls) {
52
+ return read(controls, "Pan");
53
+ }
54
+ export function setPanEnabled(controls, enabled) {
55
+ write(controls, "Pan", enabled);
56
+ }
57
+ export function isZoomEnabled(controls) {
58
+ return read(controls, "Zoom");
59
+ }
60
+ export function setZoomEnabled(controls, enabled) {
61
+ write(controls, "Zoom", enabled);
62
+ }
63
+ //# sourceMappingURL=controlsAxes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controlsAxes.js","sourceRoot":"","sources":["../../src/Controls/controlsAxes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAeH,SAAS,IAAI,CAAC,QAA2B,EAAE,IAAU;IACnD,MAAM,QAAQ,GAAI,QAAoC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACpE,IAAI,OAAO,QAAQ,KAAK,SAAS;QAAE,OAAO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QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,QAA2B;IACvD,OAAO,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,QAA2B,EAC3B,OAAgB;IAEhB,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { CameraViewPreset, FitBounds } from './orbitFraming';
2
+ /**
3
+ * Re-frames a scene on its content, keeping the view preset's direction.
4
+ *
5
+ * A preset carries a hand-written `eyePosition`, which encodes both which way
6
+ * a reader should look at the data and how far away -- but only the direction
7
+ * is a decision. The distance has to follow the viewport: a fixed one cannot
8
+ * survive a viewport that is a third as wide as the one it was authored
9
+ * against, and hand-written values routinely leave the content filling a
10
+ * quarter of the frame.
11
+ *
12
+ * So the preset's view direction and up vector are kept exactly as authored
13
+ * and only the distance is recomputed.
14
+ *
15
+ * Written as a free function taking the scene as its first argument, so it
16
+ * can be called on an existing scene instance and unit-tested without a
17
+ * renderer. The scene class wraps it as a one-line method.
18
+ */
19
+ interface Vec3Like {
20
+ set: (x: number, y: number, z: number) => void;
21
+ }
22
+ export interface FitViewScene {
23
+ camera: {
24
+ fov: number;
25
+ position: Vec3Like;
26
+ lookAt: (x: number, y: number, z: number) => void;
27
+ updateProjectionMatrix: () => void;
28
+ };
29
+ controls: {
30
+ /** OrbitControls / TrackballControls' orbit pivot. */
31
+ target?: Vec3Like;
32
+ /** TrackballControls caches the canvas's page box and recomputes it only
33
+ * here; OrbitControls measures per event and does not define this. */
34
+ handleResize?: () => void;
35
+ };
36
+ }
37
+ /**
38
+ * Returns false when there is nothing to do -- a preset whose eye sits
39
+ * exactly on its target has no direction to preserve.
40
+ *
41
+ * Does NOT render. The caller decides when to draw, which matters under
42
+ * on-demand rendering where this may be one of several changes in a frame.
43
+ */
44
+ export declare function fitView(scene: FitViewScene, preset: CameraViewPreset, aspect: number, bounds: FitBounds, margin?: number): boolean;
45
+ export {};
@@ -0,0 +1,40 @@
1
+ import { fitDistance } from './orbitFraming';
2
+ /**
3
+ * Returns false when there is nothing to do -- a preset whose eye sits
4
+ * exactly on its target has no direction to preserve.
5
+ *
6
+ * Does NOT render. The caller decides when to draw, which matters under
7
+ * on-demand rendering where this may be one of several changes in a frame.
8
+ */
9
+ export function fitView(scene, preset, aspect, bounds, margin) {
10
+ var _a, _b, _c;
11
+ const [px = 0, py = 0, pz = 0] = preset.targetPosition;
12
+ const [ex = 0, ey = 0, ez = 0] = preset.eyePosition;
13
+ const dx = ex - px;
14
+ const dy = ey - py;
15
+ const dz = ez - pz;
16
+ const length = Math.hypot(dx, dy, dz);
17
+ if (length === 0)
18
+ return false;
19
+ // Aim at the object's own centre, not at the preset's target. Presets
20
+ // target the origin, which is right for a volume whose RAS dimensions are
21
+ // centred there and wrong for a model whose bounding box is not -- framing
22
+ // one of those from the origin pushes part of it out of frame, which a
23
+ // narrow viewport makes obvious.
24
+ const [cx, cy, cz] = bounds.center;
25
+ const tx = px + cx;
26
+ const ty = py + cy;
27
+ const tz = pz + cz;
28
+ const distance = fitDistance(bounds, aspect, scene.camera.fov, margin);
29
+ scene.camera.position.set(tx + (dx / length) * distance, ty + (dy / length) * distance, tz + (dz / length) * distance);
30
+ scene.camera.lookAt(tx, ty, tz);
31
+ // LOAD-BEARING. Nothing syncs the controls' orbit pivot with
32
+ // `camera.lookAt()`, so without this the user's next drag calls
33
+ // `controls.update()`, which re-aims the camera at whatever `target` still
34
+ // held -- silently undoing everything above.
35
+ (_a = scene.controls.target) === null || _a === void 0 ? void 0 : _a.set(tx, ty, tz);
36
+ scene.camera.updateProjectionMatrix();
37
+ (_c = (_b = scene.controls).handleResize) === null || _c === void 0 ? void 0 : _c.call(_b);
38
+ return true;
39
+ }
40
+ //# sourceMappingURL=fitView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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C,EAAE,GAAG,MAAM,CAAC,GAAG,QAAQ,EAC7B,EAAE,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,QAAQ,EAC7B,EAAE,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,QAAQ,CAC9B,CAAA;IACD,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;IAC/B,6DAA6D;IAC7D,gEAAgE;IAChE,2EAA2E;IAC3E,6CAA6C;IAC7C,MAAA,KAAK,CAAC,QAAQ,CAAC,MAAM,0CAAE,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;IACtC,KAAK,CAAC,MAAM,CAAC,sBAAsB,EAAE,CAAA;IACrC,MAAA,MAAA,KAAK,CAAC,QAAQ,EAAC,YAAY,kDAAI,CAAA;IAC/B,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { AxisGatedControls } from "./controlsAxes";
2
+ /**
3
+ * Suppresses camera axes for the duration of a gesture that means something
4
+ * else -- scrubbing a slice plane, dragging an annotation anchor, painting on
5
+ * a mesh -- and puts back exactly what was there before.
6
+ *
7
+ * ## Restore what was there, never `true`
8
+ *
9
+ * This is the whole reason to have a helper rather than two assignments. The
10
+ * obvious hand-rolled version disables the axis on pointerdown and re-enables
11
+ * it on pointerup, and it is wrong on any view that was ALREADY locked: a 2D
12
+ * modality with rotation deliberately turned off silently becomes orbitable
13
+ * the first time the reader scrubs it, and nothing ever turns it back off.
14
+ *
15
+ * ## Attach the listener in the CAPTURE phase
16
+ *
17
+ * The gate cannot do this for you, and getting it wrong costs a whole
18
+ * gesture. `Copper3dTrackballControls` listens on the canvas in the bubble
19
+ * phase and latches its rotate state inside its own `pointerdown` handler
20
+ * (`onMouseDown` reads `noRotate` there and copies the pointer position). A
21
+ * listener that opens the gate in the bubble phase runs after that, so the
22
+ * first gesture both scrubs AND orbits:
23
+ *
24
+ * ```ts
25
+ * el.addEventListener("pointerdown", onDown, true); // <- the `true`
26
+ * ```
27
+ *
28
+ * ## Nesting
29
+ *
30
+ * Gates on the same controls object refcount. The first one captures and
31
+ * suppresses; the last one released restores. Each releaser is idempotent, so
32
+ * calling it from both `pointerup` and `pointercancel` is safe.
33
+ */
34
+ export interface GestureAxes {
35
+ /** Default `true` -- rotation is what a drag gesture collides with. */
36
+ rotate?: boolean;
37
+ pan?: boolean;
38
+ zoom?: boolean;
39
+ }
40
+ /**
41
+ * Suppresses the requested axes and returns the function that restores them.
42
+ *
43
+ * @param controls the scene's controls; trackball or orbit, either spelling
44
+ * @param axes which axes the gesture needs; rotate only by default
45
+ */
46
+ export declare function beginGesture(controls: AxisGatedControls, axes?: GestureAxes): () => void;
47
+ /** Whether a gesture currently holds this controls object. Mainly for tests. */
48
+ export declare function isGestureActive(controls: AxisGatedControls): boolean;
@@ -0,0 +1,67 @@
1
+ import { isPanEnabled, isRotateEnabled, isZoomEnabled, setPanEnabled, setRotateEnabled, setZoomEnabled, } from "./controlsAxes";
2
+ const active = new WeakMap();
3
+ /**
4
+ * Suppresses the requested axes and returns the function that restores them.
5
+ *
6
+ * @param controls the scene's controls; trackball or orbit, either spelling
7
+ * @param axes which axes the gesture needs; rotate only by default
8
+ */
9
+ export function beginGesture(controls, axes = {}) {
10
+ var _a, _b, _c;
11
+ const wantRotate = (_a = axes.rotate) !== null && _a !== void 0 ? _a : true;
12
+ const wantPan = (_b = axes.pan) !== null && _b !== void 0 ? _b : false;
13
+ const wantZoom = (_c = axes.zoom) !== null && _c !== void 0 ? _c : false;
14
+ let gate = active.get(controls);
15
+ if (!gate) {
16
+ // Captured BEFORE anything is suppressed, which is the point.
17
+ gate = {
18
+ holders: 0,
19
+ rotate: wantRotate ? isRotateEnabled(controls) : undefined,
20
+ pan: wantPan ? isPanEnabled(controls) : undefined,
21
+ zoom: wantZoom ? isZoomEnabled(controls) : undefined,
22
+ };
23
+ active.set(controls, gate);
24
+ }
25
+ else {
26
+ // A nested gate may ask for an axis the outer one did not. Capture that
27
+ // one too, still from its pre-suppression value.
28
+ if (wantRotate && gate.rotate === undefined)
29
+ gate.rotate = isRotateEnabled(controls);
30
+ if (wantPan && gate.pan === undefined)
31
+ gate.pan = isPanEnabled(controls);
32
+ if (wantZoom && gate.zoom === undefined)
33
+ gate.zoom = isZoomEnabled(controls);
34
+ }
35
+ gate.holders += 1;
36
+ if (wantRotate)
37
+ setRotateEnabled(controls, false);
38
+ if (wantPan)
39
+ setPanEnabled(controls, false);
40
+ if (wantZoom)
41
+ setZoomEnabled(controls, false);
42
+ let released = false;
43
+ return function release() {
44
+ if (released)
45
+ return;
46
+ released = true;
47
+ const current = active.get(controls);
48
+ if (!current)
49
+ return;
50
+ current.holders -= 1;
51
+ if (current.holders > 0)
52
+ return;
53
+ if (current.rotate !== undefined)
54
+ setRotateEnabled(controls, current.rotate);
55
+ if (current.pan !== undefined)
56
+ setPanEnabled(controls, current.pan);
57
+ if (current.zoom !== undefined)
58
+ setZoomEnabled(controls, current.zoom);
59
+ active.delete(controls);
60
+ };
61
+ }
62
+ /** Whether a gesture currently holds this controls object. Mainly for tests. */
63
+ export function isGestureActive(controls) {
64
+ var _a, _b;
65
+ return ((_b = (_a = active.get(controls)) === null || _a === void 0 ? void 0 : _a.holders) !== null && _b !== void 0 ? _b : 0) > 0;
66
+ }
67
+ //# sourceMappingURL=gestureGate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gestureGate.js","sourceRoot":"","sources":["../../src/Controls/gestureGate.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,eAAe,EACf,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,cAAc,GACf,MAAM,gBAAgB,CAAC;AAiDxB,MAAM,MAAM,GAAG,IAAI,OAAO,EAAsB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,QAA2B,EAC3B,OAAoB,EAAE;;IAEtB,MAAM,UAAU,GAAG,MAAA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aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC5C,IAAI,QAAQ;QAAE,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAE9C,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,OAAO,SAAS,OAAO;QACrB,IAAI,QAAQ;YAAE,OAAO;QACrB,QAAQ,GAAG,IAAI,CAAC;QAEhB,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACrC,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC;QACrB,IAAI,OAAO,CAAC,OAAO,GAAG,CAAC;YAAE,OAAO;QAEhC,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;YAAE,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7E,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS;YAAE,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QACpE,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;YAAE,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QACvE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1B,CAAC,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,eAAe,CAAC,QAA2B;;IACzD,OAAO,CAAC,MAAA,MAAA,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,0CAAE,OAAO,mCAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC"}
@@ -69,3 +69,42 @@ export declare function resolveViewPose(preset: CameraViewPreset, pivot: THREE.V
69
69
  * frameBox, OrbitControls' maxDistance is still the default Infinity.
70
70
  */
71
71
  export declare function resolveFarPlane(presetFar: number, maxDistance: number, dist: number): number;
72
+ export interface FitBounds {
73
+ width: number;
74
+ height: number;
75
+ depth: number;
76
+ /** The box's centre in scene units. `[0, 0, 0]` for an NRRD volume, whose
77
+ * RAS dimensions describe a box centred on the origin; a GLB's is not,
78
+ * so framing one from the origin leaves part of it out of frame. Not read
79
+ * by `fitDistance`, which only needs the extents. */
80
+ center: [number, number, number];
81
+ }
82
+ /**
83
+ * How far a perspective camera must sit from an object's centre for the whole
84
+ * object to fit in frame.
85
+ *
86
+ * Unlike `computeFraming` above this takes the viewport's ASPECT into
87
+ * account: below aspect 1 the horizontal field is the narrower of the two,
88
+ * and it is the narrower one that has to contain the object. A camera framed
89
+ * on vertical FOV alone under-frames every tall, narrow viewport.
90
+ *
91
+ * It also fits the bounding SPHERE rather than the box. Fitting the facing
92
+ * box face plus half the depth frames each object by whichever dimension
93
+ * happens to point at the camera, so a thin slab and a near-cubic volume of
94
+ * similar overall extent come out at wildly different sizes on screen. A
95
+ * sphere has no orientation, so comparable objects get comparable screen
96
+ * size -- and orbiting can no longer push a corner out of frame.
97
+ *
98
+ * @param aspect Viewport width / height. Zero or non-finite is treated as 1:
99
+ * a viewport mid-collapse measures 0 for a frame, and NaN in a
100
+ * projection matrix is unrecoverable.
101
+ * @param fovDeg The camera's VERTICAL field of view, in degrees.
102
+ * @param margin Multiplier applied at the end, and deliberately BELOW 1. A
103
+ * bounding sphere circumscribes the object -- a cube's has
104
+ * 1.73x its half-side -- so fitting the sphere exactly leaves
105
+ * the object filling well under half the frame. Letting the
106
+ * sphere overflow is what makes the object read at a sensible
107
+ * size. A tuning knob, not a correctness threshold: smaller
108
+ * means larger on screen.
109
+ */
110
+ export declare function fitDistance(bounds: FitBounds, aspect: number, fovDeg: number, margin?: number): number;
@@ -78,6 +78,45 @@ export function resolveFarPlane(presetFar, maxDistance, dist) {
78
78
  const zoomOutFar = Number.isFinite(maxDistance) ? maxDistance + dist : 0;
79
79
  return Math.max(presetFar, zoomOutFar);
80
80
  }
81
+ /** Nothing smaller than this, so a degenerate or not-yet-measured box can
82
+ * never put the camera at the origin looking at itself. */
83
+ const MIN_FIT_DISTANCE = 1e-3;
84
+ /**
85
+ * How far a perspective camera must sit from an object's centre for the whole
86
+ * object to fit in frame.
87
+ *
88
+ * Unlike `computeFraming` above this takes the viewport's ASPECT into
89
+ * account: below aspect 1 the horizontal field is the narrower of the two,
90
+ * and it is the narrower one that has to contain the object. A camera framed
91
+ * on vertical FOV alone under-frames every tall, narrow viewport.
92
+ *
93
+ * It also fits the bounding SPHERE rather than the box. Fitting the facing
94
+ * box face plus half the depth frames each object by whichever dimension
95
+ * happens to point at the camera, so a thin slab and a near-cubic volume of
96
+ * similar overall extent come out at wildly different sizes on screen. A
97
+ * sphere has no orientation, so comparable objects get comparable screen
98
+ * size -- and orbiting can no longer push a corner out of frame.
99
+ *
100
+ * @param aspect Viewport width / height. Zero or non-finite is treated as 1:
101
+ * a viewport mid-collapse measures 0 for a frame, and NaN in a
102
+ * projection matrix is unrecoverable.
103
+ * @param fovDeg The camera's VERTICAL field of view, in degrees.
104
+ * @param margin Multiplier applied at the end, and deliberately BELOW 1. A
105
+ * bounding sphere circumscribes the object -- a cube's has
106
+ * 1.73x its half-side -- so fitting the sphere exactly leaves
107
+ * the object filling well under half the frame. Letting the
108
+ * sphere overflow is what makes the object read at a sensible
109
+ * size. A tuning knob, not a correctness threshold: smaller
110
+ * means larger on screen.
111
+ */
112
+ export function fitDistance(bounds, aspect, fovDeg, margin = 0.85) {
113
+ const safeAspect = Number.isFinite(aspect) && aspect > 0 ? aspect : 1;
114
+ const vHalf = (fovDeg * Math.PI) / 360;
115
+ const hHalf = Math.atan(Math.tan(vHalf) * safeAspect);
116
+ const half = Math.min(vHalf, hHalf);
117
+ const radius = Math.hypot(bounds.width, bounds.height, bounds.depth) / 2;
118
+ return Math.max((radius / Math.sin(half)) * margin, MIN_FIT_DISTANCE);
119
+ }
81
120
  /** Project up onto the plane perpendicular to dir; fall back to any perpendicular axis when degenerate. */
82
121
  function orthogonalize(up, dir) {
83
122
  const d = up.dot(dir);
@@ -1 +1 @@
1
- {"version":3,"file":"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Q,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG;YACpC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YAC5B,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QAC9B,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAA;IAChF,CAAC;IACD,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAA;AAClE,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { Pose } from "./cameraTransitions";
2
+ /**
3
+ * Writes a camera pose onto a scene, including the one line everybody forgets.
4
+ *
5
+ * Moving a camera programmatically is three obvious assignments and one
6
+ * non-obvious one:
7
+ *
8
+ * camera.position.set(...)
9
+ * camera.up.set(...)
10
+ * camera.lookAt(...)
11
+ * controls.target.set(...) // <- this one
12
+ *
13
+ * Nothing in copper3d syncs the controls' orbit pivot with `camera.lookAt()`.
14
+ * Leave that last line out and everything appears to work until the user
15
+ * touches the mouse: the first drag calls `controls.update()`, which re-aims
16
+ * the camera at whatever `target` still held, silently undoing the move. The
17
+ * symptom -- "the camera jumps back the moment I drag" -- points at the
18
+ * controls rather than at the code that actually caused it.
19
+ *
20
+ * A free function taking the scene first, so it works on a scene instance from
21
+ * a published bundle and is unit-testable without a renderer. The scene class
22
+ * wraps it as a one-line method.
23
+ *
24
+ * `fitView` does the same thing for the specific case of re-framing on
25
+ * content; this is the general one, for a pose you already have.
26
+ */
27
+ interface Vec3Like {
28
+ set: (x: number, y: number, z: number) => void;
29
+ }
30
+ export interface PosableScene {
31
+ camera: {
32
+ position: Vec3Like;
33
+ up: Vec3Like;
34
+ lookAt: (x: number, y: number, z: number) => void;
35
+ updateProjectionMatrix?: () => void;
36
+ };
37
+ controls?: {
38
+ /** OrbitControls / TrackballControls' orbit pivot. */
39
+ target?: Vec3Like;
40
+ /** TrackballControls caches the canvas's page box and recomputes it only
41
+ * here; OrbitControls measures per event and does not define this. */
42
+ handleResize?: () => void;
43
+ };
44
+ }
45
+ /**
46
+ * Does NOT render. The caller decides when to draw, which matters under
47
+ * on-demand rendering where this may be one of several changes in a frame.
48
+ */
49
+ export declare function setCameraPose(scene: PosableScene, pose: Pose): void;
50
+ export {};
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Does NOT render. The caller decides when to draw, which matters under
3
+ * on-demand rendering where this may be one of several changes in a frame.
4
+ */
5
+ export function setCameraPose(scene, pose) {
6
+ var _a, _b, _c, _d, _e, _f;
7
+ const [px, py, pz] = pose.position;
8
+ const [ux, uy, uz] = pose.up;
9
+ const [tx, ty, tz] = pose.target;
10
+ scene.camera.position.set(px, py, pz);
11
+ // Before `lookAt`, which builds the camera's basis from `up`. Setting it
12
+ // afterwards leaves the roll from the previous pose in place until
13
+ // something else re-aims the camera.
14
+ scene.camera.up.set(ux, uy, uz);
15
+ scene.camera.lookAt(tx, ty, tz);
16
+ (_b = (_a = scene.controls) === null || _a === void 0 ? void 0 : _a.target) === null || _b === void 0 ? void 0 : _b.set(tx, ty, tz);
17
+ (_d = (_c = scene.camera).updateProjectionMatrix) === null || _d === void 0 ? void 0 : _d.call(_c);
18
+ (_f = (_e = scene.controls) === null || _e === void 0 ? void 0 : _e.handleResize) === null || _f === void 0 ? void 0 : _f.call(_e);
19
+ }
20
+ //# sourceMappingURL=setCameraPose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setCameraPose.js","sourceRoot":"","sources":["../../src/Controls/setCameraPose.ts"],"names":[],"mappings":"AAgDA;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAmB,EAAE,IAAU;;IAC3D,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;IACnC,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IAEjC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACtC,yEAAyE;IACzE,mEAAmE;IACnE,qCAAqC;IACrC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAChC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAEhC,MAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,MAAM,0CAAE,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACxC,MAAA,MAAA,KAAK,CAAC,MAAM,EAAC,sBAAsB,kDAAI,CAAC;IACxC,MAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,YAAY,kDAAI,CAAC;AACnC,CAAC"}
@@ -1,3 +1,38 @@
1
1
  import * as THREE from "three";
2
2
  import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
3
+ /**
4
+ * Points the Draco decoder at `path`, which must end in a slash -- three
5
+ * appends `draco_wasm_wrapper.js` and `draco_decoder.wasm` to it directly.
6
+ *
7
+ * On a subpath deploy the base URL has to be included: a decoder served from
8
+ * `/te-uma/draco/` is not found at `/draco/`.
9
+ *
10
+ * Call once at startup. The decoder module is fetched on first use and cached
11
+ * inside `DRACOLoader`, so a later change does not re-fetch it.
12
+ */
13
+ export declare function setDracoDecoderPath(path: string): void;
14
+ /** The same, for the Basis/KTX2 transcoder. Also expects a trailing slash. */
15
+ export declare function setKTX2TranscoderPath(path: string): void;
16
+ /**
17
+ * Optional callbacks for `scene.loadGltf`.
18
+ *
19
+ * Until 3.9.0 there were none, and the third argument every `loadGltf` passed
20
+ * to `GLTFLoader.load` was an empty function NAMED `error` sitting in the
21
+ * *onProgress* slot -- so a failed fetch or a corrupt file invoked nothing at
22
+ * all, and the caller's `callback` simply never fired. A load that fails and a
23
+ * load that is merely slow were indistinguishable from outside.
24
+ */
25
+ export interface GltfLoadOpts {
26
+ /** Download progress. Fires only when the server sends a Content-Length. */
27
+ onProgress?: (event: ProgressEvent) => void;
28
+ /** Fetch or parse failure. The one signal that a load is never coming. */
29
+ onError?: (error: unknown) => void;
30
+ }
31
+ /**
32
+ * A GLTFLoader wired to the shared Draco and KTX2 loaders.
33
+ *
34
+ * Exported so callers who need their own loader -- their own
35
+ * `LoadingManager`, `onError`, or a load not going through a copper3d scene --
36
+ * do not have to rebuild the decoder wiring and get the paths right again.
37
+ */
3
38
  export declare function copperGltfLoader(renderer: THREE.WebGLRenderer): GLTFLoader;
@@ -2,10 +2,51 @@ import * as THREE from "three";
2
2
  import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
3
3
  import { KTX2Loader } from "three/examples/jsm/loaders/KTX2Loader.js";
4
4
  import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader.js";
5
+ /**
6
+ * Where the Draco decoder and Basis transcoder are fetched from.
7
+ *
8
+ * The default reaches unpkg for the same three revision this build uses. It is
9
+ * `examples/jsm/`, NOT `examples/js/` -- three removed the latter long ago, so
10
+ * the path this defaulted to before 3.9.0 404'd, and every Draco-compressed
11
+ * GLB failed to load with a CORS error on the 404 rather than anything that
12
+ * named the real problem.
13
+ *
14
+ * Point these at your own copy with `setDracoDecoderPath` /
15
+ * `setKTX2TranscoderPath`. A CDN at runtime is a hard dependency an offline,
16
+ * air-gapped or firewalled deployment cannot satisfy, and the decoder is a few
17
+ * hundred KB you can ship yourself.
18
+ */
5
19
  const THREE_PATH = `https://unpkg.com/three@0.${THREE.REVISION}.x`;
6
20
  const MANAGER = new THREE.LoadingManager();
7
- const DRACO_LOADER = new DRACOLoader(MANAGER).setDecoderPath(`${THREE_PATH}/examples/js/libs/draco/gltf/`);
8
- const KTX2_LOADER = new KTX2Loader(MANAGER).setTranscoderPath(`${THREE_PATH}/examples/js/libs/basis`);
21
+ const DRACO_LOADER = new DRACOLoader(MANAGER).setDecoderPath(`${THREE_PATH}/examples/jsm/libs/draco/gltf/`);
22
+ // Trailing slash, which the pre-3.9.0 value also lacked: three concatenates
23
+ // the file name onto this string, so `.../libs/basis` asked for
24
+ // `libs/basisbasis_transcoder.js`.
25
+ const KTX2_LOADER = new KTX2Loader(MANAGER).setTranscoderPath(`${THREE_PATH}/examples/jsm/libs/basis/`);
26
+ /**
27
+ * Points the Draco decoder at `path`, which must end in a slash -- three
28
+ * appends `draco_wasm_wrapper.js` and `draco_decoder.wasm` to it directly.
29
+ *
30
+ * On a subpath deploy the base URL has to be included: a decoder served from
31
+ * `/te-uma/draco/` is not found at `/draco/`.
32
+ *
33
+ * Call once at startup. The decoder module is fetched on first use and cached
34
+ * inside `DRACOLoader`, so a later change does not re-fetch it.
35
+ */
36
+ export function setDracoDecoderPath(path) {
37
+ DRACO_LOADER.setDecoderPath(path);
38
+ }
39
+ /** The same, for the Basis/KTX2 transcoder. Also expects a trailing slash. */
40
+ export function setKTX2TranscoderPath(path) {
41
+ KTX2_LOADER.setTranscoderPath(path);
42
+ }
43
+ /**
44
+ * A GLTFLoader wired to the shared Draco and KTX2 loaders.
45
+ *
46
+ * Exported so callers who need their own loader -- their own
47
+ * `LoadingManager`, `onError`, or a load not going through a copper3d scene --
48
+ * do not have to rebuild the decoder wiring and get the paths right again.
49
+ */
9
50
  export function copperGltfLoader(renderer) {
10
51
  const loader = new GLTFLoader(MANAGER)
11
52
  .setCrossOrigin("anonymous")
@@ -1 +1 @@
1
- {"version":3,"file":"copperGltfLoader.js","sourceRoot":"","sources":["../../src/Loader/copperGltfLoader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAQ,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAExE,MAAM,UAAU,GAAG,6BAA6B,KAAK,CAAC,QAAQ,IAAI,CAAC;AACnE,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,cAAc,EAAE,CAAC;AAC3C,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,cAAc,CAC1D,GAAG,UAAU,+BAA+B,CAC7C,CAAC;AACF,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,iBAAiB,CAC3D,GAAG,UAAU,yBAAyB,CACvC,CAAC;AAEF,MAAM,UAAU,gBAAgB,CAAC,QAA6B;IAC5D,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC;SACnC,cAAc,CAAC,WAAW,CAAC;SAC3B,cAAc,CAAC,YAAY,CAAC;SAC5B,aAAa,CAAC,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtD,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"copperGltfLoader.js","sourceRoot":"","sources":["../../src/Loader/copperGltfLoader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAExE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,GAAG,6BAA6B,KAAK,CAAC,QAAQ,IAAI,CAAC;AAEnE,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,cAAc,EAAE,CAAC;AAC3C,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,cAAc,CAC1D,GAAG,UAAU,gCAAgC,CAC9C,CAAC;AACF,4EAA4E;AAC5E,gEAAgE;AAChE,mCAAmC;AACnC,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,iBAAiB,CAC3D,GAAG,UAAU,2BAA2B,CACzC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,WAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAkBD;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAA6B;IAC5D,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC;SACnC,cAAc,CAAC,WAAW,CAAC;SAC3B,cAAc,CAAC,YAAY,CAAC;SAC5B,aAAa,CAAC,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -3,11 +3,58 @@ import { copperScene } from "../Scene/copperScene";
3
3
  import { GUI } from "dat.gui";
4
4
  import { nrrdMeshesType, nrrdSliceType, loadingBarType } from "../types/types";
5
5
  import { Copper3dTrackballControls } from "../Controls/Copper3dTrackballControls";
6
+ /** A slice axis, in the sense `Volume.extractSlice` uses. */
7
+ export type NrrdAxis = "x" | "y" | "z";
8
+ /** All three, which is what `loadNrrd` has always extracted. */
9
+ export declare const DEFAULT_AXES: readonly NrrdAxis[];
6
10
  export interface optsType {
7
11
  openGui: boolean;
8
12
  container?: HTMLDivElement;
13
+ /**
14
+ * Which slice planes to extract. Defaults to all three, i.e. exactly what
15
+ * previous versions did.
16
+ *
17
+ * Narrow it when you display fewer. `extractSlice` walks the whole volume
18
+ * per call and the result is retained on `volume.sliceList` for the volume's
19
+ * lifetime, so an axis you never show costs a full pass over a 50MB buffer
20
+ * plus a geometry, a material and a canvas-backed texture that nothing ever
21
+ * frees.
22
+ *
23
+ * ::: warning
24
+ * The omitted axes are `undefined` on the `nrrdMeshes` / `nrrdSlices` the
25
+ * callback receives. Their types still declare all three present -- widening
26
+ * them to optional would break every existing caller's compile -- so a
27
+ * caller that narrows `axes` is responsible for only reading what it asked
28
+ * for.
29
+ * :::
30
+ */
31
+ axes?: readonly NrrdAxis[];
32
+ /**
33
+ * Download progress, in ADDITION to the built-in loading bar -- that keeps
34
+ * writing its percentage into `loadingBar.progress` exactly as before.
35
+ *
36
+ * New in 3.9.0. Until then the loading bar's text was the only progress
37
+ * signal copper3d exposed, so a caller that needed to know a large download
38
+ * was still alive had to watch that DOM node for mutations.
39
+ */
40
+ onProgress?: (event: ProgressEvent) => void;
41
+ /**
42
+ * Fetch or parse failure. New in 3.9.0; there was no error channel at all
43
+ * before, so a failed volume was indistinguishable from a slow one and the
44
+ * `callback` simply never fired.
45
+ */
46
+ onError?: (error: unknown) => void;
9
47
  }
10
48
  export declare function copperNrrdLoader(url: string, loadingBar: loadingBarType, segmentation: boolean, callback?: (volume: any, nrrdMeshes: nrrdMeshesType, nrrdSlices: nrrdSliceType, gui?: GUI) => void, opts?: optsType): void;
11
49
  export declare function copperNrrdTexture3dLoader(url: string, scene: THREE.Scene, container: HTMLDivElement, callback?: (volume: any, gui?: GUI) => void): void;
12
50
  export declare function getWholeSlices(nrrdSlices: nrrdSliceType, scene: THREE.Scene, gui: GUI, controls: Copper3dTrackballControls): void;
51
+ /**
52
+ * @deprecated Since 3.9.0, use `addVolumeBoundingBox(scene, rasDimensions)`.
53
+ *
54
+ * Kept unchanged for callers passing their own `boxCube`, which works. The
55
+ * two-argument form does not: `cube` is declared in this module and never
56
+ * assigned, so it reaches `new THREE.BoxHelper(undefined)`. This also cannot
57
+ * take a `copperSceneOnDemond` -- a sibling of `copperScene`, not a descendant
58
+ * -- and sizes the box from `volume.matrix` rather than its RAS dimensions.
59
+ */
13
60
  export declare function addBoxHelper(scene: copperScene, volume: any, boxCube?: THREE.Object3D<THREE.Object3DEventMap>): void;