@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
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reports whether a renderer can compile Baker's TSL impostor material.
|
|
3
|
-
* WebGPURenderer supports node materials directly. Classic WebGLRenderer
|
|
4
|
-
* integrations must advertise that they installed a compatible nodes handler.
|
|
5
|
-
*
|
|
6
|
-
* @param {ImpostorRenderer | undefined} renderer
|
|
7
|
-
*/
|
|
8
|
-
export function rendererSupportsImpostorNodeMaterials(renderer: ImpostorRenderer | undefined): boolean;
|
|
9
1
|
/**
|
|
10
2
|
* @param {ImpostorDescriptor} descriptor
|
|
11
3
|
* @param {Partial<ImpostorRuntimeFeatures>=} input
|
|
@@ -68,6 +60,7 @@ export function createPbrImpostorNodeMaterial(descriptor: ImpostorDescriptor, ma
|
|
|
68
60
|
geometry?: import("three").Texture | null;
|
|
69
61
|
viewBounds: import("three").DataTexture;
|
|
70
62
|
}, inputFeatures?: Partial<ImpostorRuntimeFeatures> | undefined, renderer?: ImpostorRenderer | undefined): MeshStandardNodeMaterial | ShaderMaterial;
|
|
63
|
+
export { rendererSupportsImpostorNodeMaterials } from "../rendering/renderer-support.js";
|
|
71
64
|
export const DEFAULT_IMPOSTOR_RUNTIME_FEATURES: Readonly<{
|
|
72
65
|
interpolation: true;
|
|
73
66
|
reprojection: true;
|
|
@@ -109,13 +102,7 @@ export class NeedleImpostorLoaderPlugin {
|
|
|
109
102
|
/** @param {import('three/addons/loaders/GLTFLoader.js').GLTF} result */
|
|
110
103
|
afterRoot(result: import("three/addons/loaders/GLTFLoader.js").GLTF): Promise<void>;
|
|
111
104
|
}
|
|
112
|
-
export type ImpostorRenderer =
|
|
113
|
-
isWebGPURenderer?: boolean | undefined;
|
|
114
|
-
isWebGLRenderer?: boolean | undefined;
|
|
115
|
-
capabilities?: (object & {
|
|
116
|
-
supportsNodeMaterials?: boolean;
|
|
117
|
-
}) | undefined;
|
|
118
|
-
};
|
|
105
|
+
export type ImpostorRenderer = import("../rendering/renderer-support.js").ImpostorRenderer;
|
|
119
106
|
export type ImpostorRuntimeFeatures = {
|
|
120
107
|
interpolation: boolean;
|
|
121
108
|
reprojection: boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createBoxImpostorGeometry } from "../box-impostor/box-impostor-geometry.js";
|
|
2
|
+
export { createBoxImpostorMaterial } from "../box-impostor/box-impostor-material.js";
|
|
3
|
+
export { setBoxImpostorDisplay } from "../box-impostor/box-impostor-display.js";
|
|
4
|
+
export { NEEDLE_BOX_IMPOSTOR, parseBoxImpostorDescriptor } from "../box-impostor/box-impostor-metadata.js";
|
|
5
|
+
export { NeedleBoxImpostorLoaderPlugin, registerNeedleBoxImpostorLoader } from "../box-impostor/box-impostor-runtime.js";
|
|
6
|
+
export { DEFAULT_BOX_IMPOSTOR_DISPLAY, normalizeBoxImpostorDisplay } from "../box-impostor/box-impostor-display-settings.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/public/box-impostor-runtime.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { captureWrapSkinPose } from "../rendering/wrap-skin.js";
|
|
2
|
+
export type WireframeBlendMode = import("../rendering/wireframe.js").WireframeBlendMode;
|
|
2
3
|
export { bindHull, getHullEffect, NeedleHullEffectLoaderPlugin } from "../rendering/hull-effect-runtime.js";
|
|
3
4
|
export { NEEDLE_HULL_EFFECT, parseHullEffectDescriptor } from "../rendering/hull-effect-metadata.js";
|
|
4
5
|
export { createHullEffect, prepareIceNormalAttributes, prepareAuraGeometry, prepareRayGeometry } from "../rendering/wrap-preview.js";
|
|
@@ -17,7 +17,7 @@ export type GLTFLoader = import("three/addons/loaders/GLTFLoader.js").GLTFLoader
|
|
|
17
17
|
export type GLTFParser = import("three/addons/loaders/GLTFLoader.js").GLTFParser;
|
|
18
18
|
export type GLTF = import("three/addons/loaders/GLTFLoader.js").GLTF;
|
|
19
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";
|
|
20
|
+
export type NeedleExtension = "NEEDLE_deformation_rig" | "NEEDLE_mesh_impostor" | "NEEDLE_pixel_impostor" | "NEEDLE_hull_effect" | "NEEDLE_box_impostor";
|
|
21
21
|
export type LoaderOptions = {
|
|
22
22
|
disable?: readonly NeedleExtension[];
|
|
23
23
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Match the renderer's depth convention after reconstructing a local hit.
|
|
2
|
+
* @param {import('three/webgpu').Node<'vec3'>} position
|
|
3
|
+
* @param {number} [shadowBias]
|
|
4
|
+
*/
|
|
5
|
+
export function capturedSurfaceDepth(position: import("three/webgpu").Node<"vec3">, shadowBias?: number): import("three/webgpu").Node<"float">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/rendering/captured-surface-depth.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Light reconstructed surfaces at their hit position, not the carrier face.
|
|
2
|
+
* View directions stay on the same ray; local lights also need the hit distance.
|
|
3
|
+
*/
|
|
4
|
+
export class CapturedSurfaceMaterial extends MeshStandardNodeMaterial {
|
|
5
|
+
/** @type {import('three/webgpu').Node<'vec3'> | null} */
|
|
6
|
+
capturedPositionNode: import("three/webgpu").Node<"vec3"> | null;
|
|
7
|
+
}
|
|
8
|
+
import { MeshStandardNodeMaterial } from 'three/webgpu';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/rendering/captured-surface-material.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} ImpostorRenderer
|
|
3
|
+
* @property {boolean=} isWebGPURenderer
|
|
4
|
+
* @property {boolean=} isWebGLRenderer
|
|
5
|
+
* @property {(object & {supportsNodeMaterials?: boolean})=} capabilities
|
|
6
|
+
* @property {((handler: import('three/addons/tsl/WebGLNodesHandler.js').WebGLNodesHandler) => void)=} setNodesHandler
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Reports whether a renderer can compile Baker's TSL impostor material.
|
|
10
|
+
* WebGPURenderer supports node materials directly. Classic WebGLRenderer
|
|
11
|
+
* integrations must advertise that they installed a compatible nodes handler.
|
|
12
|
+
*
|
|
13
|
+
* @param {ImpostorRenderer | undefined} renderer
|
|
14
|
+
*/
|
|
15
|
+
export function rendererSupportsImpostorNodeMaterials(renderer: ImpostorRenderer | undefined): boolean;
|
|
16
|
+
/** Enable Three's existing TSL handler only when an enabled asset needs it.
|
|
17
|
+
* Hosts with their own compiler advertise supportsNodeMaterials to retain it.
|
|
18
|
+
* @param {ImpostorRenderer | undefined} renderer */
|
|
19
|
+
export function enableRendererNodeMaterials(renderer: ImpostorRenderer | undefined): Promise<void>;
|
|
20
|
+
export type ImpostorRenderer = {
|
|
21
|
+
isWebGPURenderer?: boolean | undefined;
|
|
22
|
+
isWebGLRenderer?: boolean | undefined;
|
|
23
|
+
capabilities?: (object & {
|
|
24
|
+
supportsNodeMaterials?: boolean;
|
|
25
|
+
}) | undefined;
|
|
26
|
+
setNodesHandler?: ((handler: import("three/addons/tsl/WebGLNodesHandler.js").WebGLNodesHandler) => void) | undefined;
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/rendering/renderer-support.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @typedef {'black' | 'white' | 'invert'} WireframeBlendMode */
|
|
1
|
+
/** @typedef {'high-contrast' | 'black' | 'white' | 'invert' | 'cyan' | 'lime' | 'magenta'} WireframeBlendMode */
|
|
2
2
|
/**
|
|
3
3
|
* Produces a triangle overlay with a screen-space barycentric edge mask. Unlike
|
|
4
4
|
* hardware line primitives this supports stable, adjustable pixel thickness.
|
|
@@ -20,6 +20,6 @@ export function applyPreviewWireframeBlendMode(material: THREE.Material, mode: W
|
|
|
20
20
|
* @returns {THREE.BufferGeometry}
|
|
21
21
|
*/
|
|
22
22
|
export function createBarycentricWireframeGeometry(source: THREE.BufferGeometry): THREE.BufferGeometry;
|
|
23
|
-
export type WireframeBlendMode = "black" | "white" | "invert";
|
|
23
|
+
export type WireframeBlendMode = "high-contrast" | "black" | "white" | "invert" | "cyan" | "lime" | "magenta";
|
|
24
24
|
import * as THREE from 'three';
|
|
25
25
|
import { MeshBasicNodeMaterial } from 'three/webgpu';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/three-mesh-effects",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Three.js loaders and TSL effects for Needle Mesh Baker outputs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"three.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
26
|
"sideEffects": false,
|
|
27
|
-
"engines": {
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22"
|
|
29
|
+
},
|
|
28
30
|
"exports": {
|
|
29
31
|
".": {
|
|
30
32
|
"deno": "./src/public/index.js",
|
|
@@ -76,12 +78,29 @@
|
|
|
76
78
|
"types": "./build/types/rendering/*.d.ts",
|
|
77
79
|
"import": "./build/internal/rendering/*.js"
|
|
78
80
|
},
|
|
79
|
-
"./package.json": "./package.json"
|
|
81
|
+
"./package.json": "./package.json",
|
|
82
|
+
"./box-impostor-runtime": {
|
|
83
|
+
"deno": "./src/public/box-impostor-runtime.js",
|
|
84
|
+
"types": "./build/types/public/box-impostor-runtime.d.ts",
|
|
85
|
+
"import": "./build/box-impostor-runtime.js"
|
|
86
|
+
},
|
|
87
|
+
"./internal/box-impostor/*": {
|
|
88
|
+
"deno": "./src/box-impostor/*.js",
|
|
89
|
+
"types": "./build/types/box-impostor/*.d.ts",
|
|
90
|
+
"import": "./build/internal/box-impostor/*.js"
|
|
91
|
+
}
|
|
80
92
|
},
|
|
81
|
-
"files": [
|
|
93
|
+
"files": [
|
|
94
|
+
"build/",
|
|
95
|
+
"src/",
|
|
96
|
+
"README.md",
|
|
97
|
+
"CHANGELOG.md",
|
|
98
|
+
"SKILL.md",
|
|
99
|
+
"LICENSE"
|
|
100
|
+
],
|
|
82
101
|
"scripts": {
|
|
83
102
|
"build": "node scripts/build.mjs",
|
|
84
|
-
"test": "npm run build && node --test tests/use-loader.test.js",
|
|
103
|
+
"test": "npm run build && node --test tests/use-loader.test.js tests/box-impostor-runtime.test.js",
|
|
85
104
|
"prepare": "node scripts/prepare.mjs",
|
|
86
105
|
"prepack": "npm run build",
|
|
87
106
|
"test:packed-consumer": "node scripts/test-packed-consumer.mjs"
|
|
@@ -89,9 +108,9 @@
|
|
|
89
108
|
"devDependencies": {
|
|
90
109
|
"@needle-tools/engine": "6.0.0-alpha.2",
|
|
91
110
|
"@types/node": "^24.10.0",
|
|
92
|
-
"@types/three": "^0.
|
|
111
|
+
"@types/three": "^0.186.0",
|
|
93
112
|
"esbuild": "^0.25.12",
|
|
94
|
-
"three": "^0.
|
|
113
|
+
"three": "^0.186.1",
|
|
95
114
|
"typescript": "^5.9.3"
|
|
96
115
|
},
|
|
97
116
|
"dependencies": {
|
|
@@ -103,7 +122,9 @@
|
|
|
103
122
|
"@needle-tools/engine": "^6.0.0-alpha.2"
|
|
104
123
|
},
|
|
105
124
|
"peerDependenciesMeta": {
|
|
106
|
-
"@needle-tools/engine": {
|
|
125
|
+
"@needle-tools/engine": {
|
|
126
|
+
"optional": true
|
|
127
|
+
}
|
|
107
128
|
},
|
|
108
129
|
"repository": {
|
|
109
130
|
"type": "git",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @typedef {{depthMode:'auto'|'projection'|'depth',raySteps:8|16|32,alphaCutoff:number,interpolation:'none'|'linear'|'smooth',transparency:'auto'|'cutout'|'dithered'|'blended'}} BoxImpostorDisplay */
|
|
3
|
+
export const DEFAULT_BOX_IMPOSTOR_DISPLAY = Object.freeze({
|
|
4
|
+
depthMode: /** @type {'auto'|'projection'|'depth'} */ ('auto'),
|
|
5
|
+
raySteps: /** @type {8|16|32} */ (16),
|
|
6
|
+
alphaCutoff: 0.5,
|
|
7
|
+
interpolation: /** @type {'none'|'linear'|'smooth'} */ ('none'),
|
|
8
|
+
transparency: /** @type {'auto'|'cutout'|'dithered'|'blended'} */ ('auto'),
|
|
9
|
+
});
|
|
10
|
+
/** @param {Partial<BoxImpostorDisplay>} [input] @returns {BoxImpostorDisplay} */
|
|
11
|
+
export function normalizeBoxImpostorDisplay(input = {}) {
|
|
12
|
+
const value = { ...DEFAULT_BOX_IMPOSTOR_DISPLAY, ...input };
|
|
13
|
+
if (
|
|
14
|
+
!['auto', 'projection', 'depth'].includes(value.depthMode) ||
|
|
15
|
+
![8, 16, 32].includes(value.raySteps) ||
|
|
16
|
+
!Number.isFinite(value.alphaCutoff) ||
|
|
17
|
+
value.alphaCutoff <= 0 ||
|
|
18
|
+
value.alphaCutoff >= 1 ||
|
|
19
|
+
!['none', 'linear', 'smooth'].includes(value.interpolation) ||
|
|
20
|
+
!['auto', 'cutout', 'dithered', 'blended'].includes(value.transparency)
|
|
21
|
+
)
|
|
22
|
+
throw new Error('Invalid box impostor display settings.');
|
|
23
|
+
return {
|
|
24
|
+
depthMode: value.depthMode,
|
|
25
|
+
raySteps: value.raySteps,
|
|
26
|
+
alphaCutoff: value.alphaCutoff,
|
|
27
|
+
interpolation: value.interpolation,
|
|
28
|
+
transparency: value.transparency,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @param {{alphaMode?:'opaque'|'mask'|'blend'}} descriptor @param {BoxImpostorDisplay} settings */
|
|
33
|
+
export function boxTransparency(descriptor, settings) {
|
|
34
|
+
return settings.transparency === 'auto'
|
|
35
|
+
? descriptor.alphaMode === 'blend'
|
|
36
|
+
? 'blended'
|
|
37
|
+
: 'cutout'
|
|
38
|
+
: settings.transparency;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Auto only uses planes when every capture is flat within its stored depth bound.
|
|
42
|
+
* Captures without a flatness bound use depth reconstruction.
|
|
43
|
+
* @param {{boxes:{planes?:number[],planeErrors?:number[]}[]}} descriptor @param {BoxImpostorDisplay} settings */
|
|
44
|
+
export function boxDepthMode(descriptor, settings) {
|
|
45
|
+
if (settings.depthMode !== 'auto') return settings.depthMode;
|
|
46
|
+
return descriptor.boxes.every(
|
|
47
|
+
(box) =>
|
|
48
|
+
box.planes?.length === 6 &&
|
|
49
|
+
box.planeErrors?.length === 6 &&
|
|
50
|
+
box.planeErrors.every((error) => error <= 2 / 255),
|
|
51
|
+
)
|
|
52
|
+
? 'projection'
|
|
53
|
+
: 'depth';
|
|
54
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { createBoxImpostorMaterial } from './box-impostor-material.js';
|
|
3
|
+
|
|
4
|
+
import { normalizeBoxImpostorDisplay } from './box-impostor-display-settings.js';
|
|
5
|
+
/** @typedef {import('./box-impostor-display-settings.js').BoxImpostorDisplay} BoxImpostorDisplay */
|
|
6
|
+
/** @typedef {{materials:Map<string, ReturnType<typeof createBoxImpostorMaterial>>,release:(event:{target:import('three').Material})=>void}} VariantCache */
|
|
7
|
+
/** @type {WeakMap<import('three').Mesh, VariantCache>} */
|
|
8
|
+
const variants = new WeakMap();
|
|
9
|
+
/** Changes display without touching captured textures. Expensive settings select
|
|
10
|
+
* cached shader graphs; alpha cutoff updates a uniform. Materials own the cache:
|
|
11
|
+
* Three's WebGL node handler may dispose geometry to refresh its attributes.
|
|
12
|
+
* @param {import('three').Object3D} root @param {Partial<BoxImpostorDisplay>} options */
|
|
13
|
+
export function setBoxImpostorDisplay(root, options) {
|
|
14
|
+
root.traverse(object => {
|
|
15
|
+
const mesh = /** @type {import('three').Mesh} */ (object);
|
|
16
|
+
const binding = mesh.userData.boxImpostor;
|
|
17
|
+
if (!mesh.isMesh || !binding) return;
|
|
18
|
+
const settings = normalizeBoxImpostorDisplay({...binding.descriptor, ...options});
|
|
19
|
+
const descriptor = {...binding.descriptor, ...settings};
|
|
20
|
+
const keyFor = (/** @type {BoxImpostorDisplay} */ s) => `${s.depthMode}/${s.depthMode !== 'projection' ? s.raySteps : 0}/${s.interpolation}/${s.transparency}`;
|
|
21
|
+
let cache = variants.get(mesh);
|
|
22
|
+
if (!cache) {
|
|
23
|
+
const initial = /** @type {ReturnType<typeof createBoxImpostorMaterial>} */ (mesh.material);
|
|
24
|
+
const materials = new Map([[keyFor(normalizeBoxImpostorDisplay(binding.descriptor)), initial]]);
|
|
25
|
+
const release = (/** @type {{target:import('three').Material}} */ event) => {
|
|
26
|
+
const owned = [...materials.values()];
|
|
27
|
+
materials.clear();
|
|
28
|
+
variants.delete(mesh);
|
|
29
|
+
for (const material of owned) {
|
|
30
|
+
material.removeEventListener('dispose', release);
|
|
31
|
+
if (material !== event.target) material.dispose();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
cache = {materials, release};
|
|
35
|
+
variants.set(mesh, cache);
|
|
36
|
+
initial.addEventListener('dispose', release);
|
|
37
|
+
}
|
|
38
|
+
const key = keyFor(settings);
|
|
39
|
+
let material = cache.materials.get(key);
|
|
40
|
+
if (!material) {
|
|
41
|
+
material = createBoxImpostorMaterial(descriptor, binding.maps);
|
|
42
|
+
material.addEventListener('dispose', cache.release);
|
|
43
|
+
cache.materials.set(key, material);
|
|
44
|
+
}
|
|
45
|
+
material.userData.boxImpostor.alphaCutoff.value = settings.alphaCutoff;
|
|
46
|
+
material.userData.boxImpostor.descriptor = descriptor;
|
|
47
|
+
mesh.material = material;
|
|
48
|
+
binding.descriptor = descriptor;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Shared capture coordinates; keep this module free of renderer dependencies so
|
|
3
|
+
// standalone bundles can use the same convention without importing an engine.
|
|
4
|
+
export const BOX_FACE_AXES = Object.freeze([
|
|
5
|
+
{ normal: [1, 0, 0], right: [0, 0, -1], up: [0, 1, 0] },
|
|
6
|
+
{ normal: [-1, 0, 0], right: [0, 0, 1], up: [0, 1, 0] },
|
|
7
|
+
{ normal: [0, 1, 0], right: [1, 0, 0], up: [0, 0, -1] },
|
|
8
|
+
{ normal: [0, -1, 0], right: [1, 0, 0], up: [0, 0, 1] },
|
|
9
|
+
{ normal: [0, 0, 1], right: [1, 0, 0], up: [0, 1, 0] },
|
|
10
|
+
{ normal: [0, 0, -1], right: [-1, 0, 0], up: [0, 1, 0] },
|
|
11
|
+
]);
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// TSL graph properties are checked by rendered WebGPU/WebGL regressions.
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import { DataTexture, FloatType, RGBAFormat, NearestFilter } from 'three';
|
|
4
|
+
import {
|
|
5
|
+
Fn,
|
|
6
|
+
If,
|
|
7
|
+
attribute,
|
|
8
|
+
positionLocal,
|
|
9
|
+
uv,
|
|
10
|
+
texture,
|
|
11
|
+
textureLoad,
|
|
12
|
+
ivec2,
|
|
13
|
+
vec2,
|
|
14
|
+
vec3,
|
|
15
|
+
float,
|
|
16
|
+
int,
|
|
17
|
+
dot,
|
|
18
|
+
abs,
|
|
19
|
+
max,
|
|
20
|
+
sign,
|
|
21
|
+
transformNormalToView,
|
|
22
|
+
} from 'three/tsl';
|
|
23
|
+
import { BOX_FACE_AXES } from './box-impostor-metadata.js';
|
|
24
|
+
|
|
25
|
+
/** Rasterization resolves fitted faces without a fragment ray or depth override. */
|
|
26
|
+
export function applyBoxFaces({
|
|
27
|
+
material,
|
|
28
|
+
descriptor,
|
|
29
|
+
maps,
|
|
30
|
+
alphaCutoff,
|
|
31
|
+
transparency,
|
|
32
|
+
half,
|
|
33
|
+
toBox,
|
|
34
|
+
fromBox,
|
|
35
|
+
}) {
|
|
36
|
+
const values = new Float32Array(descriptor.boxes.length * 6 * 4);
|
|
37
|
+
descriptor.boxes.forEach((box, i) => {
|
|
38
|
+
for (let face = 0; face < 6; face++)
|
|
39
|
+
values[(i * 6 + face) * 4] = box.planes?.[face] ?? 0.5;
|
|
40
|
+
});
|
|
41
|
+
const planes = new DataTexture(
|
|
42
|
+
values,
|
|
43
|
+
6,
|
|
44
|
+
descriptor.boxes.length,
|
|
45
|
+
RGBAFormat,
|
|
46
|
+
FloatType,
|
|
47
|
+
);
|
|
48
|
+
planes.minFilter = planes.magFilter = NearestFilter;
|
|
49
|
+
planes.needsUpdate = true;
|
|
50
|
+
material.addEventListener('dispose', () => planes.dispose());
|
|
51
|
+
const face = int(attribute('boxFace', 'float'));
|
|
52
|
+
const n = attribute('normal', 'vec3');
|
|
53
|
+
const depth = textureLoad(
|
|
54
|
+
planes,
|
|
55
|
+
ivec2(face, int(attribute('boxId', 'float'))),
|
|
56
|
+
).r;
|
|
57
|
+
const proxy = positionLocal.sub(
|
|
58
|
+
n.mul(
|
|
59
|
+
dot(abs(toBox(n)), half)
|
|
60
|
+
.mul(depth)
|
|
61
|
+
.mul(2),
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
material.positionNode = proxy;
|
|
65
|
+
material.castShadowPositionNode = proxy;
|
|
66
|
+
const base = texture(maps.baseColor, uv()).level(0).toVar('boxFaceColor');
|
|
67
|
+
const orm = texture(maps.orm, uv()).level(0);
|
|
68
|
+
const coverage = max(orm.a, 1e-10);
|
|
69
|
+
const normal = Fn(() => {
|
|
70
|
+
const packed = textureLoad(
|
|
71
|
+
maps.normalDepth,
|
|
72
|
+
ivec2(uv().mul(descriptor.atlasResolution)),
|
|
73
|
+
)
|
|
74
|
+
.rg.mul(2)
|
|
75
|
+
.sub(1);
|
|
76
|
+
const decoded = vec3(
|
|
77
|
+
packed,
|
|
78
|
+
float(1).sub(abs(packed.x)).sub(abs(packed.y)),
|
|
79
|
+
).toVar();
|
|
80
|
+
If(decoded.z.lessThan(0), () => {
|
|
81
|
+
decoded.xy.assign(
|
|
82
|
+
vec2(1)
|
|
83
|
+
.sub(abs(decoded.yx))
|
|
84
|
+
.mul(sign(decoded.xy.add(1e-20))),
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
const result = vec3(0).toVar();
|
|
88
|
+
for (let f = 0; f < 6; f++) {
|
|
89
|
+
const a = BOX_FACE_AXES[f];
|
|
90
|
+
If(face.equal(f), () => {
|
|
91
|
+
result.assign(
|
|
92
|
+
fromBox(
|
|
93
|
+
vec3(...a.right)
|
|
94
|
+
.mul(decoded.x)
|
|
95
|
+
.add(vec3(...a.up).mul(decoded.y))
|
|
96
|
+
.add(vec3(...a.normal).mul(decoded.z)),
|
|
97
|
+
).normalize(),
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
})();
|
|
103
|
+
material.colorNode = base.rgb.div(coverage);
|
|
104
|
+
material.normalNode = transformNormalToView(normal);
|
|
105
|
+
material.roughnessNode = orm.g.div(coverage);
|
|
106
|
+
material.metalnessNode = orm.b.div(coverage);
|
|
107
|
+
material.aoNode = orm.r.div(coverage);
|
|
108
|
+
material.emissiveNode = texture(maps.emissive, uv())
|
|
109
|
+
.level(0)
|
|
110
|
+
.rgb.div(coverage);
|
|
111
|
+
material.maskNode = base.a.greaterThanEqual(
|
|
112
|
+
transparency === 'cutout' ? alphaCutoff : float(1 / 255),
|
|
113
|
+
);
|
|
114
|
+
material.maskShadowNode = material.maskNode;
|
|
115
|
+
if (transparency !== 'cutout') material.opacityNode = base.a;
|
|
116
|
+
material.userData.boxImpostor = { descriptor, maps, alphaCutoff };
|
|
117
|
+
return material;
|
|
118
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import {
|
|
3
|
+
BufferGeometry,
|
|
4
|
+
Float32BufferAttribute,
|
|
5
|
+
InterleavedBuffer,
|
|
6
|
+
InterleavedBufferAttribute,
|
|
7
|
+
} from 'three';
|
|
8
|
+
import {
|
|
9
|
+
BOX_FACE_AXES,
|
|
10
|
+
parseBoxImpostorDescriptor,
|
|
11
|
+
} from './box-impostor-metadata.js';
|
|
12
|
+
|
|
13
|
+
/** Portable six-face boxes (or a front card) with atlas UVs. Runtime attributes
|
|
14
|
+
* repeat each box's transform so all boxes can use a single material and draw.
|
|
15
|
+
* @param {import('./box-impostor-metadata.js').BoxImpostorDescriptor} input */
|
|
16
|
+
export function createBoxImpostorGeometry(input) {
|
|
17
|
+
const d = parseBoxImpostorDescriptor(input);
|
|
18
|
+
const depths = /** @type {number[][]} */ ([[], [], []]);
|
|
19
|
+
const positions = [],
|
|
20
|
+
normals = [],
|
|
21
|
+
uvs = [],
|
|
22
|
+
indices = [],
|
|
23
|
+
centers = [],
|
|
24
|
+
halves = [],
|
|
25
|
+
axisX = [],
|
|
26
|
+
axisY = [],
|
|
27
|
+
axisZ = [],
|
|
28
|
+
boxIds = [],
|
|
29
|
+
faces = [],
|
|
30
|
+
corners = [];
|
|
31
|
+
for (const [id, b] of d.boxes.entries())
|
|
32
|
+
for (const f of d.mode !== 'fitted' ? [4] : [0, 1, 2, 3, 4, 5]) {
|
|
33
|
+
const face = BOX_FACE_AXES[f],
|
|
34
|
+
base = positions.length / 3,
|
|
35
|
+
r = b.views[f],
|
|
36
|
+
p = d.padding;
|
|
37
|
+
for (const [x, y] of [
|
|
38
|
+
[-1, -1],
|
|
39
|
+
[1, -1],
|
|
40
|
+
[1, 1],
|
|
41
|
+
[-1, 1],
|
|
42
|
+
]) {
|
|
43
|
+
const local = face.normal.map(
|
|
44
|
+
(n, a) => (n + face.right[a] * x + face.up[a] * y) * b.halfSize[a],
|
|
45
|
+
);
|
|
46
|
+
positions.push(
|
|
47
|
+
...b.center.map(
|
|
48
|
+
(c, a) => c + local.reduce((s, v, i) => s + v * b.axes[i][a], 0),
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
normals.push(
|
|
52
|
+
...[0, 1, 2].map((a) =>
|
|
53
|
+
face.normal.reduce((s, v, i) => s + v * b.axes[i][a], 0),
|
|
54
|
+
),
|
|
55
|
+
);
|
|
56
|
+
uvs.push(
|
|
57
|
+
(r[0] + p + (x + 1) * 0.5 * (r[2] - 2 * p)) / d.atlasResolution,
|
|
58
|
+
(r[1] + p + (y + 1) * 0.5 * (r[3] - 2 * p)) / d.atlasResolution,
|
|
59
|
+
);
|
|
60
|
+
centers.push(...b.center);
|
|
61
|
+
halves.push(...b.halfSize);
|
|
62
|
+
axisX.push(...b.axes[0]);
|
|
63
|
+
axisY.push(...b.axes[1]);
|
|
64
|
+
axisZ.push(...b.axes[2]);
|
|
65
|
+
for (let axis = 0; axis < 3; axis++)
|
|
66
|
+
depths[axis].push(
|
|
67
|
+
...(
|
|
68
|
+
b.depthBounds?.slice(axis * 4, axis * 4 + 4) ?? [
|
|
69
|
+
0, 65535, 0, 65535,
|
|
70
|
+
]
|
|
71
|
+
).map((v) => v / 65535),
|
|
72
|
+
);
|
|
73
|
+
boxIds.push(id);
|
|
74
|
+
faces.push(f);
|
|
75
|
+
corners.push(x, y);
|
|
76
|
+
}
|
|
77
|
+
indices.push(base, base + 1, base + 2, base, base + 2, base + 3);
|
|
78
|
+
}
|
|
79
|
+
const geometry = new BufferGeometry();
|
|
80
|
+
for (const [name, data, size] of /** @type {[string,number[],number][]} */ ([
|
|
81
|
+
['position', positions, 3],
|
|
82
|
+
['normal', normals, 3],
|
|
83
|
+
['uv', uvs, 2],
|
|
84
|
+
['boxCenter', centers, 3],
|
|
85
|
+
['boxHalfSize', halves, 3],
|
|
86
|
+
['boxAxisX', axisX, 3],
|
|
87
|
+
['boxAxisY', axisY, 3],
|
|
88
|
+
['boxAxisZ', axisZ, 3],
|
|
89
|
+
['boxDepthX', depths[0], 4],
|
|
90
|
+
['boxDepthY', depths[1], 4],
|
|
91
|
+
['boxDepthZ', depths[2], 4],
|
|
92
|
+
['boxId', boxIds, 1],
|
|
93
|
+
['boxFace', faces, 1],
|
|
94
|
+
['cardCorner', corners, 2],
|
|
95
|
+
]))
|
|
96
|
+
geometry.setAttribute(name, new Float32BufferAttribute(data, size));
|
|
97
|
+
const names = [
|
|
98
|
+
'boxCenter',
|
|
99
|
+
'boxHalfSize',
|
|
100
|
+
'boxAxisX',
|
|
101
|
+
'boxAxisY',
|
|
102
|
+
'boxAxisZ',
|
|
103
|
+
'boxDepthX',
|
|
104
|
+
'boxDepthY',
|
|
105
|
+
'boxDepthZ',
|
|
106
|
+
'boxId',
|
|
107
|
+
'boxFace',
|
|
108
|
+
'cardCorner',
|
|
109
|
+
];
|
|
110
|
+
const stride = names.reduce(
|
|
111
|
+
(sum, name) => sum + geometry.getAttribute(name).itemSize,
|
|
112
|
+
0,
|
|
113
|
+
);
|
|
114
|
+
const data = new Float32Array((centers.length / 3) * stride),
|
|
115
|
+
buffer = new InterleavedBuffer(data, stride);
|
|
116
|
+
let offset = 0;
|
|
117
|
+
for (const name of names) {
|
|
118
|
+
const attribute = geometry.getAttribute(name);
|
|
119
|
+
for (let vertex = 0; vertex < attribute.count; vertex++)
|
|
120
|
+
for (let component = 0; component < attribute.itemSize; component++)
|
|
121
|
+
data[vertex * stride + offset + component] = attribute.getComponent(
|
|
122
|
+
vertex,
|
|
123
|
+
component,
|
|
124
|
+
);
|
|
125
|
+
geometry.setAttribute(
|
|
126
|
+
name,
|
|
127
|
+
new InterleavedBufferAttribute(buffer, attribute.itemSize, offset),
|
|
128
|
+
);
|
|
129
|
+
offset += attribute.itemSize;
|
|
130
|
+
}
|
|
131
|
+
// Barycentric components face the opposite triangle edge. Mask the shared
|
|
132
|
+
// 0–2 diagonal of each quad while retaining all four carrier boundaries.
|
|
133
|
+
geometry.userData.previewWireframeEdgeMasks = Float32Array.from(
|
|
134
|
+
{ length: indices.length }, (_, i) => [1, 0, 1, 1, 1, 0][i % 6],
|
|
135
|
+
);
|
|
136
|
+
geometry.setIndex(indices);
|
|
137
|
+
geometry.computeBoundingBox();
|
|
138
|
+
geometry.computeBoundingSphere();
|
|
139
|
+
return geometry;
|
|
140
|
+
}
|