@needle-tools/three-mesh-effects 0.1.0-alpha → 0.1.0-alpha.0
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/LICENSE +21 -21
- package/README.md +94 -88
- package/build/deformation-runtime.js.map +1 -1
- package/build/impostor-runtime-needle-engine.js.map +1 -1
- package/build/impostor-runtime.js.map +1 -1
- package/build/internal/deformation/cloth-surface.js.map +1 -1
- package/build/internal/deformation/fur-surface.js.map +1 -1
- package/build/internal/deformation/ik-constraints.js.map +1 -1
- package/build/internal/deformation/joints-json.js.map +1 -1
- package/build/internal/deformation/limits.js.map +1 -1
- package/build/internal/deformation/motion-settings.js.map +1 -1
- package/build/internal/deformation/pin-cloth.js.map +1 -1
- package/build/internal/deformation/pin-ik.js.map +1 -1
- package/build/internal/deformation/pin-types.js.map +1 -1
- package/build/internal/deformation/pin-wiggle.js.map +1 -1
- package/build/internal/deformation/pose-slots.js.map +1 -1
- package/build/internal/deformation/pose-timeline.js.map +1 -1
- package/build/internal/deformation/rig-drivers.js.map +1 -1
- package/build/internal/deformation/rig-extension.js.map +1 -1
- package/build/internal/deformation/rig-runtime.js.map +1 -1
- package/build/internal/deformation/wind.js.map +1 -1
- package/build/internal/impostor/impostor-metadata.js.map +1 -1
- package/build/internal/impostor/impostor-node-material.js.map +1 -1
- package/build/internal/impostor/impostor-runtime-support.js.map +1 -1
- package/build/internal/impostor/octahedral.js.map +1 -1
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +1 -1
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js.map +1 -1
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js.map +1 -1
- package/build/internal/rendering/skin-projection.js +52 -52
- package/build/internal/rendering/skin-projection.js.map +2 -2
- package/build/internal/rendering/surface-query.js +52 -52
- package/build/internal/rendering/surface-query.js.map +2 -2
- package/build/internal/rendering/wireframe.js.map +1 -1
- package/build/internal/rendering/wrap-preview-settings.js.map +1 -1
- package/build/internal/rendering/wrap-preview.js +52 -52
- package/build/internal/rendering/wrap-preview.js.map +2 -2
- package/build/internal/rendering/wrap-skin.js +52 -52
- package/build/internal/rendering/wrap-skin.js.map +2 -2
- package/build/pixel-impostor-runtime.js.map +1 -1
- package/build/wrap-effects.js +52 -52
- package/build/wrap-effects.js.map +2 -2
- package/package.json +107 -94
- package/src/deformation/cloth-surface.ts +223 -223
- package/src/deformation/fur-surface.ts +129 -129
- package/src/deformation/ik-constraints.ts +37 -37
- package/src/deformation/joints-json.ts +94 -94
- package/src/deformation/limits.ts +25 -25
- package/src/deformation/motion-settings.ts +9 -9
- package/src/deformation/pin-cloth.ts +149 -149
- package/src/deformation/pin-ik.ts +582 -582
- package/src/deformation/pin-types.ts +22 -22
- package/src/deformation/pin-wiggle.ts +119 -119
- package/src/deformation/pose-slots.ts +106 -106
- package/src/deformation/pose-timeline.ts +242 -242
- package/src/deformation/rig-drivers.ts +32 -32
- package/src/deformation/rig-extension.ts +87 -87
- package/src/deformation/rig-runtime.ts +416 -416
- package/src/deformation/wind.ts +36 -36
- package/src/impostor/impostor-metadata.js +137 -137
- package/src/impostor/impostor-node-material.js +1581 -1581
- package/src/impostor/impostor-runtime-support.js +139 -139
- package/src/impostor/octahedral.js +280 -280
- package/src/pixel-impostor/pixel-impostor-display.js +794 -794
- package/src/pixel-impostor/pixel-impostor-metadata.js +74 -74
- package/src/pixel-impostor/pixel-impostor-runtime.js +78 -78
- package/src/public/deformation-runtime.ts +3 -3
- package/src/public/impostor-runtime-needle-engine.js +56 -56
- package/src/public/impostor-runtime.js +21 -21
- package/src/public/pixel-impostor-runtime.js +5 -5
- package/src/public/wrap-effects.js +21 -21
- package/src/rendering/skin-projection.js +113 -113
- package/src/rendering/surface-query.js +88 -88
- package/src/rendering/wireframe.js +115 -115
- package/src/rendering/wrap-preview-settings.js +123 -123
- package/src/rendering/wrap-preview.js +645 -645
- package/src/rendering/wrap-skin.js +109 -109
- package/build/internal/public/deformation-runtime.js +0 -2143
- package/build/internal/public/deformation-runtime.js.map +0 -7
- package/build/internal/public/impostor-runtime-needle-engine.js +0 -42
- package/build/internal/public/impostor-runtime-needle-engine.js.map +0 -7
- package/build/internal/public/impostor-runtime.js +0 -1333
- package/build/internal/public/impostor-runtime.js.map +0 -7
- package/build/internal/public/pixel-impostor-runtime.js +0 -876
- package/build/internal/public/pixel-impostor-runtime.js.map +0 -7
- package/build/internal/public/wrap-effects.js +0 -5640
- package/build/internal/public/wrap-effects.js.map +0 -7
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
DataTexture,
|
|
5
|
-
FloatType,
|
|
6
|
-
NearestFilter,
|
|
7
|
-
RGBAFormat,
|
|
8
|
-
} from 'three';
|
|
9
|
-
|
|
10
|
-
import { parseImpostorDescriptor } from './impostor-metadata.js';
|
|
11
|
-
/** @import { ImpostorDescriptor } from './impostor-metadata.js' */
|
|
12
|
-
|
|
13
|
-
export { parseImpostorDescriptor } from './impostor-metadata.js';
|
|
14
|
-
|
|
15
|
-
export const REPROJECTION_CONFIDENCE_INNER_TEXELS = 0.25;
|
|
16
|
-
export const REPROJECTION_CONFIDENCE_OUTER_TEXELS = 16;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Restricts barycentric interpolation to a compact fraction of each angular
|
|
20
|
-
* transition. A value of one preserves ordinary linear barycentrics. Smaller
|
|
21
|
-
* values create an exact single-view region around each capture while the
|
|
22
|
-
* active transition remains continuous and normalized.
|
|
23
|
-
*
|
|
24
|
-
* Along a triangle edge, `blendZone` is exactly the fraction of that edge over
|
|
25
|
-
* which both endpoint captures contribute.
|
|
26
|
-
*
|
|
27
|
-
* @param {readonly [number, number, number]} inputWeights
|
|
28
|
-
* @param {number} blendZone
|
|
29
|
-
* @returns {[number, number, number]}
|
|
30
|
-
*/
|
|
31
|
-
export function applyImpostorBlendZone(inputWeights, blendZone) {
|
|
32
|
-
if (!isBlendZone(blendZone)) {
|
|
33
|
-
throw new RangeError('Impostor blend zone must be from 0.35 to 1.');
|
|
34
|
-
}
|
|
35
|
-
if (inputWeights.some((weight) => !Number.isFinite(weight) || weight < 0)) {
|
|
36
|
-
throw new RangeError('Impostor barycentric weights must be finite and non-negative.');
|
|
37
|
-
}
|
|
38
|
-
const cutoff = (1 - blendZone) * 0.5;
|
|
39
|
-
const weights = /** @type {[number, number, number]} */ (
|
|
40
|
-
inputWeights.map((weight) => Math.max(0, weight - cutoff))
|
|
41
|
-
);
|
|
42
|
-
const sum = weights[0] + weights[1] + weights[2];
|
|
43
|
-
if (!(sum > 0)) return [1, 0, 0];
|
|
44
|
-
return /** @type {[number, number, number]} */ (
|
|
45
|
-
weights.map((weight) => weight / sum)
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Keeps the angular onset of a previously occluded contour approximately
|
|
51
|
-
* stable as the atlas grid gets denser. The returned value is the temperature
|
|
52
|
-
* used by the normalized log-sum-exp union in the runtime shader.
|
|
53
|
-
*
|
|
54
|
-
* @param {number} frames
|
|
55
|
-
*/
|
|
56
|
-
export function impostorContourUnionSharpness(frames) {
|
|
57
|
-
if (!Number.isInteger(frames) || frames < 2) {
|
|
58
|
-
throw new RangeError('Impostor contour union requires at least two frames per atlas axis.');
|
|
59
|
-
}
|
|
60
|
-
return Math.max(1, 16 / frames);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* CPU mirror of the runtime's continuous geometric confidence. A binary
|
|
65
|
-
* half-texel cutoff made individual pixels (and sometimes entire thin
|
|
66
|
-
* features) switch reconstruction paths at one camera angle. The fade keeps
|
|
67
|
-
* the same bounded rejection while making angular motion continuous.
|
|
68
|
-
*
|
|
69
|
-
* @param {boolean} startedOutOfBounds
|
|
70
|
-
* @param {number} rayError
|
|
71
|
-
* @param {number} footprint
|
|
72
|
-
* @param {boolean=} reprojectionActive
|
|
73
|
-
*/
|
|
74
|
-
export function reprojectedSampleConfidence(
|
|
75
|
-
startedOutOfBounds,
|
|
76
|
-
rayError,
|
|
77
|
-
footprint,
|
|
78
|
-
reprojectionActive = true,
|
|
79
|
-
) {
|
|
80
|
-
if (startedOutOfBounds) return 0;
|
|
81
|
-
if (!reprojectionActive) return 1;
|
|
82
|
-
if (!(footprint > 0)) return 0;
|
|
83
|
-
const residual = rayError / footprint;
|
|
84
|
-
const interval = REPROJECTION_CONFIDENCE_OUTER_TEXELS
|
|
85
|
-
- REPROJECTION_CONFIDENCE_INNER_TEXELS;
|
|
86
|
-
const t = Math.min(1, Math.max(
|
|
87
|
-
0,
|
|
88
|
-
(residual - REPROJECTION_CONFIDENCE_INNER_TEXELS) / interval,
|
|
89
|
-
));
|
|
90
|
-
const eased = t * t * (3 - 2 * t);
|
|
91
|
-
return 1 - eased;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Mirrors the runtime coverage contribution used after depth reprojection.
|
|
96
|
-
* Validity can remove a frame from a pixel, but it must never renormalize the
|
|
97
|
-
* remaining frame to full opacity. Preserving angular support prevents a
|
|
98
|
-
* surface visible in only one capture from appearing as a second opaque layer.
|
|
99
|
-
*
|
|
100
|
-
* @param {readonly [number, number, number]} visibilityWeights
|
|
101
|
-
* @param {readonly [number, number, number]} correctedValidity
|
|
102
|
-
* @returns {[number, number, number]}
|
|
103
|
-
*/
|
|
104
|
-
export function resolveImpostorCoverageWeights(
|
|
105
|
-
visibilityWeights,
|
|
106
|
-
correctedValidity,
|
|
107
|
-
) {
|
|
108
|
-
const values = [...visibilityWeights, ...correctedValidity];
|
|
109
|
-
if (values.some((value) => !Number.isFinite(value) || value < 0)) {
|
|
110
|
-
throw new RangeError('Coverage weights and validity must be finite and non-negative.');
|
|
111
|
-
}
|
|
112
|
-
return /** @type {[number, number, number]} */ (
|
|
113
|
-
visibilityWeights.map((weight, index) => weight * correctedValidity[index])
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** @param {ImpostorDescriptor} descriptor */
|
|
118
|
-
export function createImpostorViewBoundsTexture(descriptor) {
|
|
119
|
-
const texture = new DataTexture(
|
|
120
|
-
new Float32Array(descriptor.viewBounds),
|
|
121
|
-
descriptor.frames,
|
|
122
|
-
descriptor.frames,
|
|
123
|
-
RGBAFormat,
|
|
124
|
-
FloatType,
|
|
125
|
-
);
|
|
126
|
-
texture.name = 'impostor view bounds';
|
|
127
|
-
texture.minFilter = NearestFilter;
|
|
128
|
-
texture.magFilter = NearestFilter;
|
|
129
|
-
texture.generateMipmaps = false;
|
|
130
|
-
texture.needsUpdate = true;
|
|
131
|
-
return texture;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/** @param {unknown} value */
|
|
135
|
-
function isBlendZone(value) {
|
|
136
|
-
return Number.isFinite(value)
|
|
137
|
-
&& /** @type {number} */ (value) >= 0.35
|
|
138
|
-
&& /** @type {number} */ (value) <= 1;
|
|
139
|
-
}
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
DataTexture,
|
|
5
|
+
FloatType,
|
|
6
|
+
NearestFilter,
|
|
7
|
+
RGBAFormat,
|
|
8
|
+
} from 'three';
|
|
9
|
+
|
|
10
|
+
import { parseImpostorDescriptor } from './impostor-metadata.js';
|
|
11
|
+
/** @import { ImpostorDescriptor } from './impostor-metadata.js' */
|
|
12
|
+
|
|
13
|
+
export { parseImpostorDescriptor } from './impostor-metadata.js';
|
|
14
|
+
|
|
15
|
+
export const REPROJECTION_CONFIDENCE_INNER_TEXELS = 0.25;
|
|
16
|
+
export const REPROJECTION_CONFIDENCE_OUTER_TEXELS = 16;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Restricts barycentric interpolation to a compact fraction of each angular
|
|
20
|
+
* transition. A value of one preserves ordinary linear barycentrics. Smaller
|
|
21
|
+
* values create an exact single-view region around each capture while the
|
|
22
|
+
* active transition remains continuous and normalized.
|
|
23
|
+
*
|
|
24
|
+
* Along a triangle edge, `blendZone` is exactly the fraction of that edge over
|
|
25
|
+
* which both endpoint captures contribute.
|
|
26
|
+
*
|
|
27
|
+
* @param {readonly [number, number, number]} inputWeights
|
|
28
|
+
* @param {number} blendZone
|
|
29
|
+
* @returns {[number, number, number]}
|
|
30
|
+
*/
|
|
31
|
+
export function applyImpostorBlendZone(inputWeights, blendZone) {
|
|
32
|
+
if (!isBlendZone(blendZone)) {
|
|
33
|
+
throw new RangeError('Impostor blend zone must be from 0.35 to 1.');
|
|
34
|
+
}
|
|
35
|
+
if (inputWeights.some((weight) => !Number.isFinite(weight) || weight < 0)) {
|
|
36
|
+
throw new RangeError('Impostor barycentric weights must be finite and non-negative.');
|
|
37
|
+
}
|
|
38
|
+
const cutoff = (1 - blendZone) * 0.5;
|
|
39
|
+
const weights = /** @type {[number, number, number]} */ (
|
|
40
|
+
inputWeights.map((weight) => Math.max(0, weight - cutoff))
|
|
41
|
+
);
|
|
42
|
+
const sum = weights[0] + weights[1] + weights[2];
|
|
43
|
+
if (!(sum > 0)) return [1, 0, 0];
|
|
44
|
+
return /** @type {[number, number, number]} */ (
|
|
45
|
+
weights.map((weight) => weight / sum)
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Keeps the angular onset of a previously occluded contour approximately
|
|
51
|
+
* stable as the atlas grid gets denser. The returned value is the temperature
|
|
52
|
+
* used by the normalized log-sum-exp union in the runtime shader.
|
|
53
|
+
*
|
|
54
|
+
* @param {number} frames
|
|
55
|
+
*/
|
|
56
|
+
export function impostorContourUnionSharpness(frames) {
|
|
57
|
+
if (!Number.isInteger(frames) || frames < 2) {
|
|
58
|
+
throw new RangeError('Impostor contour union requires at least two frames per atlas axis.');
|
|
59
|
+
}
|
|
60
|
+
return Math.max(1, 16 / frames);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* CPU mirror of the runtime's continuous geometric confidence. A binary
|
|
65
|
+
* half-texel cutoff made individual pixels (and sometimes entire thin
|
|
66
|
+
* features) switch reconstruction paths at one camera angle. The fade keeps
|
|
67
|
+
* the same bounded rejection while making angular motion continuous.
|
|
68
|
+
*
|
|
69
|
+
* @param {boolean} startedOutOfBounds
|
|
70
|
+
* @param {number} rayError
|
|
71
|
+
* @param {number} footprint
|
|
72
|
+
* @param {boolean=} reprojectionActive
|
|
73
|
+
*/
|
|
74
|
+
export function reprojectedSampleConfidence(
|
|
75
|
+
startedOutOfBounds,
|
|
76
|
+
rayError,
|
|
77
|
+
footprint,
|
|
78
|
+
reprojectionActive = true,
|
|
79
|
+
) {
|
|
80
|
+
if (startedOutOfBounds) return 0;
|
|
81
|
+
if (!reprojectionActive) return 1;
|
|
82
|
+
if (!(footprint > 0)) return 0;
|
|
83
|
+
const residual = rayError / footprint;
|
|
84
|
+
const interval = REPROJECTION_CONFIDENCE_OUTER_TEXELS
|
|
85
|
+
- REPROJECTION_CONFIDENCE_INNER_TEXELS;
|
|
86
|
+
const t = Math.min(1, Math.max(
|
|
87
|
+
0,
|
|
88
|
+
(residual - REPROJECTION_CONFIDENCE_INNER_TEXELS) / interval,
|
|
89
|
+
));
|
|
90
|
+
const eased = t * t * (3 - 2 * t);
|
|
91
|
+
return 1 - eased;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Mirrors the runtime coverage contribution used after depth reprojection.
|
|
96
|
+
* Validity can remove a frame from a pixel, but it must never renormalize the
|
|
97
|
+
* remaining frame to full opacity. Preserving angular support prevents a
|
|
98
|
+
* surface visible in only one capture from appearing as a second opaque layer.
|
|
99
|
+
*
|
|
100
|
+
* @param {readonly [number, number, number]} visibilityWeights
|
|
101
|
+
* @param {readonly [number, number, number]} correctedValidity
|
|
102
|
+
* @returns {[number, number, number]}
|
|
103
|
+
*/
|
|
104
|
+
export function resolveImpostorCoverageWeights(
|
|
105
|
+
visibilityWeights,
|
|
106
|
+
correctedValidity,
|
|
107
|
+
) {
|
|
108
|
+
const values = [...visibilityWeights, ...correctedValidity];
|
|
109
|
+
if (values.some((value) => !Number.isFinite(value) || value < 0)) {
|
|
110
|
+
throw new RangeError('Coverage weights and validity must be finite and non-negative.');
|
|
111
|
+
}
|
|
112
|
+
return /** @type {[number, number, number]} */ (
|
|
113
|
+
visibilityWeights.map((weight, index) => weight * correctedValidity[index])
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** @param {ImpostorDescriptor} descriptor */
|
|
118
|
+
export function createImpostorViewBoundsTexture(descriptor) {
|
|
119
|
+
const texture = new DataTexture(
|
|
120
|
+
new Float32Array(descriptor.viewBounds),
|
|
121
|
+
descriptor.frames,
|
|
122
|
+
descriptor.frames,
|
|
123
|
+
RGBAFormat,
|
|
124
|
+
FloatType,
|
|
125
|
+
);
|
|
126
|
+
texture.name = 'impostor view bounds';
|
|
127
|
+
texture.minFilter = NearestFilter;
|
|
128
|
+
texture.magFilter = NearestFilter;
|
|
129
|
+
texture.generateMipmaps = false;
|
|
130
|
+
texture.needsUpdate = true;
|
|
131
|
+
return texture;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** @param {unknown} value */
|
|
135
|
+
function isBlendZone(value) {
|
|
136
|
+
return Number.isFinite(value)
|
|
137
|
+
&& /** @type {number} */ (value) >= 0.35
|
|
138
|
+
&& /** @type {number} */ (value) <= 1;
|
|
139
|
+
}
|