@needle-tools/three-mesh-effects 0.2.2 → 0.3.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/CHANGELOG.md +28 -6
- package/README.md +76 -1
- package/SKILL.md +9 -1
- package/build/box-impostor-runtime.js +1298 -0
- package/build/box-impostor-runtime.js.map +7 -0
- package/build/deformation-runtime.js +85 -31
- package/build/deformation-runtime.js.map +4 -4
- package/build/hull-effects.js +60 -28
- package/build/hull-effects.js.map +3 -3
- package/build/impostor-runtime.js +235 -116
- package/build/impostor-runtime.js.map +4 -4
- package/build/index.js +4 -0
- package/build/index.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-display-settings.js +50 -0
- package/build/internal/box-impostor/box-impostor-display-settings.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-display.js +1005 -0
- package/build/internal/box-impostor/box-impostor-display.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-face-axes.js +15 -0
- package/build/internal/box-impostor/box-impostor-face-axes.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-faces.js +125 -0
- package/build/internal/box-impostor/box-impostor-faces.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-geometry.js +230 -0
- package/build/internal/box-impostor/box-impostor-geometry.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-material.js +964 -0
- package/build/internal/box-impostor/box-impostor-material.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-metadata.js +108 -0
- package/build/internal/box-impostor/box-impostor-metadata.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-projection.js +256 -0
- package/build/internal/box-impostor/box-impostor-projection.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-runtime.js +1252 -0
- package/build/internal/box-impostor/box-impostor-runtime.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-surface-search.js +21 -0
- package/build/internal/box-impostor/box-impostor-surface-search.js.map +7 -0
- package/build/internal/deformation/cloth-surface.js +23 -17
- package/build/internal/deformation/cloth-surface.js.map +3 -3
- package/build/internal/deformation/fur-surface.js +55 -12
- package/build/internal/deformation/fur-surface.js.map +3 -3
- package/build/internal/deformation/pin-cloth.js +7 -2
- package/build/internal/deformation/pin-cloth.js.map +2 -2
- package/build/internal/deformation/rig-runtime.js +85 -31
- package/build/internal/deformation/rig-runtime.js.map +4 -4
- package/build/internal/impostor/impostor-node-material.js +235 -116
- package/build/internal/impostor/impostor-node-material.js.map +4 -4
- package/build/internal/rendering/hull-effect-runtime.js +59 -27
- package/build/internal/rendering/hull-effect-runtime.js.map +3 -3
- package/build/internal/rendering/texture-slot.js +26 -0
- package/build/internal/rendering/texture-slot.js.map +7 -0
- package/build/internal/rendering/wireframe.js +41 -9
- package/build/internal/rendering/wireframe.js.map +2 -2
- package/build/internal/rendering/wrap-preview.js +59 -27
- package/build/internal/rendering/wrap-preview.js.map +3 -3
- package/build/types/box-impostor/box-impostor-display-settings.d.ts +30 -0
- package/build/types/box-impostor/box-impostor-display-settings.js +1 -0
- package/build/types/box-impostor/box-impostor-display.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-display.js +1 -0
- package/build/types/box-impostor/box-impostor-face-axes.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-face-axes.js +1 -0
- package/build/types/box-impostor/box-impostor-faces.d.ts +11 -0
- package/build/types/box-impostor/box-impostor-faces.js +1 -0
- package/build/types/box-impostor/box-impostor-geometry.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-geometry.js +1 -0
- package/build/types/box-impostor/box-impostor-material.d.ts +10 -0
- package/build/types/box-impostor/box-impostor-material.js +1 -0
- package/build/types/box-impostor/box-impostor-metadata.d.ts +31 -0
- package/build/types/box-impostor/box-impostor-metadata.js +1 -0
- package/build/types/box-impostor/box-impostor-projection.d.ts +19 -0
- package/build/types/box-impostor/box-impostor-projection.js +1 -0
- package/build/types/box-impostor/box-impostor-runtime.d.ts +25 -0
- package/build/types/box-impostor/box-impostor-runtime.js +1 -0
- package/build/types/box-impostor/box-impostor-surface-search.d.ts +13 -0
- package/build/types/box-impostor/box-impostor-surface-search.js +1 -0
- package/build/types/deformation/cloth-surface.d.ts +1 -0
- package/build/types/deformation/pin-cloth.d.ts +1 -0
- package/build/types/public/box-impostor-runtime.d.ts +6 -0
- package/build/types/public/box-impostor-runtime.js +1 -0
- package/build/types/public/hull-effects.d.ts +1 -0
- package/build/types/public/index.d.ts +1 -1
- package/build/types/rendering/texture-slot.d.ts +10 -0
- package/build/types/rendering/texture-slot.js +1 -0
- package/build/types/rendering/wireframe.d.ts +2 -2
- package/package.json +27 -6
- package/src/box-impostor/box-impostor-display-settings.js +54 -0
- package/src/box-impostor/box-impostor-display.js +38 -0
- package/src/box-impostor/box-impostor-face-axes.js +11 -0
- package/src/box-impostor/box-impostor-faces.js +118 -0
- package/src/box-impostor/box-impostor-geometry.js +140 -0
- package/src/box-impostor/box-impostor-material.js +721 -0
- package/src/box-impostor/box-impostor-metadata.js +122 -0
- package/src/box-impostor/box-impostor-projection.js +287 -0
- package/src/box-impostor/box-impostor-runtime.js +122 -0
- package/src/box-impostor/box-impostor-surface-search.js +11 -0
- package/src/deformation/cloth-surface.ts +28 -17
- package/src/deformation/fur-surface.ts +22 -12
- package/src/deformation/pin-cloth.ts +9 -3
- package/src/impostor/impostor-node-material.js +238 -150
- package/src/public/box-impostor-runtime.js +14 -0
- package/src/public/hull-effects.js +1 -0
- package/src/public/index.js +5 -1
- package/src/rendering/texture-slot.js +27 -0
- package/src/rendering/wireframe.js +51 -13
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/** Keep material-slot texture replacement connected to the shader nodes.
|
|
4
|
+
* @param {import('three').Material} material
|
|
5
|
+
* @param {string} slot
|
|
6
|
+
* @param {import('three').Texture} initial
|
|
7
|
+
* @param {{value: import('three').Texture}[]} nodes
|
|
8
|
+
* @param {((value: import('three').Texture) => void)=} onChange
|
|
9
|
+
*/
|
|
10
|
+
export function bindTextureSlot(material, slot, initial, nodes, onChange) {
|
|
11
|
+
let current = initial;
|
|
12
|
+
Object.defineProperty(material, slot, {
|
|
13
|
+
configurable: true, enumerable: true,
|
|
14
|
+
get: () => current,
|
|
15
|
+
set: (/** @type {import('three').Texture} */ value) => {
|
|
16
|
+
value.channel = current.channel;
|
|
17
|
+
value.offset = current.offset;
|
|
18
|
+
value.repeat = current.repeat;
|
|
19
|
+
value.center = current.center;
|
|
20
|
+
value.rotation = current.rotation;
|
|
21
|
+
current = value;
|
|
22
|
+
for (const node of nodes) node.value = value;
|
|
23
|
+
onChange?.(value);
|
|
24
|
+
material.needsUpdate = true;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import * as THREE from 'three';
|
|
3
3
|
import { MeshBasicNodeMaterial } from 'three/webgpu';
|
|
4
|
-
import { attribute, fwidth, min, vec3, uniform, float } from 'three/tsl';
|
|
5
|
-
/** @typedef {'black' | 'white' | 'invert'} WireframeBlendMode */
|
|
4
|
+
import { attribute, fwidth, min, vec3, uniform, float, mix } from 'three/tsl';
|
|
5
|
+
/** @typedef {'high-contrast' | 'black' | 'white' | 'invert' | 'cyan' | 'lime' | 'magenta'} WireframeBlendMode */
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Produces a triangle overlay with a screen-space barycentric edge mask. Unlike
|
|
@@ -25,14 +25,15 @@ export function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thick
|
|
|
25
25
|
edgeDistanceVector.z,
|
|
26
26
|
);
|
|
27
27
|
const halfWidth = thicknessNode.mul(0.5);
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
);
|
|
28
|
+
const coverage = lineCoverage(edgeDistance, halfWidth);
|
|
29
|
+
// A narrow halo preserves dark-background visibility without making the
|
|
30
|
+
// antialiased gray outline dominate the black core on dense geometry.
|
|
31
|
+
const contrastCore = lineCoverage(edgeDistance, halfWidth.max(1));
|
|
32
|
+
const contrastCoverage = lineCoverage(edgeDistance, halfWidth.max(1).add(0.125));
|
|
33
|
+
const contrast = uniform(0);
|
|
34
|
+
const opacity = mix(coverage, contrastCoverage, contrast);
|
|
34
35
|
const material = new MeshBasicNodeMaterial({
|
|
35
|
-
name: isImpostor ? '
|
|
36
|
+
name: isImpostor ? 'Impostor quad overlay' : 'Mesh wireframe overlay',
|
|
36
37
|
color: 0x000000,
|
|
37
38
|
side: isImpostor ? THREE.DoubleSide : sourceMaterial.side,
|
|
38
39
|
depthTest: !isImpostor,
|
|
@@ -44,20 +45,39 @@ export function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thick
|
|
|
44
45
|
});
|
|
45
46
|
material.transparent = true;
|
|
46
47
|
material.premultipliedAlpha = true;
|
|
47
|
-
material.opacityNode =
|
|
48
|
-
|
|
48
|
+
material.opacityNode = opacity;
|
|
49
|
+
const lineColor = uniform(new THREE.Vector3());
|
|
50
|
+
material.colorNode = mix(lineColor,
|
|
51
|
+
vec3(float(1).sub(contrastCore.div(contrastCoverage.max(1e-4)))).mul(0.45), contrast,
|
|
52
|
+
);
|
|
53
|
+
material.maskNode = opacity.greaterThan(1 / 1024);
|
|
49
54
|
if ('positionNode' in sourceMaterial) {
|
|
50
55
|
const sourceNodeMaterial = /** @type {import('three/webgpu').NodeMaterial} */ (sourceMaterial);
|
|
51
56
|
material.positionNode = sourceNodeMaterial.positionNode ?? null;
|
|
52
57
|
}
|
|
53
58
|
material.userData.previewWireframeThickness = thicknessNode;
|
|
59
|
+
material.userData.previewWireframeContrast = contrast;
|
|
60
|
+
material.userData.previewWireframeColor = lineColor;
|
|
54
61
|
applyPreviewWireframeBlendMode(material, blendMode);
|
|
55
62
|
return material;
|
|
56
63
|
}
|
|
57
64
|
|
|
65
|
+
/** Screen-space interval coverage with a one-pixel box filter. The second
|
|
66
|
+
* ramp preserves integrated energy for subpixel line widths.
|
|
67
|
+
* @param {import('three/webgpu').Node<'float'>} distance
|
|
68
|
+
* @param {import('three/webgpu').Node<'float'>} halfWidth
|
|
69
|
+
*/
|
|
70
|
+
function lineCoverage(distance, halfWidth) {
|
|
71
|
+
return halfWidth.add(0.5).sub(distance).clamp(0, 1).sub(
|
|
72
|
+
float(0.5).sub(halfWidth).sub(distance).clamp(0, 1),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
58
76
|
/** @param {string} value @returns {WireframeBlendMode} */
|
|
59
77
|
export function parseWireframeBlendMode(value) {
|
|
60
|
-
return value === '
|
|
78
|
+
return value === 'black' || value === 'white' || value === 'invert'
|
|
79
|
+
|| value === 'cyan' || value === 'lime' || value === 'magenta'
|
|
80
|
+
? value : 'high-contrast';
|
|
61
81
|
}
|
|
62
82
|
|
|
63
83
|
/**
|
|
@@ -66,7 +86,10 @@ export function parseWireframeBlendMode(value) {
|
|
|
66
86
|
*/
|
|
67
87
|
export function applyPreviewWireframeBlendMode(material, mode) {
|
|
68
88
|
const basic = /** @type {import('three/webgpu').MeshBasicNodeMaterial} */ (material);
|
|
69
|
-
|
|
89
|
+
const colors = { black: 0x000000, cyan: 0x00ffff, lime: 0x39ff14, magenta: 0xff00ff };
|
|
90
|
+
basic.color.set(mode in colors ? colors[/** @type {keyof typeof colors} */ (mode)] : 0xffffff);
|
|
91
|
+
basic.userData.previewWireframeColor.value.set(basic.color.r, basic.color.g, basic.color.b);
|
|
92
|
+
basic.userData.previewWireframeContrast.value = mode === 'high-contrast' ? 1 : 0;
|
|
70
93
|
if (mode === 'invert') {
|
|
71
94
|
basic.blending = THREE.CustomBlending;
|
|
72
95
|
basic.blendEquation = THREE.AddEquation;
|
|
@@ -111,5 +134,20 @@ export function createBarycentricWireframeGeometry(source) {
|
|
|
111
134
|
'previewWireframeEdgeMask',
|
|
112
135
|
new THREE.BufferAttribute(edgeMask, 3),
|
|
113
136
|
);
|
|
137
|
+
// toNonIndexed separates even interleaved source attributes. Cards need
|
|
138
|
+
// their camera-facing transform attributes as well as edge coordinates;
|
|
139
|
+
// separate buffers exceed WebGPU's portable eight-buffer limit.
|
|
140
|
+
const floats = Object.entries(geometry.attributes)
|
|
141
|
+
.filter(([, value]) => value.array instanceof Float32Array);
|
|
142
|
+
const stride = floats.reduce((sum, [, value]) => sum + value.itemSize, 0);
|
|
143
|
+
const packed = new THREE.InterleavedBuffer(new Float32Array(vertexCount * stride), stride);
|
|
144
|
+
let offset = 0;
|
|
145
|
+
for (const [name, value] of floats) {
|
|
146
|
+
for (let vertex = 0; vertex < vertexCount; vertex++)
|
|
147
|
+
for (let component = 0; component < value.itemSize; component++)
|
|
148
|
+
packed.array[vertex * stride + offset + component] = value.getComponent(vertex, component);
|
|
149
|
+
geometry.setAttribute(name, new THREE.InterleavedBufferAttribute(packed, value.itemSize, offset, value.normalized));
|
|
150
|
+
offset += value.itemSize;
|
|
151
|
+
}
|
|
114
152
|
return geometry;
|
|
115
153
|
}
|