@needle-tools/three-mesh-effects 0.2.3 → 0.3.2
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 +34 -8
- package/README.md +86 -3
- package/SKILL.md +14 -4
- package/build/box-impostor-runtime.js +1423 -0
- package/build/box-impostor-runtime.js.map +7 -0
- package/build/deformation-runtime.js +30 -19
- package/build/deformation-runtime.js.map +3 -3
- package/build/hull-effects.js +60 -28
- package/build/hull-effects.js.map +3 -3
- package/build/impostor-runtime.js +264 -133
- package/build/impostor-runtime.js.map +4 -4
- package/build/index.js +8 -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 +1102 -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 +1056 -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 +276 -0
- package/build/internal/box-impostor/box-impostor-projection.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-runtime.js +1369 -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/pin-cloth.js +7 -2
- package/build/internal/deformation/pin-cloth.js.map +2 -2
- package/build/internal/deformation/rig-runtime.js +30 -19
- package/build/internal/deformation/rig-runtime.js.map +3 -3
- package/build/internal/impostor/impostor-node-material.js +264 -133
- package/build/internal/impostor/impostor-node-material.js.map +4 -4
- package/build/internal/pixel-impostor/pixel-impostor-display.js +84 -38
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +4 -4
- package/build/internal/rendering/captured-surface-depth.js +35 -0
- package/build/internal/rendering/captured-surface-depth.js.map +7 -0
- package/build/internal/rendering/captured-surface-material.js +28 -0
- package/build/internal/rendering/captured-surface-material.js.map +7 -0
- 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/renderer-support.js +31 -0
- package/build/internal/rendering/renderer-support.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/pixel-impostor-runtime.js +84 -38
- package/build/pixel-impostor-runtime.js.map +4 -4
- 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 +13 -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 +14 -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 +19 -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/impostor/impostor-node-material.d.ts +2 -15
- 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/captured-surface-depth.d.ts +5 -0
- package/build/types/rendering/captured-surface-depth.js +1 -0
- package/build/types/rendering/captured-surface-material.d.ts +8 -0
- package/build/types/rendering/captured-surface-material.js +1 -0
- package/build/types/rendering/renderer-support.d.ts +27 -0
- package/build/types/rendering/renderer-support.js +1 -0
- package/build/types/rendering/wireframe.d.ts +2 -2
- package/package.json +29 -8
- package/src/box-impostor/box-impostor-display-settings.js +54 -0
- package/src/box-impostor/box-impostor-display.js +50 -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 +771 -0
- package/src/box-impostor/box-impostor-metadata.js +122 -0
- package/src/box-impostor/box-impostor-projection.js +276 -0
- package/src/box-impostor/box-impostor-runtime.js +124 -0
- package/src/box-impostor/box-impostor-surface-search.js +11 -0
- package/src/deformation/cloth-surface.ts +28 -17
- package/src/deformation/pin-cloth.ts +9 -3
- package/src/impostor/impostor-node-material.js +188 -157
- package/src/pixel-impostor/pixel-impostor-display.js +5 -13
- package/src/public/box-impostor-runtime.js +14 -0
- package/src/public/hull-effects.js +1 -0
- package/src/public/index.js +10 -1
- package/src/rendering/captured-surface-depth.js +55 -0
- package/src/rendering/captured-surface-material.js +27 -0
- package/src/rendering/renderer-support.js +50 -0
- package/src/rendering/wireframe.js +51 -13
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import * as TSL from 'three/tsl';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {object} ImpostorRenderer
|
|
6
|
+
* @property {boolean=} isWebGPURenderer
|
|
7
|
+
* @property {boolean=} isWebGLRenderer
|
|
8
|
+
* @property {(object & {supportsNodeMaterials?: boolean})=} capabilities
|
|
9
|
+
* @property {((handler: import('three/addons/tsl/WebGLNodesHandler.js').WebGLNodesHandler) => void)=} setNodesHandler
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Reports whether a renderer can compile Baker's TSL impostor material.
|
|
14
|
+
* WebGPURenderer supports node materials directly. Classic WebGLRenderer
|
|
15
|
+
* integrations must advertise that they installed a compatible nodes handler.
|
|
16
|
+
*
|
|
17
|
+
* @param {ImpostorRenderer | undefined} renderer
|
|
18
|
+
*/
|
|
19
|
+
export function rendererSupportsImpostorNodeMaterials(renderer) {
|
|
20
|
+
if (typeof Reflect.get(TSL, 'struct') !== 'function') return false;
|
|
21
|
+
return renderer?.isWebGPURenderer === true
|
|
22
|
+
|| renderer?.capabilities?.supportsNodeMaterials === true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @type {WeakMap<ImpostorRenderer, Promise<void>>} */
|
|
26
|
+
const pending = new WeakMap();
|
|
27
|
+
|
|
28
|
+
/** Enable Three's existing TSL handler only when an enabled asset needs it.
|
|
29
|
+
* Hosts with their own compiler advertise supportsNodeMaterials to retain it.
|
|
30
|
+
* @param {ImpostorRenderer | undefined} renderer */
|
|
31
|
+
export async function enableRendererNodeMaterials(renderer) {
|
|
32
|
+
if (rendererSupportsImpostorNodeMaterials(renderer) ||
|
|
33
|
+
!renderer?.isWebGLRenderer || !renderer.setNodesHandler ||
|
|
34
|
+
typeof Reflect.get(TSL, 'struct') !== 'function') return;
|
|
35
|
+
let setup = pending.get(renderer);
|
|
36
|
+
if (!setup) {
|
|
37
|
+
setup = import('three/addons/tsl/WebGLNodesHandler.js').then(({WebGLNodesHandler}) => {
|
|
38
|
+
if (rendererSupportsImpostorNodeMaterials(renderer)) return;
|
|
39
|
+
renderer.setNodesHandler?.(new WebGLNodesHandler());
|
|
40
|
+
renderer.capabilities ??= {};
|
|
41
|
+
renderer.capabilities.supportsNodeMaterials = true;
|
|
42
|
+
}).catch(error => {
|
|
43
|
+
pending.delete(renderer);
|
|
44
|
+
throw error;
|
|
45
|
+
});
|
|
46
|
+
pending.set(renderer, setup);
|
|
47
|
+
}
|
|
48
|
+
await setup;
|
|
49
|
+
}
|
|
50
|
+
|
|
@@ -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
|
}
|