@needle-tools/three-mesh-effects 0.1.0 → 0.1.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.
- package/README.md +25 -10
- package/build/{wrap-effects.js → hull-effects.js} +38 -33
- package/build/hull-effects.js.map +7 -0
- package/build/internal/rendering/wrap-preview-settings.js +14 -10
- package/build/internal/rendering/wrap-preview-settings.js.map +2 -2
- package/build/internal/rendering/wrap-preview.js +24 -23
- package/build/internal/rendering/wrap-preview.js.map +2 -2
- package/build/types/public/hull-effects.d.ts +4 -0
- package/build/types/public/hull-effects.js +1 -0
- package/build/types/rendering/wrap-preview-settings.d.ts +6 -7
- package/build/types/rendering/wrap-preview.d.ts +7 -5
- package/package.json +5 -5
- package/src/public/{wrap-effects.js → hull-effects.js} +4 -4
- package/src/rendering/wrap-preview-settings.js +7 -6
- package/src/rendering/wrap-preview.js +25 -24
- package/build/types/public/wrap-effects.d.ts +0 -4
- package/build/types/public/wrap-effects.js +0 -1
- package/build/wrap-effects.js.map +0 -7
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { captureWrapSkinPose } from "../rendering/wrap-skin.js";
|
|
2
|
+
export { createHullEffect, prepareIceNormalAttributes, prepareAuraGeometry, prepareRayGeometry } from "../rendering/wrap-preview.js";
|
|
3
|
+
export { HULL_EFFECT_MODES, HULL_EFFECT_CONTROLS, createHullEffectValues, isWrapTopology } from "../rendering/wrap-preview-settings.js";
|
|
4
|
+
export { createBarycentricWireframeGeometry, createPreviewWireframeMaterial, applyPreviewWireframeBlendMode, parseWireframeBlendMode } from "../rendering/wireframe.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/public/hull-effects.js';
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
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
|
|
12
|
+
export const HULL_EFFECT_CONTROLS: Record<string, {
|
|
14
13
|
key: string;
|
|
15
14
|
label: string;
|
|
16
15
|
min: number;
|
|
@@ -18,21 +18,23 @@ export function prepareRayGeometry(source: THREE.BufferGeometry): THREE.BufferGe
|
|
|
18
18
|
* compile-time shader variant changed; create a new effect in that case.
|
|
19
19
|
* @param {THREE.Object3D} asset
|
|
20
20
|
* @param {THREE.Object3D} original
|
|
21
|
-
* @param {string}
|
|
22
|
-
* @param {Record<string, number>} values
|
|
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
|
|
26
|
+
export function createHullEffect(asset: THREE.Object3D, original: THREE.Object3D, 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.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Three.js loaders and TSL effects for Needle Mesh Baker outputs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"three.js",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"types": "./build/types/public/deformation-runtime.d.ts",
|
|
32
32
|
"import": "./build/deformation-runtime.js"
|
|
33
33
|
},
|
|
34
|
-
"./
|
|
35
|
-
"deno": "./src/public/
|
|
36
|
-
"types": "./build/types/public/
|
|
37
|
-
"import": "./build/
|
|
34
|
+
"./hull-effects": {
|
|
35
|
+
"deno": "./src/public/hull-effects.js",
|
|
36
|
+
"types": "./build/types/public/hull-effects.d.ts",
|
|
37
|
+
"import": "./build/hull-effects.js"
|
|
38
38
|
},
|
|
39
39
|
"./pixel-impostor-runtime": {
|
|
40
40
|
"deno": "./src/public/pixel-impostor-runtime.js",
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
export {
|
|
4
|
-
|
|
4
|
+
createHullEffect,
|
|
5
5
|
prepareIceNormalAttributes,
|
|
6
6
|
prepareAuraGeometry,
|
|
7
7
|
prepareRayGeometry,
|
|
8
8
|
} from '../rendering/wrap-preview.js';
|
|
9
9
|
export {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
HULL_EFFECT_MODES,
|
|
11
|
+
HULL_EFFECT_CONTROLS,
|
|
12
|
+
createHullEffectValues,
|
|
13
13
|
isWrapTopology,
|
|
14
14
|
} from '../rendering/wrap-preview-settings.js';
|
|
15
15
|
export { captureWrapSkinPose } from '../rendering/wrap-skin.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Lightweight UI contract; importing controls must not import shader graphs.
|
|
2
|
-
export const
|
|
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
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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 {
|
|
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 {
|
|
@@ -116,20 +116,21 @@ export function prepareRayGeometry(source) {
|
|
|
116
116
|
* compile-time shader variant changed; create a new effect in that case.
|
|
117
117
|
* @param {THREE.Object3D} asset
|
|
118
118
|
* @param {THREE.Object3D} original
|
|
119
|
-
* @param {string}
|
|
120
|
-
* @param {Record<string, number>} values
|
|
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
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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;
|
|
@@ -618,20 +619,20 @@ export function createWrapPreview(asset, original, mode, values, options = {}) {
|
|
|
618
619
|
return {
|
|
619
620
|
group,
|
|
620
621
|
syncAnimation() { skin?.update(); },
|
|
621
|
-
/** @param {Record<string, number>} next */
|
|
622
|
+
/** @param {Record<string, string | number>} next */
|
|
622
623
|
update(next) {
|
|
623
|
-
|
|
624
|
-
if (mode === 'ice' && (
|
|
625
|
-
if (mode === 'force-field' && (
|
|
626
|
-
if ((mode === 'ivy' || mode === 'lava') && (
|
|
627
|
-
if (mode === 'heat-haze' && (
|
|
628
|
-
if (mode === 'shroud' && (
|
|
629
|
-
effectColor.value.setHex(
|
|
630
|
-
borderColor.value.setHex(
|
|
631
|
-
warmColor.value.setHex(
|
|
632
|
-
hotColor.value.setHex(
|
|
633
|
-
for (const [key, value] of Object.entries(
|
|
634
|
-
for (const material of materials) if (material.userData.previewWireframeThickness) material.userData.previewWireframeThickness.value =
|
|
624
|
+
const validated = validatedValues(next);
|
|
625
|
+
if (mode === 'ice' && (validated.dispersion > 0) !== dispersionEnabled) return false;
|
|
626
|
+
if (mode === 'force-field' && (validated.noise > 0) !== fieldNoiseEnabled) return false;
|
|
627
|
+
if ((mode === 'ivy' || mode === 'lava') && (validated.noise > 0) !== growthNoiseEnabled) return false;
|
|
628
|
+
if (mode === 'heat-haze' && (validated.strength > 0) !== hazeNoiseEnabled) return false;
|
|
629
|
+
if (mode === 'shroud' && (validated.amplitude > 0) !== shroudCurlEnabled) return false;
|
|
630
|
+
effectColor.value.setHex(validated.color ?? 0xffffff);
|
|
631
|
+
borderColor.value.setHex(validated.borderColor ?? 0x000000);
|
|
632
|
+
warmColor.value.setHex(validated.warmColor ?? 0xffb52a);
|
|
633
|
+
hotColor.value.setHex(validated.hotColor ?? 0xfff4d6);
|
|
634
|
+
for (const [key, value] of Object.entries(validated)) if (uniforms[key]) uniforms[key].value = value;
|
|
635
|
+
for (const material of materials) if (material.userData.previewWireframeThickness) material.userData.previewWireframeThickness.value = validated.width;
|
|
635
636
|
return true;
|
|
636
637
|
},
|
|
637
638
|
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';
|