@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
package/README.md
CHANGED
|
@@ -19,16 +19,25 @@ optional import. The examples below use ordinary Three.js and assume an existing
|
|
|
19
19
|
|
|
20
20
|
## Hull effects
|
|
21
21
|
|
|
22
|
-
Hull effects
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
Hull effects need two models: the hull GLB exported by Mesh Baker, and the
|
|
23
|
+
original source model you uploaded. The hull supplies the effect's surface;
|
|
24
|
+
the source remains visible inside it and supplies its appearance and animation.
|
|
25
|
+
Available modes and their defaults are in `HULL_EFFECT_MODES` and
|
|
26
|
+
`createHullEffectValues()`:
|
|
25
27
|
|
|
26
28
|

|
|
27
29
|
|
|
28
30
|
```js
|
|
29
|
-
import {
|
|
31
|
+
import { createHullEffect, createHullEffectValues } from '@needle-tools/three-mesh-effects/hull-effects';
|
|
32
|
+
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
|
30
33
|
|
|
31
|
-
const
|
|
34
|
+
const loader = new GLTFLoader();
|
|
35
|
+
const [{ scene: hull }, { scene: original }] = await Promise.all([
|
|
36
|
+
loader.loadAsync('/hull.glb'), // Exported by Mesh Baker.
|
|
37
|
+
loader.loadAsync('/original.glb'), // The model uploaded to Mesh Baker.
|
|
38
|
+
]);
|
|
39
|
+
scene.add(hull);
|
|
40
|
+
const effect = createHullEffect(hull, original, createHullEffectValues().flames);
|
|
32
41
|
// For animated models, advance both mixers and call effect.syncAnimation() each frame.
|
|
33
42
|
// Call effect.dispose() at teardown.
|
|
34
43
|
```
|
|
@@ -45,7 +54,9 @@ Register the extension loader before loading an exported impostor GLB:
|
|
|
45
54
|
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
|
46
55
|
import { registerNeedleImpostorLoader } from '@needle-tools/three-mesh-effects/impostor-runtime';
|
|
47
56
|
|
|
48
|
-
const loader =
|
|
57
|
+
const loader = new GLTFLoader();
|
|
58
|
+
// Register before loading so the extension can replace the portable fallback.
|
|
59
|
+
registerNeedleImpostorLoader(loader, { renderer });
|
|
49
60
|
const { scene: model } = await loader.loadAsync('/result_impostor.glb');
|
|
50
61
|
scene.add(model);
|
|
51
62
|
```
|
|
@@ -60,8 +71,10 @@ import { AnimationMixer, Clock } from 'three';
|
|
|
60
71
|
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
|
61
72
|
import { registerNeedleDeformationRigLoader, getDeformationRig } from '@needle-tools/three-mesh-effects/deformation-runtime';
|
|
62
73
|
|
|
63
|
-
const
|
|
64
|
-
|
|
74
|
+
const loader = new GLTFLoader();
|
|
75
|
+
// Register before loading so the rig extension is available while parsing.
|
|
76
|
+
registerNeedleDeformationRigLoader(loader);
|
|
77
|
+
const { scene: riggedModel, animations } = await loader.loadAsync('/rigged.glb');
|
|
65
78
|
scene.add(riggedModel);
|
|
66
79
|
const clock = new Clock();
|
|
67
80
|
const mixer = new AnimationMixer(riggedModel);
|
|
@@ -89,8 +102,10 @@ create the display that matches the chosen workbench mode:
|
|
|
89
102
|
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
|
90
103
|
import { registerNeedlePixelImpostorLoader, createPixelImpostorDisplay } from '@needle-tools/three-mesh-effects/pixel-impostor-runtime';
|
|
91
104
|
|
|
92
|
-
const
|
|
93
|
-
|
|
105
|
+
const loader = new GLTFLoader();
|
|
106
|
+
// Register before loading so the pixel atlas is available while parsing.
|
|
107
|
+
registerNeedlePixelImpostorLoader(loader);
|
|
108
|
+
const { scene: pixelModel } = await loader.loadAsync('/pixel.glb');
|
|
94
109
|
scene.add(pixelModel);
|
|
95
110
|
const display = createPixelImpostorDisplay(pixelModel, { renderer, mode: 'screen-pixels', pixelSize: 5 });
|
|
96
111
|
// Call display.updateViewport() after a resize and display.dispose() at teardown.
|
|
@@ -7,8 +7,8 @@ import { clone as cloneSkeleton } from "three/addons/utils/SkeletonUtils.js";
|
|
|
7
7
|
import { mergeVertices } from "three/addons/utils/BufferGeometryUtils.js";
|
|
8
8
|
|
|
9
9
|
// src/rendering/wrap-preview-settings.js
|
|
10
|
-
var
|
|
11
|
-
var
|
|
10
|
+
var HULL_EFFECT_MODES = ["ice", "force-field", "tech-cage", "flames", "aura", "outline", "godrays", "wind-frosted", "shroud", "lava", "ivy", "heat-haze"];
|
|
11
|
+
var HULL_EFFECT_CONTROLS = {
|
|
12
12
|
"heat-haze": [
|
|
13
13
|
{ key: "strength", label: "Distortion", min: 0, max: 1, step: 0.01, value: 0.35, title: "Strength of the bubbling refractive normals." },
|
|
14
14
|
{ key: "detail", label: "Detail", min: 1, max: 16, step: 0.25, value: 5, title: "Spatial scale of the smooth heat bubbles." },
|
|
@@ -112,11 +112,15 @@ var WRAP_PREVIEW_CONTROLS = {
|
|
|
112
112
|
{ key: "scale", label: "Detail", min: 1, max: 12, step: 0.25, value: 5, title: "Detail of frost patches and pointed icicles." }
|
|
113
113
|
]
|
|
114
114
|
};
|
|
115
|
-
function
|
|
116
|
-
return
|
|
117
|
-
mode
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
function createHullEffectValues() {
|
|
116
|
+
return (
|
|
117
|
+
/** @type {Record<string, Record<string, number> & {mode: string}>} */
|
|
118
|
+
/** @type {unknown} */
|
|
119
|
+
Object.fromEntries(Object.entries(HULL_EFFECT_CONTROLS).map(([mode, controls]) => [
|
|
120
|
+
mode,
|
|
121
|
+
{ mode, ...Object.fromEntries(controls.map((control) => [control.key, control.value])) }
|
|
122
|
+
]))
|
|
123
|
+
);
|
|
120
124
|
}
|
|
121
125
|
function isWrapTopology(topology) {
|
|
122
126
|
if (!topology || typeof topology !== "object") return false;
|
|
@@ -5079,14 +5083,15 @@ function prepareRayGeometry(source) {
|
|
|
5079
5083
|
geometry.setAttribute("rayTangent", new THREE3.Float32BufferAttribute(tangents, 3));
|
|
5080
5084
|
return geometry;
|
|
5081
5085
|
}
|
|
5082
|
-
function
|
|
5083
|
-
const
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5086
|
+
function createHullEffect(asset, original, effect, options = {}) {
|
|
5087
|
+
const { mode, ...inputValues } = effect;
|
|
5088
|
+
const controls = mode === "control" ? [] : HULL_EFFECT_CONTROLS[mode];
|
|
5089
|
+
if (!controls) throw new Error(`Unknown hull effect: ${mode}`);
|
|
5090
|
+
const validatedValues = (input) => Object.fromEntries(controls.map((control) => {
|
|
5091
|
+
const value = input[control.key];
|
|
5092
|
+
return [control.key, typeof value === "number" && Number.isFinite(value) ? THREE3.MathUtils.clamp(value, control.min, control.max) : control.value];
|
|
5093
|
+
}));
|
|
5094
|
+
const values = validatedValues(inputValues);
|
|
5090
5095
|
const group = new THREE3.Group();
|
|
5091
5096
|
group.name = `Wrap preview: ${mode}`;
|
|
5092
5097
|
group.userData.wrapPreview = true;
|
|
@@ -5595,20 +5600,20 @@ function createWrapPreview(asset, original, mode, values, options = {}) {
|
|
|
5595
5600
|
syncAnimation() {
|
|
5596
5601
|
skin?.update();
|
|
5597
5602
|
},
|
|
5598
|
-
/** @param {Record<string, number>} next */
|
|
5603
|
+
/** @param {Record<string, string | number>} next */
|
|
5599
5604
|
update(next) {
|
|
5600
|
-
|
|
5601
|
-
if (mode === "ice" &&
|
|
5602
|
-
if (mode === "force-field" &&
|
|
5603
|
-
if ((mode === "ivy" || mode === "lava") &&
|
|
5604
|
-
if (mode === "heat-haze" &&
|
|
5605
|
-
if (mode === "shroud" &&
|
|
5606
|
-
effectColor.value.setHex(
|
|
5607
|
-
borderColor.value.setHex(
|
|
5608
|
-
warmColor.value.setHex(
|
|
5609
|
-
hotColor.value.setHex(
|
|
5610
|
-
for (const [key, value] of Object.entries(
|
|
5611
|
-
for (const material of materials) if (material.userData.previewWireframeThickness) material.userData.previewWireframeThickness.value =
|
|
5605
|
+
const validated = validatedValues(next);
|
|
5606
|
+
if (mode === "ice" && validated.dispersion > 0 !== dispersionEnabled) return false;
|
|
5607
|
+
if (mode === "force-field" && validated.noise > 0 !== fieldNoiseEnabled) return false;
|
|
5608
|
+
if ((mode === "ivy" || mode === "lava") && validated.noise > 0 !== growthNoiseEnabled) return false;
|
|
5609
|
+
if (mode === "heat-haze" && validated.strength > 0 !== hazeNoiseEnabled) return false;
|
|
5610
|
+
if (mode === "shroud" && validated.amplitude > 0 !== shroudCurlEnabled) return false;
|
|
5611
|
+
effectColor.value.setHex(validated.color ?? 16777215);
|
|
5612
|
+
borderColor.value.setHex(validated.borderColor ?? 0);
|
|
5613
|
+
warmColor.value.setHex(validated.warmColor ?? 16758058);
|
|
5614
|
+
hotColor.value.setHex(validated.hotColor ?? 16774358);
|
|
5615
|
+
for (const [key, value] of Object.entries(validated)) if (uniforms[key]) uniforms[key].value = value;
|
|
5616
|
+
for (const material of materials) if (material.userData.previewWireframeThickness) material.userData.previewWireframeThickness.value = validated.width;
|
|
5612
5617
|
return true;
|
|
5613
5618
|
},
|
|
5614
5619
|
dispose() {
|
|
@@ -5623,18 +5628,18 @@ function createWrapPreview(asset, original, mode, values, options = {}) {
|
|
|
5623
5628
|
};
|
|
5624
5629
|
}
|
|
5625
5630
|
export {
|
|
5626
|
-
|
|
5627
|
-
|
|
5631
|
+
HULL_EFFECT_CONTROLS,
|
|
5632
|
+
HULL_EFFECT_MODES,
|
|
5628
5633
|
applyPreviewWireframeBlendMode,
|
|
5629
5634
|
captureWrapSkinPose,
|
|
5630
5635
|
createBarycentricWireframeGeometry,
|
|
5636
|
+
createHullEffect,
|
|
5637
|
+
createHullEffectValues,
|
|
5631
5638
|
createPreviewWireframeMaterial,
|
|
5632
|
-
createWrapPreview,
|
|
5633
|
-
createWrapPreviewValues,
|
|
5634
5639
|
isWrapTopology,
|
|
5635
5640
|
parseWireframeBlendMode,
|
|
5636
5641
|
prepareAuraGeometry,
|
|
5637
5642
|
prepareIceNormalAttributes,
|
|
5638
5643
|
prepareRayGeometry
|
|
5639
5644
|
};
|
|
5640
|
-
//# sourceMappingURL=
|
|
5645
|
+
//# sourceMappingURL=hull-effects.js.map
|