@needle-tools/three-mesh-effects 0.0.0-stage → 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 -0
- package/README.md +93 -2
- package/build/deformation-runtime.js +2143 -0
- package/build/deformation-runtime.js.map +7 -0
- package/build/impostor-runtime-needle-engine.js +42 -0
- package/build/impostor-runtime-needle-engine.js.map +7 -0
- package/build/impostor-runtime.js +1333 -0
- package/build/impostor-runtime.js.map +7 -0
- package/build/internal/deformation/cloth-surface.js +288 -0
- package/build/internal/deformation/cloth-surface.js.map +7 -0
- package/build/internal/deformation/fur-surface.js +130 -0
- package/build/internal/deformation/fur-surface.js.map +7 -0
- package/build/internal/deformation/ik-constraints.js +44 -0
- package/build/internal/deformation/ik-constraints.js.map +7 -0
- package/build/internal/deformation/joints-json.js +197 -0
- package/build/internal/deformation/joints-json.js.map +7 -0
- package/build/internal/deformation/limits.js +16 -0
- package/build/internal/deformation/limits.js.map +7 -0
- package/build/internal/deformation/motion-settings.js +12 -0
- package/build/internal/deformation/motion-settings.js.map +7 -0
- package/build/internal/deformation/pin-cloth.js +196 -0
- package/build/internal/deformation/pin-cloth.js.map +7 -0
- package/build/internal/deformation/pin-ik.js +650 -0
- package/build/internal/deformation/pin-ik.js.map +7 -0
- package/build/internal/deformation/pin-types.js +12 -0
- package/build/internal/deformation/pin-types.js.map +7 -0
- package/build/internal/deformation/pin-wiggle.js +249 -0
- package/build/internal/deformation/pin-wiggle.js.map +7 -0
- package/build/internal/deformation/pose-slots.js +84 -0
- package/build/internal/deformation/pose-slots.js.map +7 -0
- package/build/internal/deformation/pose-timeline.js +210 -0
- package/build/internal/deformation/pose-timeline.js.map +7 -0
- package/build/internal/deformation/rig-drivers.js +48 -0
- package/build/internal/deformation/rig-drivers.js.map +7 -0
- package/build/internal/deformation/rig-extension.js +334 -0
- package/build/internal/deformation/rig-extension.js.map +7 -0
- package/build/internal/deformation/rig-runtime.js +2141 -0
- package/build/internal/deformation/rig-runtime.js.map +7 -0
- package/build/internal/deformation/wind.js +34 -0
- package/build/internal/deformation/wind.js.map +7 -0
- package/build/internal/impostor/impostor-metadata.js +77 -0
- package/build/internal/impostor/impostor-metadata.js.map +7 -0
- package/build/internal/impostor/impostor-node-material.js +1331 -0
- package/build/internal/impostor/impostor-node-material.js.map +7 -0
- package/build/internal/impostor/impostor-runtime-support.js +162 -0
- package/build/internal/impostor/impostor-runtime-support.js.map +7 -0
- package/build/internal/impostor/octahedral.js +232 -0
- package/build/internal/impostor/octahedral.js.map +7 -0
- package/build/internal/pixel-impostor/pixel-impostor-display.js +728 -0
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +7 -0
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js +71 -0
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js.map +7 -0
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js +150 -0
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js.map +7 -0
- package/build/internal/rendering/skin-projection.js +4630 -0
- package/build/internal/rendering/skin-projection.js.map +7 -0
- package/build/internal/rendering/surface-query.js +4519 -0
- package/build/internal/rendering/surface-query.js.map +7 -0
- package/build/internal/rendering/wireframe.js +112 -0
- package/build/internal/rendering/wireframe.js.map +7 -0
- package/build/internal/rendering/wrap-preview-settings.js +126 -0
- package/build/internal/rendering/wrap-preview-settings.js.map +7 -0
- package/build/internal/rendering/wrap-preview.js +5610 -0
- package/build/internal/rendering/wrap-preview.js.map +7 -0
- package/build/internal/rendering/wrap-skin.js +4746 -0
- package/build/internal/rendering/wrap-skin.js.map +7 -0
- package/build/pixel-impostor-runtime.js +876 -0
- package/build/pixel-impostor-runtime.js.map +7 -0
- package/build/types/deformation/cloth-surface.d.ts +39 -0
- package/build/types/deformation/cloth-surface.js +1 -0
- package/build/types/deformation/fur-surface.d.ts +27 -0
- package/build/types/deformation/fur-surface.js +1 -0
- package/build/types/deformation/ik-constraints.d.ts +18 -0
- package/build/types/deformation/ik-constraints.js +1 -0
- package/build/types/deformation/joints-json.d.ts +17 -0
- package/build/types/deformation/joints-json.js +1 -0
- package/build/types/deformation/limits.d.ts +23 -0
- package/build/types/deformation/limits.js +1 -0
- package/build/types/deformation/motion-settings.d.ts +9 -0
- package/build/types/deformation/motion-settings.js +1 -0
- package/build/types/deformation/pin-cloth.d.ts +28 -0
- package/build/types/deformation/pin-cloth.js +1 -0
- package/build/types/deformation/pin-ik.d.ts +37 -0
- package/build/types/deformation/pin-ik.js +1 -0
- package/build/types/deformation/pin-types.d.ts +53 -0
- package/build/types/deformation/pin-types.js +1 -0
- package/build/types/deformation/pin-wiggle.d.ts +16 -0
- package/build/types/deformation/pin-wiggle.js +1 -0
- package/build/types/deformation/pose-slots.d.ts +41 -0
- package/build/types/deformation/pose-slots.js +1 -0
- package/build/types/deformation/pose-timeline.d.ts +65 -0
- package/build/types/deformation/pose-timeline.js +1 -0
- package/build/types/deformation/rig-drivers.d.ts +19 -0
- package/build/types/deformation/rig-drivers.js +1 -0
- package/build/types/deformation/rig-extension.d.ts +33 -0
- package/build/types/deformation/rig-extension.js +1 -0
- package/build/types/deformation/rig-runtime.d.ts +95 -0
- package/build/types/deformation/rig-runtime.js +1 -0
- package/build/types/deformation/wind.d.ts +16 -0
- package/build/types/deformation/wind.js +1 -0
- package/build/types/impostor/impostor-metadata.d.ts +61 -0
- package/build/types/impostor/impostor-metadata.js +1 -0
- package/build/types/impostor/impostor-node-material.d.ts +140 -0
- package/build/types/impostor/impostor-node-material.js +1 -0
- package/build/types/impostor/impostor-runtime-support.d.ts +52 -0
- package/build/types/impostor/impostor-runtime-support.js +1 -0
- package/build/types/impostor/octahedral.d.ts +84 -0
- package/build/types/impostor/octahedral.js +1 -0
- package/build/types/pixel-impostor/pixel-impostor-display.d.ts +48 -0
- package/build/types/pixel-impostor/pixel-impostor-display.js +1 -0
- package/build/types/pixel-impostor/pixel-impostor-metadata.d.ts +34 -0
- package/build/types/pixel-impostor/pixel-impostor-metadata.js +1 -0
- package/build/types/pixel-impostor/pixel-impostor-runtime.d.ts +18 -0
- package/build/types/pixel-impostor/pixel-impostor-runtime.js +1 -0
- package/build/types/public/deformation-runtime.d.ts +3 -0
- package/build/types/public/deformation-runtime.js +1 -0
- package/build/types/public/impostor-runtime-needle-engine.d.ts +31 -0
- package/build/types/public/impostor-runtime-needle-engine.js +1 -0
- package/build/types/public/impostor-runtime.d.ts +6 -0
- package/build/types/public/impostor-runtime.js +1 -0
- package/build/types/public/pixel-impostor-runtime.d.ts +3 -0
- package/build/types/public/pixel-impostor-runtime.js +1 -0
- package/build/types/public/wrap-effects.d.ts +4 -0
- package/build/types/public/wrap-effects.js +1 -0
- package/build/types/rendering/skin-projection.d.ts +44 -0
- package/build/types/rendering/skin-projection.js +1 -0
- package/build/types/rendering/surface-query.d.ts +66 -0
- package/build/types/rendering/surface-query.js +1 -0
- package/build/types/rendering/wireframe.d.ts +25 -0
- package/build/types/rendering/wireframe.js +1 -0
- package/build/types/rendering/wrap-preview-settings.d.ts +22 -0
- package/build/types/rendering/wrap-preview-settings.js +1 -0
- package/build/types/rendering/wrap-preview.d.ts +39 -0
- package/build/types/rendering/wrap-preview.js +1 -0
- package/build/types/rendering/wrap-skin.d.ts +14 -0
- package/build/types/rendering/wrap-skin.js +1 -0
- package/build/wrap-effects.js +5640 -0
- package/build/wrap-effects.js.map +7 -0
- package/package.json +105 -4
- package/src/deformation/cloth-surface.ts +223 -0
- package/src/deformation/fur-surface.ts +129 -0
- package/src/deformation/ik-constraints.ts +37 -0
- package/src/deformation/joints-json.ts +94 -0
- package/src/deformation/limits.ts +25 -0
- package/src/deformation/motion-settings.ts +9 -0
- package/src/deformation/pin-cloth.ts +149 -0
- package/src/deformation/pin-ik.ts +582 -0
- package/src/deformation/pin-types.ts +22 -0
- package/src/deformation/pin-wiggle.ts +119 -0
- package/src/deformation/pose-slots.ts +106 -0
- package/src/deformation/pose-timeline.ts +242 -0
- package/src/deformation/rig-drivers.ts +32 -0
- package/src/deformation/rig-extension.ts +87 -0
- package/src/deformation/rig-runtime.ts +416 -0
- package/src/deformation/wind.ts +36 -0
- package/src/impostor/impostor-metadata.js +137 -0
- package/src/impostor/impostor-node-material.js +1581 -0
- package/src/impostor/impostor-runtime-support.js +139 -0
- package/src/impostor/octahedral.js +280 -0
- package/src/pixel-impostor/pixel-impostor-display.js +794 -0
- package/src/pixel-impostor/pixel-impostor-metadata.js +74 -0
- package/src/pixel-impostor/pixel-impostor-runtime.js +78 -0
- package/src/public/deformation-runtime.ts +3 -0
- package/src/public/impostor-runtime-needle-engine.js +56 -0
- package/src/public/impostor-runtime.js +21 -0
- package/src/public/pixel-impostor-runtime.js +5 -0
- package/src/public/wrap-effects.js +21 -0
- package/src/rendering/skin-projection.js +113 -0
- package/src/rendering/surface-query.js +88 -0
- package/src/rendering/wireframe.js +115 -0
- package/src/rendering/wrap-preview-settings.js +123 -0
- package/src/rendering/wrap-preview.js +645 -0
- package/src/rendering/wrap-skin.js +109 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
// src/impostor/octahedral.js
|
|
4
|
+
var PERSPECTIVE_RAY_PLANE_SIGN = -1;
|
|
5
|
+
function captureDepthFromPoint(point, direction, radius) {
|
|
6
|
+
if (!(radius > 0) || !Number.isFinite(radius)) {
|
|
7
|
+
throw new RangeError("Capture radius must be positive and finite.");
|
|
8
|
+
}
|
|
9
|
+
const normalizedDirection = normalize3(direction);
|
|
10
|
+
return (radius - dot3(point, normalizedDirection)) / (2 * radius);
|
|
11
|
+
}
|
|
12
|
+
function intersectRayWithCaptureDepth(rayOrigin, rayDirection, captureDirection, depth, radius) {
|
|
13
|
+
if (!(radius > 0) || !Number.isFinite(radius) || !Number.isFinite(depth)) {
|
|
14
|
+
throw new RangeError("Capture depth and radius must be finite, with a positive radius.");
|
|
15
|
+
}
|
|
16
|
+
const ray = normalize3(rayDirection);
|
|
17
|
+
const capture = normalize3(captureDirection);
|
|
18
|
+
const denominator = dot3(ray, capture);
|
|
19
|
+
if (Math.abs(denominator) < 1e-8) {
|
|
20
|
+
throw new RangeError("Runtime ray is parallel to the capture-depth plane.");
|
|
21
|
+
}
|
|
22
|
+
const planeDepth = radius - 2 * radius * depth;
|
|
23
|
+
const distance = (planeDepth - dot3(rayOrigin, capture)) / denominator;
|
|
24
|
+
return (
|
|
25
|
+
/** @type {[number, number, number]} */
|
|
26
|
+
rayOrigin.map((value, index) => value + ray[index] * distance)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
function gridToDirection(coordinate, mapping) {
|
|
30
|
+
const [u, v] = coordinate;
|
|
31
|
+
let x;
|
|
32
|
+
let y;
|
|
33
|
+
let z;
|
|
34
|
+
if (mapping === "hemisphere") {
|
|
35
|
+
x = u - v;
|
|
36
|
+
z = -1 + u + v;
|
|
37
|
+
y = 1 - Math.abs(x) - Math.abs(z);
|
|
38
|
+
} else {
|
|
39
|
+
x = u * 2 - 1;
|
|
40
|
+
z = v * 2 - 1;
|
|
41
|
+
y = 1 - Math.abs(x) - Math.abs(z);
|
|
42
|
+
if (y < 0) {
|
|
43
|
+
const oldX = x;
|
|
44
|
+
x = nonZeroSign(x) * (1 - Math.abs(z));
|
|
45
|
+
z = nonZeroSign(z) * (1 - Math.abs(oldX));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return normalize3([x, y, z]);
|
|
49
|
+
}
|
|
50
|
+
function directionToGrid(input, mapping) {
|
|
51
|
+
let [x, y, z] = normalize3(input);
|
|
52
|
+
if (mapping === "hemisphere") y = Math.max(y, 1e-6);
|
|
53
|
+
const inverseL1 = 1 / Math.max(1e-12, Math.abs(x) + Math.abs(y) + Math.abs(z));
|
|
54
|
+
x *= inverseL1;
|
|
55
|
+
y *= inverseL1;
|
|
56
|
+
z *= inverseL1;
|
|
57
|
+
if (mapping === "hemisphere") {
|
|
58
|
+
return clamp2([(x + z) * 0.5 + 0.5, (z - x) * 0.5 + 0.5]);
|
|
59
|
+
}
|
|
60
|
+
if (y < 0) {
|
|
61
|
+
const oldX = x;
|
|
62
|
+
x = nonZeroSign(x) * (1 - Math.abs(z));
|
|
63
|
+
z = nonZeroSign(z) * (1 - Math.abs(oldX));
|
|
64
|
+
}
|
|
65
|
+
return clamp2([x * 0.5 + 0.5, z * 0.5 + 0.5]);
|
|
66
|
+
}
|
|
67
|
+
function nearestOctahedralCapture(inputDirection, mapping, frames) {
|
|
68
|
+
if (mapping !== "hemisphere" && mapping !== "full") {
|
|
69
|
+
throw new RangeError("Impostor mapping must be hemisphere or full.");
|
|
70
|
+
}
|
|
71
|
+
if (!Number.isInteger(frames) || frames < 2) {
|
|
72
|
+
throw new RangeError("Impostor capture search requires at least two frames per axis.");
|
|
73
|
+
}
|
|
74
|
+
const direction = normalize3(inputDirection);
|
|
75
|
+
let bestFrame = (
|
|
76
|
+
/** @type {[number, number]} */
|
|
77
|
+
[0, 0]
|
|
78
|
+
);
|
|
79
|
+
let bestDirection = gridToDirection([0, 0], mapping);
|
|
80
|
+
let bestDot = -Number.POSITIVE_INFINITY;
|
|
81
|
+
for (let y = 0; y < frames; y++) {
|
|
82
|
+
for (let x = 0; x < frames; x++) {
|
|
83
|
+
const candidate = gridToDirection([x / (frames - 1), y / (frames - 1)], mapping);
|
|
84
|
+
const similarity = dot3(direction, candidate);
|
|
85
|
+
if (similarity <= bestDot) continue;
|
|
86
|
+
bestDot = similarity;
|
|
87
|
+
bestFrame = [x, y];
|
|
88
|
+
bestDirection = candidate;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
frame: bestFrame,
|
|
93
|
+
direction: bestDirection,
|
|
94
|
+
dot: Math.max(-1, Math.min(1, bestDot)),
|
|
95
|
+
angleDegrees: Math.acos(Math.max(-1, Math.min(1, bestDot))) * 180 / Math.PI
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function extrapolateSphericalDirection(startDirection, endDirection, multiplier) {
|
|
99
|
+
if (!Number.isFinite(multiplier) || multiplier < 0) {
|
|
100
|
+
throw new RangeError("Spherical extrapolation multiplier must be finite and non-negative.");
|
|
101
|
+
}
|
|
102
|
+
const start = normalize3(startDirection);
|
|
103
|
+
const end = normalize3(endDirection);
|
|
104
|
+
const similarity = Math.max(-1, Math.min(1, dot3(start, end)));
|
|
105
|
+
const angle = Math.acos(similarity);
|
|
106
|
+
const axis = cross3(start, end);
|
|
107
|
+
const axisLength = Math.hypot(...axis);
|
|
108
|
+
if (angle < 1e-8 || axisLength < 1e-8) return end;
|
|
109
|
+
const unitAxis = (
|
|
110
|
+
/** @type {[number, number, number]} */
|
|
111
|
+
axis.map((component) => component / axisLength)
|
|
112
|
+
);
|
|
113
|
+
const projectedAngle = angle * multiplier;
|
|
114
|
+
const cosine = Math.cos(projectedAngle);
|
|
115
|
+
const sine = Math.sin(projectedAngle);
|
|
116
|
+
const axisCrossStart = cross3(unitAxis, start);
|
|
117
|
+
const axisDotStart = dot3(unitAxis, start);
|
|
118
|
+
return normalize3(
|
|
119
|
+
/** @type {[number, number, number]} */
|
|
120
|
+
start.map((component, index) => component * cosine + axisCrossStart[index] * sine + unitAxis[index] * axisDotStart * (1 - cosine))
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
function selectOctahedralFrames(direction, mapping, frames) {
|
|
124
|
+
const scale = frames - 1;
|
|
125
|
+
const grid = directionToGrid(direction, mapping);
|
|
126
|
+
const gx = grid[0] * scale;
|
|
127
|
+
const gy = grid[1] * scale;
|
|
128
|
+
const x = Math.min(scale - 1, Math.floor(gx));
|
|
129
|
+
const y = Math.min(scale - 1, Math.floor(gy));
|
|
130
|
+
const fx = gx - x;
|
|
131
|
+
const fy = gy - y;
|
|
132
|
+
const base = gridToDirection([x / scale, y / scale], mapping);
|
|
133
|
+
const right = gridToDirection([(x + 1) / scale, y / scale], mapping);
|
|
134
|
+
const up = gridToDirection([x / scale, (y + 1) / scale], mapping);
|
|
135
|
+
const diagonal = gridToDirection([(x + 1) / scale, (y + 1) / scale], mapping);
|
|
136
|
+
const antiDiagonal = mapping === "hemisphere" && x + y === scale - 1 || dot3(right, up) > dot3(base, diagonal);
|
|
137
|
+
if (antiDiagonal) {
|
|
138
|
+
if (fx + fy <= 1) {
|
|
139
|
+
return {
|
|
140
|
+
frames: (
|
|
141
|
+
/** @type {[[number, number], [number, number], [number, number]]} */
|
|
142
|
+
[
|
|
143
|
+
[x, y],
|
|
144
|
+
[x + 1, y],
|
|
145
|
+
[x, y + 1]
|
|
146
|
+
]
|
|
147
|
+
),
|
|
148
|
+
weights: (
|
|
149
|
+
/** @type {[number, number, number]} */
|
|
150
|
+
[1 - fx - fy, fx, fy]
|
|
151
|
+
)
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
frames: (
|
|
156
|
+
/** @type {[[number, number], [number, number], [number, number]]} */
|
|
157
|
+
[
|
|
158
|
+
[x + 1, y + 1],
|
|
159
|
+
[x, y + 1],
|
|
160
|
+
[x + 1, y]
|
|
161
|
+
]
|
|
162
|
+
),
|
|
163
|
+
weights: (
|
|
164
|
+
/** @type {[number, number, number]} */
|
|
165
|
+
[fx + fy - 1, 1 - fx, 1 - fy]
|
|
166
|
+
)
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const horizontal = fx > fy;
|
|
170
|
+
return {
|
|
171
|
+
frames: (
|
|
172
|
+
/** @type {[[number, number], [number, number], [number, number]]} */
|
|
173
|
+
[
|
|
174
|
+
[x, y],
|
|
175
|
+
horizontal ? [x + 1, y] : [x, y + 1],
|
|
176
|
+
[x + 1, y + 1]
|
|
177
|
+
]
|
|
178
|
+
),
|
|
179
|
+
weights: (
|
|
180
|
+
/** @type {[number, number, number]} */
|
|
181
|
+
[
|
|
182
|
+
Math.min(1 - fx, 1 - fy),
|
|
183
|
+
Math.abs(fx - fy),
|
|
184
|
+
Math.min(fx, fy)
|
|
185
|
+
]
|
|
186
|
+
)
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function dot3(a, b) {
|
|
190
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
191
|
+
}
|
|
192
|
+
function cross3(a, b) {
|
|
193
|
+
return (
|
|
194
|
+
/** @type {[number, number, number]} */
|
|
195
|
+
[
|
|
196
|
+
a[1] * b[2] - a[2] * b[1],
|
|
197
|
+
a[2] * b[0] - a[0] * b[2],
|
|
198
|
+
a[0] * b[1] - a[1] * b[0]
|
|
199
|
+
]
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
function normalize3(value) {
|
|
203
|
+
const length = Math.hypot(...value);
|
|
204
|
+
if (length < 1e-12) return (
|
|
205
|
+
/** @type {[number, number, number]} */
|
|
206
|
+
[0, 1, 0]
|
|
207
|
+
);
|
|
208
|
+
return (
|
|
209
|
+
/** @type {[number, number, number]} */
|
|
210
|
+
value.map((component) => component / length)
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
function clamp2(value) {
|
|
214
|
+
return (
|
|
215
|
+
/** @type {[number, number]} */
|
|
216
|
+
value.map((component) => Math.max(0, Math.min(1, component)))
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
function nonZeroSign(value) {
|
|
220
|
+
return value < 0 ? -1 : 1;
|
|
221
|
+
}
|
|
222
|
+
export {
|
|
223
|
+
PERSPECTIVE_RAY_PLANE_SIGN,
|
|
224
|
+
captureDepthFromPoint,
|
|
225
|
+
directionToGrid,
|
|
226
|
+
extrapolateSphericalDirection,
|
|
227
|
+
gridToDirection,
|
|
228
|
+
intersectRayWithCaptureDepth,
|
|
229
|
+
nearestOctahedralCapture,
|
|
230
|
+
selectOctahedralFrames
|
|
231
|
+
};
|
|
232
|
+
//# sourceMappingURL=octahedral.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/impostor/octahedral.js"],
|
|
4
|
+
"sourcesContent": ["// @ts-check\n\n// A billboard point samples the capture camera along point -> camera, so its\n// local plane offset is subtracted from the object-center camera vector.\nexport const PERSPECTIVE_RAY_PLANE_SIGN = -1;\n\n/**\n * Encodes a local-space point into the orthographic capture depth used by the\n * normal/depth atlas. Capture cameras sit at `direction * 2r` and cover the\n * interval from +r to -r along their forward axis.\n *\n * @param {[number, number, number]} point\n * @param {[number, number, number]} direction Unit capture direction.\n * @param {number} radius\n */\nexport function captureDepthFromPoint(point, direction, radius) {\n if (!(radius > 0) || !Number.isFinite(radius)) {\n throw new RangeError('Capture radius must be positive and finite.');\n }\n const normalizedDirection = normalize3(direction);\n return (radius - dot3(point, normalizedDirection)) / (2 * radius);\n}\n\n/**\n * Intersects a runtime point-to-camera ray with the capture-depth plane\n * `dot(P, captureDirection) = radius - 2 * radius * depth`.\n *\n * This is the fixed-point step solved by the runtime parallax shader. It is\n * deliberately expressed independently here so sign and scale regressions are\n * caught by browserless tests.\n *\n * @param {[number, number, number]} rayOrigin\n * @param {[number, number, number]} rayDirection Unit point-to-camera ray.\n * @param {[number, number, number]} captureDirection Unit capture direction.\n * @param {number} depth\n * @param {number} radius\n * @returns {[number, number, number]}\n */\nexport function intersectRayWithCaptureDepth(\n rayOrigin,\n rayDirection,\n captureDirection,\n depth,\n radius,\n) {\n if (!(radius > 0) || !Number.isFinite(radius) || !Number.isFinite(depth)) {\n throw new RangeError('Capture depth and radius must be finite, with a positive radius.');\n }\n const ray = normalize3(rayDirection);\n const capture = normalize3(captureDirection);\n const denominator = dot3(ray, capture);\n if (Math.abs(denominator) < 1e-8) {\n throw new RangeError('Runtime ray is parallel to the capture-depth plane.');\n }\n const planeDepth = radius - 2 * radius * depth;\n const distance = (planeDepth - dot3(rayOrigin, capture)) / denominator;\n return /** @type {[number, number, number]} */ (rayOrigin.map((value, index) => (\n value + ray[index] * distance\n )));\n}\n\n/**\n * Decodes a regular or upper-hemisphere octahedral grid coordinate.\n * Y is the up axis used throughout the baker and preview runtime.\n *\n * @param {[number, number]} coordinate normalized 0..1 grid coordinate\n * @param {'hemisphere' | 'full'} mapping\n * @returns {[number, number, number]}\n */\nexport function gridToDirection(coordinate, mapping) {\n const [u, v] = coordinate;\n let x;\n let y;\n let z;\n if (mapping === 'hemisphere') {\n x = u - v;\n z = -1 + u + v;\n y = 1 - Math.abs(x) - Math.abs(z);\n } else {\n x = u * 2 - 1;\n z = v * 2 - 1;\n y = 1 - Math.abs(x) - Math.abs(z);\n if (y < 0) {\n const oldX = x;\n x = nonZeroSign(x) * (1 - Math.abs(z));\n z = nonZeroSign(z) * (1 - Math.abs(oldX));\n }\n }\n return normalize3([x, y, z]);\n}\n\n/**\n * @param {[number, number, number]} input\n * @param {'hemisphere' | 'full'} mapping\n * @returns {[number, number]}\n */\nexport function directionToGrid(input, mapping) {\n let [x, y, z] = normalize3(input);\n if (mapping === 'hemisphere') y = Math.max(y, 1e-6);\n const inverseL1 = 1 / Math.max(1e-12, Math.abs(x) + Math.abs(y) + Math.abs(z));\n x *= inverseL1;\n y *= inverseL1;\n z *= inverseL1;\n if (mapping === 'hemisphere') {\n return clamp2([(x + z) * 0.5 + 0.5, (z - x) * 0.5 + 0.5]);\n }\n if (y < 0) {\n const oldX = x;\n x = nonZeroSign(x) * (1 - Math.abs(z));\n z = nonZeroSign(z) * (1 - Math.abs(oldX));\n }\n return clamp2([x * 0.5 + 0.5, z * 0.5 + 0.5]);\n}\n\n/**\n * Finds the authored grid direction with the smallest spherical angle to an\n * arbitrary view. Octahedral coordinates are not equal-area, so independently\n * rounding U/V is not guaranteed to choose the closest capture near folds.\n * The production grids contain at most 24\u00B2 views; an exact dot-product search\n * is both cheap and unambiguous for an interaction that runs on orbit release.\n *\n * @param {[number, number, number]} inputDirection\n * @param {'hemisphere' | 'full'} mapping\n * @param {number} frames\n */\nexport function nearestOctahedralCapture(inputDirection, mapping, frames) {\n if (mapping !== 'hemisphere' && mapping !== 'full') {\n throw new RangeError('Impostor mapping must be hemisphere or full.');\n }\n if (!Number.isInteger(frames) || frames < 2) {\n throw new RangeError('Impostor capture search requires at least two frames per axis.');\n }\n const direction = normalize3(inputDirection);\n let bestFrame = /** @type {[number, number]} */ ([0, 0]);\n let bestDirection = gridToDirection([0, 0], mapping);\n let bestDot = -Number.POSITIVE_INFINITY;\n for (let y = 0; y < frames; y++) {\n for (let x = 0; x < frames; x++) {\n const candidate = gridToDirection([x / (frames - 1), y / (frames - 1)], mapping);\n const similarity = dot3(direction, candidate);\n if (similarity <= bestDot) continue;\n bestDot = similarity;\n bestFrame = [x, y];\n bestDirection = candidate;\n }\n }\n return {\n frame: bestFrame,\n direction: bestDirection,\n dot: Math.max(-1, Math.min(1, bestDot)),\n angleDegrees: Math.acos(Math.max(-1, Math.min(1, bestDot))) * 180 / Math.PI,\n };\n}\n\n/**\n * Projects a spherical direction beyond the latest sample. OrbitControls'\n * residual release motion supplies the two samples; values above one look\n * ahead in the same direction, so a fast release cannot select the capture\n * behind its visible trajectory.\n *\n * @param {[number, number, number]} startDirection\n * @param {[number, number, number]} endDirection\n * @param {number} multiplier 1 returns the end sample, 1.5 projects half of\n * the sampled angular motion beyond it.\n * @returns {[number, number, number]}\n */\nexport function extrapolateSphericalDirection(startDirection, endDirection, multiplier) {\n if (!Number.isFinite(multiplier) || multiplier < 0) {\n throw new RangeError('Spherical extrapolation multiplier must be finite and non-negative.');\n }\n const start = normalize3(startDirection);\n const end = normalize3(endDirection);\n const similarity = Math.max(-1, Math.min(1, dot3(start, end)));\n const angle = Math.acos(similarity);\n const axis = cross3(start, end);\n const axisLength = Math.hypot(...axis);\n if (angle < 1e-8 || axisLength < 1e-8) return end;\n const unitAxis = /** @type {[number, number, number]} */ (\n axis.map((component) => component / axisLength)\n );\n const projectedAngle = angle * multiplier;\n const cosine = Math.cos(projectedAngle);\n const sine = Math.sin(projectedAngle);\n const axisCrossStart = cross3(unitAxis, start);\n const axisDotStart = dot3(unitAxis, start);\n return normalize3(/** @type {[number, number, number]} */ (start.map((component, index) => (\n component * cosine\n + axisCrossStart[index] * sine\n + unitAxis[index] * axisDotStart * (1 - cosine)\n ))));\n}\n\n/**\n * Returns the three vertices and barycentric weights of the grid triangle\n * containing a direction. The diagonal is chosen consistently on CPU and GPU.\n *\n * @param {[number, number, number]} direction\n * @param {'hemisphere' | 'full'} mapping\n * @param {number} frames\n */\nexport function selectOctahedralFrames(direction, mapping, frames) {\n const scale = frames - 1;\n const grid = directionToGrid(direction, mapping);\n const gx = grid[0] * scale;\n const gy = grid[1] * scale;\n const x = Math.min(scale - 1, Math.floor(gx));\n const y = Math.min(scale - 1, Math.floor(gy));\n const fx = gx - x;\n const fy = gy - y;\n const base = gridToDirection([x / scale, y / scale], mapping);\n const right = gridToDirection([(x + 1) / scale, y / scale], mapping);\n const up = gridToDirection([x / scale, (y + 1) / scale], mapping);\n const diagonal = gridToDirection([(x + 1) / scale, (y + 1) / scale], mapping);\n // Octahedral grid quads are strongly warped on the sphere, especially at\n // low view counts. Use the shorter of their two spherical diagonals instead\n // of always connecting base -> diagonal. Fold cells still necessarily use\n // the anti-diagonal because it is the captured z=0 view edge.\n const antiDiagonal = mapping === 'hemisphere' && x + y === scale - 1\n || dot3(right, up) > dot3(base, diagonal);\n if (antiDiagonal) {\n if (fx + fy <= 1) {\n return {\n frames: /** @type {[[number, number], [number, number], [number, number]]} */ ([\n [x, y], [x + 1, y], [x, y + 1],\n ]),\n weights: /** @type {[number, number, number]} */ ([1 - fx - fy, fx, fy]),\n };\n }\n return {\n frames: /** @type {[[number, number], [number, number], [number, number]]} */ ([\n [x + 1, y + 1], [x, y + 1], [x + 1, y],\n ]),\n weights: /** @type {[number, number, number]} */ ([fx + fy - 1, 1 - fx, 1 - fy]),\n };\n }\n const horizontal = fx > fy;\n return {\n frames: /** @type {[[number, number], [number, number], [number, number]]} */ ([\n [x, y],\n horizontal ? [x + 1, y] : [x, y + 1],\n [x + 1, y + 1],\n ]),\n weights: /** @type {[number, number, number]} */ ([\n Math.min(1 - fx, 1 - fy),\n Math.abs(fx - fy),\n Math.min(fx, fy),\n ]),\n };\n}\n\n/** @param {[number, number, number]} a @param {[number, number, number]} b */\nfunction dot3(a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n}\n\n/** @param {[number, number, number]} a @param {[number, number, number]} b */\nfunction cross3(a, b) {\n return /** @type {[number, number, number]} */ ([\n a[1] * b[2] - a[2] * b[1],\n a[2] * b[0] - a[0] * b[2],\n a[0] * b[1] - a[1] * b[0],\n ]);\n}\n\n/** @param {[number, number, number]} value */\nfunction normalize3(value) {\n const length = Math.hypot(...value);\n if (length < 1e-12) return /** @type {[number, number, number]} */ ([0, 1, 0]);\n return /** @type {[number, number, number]} */ (value.map((component) => component / length));\n}\n\n/** @param {[number, number]} value */\nfunction clamp2(value) {\n return /** @type {[number, number]} */ (value.map((component) => Math.max(0, Math.min(1, component))));\n}\n\n/** @param {number} value */\nfunction nonZeroSign(value) {\n return value < 0 ? -1 : 1;\n}\n"],
|
|
5
|
+
"mappings": ";;;AAIO,IAAM,6BAA6B;AAWnC,SAAS,sBAAsB,OAAO,WAAW,QAAQ;AAC9D,MAAI,EAAE,SAAS,MAAM,CAAC,OAAO,SAAS,MAAM,GAAG;AAC7C,UAAM,IAAI,WAAW,6CAA6C;AAAA,EACpE;AACA,QAAM,sBAAsB,WAAW,SAAS;AAChD,UAAQ,SAAS,KAAK,OAAO,mBAAmB,MAAM,IAAI;AAC5D;AAiBO,SAAS,6BACd,WACA,cACA,kBACA,OACA,QACA;AACA,MAAI,EAAE,SAAS,MAAM,CAAC,OAAO,SAAS,MAAM,KAAK,CAAC,OAAO,SAAS,KAAK,GAAG;AACxE,UAAM,IAAI,WAAW,kEAAkE;AAAA,EACzF;AACA,QAAM,MAAM,WAAW,YAAY;AACnC,QAAM,UAAU,WAAW,gBAAgB;AAC3C,QAAM,cAAc,KAAK,KAAK,OAAO;AACrC,MAAI,KAAK,IAAI,WAAW,IAAI,MAAM;AAChC,UAAM,IAAI,WAAW,qDAAqD;AAAA,EAC5E;AACA,QAAM,aAAa,SAAS,IAAI,SAAS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