@nakednous/tree 0.0.11 → 0.0.13
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/README.md +44 -20
- package/dist/index.js +417 -589
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -219,24 +219,48 @@ One-keyframe behaviour: `play()` with exactly one keyframe snaps `eval()` to tha
|
|
|
219
219
|
|
|
220
220
|
**Spaces:** `WORLD`, `EYE`, `SCREEN`, `NDC`, `MODEL`, `MATRIX` (custom frame).
|
|
221
221
|
|
|
222
|
-
|
|
222
|
+
#### Conventions
|
|
223
|
+
|
|
224
|
+
Three independent conventions are controlled by caller-supplied parameters:
|
|
225
|
+
|
|
226
|
+
**NDC Z** — passed as `ndcZMin`:
|
|
227
|
+
```
|
|
228
|
+
WEBGL = −1 z ∈ [−1, 1]
|
|
229
|
+
WEBGPU = 0 z ∈ [ 0, 1]
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**Viewport** — `vp = [x, y, w, h]` with signed `h`:
|
|
233
|
+
```
|
|
234
|
+
h < 0 screen y-down (DOM / p5 mouseX·mouseY) → [0, canvasH, canvasW, −canvasH]
|
|
235
|
+
h > 0 screen y-up (OpenGL gl_FragCoord) → [0, 0, canvasW, canvasH]
|
|
236
|
+
```
|
|
237
|
+
The sign of `h` is the only thing that differs — no branching, no flags.
|
|
238
|
+
|
|
239
|
+
**NDC Y** — controlled by `ndcYSign` in the projection constructors (`form.js`):
|
|
240
|
+
```
|
|
241
|
+
+1 NDC y-up (default) — OpenGL / WebGL / WebGPU / Three.js / p5v2
|
|
242
|
+
−1 NDC y-down — native Vulkan clip space
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
#### Usage
|
|
223
246
|
|
|
224
247
|
```js
|
|
225
248
|
import { mapLocation, mapDirection, WORLD, SCREEN, WEBGL } from '@nakednous/tree'
|
|
226
249
|
|
|
227
250
|
const out = new Float32Array(3)
|
|
228
251
|
const m = {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
252
|
+
mat4Proj: /* Float32Array(16) — projection (eye → clip) */,
|
|
253
|
+
mat4View: /* Float32Array(16) — view (world → eye) */,
|
|
254
|
+
mat4PV?: /* mat4Proj × mat4View — optional, computed if absent */,
|
|
255
|
+
mat4PVInv?: /* inv(mat4PV) — optional, computed if absent */,
|
|
233
256
|
}
|
|
234
|
-
const vp = [0, height, width, -height]
|
|
257
|
+
const vp = [0, height, width, -height] // signed h = screen y-down
|
|
235
258
|
|
|
236
259
|
mapLocation(out, worldX, worldY, worldZ, WORLD, SCREEN, m, vp, WEBGL)
|
|
237
260
|
```
|
|
238
261
|
|
|
239
|
-
The matrices bag `m` is assembled by the host
|
|
262
|
+
The matrices bag `m` is assembled by the host. All pairs are supported:
|
|
263
|
+
WORLD↔EYE, WORLD↔SCREEN, WORLD↔NDC, EYE↔SCREEN, SCREEN↔NDC, WORLD↔MATRIX, and their reverses.
|
|
240
264
|
|
|
241
265
|
---
|
|
242
266
|
|
|
@@ -289,14 +313,14 @@ mat4PV mat4MV
|
|
|
289
313
|
**Matrix construction from specs** (`form.js`):
|
|
290
314
|
```
|
|
291
315
|
mat4FromBasis — rigid frame from orthonormal basis + translation
|
|
292
|
-
|
|
293
|
-
|
|
316
|
+
mat4View — view matrix (world→eye) from lookat params
|
|
317
|
+
mat4Eye — eye matrix (eye→world) from lookat params
|
|
294
318
|
mat4FromTRS — column-major mat4 from flat TRS scalars
|
|
295
319
|
mat4FromTranslation — translation-only mat4
|
|
296
320
|
mat4FromScale — scale-only mat4
|
|
297
|
-
mat4Perspective — perspective projection
|
|
298
|
-
mat4Ortho — orthographic projection
|
|
299
|
-
mat4Frustum — off-centre perspective
|
|
321
|
+
mat4Perspective — perspective projection (ndcZMin, ndcYSign)
|
|
322
|
+
mat4Ortho — orthographic projection (ndcZMin, ndcYSign)
|
|
323
|
+
mat4Frustum — off-centre perspective (ndcZMin, ndcYSign)
|
|
300
324
|
mat4Bias — NDC→texture/UV remap [0,1] for shadow mapping
|
|
301
325
|
mat4Reflect — reflection across a plane
|
|
302
326
|
mat4ToTranslation — extract translation (col 3)
|
|
@@ -312,7 +336,7 @@ projLeft projRight projTop projBottom
|
|
|
312
336
|
|
|
313
337
|
**Pixel ratio:** `pixelRatio(proj, vpH, eyeZ, ndcZMin)` — world-units-per-pixel at a given depth, handles both perspective and orthographic.
|
|
314
338
|
|
|
315
|
-
**Pick matrix:** `mat4Pick(proj, px, py,
|
|
339
|
+
**Pick matrix:** `mat4Pick(proj, px, py, vp)` — mutates a projection matrix in-place so that the pixel at `(px, py)` maps to the full NDC square, making a 1×1 FBO render contain exactly that pixel. Takes the same signed viewport `vp` as `mapLocation` — the y-convention is preserved automatically.
|
|
316
340
|
|
|
317
341
|
---
|
|
318
342
|
|
|
@@ -337,7 +361,7 @@ ORIGIN, i, j, k, _i, _j, _k
|
|
|
337
361
|
|
|
338
362
|
## Performance contract
|
|
339
363
|
|
|
340
|
-
All
|
|
364
|
+
All functions in this package follow an **out-first, zero-allocation** contract:
|
|
341
365
|
|
|
342
366
|
- `out` is the first parameter — the caller owns the buffer
|
|
343
367
|
- the function writes into `out` and returns it
|
|
@@ -346,15 +370,15 @@ All hot-path functions follow an **out-first, zero-allocation** contract:
|
|
|
346
370
|
|
|
347
371
|
```js
|
|
348
372
|
// allocate once
|
|
349
|
-
const out
|
|
350
|
-
const
|
|
351
|
-
const
|
|
373
|
+
const out = new Float32Array(3)
|
|
374
|
+
const mat4PV = new Float32Array(16)
|
|
375
|
+
const mat4PVInv = new Float32Array(16)
|
|
352
376
|
|
|
353
377
|
// per frame — zero allocation
|
|
354
|
-
mat4Mul(
|
|
355
|
-
mat4Invert(
|
|
378
|
+
mat4Mul(mat4PV, proj, view)
|
|
379
|
+
mat4Invert(mat4PVInv, mat4PV)
|
|
356
380
|
mapLocation(out, px, py, pz, WORLD, SCREEN,
|
|
357
|
-
{
|
|
381
|
+
{ mat4Proj: proj, mat4View: view, mat4PV, mat4PVInv }, vp, WEBGL)
|
|
358
382
|
```
|
|
359
383
|
|
|
360
384
|
---
|