@solidrt/3d 0.0.55 → 0.0.57
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/AGENTS.md +1206 -224
- package/README.md +16 -7
- package/examples/README.md +88 -9
- package/examples/aim.tsx +2 -3
- package/examples/cascades.tsx +1 -4
- package/examples/collision.tsx +263 -0
- package/examples/first-person.tsx +129 -0
- package/examples/fleet.tsx +200 -0
- package/examples/fog.tsx +2 -3
- package/examples/instanced.tsx +72 -32
- package/examples/lamps.tsx +92 -0
- package/examples/lit.tsx +3 -5
- package/examples/materials.tsx +150 -0
- package/examples/model-load.tsx +95 -0
- package/examples/model.glb +0 -0
- package/examples/model.tsx +35 -9
- package/examples/pick.tsx +145 -37
- package/examples/probe.tsx +107 -0
- package/examples/scene-background.tsx +2 -4
- package/examples/scene-basic.tsx +2 -4
- package/examples/scene-views.tsx +68 -48
- package/examples/shadows.tsx +2 -4
- package/examples/sky-lit.tsx +92 -0
- package/examples/skybox.tsx +134 -0
- package/examples/sprites.tsx +4 -6
- package/examples/standard.tsx +138 -0
- package/examples/sweep-paths.tsx +2 -4
- package/package.json +3 -3
- package/src/camera.ts +148 -0
- package/src/clip.ts +96 -0
- package/src/collision.ts +20 -0
- package/src/color.ts +32 -0
- package/src/components/context.tsx +35 -0
- package/src/components/directional-light.tsx +48 -0
- package/src/components/first-person-camera.tsx +72 -0
- package/src/components/group.tsx +18 -0
- package/src/components/hemisphere-light.tsx +24 -0
- package/src/components/index.ts +46 -0
- package/src/components/instanced-mesh.tsx +105 -0
- package/src/components/mesh.tsx +92 -0
- package/src/components/node-props.ts +90 -0
- package/src/components/orbit-camera.tsx +75 -0
- package/src/components/perspective-camera.tsx +32 -0
- package/src/components/point-light.tsx +52 -0
- package/src/components/record-mesh.tsx +68 -0
- package/src/components/scene.tsx +281 -0
- package/src/components/spot-light.tsx +65 -0
- package/src/components/sprite.tsx +38 -0
- package/src/components/view3d.tsx +152 -0
- package/src/environment-bake.ts +492 -0
- package/src/environment.ts +325 -0
- package/src/first-person.ts +258 -0
- package/src/geometry.ts +6 -2
- package/src/glsl.ts +1343 -82
- package/src/gltf.ts +432 -112
- package/src/index.ts +61 -9
- package/src/input.ts +70 -0
- package/src/light.ts +383 -0
- package/src/material.ts +667 -232
- package/src/math.ts +110 -0
- package/src/mesh.ts +728 -0
- package/src/mixer.ts +476 -0
- package/src/model-file.ts +80 -15
- package/src/model.ts +204 -35
- package/src/node.ts +579 -0
- package/src/orbit.ts +292 -212
- package/src/scene-pointer.ts +294 -0
- package/src/scene-shadows.ts +471 -0
- package/src/scene.ts +1435 -1576
- package/tools/environment.ts +69 -0
- package/tools/model.ts +4 -3
- package/src/components.tsx +0 -420
package/src/math.ts
CHANGED
|
@@ -99,6 +99,54 @@ export function invertAffine(out: Mat4, m: Mat4): Mat4 {
|
|
|
99
99
|
return out
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Invert a GENERAL matrix - a projection or a view-projection, where
|
|
104
|
+
* invertAffine's bottom-row shortcut does not hold. The camera's
|
|
105
|
+
* uInvViewProj (a world-space ray from a clip position) is the consumer;
|
|
106
|
+
* a world matrix should keep using invertAffine. `out` may alias `m`. A
|
|
107
|
+
* singular matrix yields the raw adjugate instead of NaNs, the same policy
|
|
108
|
+
* as invertAffine.
|
|
109
|
+
*/
|
|
110
|
+
export function invert(out: Mat4, m: Mat4): Mat4 {
|
|
111
|
+
let a00 = m[0], a01 = m[1], a02 = m[2], a03 = m[3]
|
|
112
|
+
let a10 = m[4], a11 = m[5], a12 = m[6], a13 = m[7]
|
|
113
|
+
let a20 = m[8], a21 = m[9], a22 = m[10], a23 = m[11]
|
|
114
|
+
let a30 = m[12], a31 = m[13], a32 = m[14], a33 = m[15]
|
|
115
|
+
// The twelve 2x2 minors every cofactor is built from (Laplace on pairs
|
|
116
|
+
// of rows), so each of the sixteen entries costs two multiplies.
|
|
117
|
+
let b00 = a00 * a11 - a01 * a10
|
|
118
|
+
let b01 = a00 * a12 - a02 * a10
|
|
119
|
+
let b02 = a00 * a13 - a03 * a10
|
|
120
|
+
let b03 = a01 * a12 - a02 * a11
|
|
121
|
+
let b04 = a01 * a13 - a03 * a11
|
|
122
|
+
let b05 = a02 * a13 - a03 * a12
|
|
123
|
+
let b06 = a20 * a31 - a21 * a30
|
|
124
|
+
let b07 = a20 * a32 - a22 * a30
|
|
125
|
+
let b08 = a20 * a33 - a23 * a30
|
|
126
|
+
let b09 = a21 * a32 - a22 * a31
|
|
127
|
+
let b10 = a21 * a33 - a23 * a31
|
|
128
|
+
let b11 = a22 * a33 - a23 * a32
|
|
129
|
+
let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06
|
|
130
|
+
let s = 1 / (det || 1)
|
|
131
|
+
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * s
|
|
132
|
+
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * s
|
|
133
|
+
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * s
|
|
134
|
+
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * s
|
|
135
|
+
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * s
|
|
136
|
+
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * s
|
|
137
|
+
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * s
|
|
138
|
+
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * s
|
|
139
|
+
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * s
|
|
140
|
+
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * s
|
|
141
|
+
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * s
|
|
142
|
+
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * s
|
|
143
|
+
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * s
|
|
144
|
+
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * s
|
|
145
|
+
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * s
|
|
146
|
+
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * s
|
|
147
|
+
return out
|
|
148
|
+
}
|
|
149
|
+
|
|
102
150
|
/** out = a * b (column vectors: b applies first). out may alias a or b. */
|
|
103
151
|
export function multiply(out: Mat4, a: Mat4, b: Mat4): Mat4 {
|
|
104
152
|
let a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3]
|
|
@@ -174,6 +222,68 @@ export function normalMatrix(out: Mat4, m: Mat4): Mat4 {
|
|
|
174
222
|
return out
|
|
175
223
|
}
|
|
176
224
|
|
|
225
|
+
/** The determinant of a matrix's upper 3x3 - negative means the transform
|
|
226
|
+
* mirrors (flips handedness, and with it triangle winding). */
|
|
227
|
+
export function det3(m: Mat4): number {
|
|
228
|
+
return (
|
|
229
|
+
m[0] * (m[5] * m[10] - m[6] * m[9]) -
|
|
230
|
+
m[4] * (m[1] * m[10] - m[2] * m[9]) +
|
|
231
|
+
m[8] * (m[1] * m[6] - m[2] * m[5])
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Split an affine matrix into the TRS `compose()` builds: translation from
|
|
237
|
+
* the last column, scale from the basis column lengths (x negated when the
|
|
238
|
+
* matrix mirrors, so `compose(decompose(m))` keeps the handedness), and the
|
|
239
|
+
* rotation from the scale-normalized basis. Lossy for a SHEARED matrix -
|
|
240
|
+
* TRS cannot represent shear, so it is silently dropped; a zero-scale axis
|
|
241
|
+
* yields a best-effort unit rotation rather than NaNs.
|
|
242
|
+
*/
|
|
243
|
+
export function decompose(m: Mat4, position: Vec3, rotation: Quat, scale: Vec3): void {
|
|
244
|
+
position[0] = m[12]; position[1] = m[13]; position[2] = m[14]
|
|
245
|
+
let sx = Math.hypot(m[0], m[1], m[2])
|
|
246
|
+
let sy = Math.hypot(m[4], m[5], m[6])
|
|
247
|
+
let sz = Math.hypot(m[8], m[9], m[10])
|
|
248
|
+
if (det3(m) < 0) sx = -sx
|
|
249
|
+
scale[0] = sx; scale[1] = sy; scale[2] = sz
|
|
250
|
+
let ix = sx === 0 ? 0 : 1 / sx
|
|
251
|
+
let iy = sy === 0 ? 0 : 1 / sy
|
|
252
|
+
let iz = sz === 0 ? 0 : 1 / sz
|
|
253
|
+
// Row-major elements of the pure-rotation 3x3 (columns un-scaled).
|
|
254
|
+
let r00 = m[0] * ix, r01 = m[4] * iy, r02 = m[8] * iz
|
|
255
|
+
let r10 = m[1] * ix, r11 = m[5] * iy, r12 = m[9] * iz
|
|
256
|
+
let r20 = m[2] * ix, r21 = m[6] * iy, r22 = m[10] * iz
|
|
257
|
+
// Shepperd's method: branch on the largest diagonal term for stability.
|
|
258
|
+
let trace = r00 + r11 + r22
|
|
259
|
+
if (trace > 0) {
|
|
260
|
+
let s = Math.sqrt(trace + 1) * 2
|
|
261
|
+
rotation[3] = s / 4
|
|
262
|
+
rotation[0] = (r21 - r12) / s
|
|
263
|
+
rotation[1] = (r02 - r20) / s
|
|
264
|
+
rotation[2] = (r10 - r01) / s
|
|
265
|
+
} else if (r00 > r11 && r00 > r22) {
|
|
266
|
+
let s = Math.sqrt(1 + r00 - r11 - r22) * 2
|
|
267
|
+
rotation[3] = (r21 - r12) / s
|
|
268
|
+
rotation[0] = s / 4
|
|
269
|
+
rotation[1] = (r01 + r10) / s
|
|
270
|
+
rotation[2] = (r02 + r20) / s
|
|
271
|
+
} else if (r11 > r22) {
|
|
272
|
+
let s = Math.sqrt(1 + r11 - r00 - r22) * 2
|
|
273
|
+
rotation[3] = (r02 - r20) / s
|
|
274
|
+
rotation[0] = (r01 + r10) / s
|
|
275
|
+
rotation[1] = s / 4
|
|
276
|
+
rotation[2] = (r12 + r21) / s
|
|
277
|
+
} else {
|
|
278
|
+
let s = Math.sqrt(1 + r22 - r00 - r11) * 2
|
|
279
|
+
rotation[3] = (r10 - r01) / s
|
|
280
|
+
rotation[0] = (r02 + r20) / s
|
|
281
|
+
rotation[1] = (r12 + r21) / s
|
|
282
|
+
rotation[2] = s / 4
|
|
283
|
+
}
|
|
284
|
+
quatNormalize(rotation, rotation)
|
|
285
|
+
}
|
|
286
|
+
|
|
177
287
|
/**
|
|
178
288
|
* Right-handed perspective projection with the engine's y-down clip flip
|
|
179
289
|
* BAKED IN (row two is negated): geometry authored y-up displays y-up, and
|