@needle-tools/three-mesh-effects 0.1.0 → 0.2.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 (34) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +114 -16
  3. package/build/hull-effects.js +5747 -0
  4. package/build/hull-effects.js.map +7 -0
  5. package/build/index.js +57 -0
  6. package/build/index.js.map +7 -0
  7. package/build/internal/rendering/hull-effect-metadata.js +136 -0
  8. package/build/internal/rendering/hull-effect-metadata.js.map +7 -0
  9. package/build/{wrap-effects.js → internal/rendering/hull-effect-runtime.js} +131 -64
  10. package/build/internal/rendering/hull-effect-runtime.js.map +7 -0
  11. package/build/internal/rendering/wrap-preview-settings.js +14 -10
  12. package/build/internal/rendering/wrap-preview-settings.js.map +2 -2
  13. package/build/internal/rendering/wrap-preview.js +33 -30
  14. package/build/internal/rendering/wrap-preview.js.map +2 -2
  15. package/build/types/public/hull-effects.d.ts +6 -0
  16. package/build/types/public/hull-effects.js +1 -0
  17. package/build/types/public/index.d.ts +23 -0
  18. package/build/types/public/index.js +1 -0
  19. package/build/types/rendering/hull-effect-metadata.d.ts +12 -0
  20. package/build/types/rendering/hull-effect-metadata.js +1 -0
  21. package/build/types/rendering/hull-effect-runtime.d.ts +39 -0
  22. package/build/types/rendering/hull-effect-runtime.js +1 -0
  23. package/build/types/rendering/wrap-preview-settings.d.ts +6 -7
  24. package/build/types/rendering/wrap-preview.d.ts +8 -6
  25. package/package.json +12 -6
  26. package/src/public/{wrap-effects.js → hull-effects.js} +7 -4
  27. package/src/public/index.js +73 -0
  28. package/src/rendering/hull-effect-metadata.js +27 -0
  29. package/src/rendering/hull-effect-runtime.js +89 -0
  30. package/src/rendering/wrap-preview-settings.js +7 -6
  31. package/src/rendering/wrap-preview.js +35 -32
  32. package/build/types/public/wrap-effects.d.ts +0 -4
  33. package/build/types/public/wrap-effects.js +0 -1
  34. package/build/wrap-effects.js.map +0 -7
@@ -0,0 +1,6 @@
1
+ export { captureWrapSkinPose } from "../rendering/wrap-skin.js";
2
+ export { bindHull, getHullEffect, NeedleHullEffectLoaderPlugin } from "../rendering/hull-effect-runtime.js";
3
+ export { NEEDLE_HULL_EFFECT, parseHullEffectDescriptor } from "../rendering/hull-effect-metadata.js";
4
+ export { createHullEffect, prepareIceNormalAttributes, prepareAuraGeometry, prepareRayGeometry } from "../rendering/wrap-preview.js";
5
+ export { HULL_EFFECT_MODES, HULL_EFFECT_CONTROLS, createHullEffectValues, isWrapTopology } from "../rendering/wrap-preview-settings.js";
6
+ export { createBarycentricWireframeGeometry, createPreviewWireframeMaterial, applyPreviewWireframeBlendMode, parseWireframeBlendMode } from "../rendering/wireframe.js";
@@ -0,0 +1 @@
1
+ export * from '../../../src/public/hull-effects.js';
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Enable all Needle glTF extensions before calling load/loadAsync or parse/parseAsync.
3
+ * Handlers are imported only when a parsed asset declares their extension. Returns
4
+ * the same loader; repeated registration updates its renderer without adding plugins.
5
+ * Existing decoder and texture-loader configuration is preserved.
6
+ * Disabled optional extensions retain their portable fallback; disabled required
7
+ * extensions reject the load. Calling again replaces the options for future parses.
8
+ *
9
+ * @template {GLTFLoader} T
10
+ * @param {T} loader
11
+ * @param {Renderer} renderer
12
+ * @param {LoaderOptions} [options]
13
+ * @returns {T}
14
+ */
15
+ export function useLoader<T extends GLTFLoader>(loader: T, renderer: Renderer, options?: LoaderOptions): T;
16
+ export type GLTFLoader = import("three/addons/loaders/GLTFLoader.js").GLTFLoader;
17
+ export type GLTFParser = import("three/addons/loaders/GLTFLoader.js").GLTFParser;
18
+ export type GLTF = import("three/addons/loaders/GLTFLoader.js").GLTF;
19
+ export type Renderer = import("../impostor/impostor-node-material.js").ImpostorRenderer;
20
+ export type NeedleExtension = "NEEDLE_deformation_rig" | "NEEDLE_mesh_impostor" | "NEEDLE_pixel_impostor" | "NEEDLE_hull_effect";
21
+ export type LoaderOptions = {
22
+ disable?: readonly NeedleExtension[];
23
+ };
@@ -0,0 +1 @@
1
+ export * from '../../../src/public/index.js';
@@ -0,0 +1,12 @@
1
+ /** @typedef {{version: 1, mode: string, values: Record<string, number>}} HullEffectDescriptor */
2
+ /** Validate the runtime contract before building any shader graphs.
3
+ * @param {unknown} raw
4
+ * @returns {HullEffectDescriptor}
5
+ */
6
+ export function parseHullEffectDescriptor(raw: unknown): HullEffectDescriptor;
7
+ export const NEEDLE_HULL_EFFECT: "NEEDLE_hull_effect";
8
+ export type HullEffectDescriptor = {
9
+ version: 1;
10
+ mode: string;
11
+ values: Record<string, number>;
12
+ };
@@ -0,0 +1 @@
1
+ export * from '../../../src/rendering/hull-effect-metadata.js';
@@ -0,0 +1,39 @@
1
+ /** Get the automatically loaded hull effect for updating or disposing it.
2
+ * @param {Object3D} hull
3
+ */
4
+ export function getHullEffect(hull: Object3D): {
5
+ group: import("three").Group<import("three").Object3DEventMap>;
6
+ syncAnimation(): void;
7
+ update(next: Record<string, string | number>): boolean;
8
+ dispose(): void;
9
+ } | undefined;
10
+ /** Attach a borrowed original to a hull initialized by useLoader. Replaces its
11
+ * standalone effect with the same settings and sets up animation syncing.
12
+ * Advance the original's mixer before syncAnimation(). The original's resources
13
+ * remain owned by the caller. Pass null to return to a standalone effect.
14
+ * @param {Object3D} hull
15
+ * @param {Object3D | null} original
16
+ * @param {{animate?: boolean}} [options]
17
+ */
18
+ export function bindHull(hull: Object3D, original: Object3D | null, options?: {
19
+ animate?: boolean;
20
+ }): {
21
+ group: import("three").Group<import("three").Object3DEventMap>;
22
+ syncAnimation(): void;
23
+ update(next: Record<string, string | number>): boolean;
24
+ dispose(): void;
25
+ };
26
+ /** Three.js loader for scene-scoped hull effects. The portable hull stays in the
27
+ * glTF; supporting renderers build the selected effect after loading its scene.
28
+ */
29
+ export class NeedleHullEffectLoaderPlugin {
30
+ /** @param {import('three/addons/loaders/GLTFLoader.js').GLTFParser} parser */
31
+ constructor(parser: import("three/addons/loaders/GLTFLoader.js").GLTFParser);
32
+ name: string;
33
+ parser: import("three/addons/loaders/GLTFLoader.js").GLTFParser;
34
+ /** @param {import('three/addons/loaders/GLTFLoader.js').GLTF} result */
35
+ afterRoot(result: import("three/addons/loaders/GLTFLoader.js").GLTF): Promise<void>;
36
+ }
37
+ export type Object3D = import("three").Object3D;
38
+ export type HullEffect = ReturnType<typeof createHullEffect>;
39
+ import { createHullEffect } from './wrap-preview.js';
@@ -0,0 +1 @@
1
+ export * from '../../../src/rendering/hull-effect-runtime.js';
@@ -1,16 +1,15 @@
1
- export function createWrapPreviewValues(): {
2
- [k: string]: {
3
- [k: string]: number;
4
- };
5
- };
1
+ /** @returns {Record<string, Record<string, number> & {mode: string}>} */
2
+ export function createHullEffectValues(): Record<string, Record<string, number> & {
3
+ mode: string;
4
+ }>;
6
5
  /** Includes older reports whose wrap stages live inside material groups.
7
6
  * @param {unknown} topology
8
7
  * @returns {boolean}
9
8
  */
10
9
  export function isWrapTopology(topology: unknown): boolean;
11
- export const WRAP_PREVIEW_MODES: string[];
10
+ export const HULL_EFFECT_MODES: string[];
12
11
  /** @type {Record<string, {key: string, label: string, min: number, max: number, step: number, value: number, title: string, kind?: string}[]>} */
13
- export const WRAP_PREVIEW_CONTROLS: Record<string, {
12
+ export const HULL_EFFECT_CONTROLS: Record<string, {
14
13
  key: string;
15
14
  label: string;
16
15
  min: number;
@@ -17,22 +17,24 @@ export function prepareRayGeometry(source: THREE.BufferGeometry): THREE.BufferGe
17
17
  * before unloading the source or wrap. `update(values)` returns false when a
18
18
  * compile-time shader variant changed; create a new effect in that case.
19
19
  * @param {THREE.Object3D} asset
20
- * @param {THREE.Object3D} original
21
- * @param {string} mode
22
- * @param {Record<string, number>} values
20
+ * @param {THREE.Object3D | null} original Null renders the hull effect alone.
21
+ * @param {{mode: string, [key: string]: string | number}} effect
23
22
  * @param {{animate?: boolean,
24
23
  * geometry?: (source: THREE.BufferGeometry) => THREE.BufferGeometry,
25
24
  * material?: (source: THREE.Material, impostor: boolean, width: number, blend: 'white') => MeshBasicNodeMaterial}=} options
26
25
  */
27
- export function createWrapPreview(asset: THREE.Object3D, original: THREE.Object3D, mode: string, values: Record<string, number>, options?: {
26
+ export function createHullEffect(asset: THREE.Object3D, original: THREE.Object3D | null, effect: {
27
+ mode: string;
28
+ [key: string]: string | number;
29
+ }, options?: {
28
30
  animate?: boolean;
29
31
  geometry?: (source: THREE.BufferGeometry) => THREE.BufferGeometry;
30
32
  material?: (source: THREE.Material, impostor: boolean, width: number, blend: "white") => MeshBasicNodeMaterial;
31
33
  } | undefined): {
32
34
  group: THREE.Group<THREE.Object3DEventMap>;
33
35
  syncAnimation(): void;
34
- /** @param {Record<string, number>} next */
35
- update(next: Record<string, number>): boolean;
36
+ /** @param {Record<string, string | number>} next */
37
+ update(next: Record<string, string | number>): boolean;
36
38
  dispose(): void;
37
39
  };
38
40
  import * as THREE from 'three';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/three-mesh-effects",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Three.js loaders and TSL effects for Needle Mesh Baker outputs.",
5
5
  "keywords": [
6
6
  "three.js",
@@ -26,15 +26,20 @@
26
26
  "sideEffects": false,
27
27
  "engines": { "node": ">=22" },
28
28
  "exports": {
29
+ ".": {
30
+ "deno": "./src/public/index.js",
31
+ "types": "./build/types/public/index.d.ts",
32
+ "import": "./build/index.js"
33
+ },
29
34
  "./deformation-runtime": {
30
35
  "deno": "./src/public/deformation-runtime.ts",
31
36
  "types": "./build/types/public/deformation-runtime.d.ts",
32
37
  "import": "./build/deformation-runtime.js"
33
38
  },
34
- "./wrap-effects": {
35
- "deno": "./src/public/wrap-effects.js",
36
- "types": "./build/types/public/wrap-effects.d.ts",
37
- "import": "./build/wrap-effects.js"
39
+ "./hull-effects": {
40
+ "deno": "./src/public/hull-effects.js",
41
+ "types": "./build/types/public/hull-effects.d.ts",
42
+ "import": "./build/hull-effects.js"
38
43
  },
39
44
  "./pixel-impostor-runtime": {
40
45
  "deno": "./src/public/pixel-impostor-runtime.js",
@@ -73,9 +78,10 @@
73
78
  },
74
79
  "./package.json": "./package.json"
75
80
  },
76
- "files": ["build/", "src/", "README.md", "LICENSE"],
81
+ "files": ["build/", "src/", "README.md", "CHANGELOG.md", "LICENSE"],
77
82
  "scripts": {
78
83
  "build": "node scripts/build.mjs",
84
+ "test": "npm run build && node --test tests/use-loader.test.js",
79
85
  "prepare": "node scripts/prepare.mjs",
80
86
  "prepack": "npm run build",
81
87
  "test:packed-consumer": "node scripts/test-packed-consumer.mjs"
@@ -1,15 +1,18 @@
1
1
  // @ts-check
2
2
 
3
+ export { bindHull, getHullEffect, NeedleHullEffectLoaderPlugin } from '../rendering/hull-effect-runtime.js';
4
+ export { NEEDLE_HULL_EFFECT, parseHullEffectDescriptor } from '../rendering/hull-effect-metadata.js';
5
+
3
6
  export {
4
- createWrapPreview,
7
+ createHullEffect,
5
8
  prepareIceNormalAttributes,
6
9
  prepareAuraGeometry,
7
10
  prepareRayGeometry,
8
11
  } from '../rendering/wrap-preview.js';
9
12
  export {
10
- WRAP_PREVIEW_MODES,
11
- WRAP_PREVIEW_CONTROLS,
12
- createWrapPreviewValues,
13
+ HULL_EFFECT_MODES,
14
+ HULL_EFFECT_CONTROLS,
15
+ createHullEffectValues,
13
16
  isWrapTopology,
14
17
  } from '../rendering/wrap-preview-settings.js';
15
18
  export { captureWrapSkinPose } from '../rendering/wrap-skin.js';
@@ -0,0 +1,73 @@
1
+ // @ts-check
2
+
3
+ /** @typedef {import('three/addons/loaders/GLTFLoader.js').GLTFLoader} GLTFLoader */
4
+ /** @typedef {import('three/addons/loaders/GLTFLoader.js').GLTFParser} GLTFParser */
5
+ /** @typedef {import('three/addons/loaders/GLTFLoader.js').GLTF} GLTF */
6
+ /** @typedef {import('../impostor/impostor-node-material.js').ImpostorRenderer} Renderer */
7
+
8
+ /** @typedef {'NEEDLE_deformation_rig' | 'NEEDLE_mesh_impostor' | 'NEEDLE_pixel_impostor' | 'NEEDLE_hull_effect'} NeedleExtension */
9
+ /** @typedef {{disable?: readonly NeedleExtension[]}} LoaderOptions */
10
+
11
+ /** @type {WeakMap<GLTFLoader, {renderer: Renderer, disabled: Set<NeedleExtension>}>} */
12
+ const registrations = new WeakMap();
13
+
14
+ /**
15
+ * Enable all Needle glTF extensions before calling load/loadAsync or parse/parseAsync.
16
+ * Handlers are imported only when a parsed asset declares their extension. Returns
17
+ * the same loader; repeated registration updates its renderer without adding plugins.
18
+ * Existing decoder and texture-loader configuration is preserved.
19
+ * Disabled optional extensions retain their portable fallback; disabled required
20
+ * extensions reject the load. Calling again replaces the options for future parses.
21
+ *
22
+ * @template {GLTFLoader} T
23
+ * @param {T} loader
24
+ * @param {Renderer} renderer
25
+ * @param {LoaderOptions} [options]
26
+ * @returns {T}
27
+ */
28
+ export function useLoader(loader, renderer, options = {}) {
29
+ const disabled = new Set(options.disable);
30
+ const existing = registrations.get(loader);
31
+ if (existing) { existing.renderer = renderer; existing.disabled = disabled; return loader; }
32
+ const state = { renderer, disabled };
33
+ registrations.set(loader, state);
34
+
35
+ // Register each real extension name synchronously so GLTFLoader recognizes
36
+ // required extensions before asynchronous postprocessing starts.
37
+ /** @param {NeedleExtension} name @param {(parser: GLTFParser, result: GLTF, renderer: Renderer) => Promise<void>} apply */
38
+ const register = (name, apply) => {
39
+ loader.register(parser => {
40
+ const disabled = state.disabled.has(name);
41
+ const renderer = state.renderer;
42
+ return {
43
+ name,
44
+ async afterRoot(result) {
45
+ const json = /** @type {{extensionsUsed?: string[], extensionsRequired?: string[]}} */ (parser.json);
46
+ if (!json.extensionsUsed?.includes(name) && !json.extensionsRequired?.includes(name)) return;
47
+ if (disabled) {
48
+ if (json.extensionsRequired?.includes(name)) throw new Error(`Required glTF extension ${name} is disabled in useLoader.`);
49
+ return;
50
+ }
51
+ await apply(parser, result, renderer);
52
+ },
53
+ };
54
+ });
55
+ };
56
+ register('NEEDLE_deformation_rig', async (parser, result) => {
57
+ const { NeedleDeformationRigLoaderPlugin } = await import('@needle-tools/three-mesh-effects/deformation-runtime');
58
+ await new NeedleDeformationRigLoaderPlugin(parser).afterRoot(result);
59
+ });
60
+ register('NEEDLE_mesh_impostor', async (parser, result, renderer) => {
61
+ const { NeedleImpostorLoaderPlugin } = await import('@needle-tools/three-mesh-effects/impostor-runtime');
62
+ await new NeedleImpostorLoaderPlugin(parser, { renderer }).afterRoot(result);
63
+ });
64
+ register('NEEDLE_pixel_impostor', async (parser, result) => {
65
+ const { NeedlePixelImpostorLoaderPlugin } = await import('@needle-tools/three-mesh-effects/pixel-impostor-runtime');
66
+ await new NeedlePixelImpostorLoaderPlugin(parser).afterRoot(result);
67
+ });
68
+ register('NEEDLE_hull_effect', async (parser, result) => {
69
+ const { NeedleHullEffectLoaderPlugin } = await import('@needle-tools/three-mesh-effects/hull-effects');
70
+ await new NeedleHullEffectLoaderPlugin(parser).afterRoot(result);
71
+ });
72
+ return loader;
73
+ }
@@ -0,0 +1,27 @@
1
+ // @ts-check
2
+ import { HULL_EFFECT_CONTROLS } from './wrap-preview-settings.js';
3
+
4
+ export const NEEDLE_HULL_EFFECT = 'NEEDLE_hull_effect';
5
+
6
+ /** @typedef {{version: 1, mode: string, values: Record<string, number>}} HullEffectDescriptor */
7
+
8
+ /** Validate the runtime contract before building any shader graphs.
9
+ * @param {unknown} raw
10
+ * @returns {HullEffectDescriptor}
11
+ */
12
+ export function parseHullEffectDescriptor(raw) {
13
+ if (!raw || typeof raw !== 'object') throw new Error('Invalid NEEDLE_hull_effect descriptor.');
14
+ const record = /** @type {Record<string, unknown>} */ (raw);
15
+ if (record.version !== 1) throw new Error('Unsupported NEEDLE_hull_effect version.');
16
+ if (typeof record.mode !== 'string' || !Object.hasOwn(HULL_EFFECT_CONTROLS, record.mode)) throw new Error('Unknown NEEDLE_hull_effect mode.');
17
+ if (!record.values || typeof record.values !== 'object' || Array.isArray(record.values)) throw new Error('Invalid NEEDLE_hull_effect values.');
18
+ const input = /** @type {Record<string, unknown>} */ (record.values);
19
+ /** @type {Record<string, number>} */
20
+ const values = {};
21
+ for (const control of HULL_EFFECT_CONTROLS[record.mode]) {
22
+ const value = Object.hasOwn(input, control.key) ? input[control.key] : control.value;
23
+ if (typeof value !== 'number' || !Number.isFinite(value)) throw new Error(`Invalid NEEDLE_hull_effect value: ${control.key}.`);
24
+ values[control.key] = Math.max(control.min, Math.min(control.max, value));
25
+ }
26
+ return { version: 1, mode: record.mode, values };
27
+ }
@@ -0,0 +1,89 @@
1
+ // @ts-check
2
+ import { createHullEffect } from './wrap-preview.js';
3
+ import { NEEDLE_HULL_EFFECT, parseHullEffectDescriptor } from './hull-effect-metadata.js';
4
+
5
+ /** @typedef {import('three').Object3D} Object3D */
6
+ /** @typedef {ReturnType<typeof createHullEffect>} HullEffect */
7
+ /** @type {WeakMap<Object3D, {descriptor: import('./hull-effect-metadata.js').HullEffectDescriptor, effect: HullEffect, disposed: boolean}>} */
8
+ const hulls = new WeakMap();
9
+
10
+ /** Get the automatically loaded hull effect for updating or disposing it.
11
+ * @param {Object3D} hull
12
+ */
13
+ export function getHullEffect(hull) { return hulls.get(hull)?.effect; }
14
+
15
+ /** Attach a borrowed original to a hull initialized by useLoader. Replaces its
16
+ * standalone effect with the same settings and sets up animation syncing.
17
+ * Advance the original's mixer before syncAnimation(). The original's resources
18
+ * remain owned by the caller. Pass null to return to a standalone effect.
19
+ * @param {Object3D} hull
20
+ * @param {Object3D | null} original
21
+ * @param {{animate?: boolean}} [options]
22
+ */
23
+ export function bindHull(hull, original, options = {}) {
24
+ const state = hulls.get(hull);
25
+ if (!state || state.disposed) throw new Error('Load this hull with useLoader before calling bindHull.');
26
+ if (original && (original === hull || isAncestor(hull, original) || isAncestor(original, hull))) throw new Error('Hull and original must have separate hierarchies.');
27
+ state.effect.dispose();
28
+ const effect = createHullEffect(hull, original, { ...state.descriptor.values, mode: state.descriptor.mode }, options);
29
+ state.effect = manageEffect(hull, state, effect);
30
+ state.disposed = false;
31
+ hulls.set(hull, state);
32
+ return state.effect;
33
+ }
34
+
35
+ /** @param {Object3D} ancestor @param {Object3D} object */
36
+ function isAncestor(ancestor, object) {
37
+ for (let parent = object.parent; parent; parent = parent.parent) if (parent === ancestor) return true;
38
+ return false;
39
+ }
40
+
41
+ /** Keep runtime edits when binding later; an old binding must not dispose its replacement.
42
+ * @param {Object3D} hull
43
+ * @param {{descriptor: import('./hull-effect-metadata.js').HullEffectDescriptor, effect: HullEffect, disposed: boolean}} state
44
+ * @param {HullEffect} effect
45
+ */
46
+ function manageEffect(hull, state, effect) {
47
+ const update = effect.update.bind(effect), dispose = effect.dispose.bind(effect);
48
+ let disposed = false;
49
+ effect.update = next => {
50
+ if (disposed || !update(next)) return false;
51
+ state.descriptor = parseHullEffectDescriptor({ ...state.descriptor, values: next });
52
+ return true;
53
+ };
54
+ effect.dispose = () => {
55
+ if (disposed) return;
56
+ disposed = true;
57
+ dispose();
58
+ if (state.effect === effect) { state.disposed = true; hulls.delete(hull); }
59
+ };
60
+ return effect;
61
+ }
62
+
63
+ /** Three.js loader for scene-scoped hull effects. The portable hull stays in the
64
+ * glTF; supporting renderers build the selected effect after loading its scene.
65
+ */
66
+ export class NeedleHullEffectLoaderPlugin {
67
+ name = NEEDLE_HULL_EFFECT;
68
+ /** @param {import('three/addons/loaders/GLTFLoader.js').GLTFParser} parser */
69
+ constructor(parser) { this.parser = parser; }
70
+ /** @param {import('three/addons/loaders/GLTFLoader.js').GLTF} result */
71
+ async afterRoot(result) {
72
+ const json = /** @type {{scenes?: {extensions?: Record<string, unknown>}[]}} */ (this.parser.json);
73
+ const pending = result.scenes.flatMap((scene, index) => {
74
+ const raw = json.scenes?.[index]?.extensions?.[this.name];
75
+ return raw === undefined ? [] : [{ scene, descriptor: parseHullEffectDescriptor(raw) }];
76
+ });
77
+ /** @type {HullEffect[]} */
78
+ const created = [];
79
+ try {
80
+ for (const { scene, descriptor } of pending) {
81
+ const effect = createHullEffect(scene, null, { ...descriptor.values, mode: descriptor.mode }, { animate: result.animations.length ? true : undefined });
82
+ const state = { descriptor, effect, disposed: false };
83
+ state.effect = manageEffect(scene, state, effect);
84
+ hulls.set(scene, state);
85
+ created.push(state.effect);
86
+ }
87
+ } catch (error) { for (const effect of created) effect.dispose(); throw error; }
88
+ }
89
+ }
@@ -1,7 +1,7 @@
1
1
  // Lightweight UI contract; importing controls must not import shader graphs.
2
- export const WRAP_PREVIEW_MODES = ['ice', 'force-field', 'tech-cage', 'flames', 'aura', 'outline', 'godrays', 'wind-frosted', 'shroud', 'lava', 'ivy', 'heat-haze'];
2
+ export const HULL_EFFECT_MODES = ['ice', 'force-field', 'tech-cage', 'flames', 'aura', 'outline', 'godrays', 'wind-frosted', 'shroud', 'lava', 'ivy', 'heat-haze'];
3
3
  /** @type {Record<string, {key: string, label: string, min: number, max: number, step: number, value: number, title: string, kind?: string}[]>} */
4
- export const WRAP_PREVIEW_CONTROLS = {
4
+ export const HULL_EFFECT_CONTROLS = {
5
5
  'heat-haze': [
6
6
  { key: 'strength', label: 'Distortion', min: 0, max: 1, step: 0.01, value: 0.35, title: 'Strength of the bubbling refractive normals.' },
7
7
  { key: 'detail', label: 'Detail', min: 1, max: 16, step: 0.25, value: 5, title: 'Spatial scale of the smooth heat bubbles.' },
@@ -105,10 +105,11 @@ export const WRAP_PREVIEW_CONTROLS = {
105
105
  { key: 'scale', label: 'Detail', min: 1, max: 12, step: 0.25, value: 5, title: 'Detail of frost patches and pointed icicles.' },
106
106
  ],
107
107
  };
108
- export function createWrapPreviewValues() {
109
- return Object.fromEntries(Object.entries(WRAP_PREVIEW_CONTROLS).map(([mode, controls]) => [mode,
110
- Object.fromEntries(controls.map(control => [control.key, control.value])),
111
- ]));
108
+ /** @returns {Record<string, Record<string, number> & {mode: string}>} */
109
+ export function createHullEffectValues() {
110
+ return /** @type {Record<string, Record<string, number> & {mode: string}>} */ (/** @type {unknown} */ (Object.fromEntries(Object.entries(HULL_EFFECT_CONTROLS).map(([mode, controls]) => [mode,
111
+ { mode, ...Object.fromEntries(controls.map(control => [control.key, control.value])) },
112
+ ]))));
112
113
  }
113
114
 
114
115
  /** Includes older reports whose wrap stages live inside material groups.
@@ -3,7 +3,7 @@ import * as THREE from 'three';
3
3
  import { MeshBasicNodeMaterial, MeshPhysicalNodeMaterial, MeshStandardNodeMaterial } from 'three/webgpu';
4
4
  import { clone as cloneSkeleton } from 'three/addons/utils/SkeletonUtils.js';
5
5
  import { mergeVertices } from 'three/addons/utils/BufferGeometryUtils.js';
6
- import { WRAP_PREVIEW_CONTROLS } from './wrap-preview-settings.js';
6
+ import { HULL_EFFECT_CONTROLS } from './wrap-preview-settings.js';
7
7
  import { createWrapSkin } from './wrap-skin.js';
8
8
  import { createBarycentricWireframeGeometry, createPreviewWireframeMaterial } from './wireframe.js';
9
9
  import {
@@ -115,21 +115,22 @@ export function prepareRayGeometry(source) {
115
115
  * before unloading the source or wrap. `update(values)` returns false when a
116
116
  * compile-time shader variant changed; create a new effect in that case.
117
117
  * @param {THREE.Object3D} asset
118
- * @param {THREE.Object3D} original
119
- * @param {string} mode
120
- * @param {Record<string, number>} values
118
+ * @param {THREE.Object3D | null} original Null renders the hull effect alone.
119
+ * @param {{mode: string, [key: string]: string | number}} effect
121
120
  * @param {{animate?: boolean,
122
121
  * geometry?: (source: THREE.BufferGeometry) => THREE.BufferGeometry,
123
122
  * material?: (source: THREE.Material, impostor: boolean, width: number, blend: 'white') => MeshBasicNodeMaterial}=} options
124
123
  */
125
- export function createWrapPreview(asset, original, mode, values, options = {}) {
126
- const controls = mode === 'control' ? [] : WRAP_PREVIEW_CONTROLS[mode];
127
- if (!controls) throw new Error(`Unknown wrap preview: ${mode}`);
128
- /** @param {Record<string, number>} input */
129
- const validatedValues = input => Object.fromEntries(controls.map(control => [control.key,
130
- Number.isFinite(input[control.key]) ? THREE.MathUtils.clamp(input[control.key], control.min, control.max) : control.value,
131
- ]));
132
- values = validatedValues(values);
124
+ export function createHullEffect(asset, original, effect, options = {}) {
125
+ const { mode, ...inputValues } = effect;
126
+ const controls = mode === 'control' ? [] : HULL_EFFECT_CONTROLS[mode];
127
+ if (!controls) throw new Error(`Unknown hull effect: ${mode}`);
128
+ /** @param {Record<string, string | number>} input */
129
+ const validatedValues = input => Object.fromEntries(controls.map(control => {
130
+ const value = input[control.key];
131
+ return [control.key, typeof value === 'number' && Number.isFinite(value) ? THREE.MathUtils.clamp(value, control.min, control.max) : control.value];
132
+ }));
133
+ const values = validatedValues(inputValues);
133
134
  const group = new THREE.Group();
134
135
  group.name = `Wrap preview: ${mode}`;
135
136
  group.userData.wrapPreview = true;
@@ -150,7 +151,7 @@ export function createWrapPreview(asset, original, mode, values, options = {}) {
150
151
  const hazeNoiseEnabled = mode === 'heat-haze' && values.strength > 0;
151
152
  const shroudCurlEnabled = mode === 'shroud' && values.amplitude > 0;
152
153
  asset.updateWorldMatrix(true, true);
153
- original.updateWorldMatrix(true, true);
154
+ original?.updateWorldMatrix(true, true);
154
155
  const inverse = asset.matrixWorld.clone().invert();
155
156
  /** @type {THREE.BufferGeometry[]} */
156
157
  const shells = [];
@@ -166,12 +167,14 @@ export function createWrapPreview(asset, original, mode, values, options = {}) {
166
167
  const center = uniform(bounds.getCenter(new THREE.Vector3()));
167
168
  const size = Math.max(bounds.getSize(new THREE.Vector3()).length(), 1e-5);
168
169
  const normalized = positionLocal.sub(center).div(size);
169
- const sourceCopy = cloneSkeleton(original);
170
- sourceCopy.name = 'Original inside wrap';
171
- if (mode === 'control') sourceCopy.visible = false;
172
- sourceCopy.matrix.copy(inverse.clone().multiply(original.matrixWorld));
170
+ const animationSource = original ?? asset;
171
+ const sourceCopy = cloneSkeleton(animationSource);
172
+ sourceCopy.name = original ? 'Original inside wrap' : 'Hull animation driver';
173
+ if (!original || mode === 'control') sourceCopy.visible = false;
174
+ if (original) sourceCopy.matrix.copy(inverse.clone().multiply(original.matrixWorld));
175
+ else sourceCopy.matrix.identity();
173
176
  sourceCopy.matrixAutoUpdate = false;
174
- const skin = createWrapSkin(original, sourceCopy, asset, options.animate);
177
+ const skin = createWrapSkin(animationSource, sourceCopy, asset, options.animate);
175
178
  /** @type {THREE.Object3D[]} */
176
179
  const helpers = [];
177
180
  sourceCopy.traverse(object => { if (object.userData.previewWireframeOverlay || object.userData.previewGaussianSplat || object.userData.wrapPreview) helpers.push(object); });
@@ -189,7 +192,7 @@ export function createWrapPreview(asset, original, mode, values, options = {}) {
189
192
  };
190
193
  object.material = Array.isArray(object.material) ? object.material.map(cloneMaterial) : cloneMaterial(object.material);
191
194
  });
192
- group.add(sourceCopy);
195
+ if (original || skin) group.add(sourceCopy);
193
196
 
194
197
  // Construct only the selected graph. In particular, curl and transmission
195
198
  // are absent from the other modes, not hidden behind runtime uniforms.
@@ -618,20 +621,20 @@ export function createWrapPreview(asset, original, mode, values, options = {}) {
618
621
  return {
619
622
  group,
620
623
  syncAnimation() { skin?.update(); },
621
- /** @param {Record<string, number>} next */
624
+ /** @param {Record<string, string | number>} next */
622
625
  update(next) {
623
- next = validatedValues(next);
624
- if (mode === 'ice' && (next.dispersion > 0) !== dispersionEnabled) return false;
625
- if (mode === 'force-field' && (next.noise > 0) !== fieldNoiseEnabled) return false;
626
- if ((mode === 'ivy' || mode === 'lava') && (next.noise > 0) !== growthNoiseEnabled) return false;
627
- if (mode === 'heat-haze' && (next.strength > 0) !== hazeNoiseEnabled) return false;
628
- if (mode === 'shroud' && (next.amplitude > 0) !== shroudCurlEnabled) return false;
629
- effectColor.value.setHex(next.color ?? 0xffffff);
630
- borderColor.value.setHex(next.borderColor ?? 0x000000);
631
- warmColor.value.setHex(next.warmColor ?? 0xffb52a);
632
- hotColor.value.setHex(next.hotColor ?? 0xfff4d6);
633
- for (const [key, value] of Object.entries(next)) if (uniforms[key]) uniforms[key].value = value;
634
- for (const material of materials) if (material.userData.previewWireframeThickness) material.userData.previewWireframeThickness.value = next.width;
626
+ const validated = validatedValues(next);
627
+ if (mode === 'ice' && (validated.dispersion > 0) !== dispersionEnabled) return false;
628
+ if (mode === 'force-field' && (validated.noise > 0) !== fieldNoiseEnabled) return false;
629
+ if ((mode === 'ivy' || mode === 'lava') && (validated.noise > 0) !== growthNoiseEnabled) return false;
630
+ if (mode === 'heat-haze' && (validated.strength > 0) !== hazeNoiseEnabled) return false;
631
+ if (mode === 'shroud' && (validated.amplitude > 0) !== shroudCurlEnabled) return false;
632
+ effectColor.value.setHex(validated.color ?? 0xffffff);
633
+ borderColor.value.setHex(validated.borderColor ?? 0x000000);
634
+ warmColor.value.setHex(validated.warmColor ?? 0xffb52a);
635
+ hotColor.value.setHex(validated.hotColor ?? 0xfff4d6);
636
+ for (const [key, value] of Object.entries(validated)) if (uniforms[key]) uniforms[key].value = value;
637
+ for (const material of materials) if (material.userData.previewWireframeThickness) material.userData.previewWireframeThickness.value = validated.width;
635
638
  return true;
636
639
  },
637
640
  dispose() {
@@ -1,4 +0,0 @@
1
- export { captureWrapSkinPose } from "../rendering/wrap-skin.js";
2
- export { createWrapPreview, prepareIceNormalAttributes, prepareAuraGeometry, prepareRayGeometry } from "../rendering/wrap-preview.js";
3
- export { WRAP_PREVIEW_MODES, WRAP_PREVIEW_CONTROLS, createWrapPreviewValues, isWrapTopology } from "../rendering/wrap-preview-settings.js";
4
- export { createBarycentricWireframeGeometry, createPreviewWireframeMaterial, applyPreviewWireframeBlendMode, parseWireframeBlendMode } from "../rendering/wireframe.js";
@@ -1 +0,0 @@
1
- export * from '../../../src/public/wrap-effects.js';