Skip to content

Commit c7ef0af

Browse files
committed
fix: rename matrix keys to new convention
- track: eMatrix → mat4Eye, mMatrix → mat4Model in keyframe spec parsers - panel: ipvMatrix → mat4PVInv in _centerAtDepth (silent unproject failure)
1 parent d4da83b commit c7ef0af

File tree

7 files changed

+85
-83
lines changed

7 files changed

+85
-83
lines changed

README.md

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ function draw() {
7373
`add()` accepts flexible specs. Top-level forms:
7474

7575
```js
76-
track.add({ pos, rot, scl }) // explicit TRS — rot accepts any form below
77-
track.add({ pos, rot, scl, tanIn, tanOut }) // with Hermite tangents (vec3, optional)
78-
track.add({ mMatrix: mat4 }) // decompose model matrix into TRS
79-
track.add([ spec, spec, ... ]) // bulk
76+
track.add({ pos, rot, scl }) // explicit TRS — rot accepts any form below
77+
track.add({ pos, rot, scl, tanIn, tanOut }) // with Hermite tangents (vec3, optional)
78+
track.add({ mat4Model: mat4 }) // decompose a column-major model matrix into TRS
79+
track.add([ spec, spec, ... ]) // bulk
8080
```
8181

8282
`tanIn` is the incoming position tangent at this keyframe; `tanOut` is the outgoing tangent. When only one is given, the other mirrors it. When neither is given, centripetal Catmull-Rom tangents are auto-computed — identical to the default smooth behavior.
@@ -98,7 +98,7 @@ track.add({ pos:[0,0,0], rot: { euler:[rx,ry,rz] } }) // intrinsic
9898
track.add({ pos:[0,0,0], rot: { euler:[rx,ry,rz], order:'XYZ' } }) // explicit order
9999
track.add({ pos:[0,0,0], rot: { from:[0,0,1], to:[1,0,0] } }) // shortest arc
100100
track.add({ pos:[0,0,0], rot: { mat3: rotationMatrix } }) // 3×3 col-major
101-
track.add({ pos:[0,0,0], rot: { eMatrix: eyeMat } }) // from eye matrix
101+
track.add({ pos:[0,0,0], rot: { mat4Eye: eyeMat } }) // from eye matrix
102102
```
103103

104104
Supported Euler orders: `YXZ` (default, matches p5 Y-up), `XYZ`, `ZYX`, `ZXY`, `XZY`, `YZX`. All are intrinsic — extrinsic `ABC` equals intrinsic `CBA` with the same angles.
@@ -126,7 +126,7 @@ let track
126126

127127
function setup() {
128128
createCanvas(600, 400, WEBGL)
129-
track = createCameraTrack() // binds to the default camera
129+
track = createCameraTrack() // binds to the default camera
130130

131131
track.add({ eye:[0,0,500], center:[0,0,0] })
132132
track.add({ eye:[300,-150,0], center:[0,0,0] })
@@ -136,7 +136,7 @@ function setup() {
136136

137137
function draw() {
138138
background(20)
139-
orbitControl() // works freely when track is stopped
139+
orbitControl() // works freely when track is stopped
140140
axes(); grid()
141141
}
142142
```
@@ -154,7 +154,7 @@ track.add() // shortcut — captures track's bound camera
154154
track.add([ spec, spec, ... ]) // bulk
155155
```
156156
157-
For matrix-based capture use `track.add({ mMatrix: eMatrix })` on a `PoseTrack` for full-fidelity TRS including roll, or `cam.capturePose()` for lookat-style capture.
157+
For matrix-based capture use `track.add({ mat4Model: mat4Eye })` on a `PoseTrack` for full-fidelity TRS including roll, or `cam.capturePose()` for lookat-style capture.
158158
159159
`fov` (radians) animates perspective field of view.
160160
`halfHeight` (world units) animates the vertical extent of an ortho frustum —
@@ -179,14 +179,14 @@ All tracks share the same transport API:
179179
180180
```js
181181
track.play({ duration, loop, bounce, rate, onPlay, onEnd, onStop })
182-
track.stop([rewind]) // rewind=true seeks to origin
183-
track.reset() // clear all keyframes and stop
184-
track.seek(t) // t ∈ [0, 1]
185-
track.time() // → number ∈ [0, 1]
186-
track.info() // → { keyframes, segments, playing, loop, ... }
187-
track.add(spec) // append keyframe(s)
188-
track.set(i, spec) // replace keyframe at index
189-
track.remove(i) // remove keyframe at index
182+
track.stop([rewind]) // rewind=true seeks to origin
183+
track.reset() // clear all keyframes and stop
184+
track.seek(t) // t ∈ [0, 1]
185+
track.time() // → number ∈ [0, 1]
186+
track.info() // → { keyframes, segments, playing, loop, ... }
187+
track.add(spec) // append keyframe(s)
188+
track.set(i, spec) // replace keyframe at index
189+
track.remove(i) // remove keyframe at index
190190
```
191191
192192
| Option | Default | Description |
@@ -223,9 +223,9 @@ reset() → onStop → _onDeactivate
223223
## Camera helpers
224224
225225
```js
226-
getCamera() // current p5.Camera (curCamera)
227-
cam.capturePose([out]) // → { eye, center, up, fov, halfHeight }
228-
cam.applyPose(pose) // write pose back to camera
226+
getCamera() // current p5.Camera (curCamera)
227+
cam.capturePose([out]) // → { eye, center, up, fov, halfHeight }
228+
cam.applyPose(pose) // write pose back to camera
229229
```
230230
231231
---
@@ -265,12 +265,12 @@ mat3Direction(out, from, to) // direction transform: to₃ · inv(from₃), 9-e
265265
**Raw matrix math** — forwarded from `@nakednous/tree`, same out-first contract:
266266
267267
```js
268-
mat4Mul(out, A, B) // out = A · B (column-major)
269-
mat4Invert(out, src) // out = inv(src), null if singular
270-
mat4MulPoint(out, m, point) // out = m · [x,y,z,1] perspective-divided
271-
// point: Float32Array | ArrayLike | p5.Vector
272-
mat4MulDir(out, m, dx,dy,dz) // out = 3×3 block of m applied to direction
273-
// no translation, no perspective divide
268+
mat4Mul(out, A, B) // out = A · B (column-major)
269+
mat4Invert(out, src) // out = inv(src), null if singular
270+
mat4MulPoint(out, m, point) // out = m · [x,y,z,1] perspective-divided
271+
// point: Float32Array | ArrayLike | p5.Vector
272+
mat4MulDir(out, m, dx,dy,dz) // out = 3×3 block of m applied to direction
273+
// no translation, no perspective divide
274274
```
275275
276276
**Zero-allocation draw-loop pattern:**
@@ -280,7 +280,7 @@ mat4MulDir(out, m, dx,dy,dz) // out = 3×3 block of m applied to direction
280280
const e = new Float32Array(16)
281281
const pm = new Float32Array(16)
282282
const pv = new Float32Array(16)
283-
const wlm = new Float32Array(16) // e.g. bias · lightPV for shadow mapping
283+
const wlm = new Float32Array(16) // e.g. bias · lightPV for shadow mapping
284284
const pt = new Float32Array(3)
285285

286286
// draw — zero allocations
@@ -312,13 +312,13 @@ pixelRatio([worldPos], [{ mat4Proj, mat4View }])
312312
`out` is opt-in. When provided via `opts.out` the result is written into it (zero-alloc hot path). When omitted a fresh `p5.Vector` is allocated and returned. Return type matches `opts.out`.
313313
314314
```js
315-
mapLocation([point], [opts]) // map a point between spaces
316-
mapLocation([opts]) // input defaults to p5.Tree.ORIGIN
317-
mapLocation() // ORIGIN, EYE → WORLD → p5.Vector
315+
mapLocation([point], [opts]) // map a point between spaces
316+
mapLocation([opts]) // input defaults to p5.Tree.ORIGIN
317+
mapLocation() // ORIGIN, EYE → WORLD → p5.Vector
318318

319-
mapDirection([dir], [opts]) // map a direction between spaces
320-
mapDirection([opts]) // input defaults to p5.Tree._k
321-
mapDirection() // _k, EYE → WORLD → p5.Vector
319+
mapDirection([dir], [opts]) // map a direction between spaces
320+
mapDirection([opts]) // input defaults to p5.Tree._k
321+
mapDirection() // _k, EYE → WORLD → p5.Vector
322322
```
323323
324324
`point` / `dir` accept `Float32Array` | `ArrayLike` | `p5.Vector`.
@@ -392,8 +392,8 @@ const panel = createPanel({
392392
panel.tick()
393393
```
394394
395-
| Option | Default | Description |
396-
|------------|-----------------|----------------------------------------------------------|
395+
| Option | Default | Description |
396+
|------------|-----------------|---------------------------------------------------------|
397397
| `target` | — | `fn(name, value)` or object with `.set(name, value)`. |
398398
| `x` / `y` | `0` | Position (px). |
399399
| `width` | `120` | Slider width (px). |
@@ -453,12 +453,12 @@ createPanel(track, {
453453
**Returned handle** (both panel types):
454454
455455
```js
456-
panel.el // HTMLElement container
457-
panel.visible // get/set boolean
458-
panel.collapsed // get/set boolean (requires collapsible + title)
459-
panel.parent(el) // re-mount into a different HTMLElement
460-
panel.tick() // called automatically — no need to call manually
461-
panel.dispose() // remove from DOM
456+
panel.el // HTMLElement container
457+
panel.visible // get/set boolean
458+
panel.collapsed // get/set boolean (requires collapsible + title)
459+
panel.parent(el) // re-mount into a different HTMLElement
460+
panel.tick() // called automatically — no need to call manually
461+
panel.dispose() // remove from DOM
462462
```
463463
464464
## Collapsible panels
@@ -489,8 +489,8 @@ A lightweight multi-pass pipeline for `p5.Framebuffer`, `p5.strands`, and standa
489489
pipe(source, passes, options)
490490
```
491491
492-
| Parameter | Description |
493-
|-----------|-------------------------------------------------------|
492+
| Parameter | Description |
493+
|-----------|------------------------------------------------------|
494494
| `source` | `p5.Framebuffer`, texture, image, or graphics. |
495495
| `passes` | Array of filters, or a single filter instance. |
496496
| `options` | See table below. |
@@ -503,7 +503,7 @@ pipe(source, passes, options)
503503
| `ping` / `pong` | — | User-provided framebuffers (advanced override). |
504504
| `clear` | `true` | Clear each pass target before drawing. |
505505
| `clearDisplay` | `true` | Clear main canvas before final blit. |
506-
| `clearFn` | `background(0)` | Custom clear strategy for passes. |
506+
| `clearFn` | `background(0)` | Custom clear strategy for passes. |
507507
| `clearDisplayFn` | `clearFn` | Custom clear strategy for display stage. |
508508
| `draw` | full blit | Custom draw strategy for placing texture on target. |
509509
@@ -590,7 +590,7 @@ Both accept the same options object:
590590
# Utilities
591591
592592
```js
593-
p5.Tree.VERSION // '0.0.34'
593+
p5.Tree.VERSION // '0.0.35'
594594
```
595595
596596
## Shader helpers
@@ -619,9 +619,9 @@ shader.setUniform('texOffset', texelSize(myFbo))
619619
Frustum culling against the current camera:
620620
621621
```js
622-
visibility({ corner1, corner2 }) // axis-aligned box
623-
visibility({ center, radius }) // sphere
624-
visibility({ center }) // point
622+
visibility({ corner1, corner2 }) // axis-aligned box
623+
visibility({ center, radius }) // sphere
624+
visibility({ center }) // point
625625
```
626626
627627
Returns:
@@ -665,9 +665,9 @@ Latest:
665665
666666
Tagged:
667667
668-
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.34/dist/p5.tree.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.34/dist/p5.tree.js)
669-
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.34/dist/p5.tree.min.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.34/dist/p5.tree.min.js)
670-
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.34/dist/p5.tree.esm.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.34/dist/p5.tree.esm.js)
668+
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.35/dist/p5.tree.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.35/dist/p5.tree.js)
669+
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.35/dist/p5.tree.min.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.35/dist/p5.tree.min.js)
670+
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.35/dist/p5.tree.esm.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.35/dist/p5.tree.esm.js)
671671
672672
---
673673

deps/tree/README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ Playback features: signed `rate` (negative reverses), `loop`, `bounce`, `seek(t)
8282
`add()` accepts flexible specs. Top-level forms:
8383

8484
```js
85-
track.add({ pos, rot, scl }) // explicit TRS — rot accepts any form below
86-
track.add({ pos, rot, scl, tanIn, tanOut }) // with Hermite tangents (vec3, optional)
87-
track.add({ mMatrix: mat4 }) // decompose a column-major model matrix into TRS
88-
track.add([ spec, spec, ... ]) // bulk
85+
track.add({ pos, rot, scl }) // explicit TRS — rot accepts any form below
86+
track.add({ pos, rot, scl, tanIn, tanOut }) // with Hermite tangents (vec3, optional)
87+
track.add({ mMatrix: mat4 }) // decompose a column-major model matrix into TRS
88+
track.add([ spec, spec, ... ]) // bulk
8989
```
9090

9191
`tanIn` is the incoming position tangent at this keyframe; `tanOut` is the outgoing tangent. When only one is given, the other mirrors it. When neither is given, centripetal Catmull-Rom tangents are auto-computed from neighboring keyframes.
@@ -100,16 +100,16 @@ track.add({ pos:[300,0,0] }) // auto tangents
100100
`rot` sub-forms — all normalised internally:
101101

102102
```js
103-
rot: [x,y,z,w] // raw quaternion
104-
rot: { axis:[x,y,z], angle } // axis-angle
105-
rot: { dir:[x,y,z], up?:[x,y,z] } // look direction (−Z forward)
106-
rot: { euler:[rx,ry,rz], order?:'YXZ' } // intrinsic Euler angles (radians)
107-
// orders: YXZ (default), XYZ, ZYX,
108-
// ZXY, XZY, YZX
109-
// extrinsic ABC = intrinsic CBA
110-
rot: { from:[x,y,z], to:[x,y,z] } // shortest-arc between directions
111-
rot: { mat3: Float32Array|Array } // column-major 3×3 rotation matrix
112-
rot: { eMatrix: mat4 } // rotation block of an eye matrix
103+
rot: [x,y,z,w] // raw quaternion
104+
rot: { axis:[x,y,z], angle } // axis-angle
105+
rot: { dir:[x,y,z], up?:[x,y,z] } // look direction (−Z forward)
106+
rot: { euler:[rx,ry,rz], order?:'YXZ' } // intrinsic Euler angles (radians)
107+
// orders: YXZ (default), XYZ, ZYX,
108+
// ZXY, XZY, YZX
109+
// extrinsic ABC = intrinsic CBA
110+
rot: { from:[x,y,z], to:[x,y,z] } // shortest-arc between directions
111+
rot: { mat3: Float32Array|Array } // column-major 3×3 rotation matrix
112+
rot: { eMatrix: mat4 } // rotation block of an eye matrix
113113
```
114114

115115
---
@@ -284,6 +284,8 @@ pointVisibility(planes, px, py, pz)
284284
285285
Three-state result: `VISIBLE` (fully inside), `SEMIVISIBLE` (intersecting), `INVISIBLE` (fully outside).
286286
287+
**Sign contract:** `top > 0`, `bottom < 0`, `right > 0`, `left < 0` for standard y-up camera.
288+
287289
---
288290
289291
### Quaternion and matrix math

deps/tree/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nakednous/tree",
3-
"version": "0.0.15",
3+
"version": "0.0.16",
44
"description": "tree — pure numeric core. Zero dependencies.",
55
"type": "module",
66
"main": "dist/index.js",

deps/tree/src/track.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ const _EULER_ORDERS = new Set(['XYZ','XZY','YXZ','YZX','ZXY','ZYX']);
218218
*
219219
* [x,y,z,w] — raw quaternion array
220220
* { axis:[x,y,z], angle } — axis-angle
221-
* { dir:[x,y,z], up?:[x,y,z] } — forward direction (−Z) with optional up
222-
* { eMatrix: mat4 } — rotation block of an eye matrix
221+
* { dir:[x,y,z], up?:[x,y,z] } — forward direction (−Z) with optional up
222+
* { mat4Eye: mat4 } — rotation block of an eye matrix
223223
* { mat3: mat3 } — column-major 3×3 rotation matrix
224224
* { euler:[rx,ry,rz], order? } — intrinsic Euler (default order: YXZ)
225-
* { from:[x,y,z], to:[x,y,z] } — shortest-arc rotation
225+
* { from:[x,y,z], to:[x,y,z] } — shortest-arc rotation
226226
*
227227
* @param {*} v
228228
* @returns {number[]|null} [x,y,z,w] or null if unparseable.
@@ -249,10 +249,10 @@ function _parseQuat(v) {
249249
return qFromLookDir([0,0,0,1], d, u);
250250
}
251251

252-
// { eMatrix }
253-
if (v.eMatrix != null) {
254-
const m = (ArrayBuffer.isView(v.eMatrix) || Array.isArray(v.eMatrix))
255-
? v.eMatrix : (v.eMatrix.mat4 ?? null);
252+
// { mat4Eye }
253+
if (v.mat4Eye != null) {
254+
const m = (ArrayBuffer.isView(v.mat4Eye) || Array.isArray(v.mat4Eye))
255+
? v.mat4Eye : (v.mat4Eye.mat4 ?? null);
256256
if (!m || m.length < 16) return null;
257257
return qFromRotMat3x3([0,0,0,1], m[0],m[4],m[8], m[1],m[5],m[9], m[2],m[6],m[10]);
258258
}
@@ -310,7 +310,7 @@ function _parseQuat(v) {
310310
*
311311
* Accepted forms:
312312
*
313-
* { mMatrix }
313+
* { mat4Model }
314314
* Decompose a column-major mat4 into TRS via mat4ToTransform.
315315
* Float32Array(16), plain Array, or { mat4 } wrapper.
316316
*
@@ -326,10 +326,10 @@ function _parseQuat(v) {
326326
function _parseSpec(spec) {
327327
if (!spec || typeof spec !== 'object') return null;
328328

329-
// { mMatrix } — full TRS decomposition from model matrix
330-
if (spec.mMatrix != null) {
331-
const m = (ArrayBuffer.isView(spec.mMatrix) || Array.isArray(spec.mMatrix))
332-
? spec.mMatrix : (spec.mMatrix.mat4 ?? null);
329+
// { mat4Model } — full TRS decomposition from model matrix
330+
if (spec.mat4Model != null) {
331+
const m = (ArrayBuffer.isView(spec.mat4Model) || Array.isArray(spec.mat4Model))
332+
? spec.mat4Model : (spec.mat4Model.mat4 ?? null);
333333
if (!m || m.length < 16) return null;
334334
const kf = mat4ToTransform({ pos:[0,0,0], rot:[0,0,0,1], scl:[1,1,1] }, m);
335335
kf.tanIn = null; kf.tanOut = null;
@@ -366,7 +366,7 @@ function _sameTransform(a, b) {
366366
* When absent, centripetal Catmull-Rom tangents are auto-computed at eval time.
367367
*
368368
* Removed forms (task 2):
369-
* { vMatrix } and { eMatrix } — use PoseTrack.add({ mMatrix: eMatrix }) for
369+
* { mat4View } and { mat4Eye } — use PoseTrack.add({ mat4Model: mat4Eye }) for
370370
* full-fidelity capture including roll, or cam.capturePose() for lookat-style.
371371
*
372372
* @param {Object} spec
@@ -865,7 +865,7 @@ export class PoseTrack extends Track {
865865
* { eye, center?, up?, fov?, halfHeight?,
866866
* eyeTanIn?, eyeTanOut?, centerTanIn?, centerTanOut? }
867867
*
868-
* To capture a matrix-based pose, use PoseTrack.add({ mMatrix: eMatrix })
868+
* To capture a matrix-based pose, use PoseTrack.add({ mat4Model: mat4Eye })
869869
* for full-fidelity including roll, or cam.capturePose() for lookat-style.
870870
*/
871871
export class CameraTrack extends Track {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "p5.tree",
3-
"version": "0.0.34",
3+
"version": "0.0.35",
44
"description": "Render pipeline for p5.js v2 — pose and camera interpolation, space transforms, frustum visibility, HUD, post-processing pipe, picking, and declarative control panels.",
55
"type": "module",
66
"main": "dist/p5.tree.esm.js",
@@ -49,7 +49,7 @@
4949
"p5": "^2.2.3"
5050
},
5151
"dependencies": {
52-
"@nakednous/tree": "^0.0.15",
52+
"@nakednous/tree": "^0.0.16",
5353
"@nakednous/ui": "^0.0.8"
5454
},
5555
"devDependencies": {

src/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function installConstants(p5) {
1212
const CONST = value => ({ value, writable: false, enumerable: true, configurable: false });
1313

1414
Object.defineProperties(p5.Tree, {
15-
VERSION: CONST('0.0.34'),
15+
VERSION: CONST('0.0.35'),
1616
NONE: CONST(0),
1717

1818
// Core constants (spaces, visibility, NDC, basis vectors)

src/panel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function _centerAtDepth(pInst, d) {
9090
const ndcZ = ndcMin + d * (1 - ndcMin);
9191
mat4Mul(_sc_pv, proj, view);
9292
if (!mat4Invert(_sc_ipv, _sc_pv)) return null;
93-
coreMapLocation(_sc_v3, 0, 0, ndcZ, NDC, WORLD, { ipvMatrix: _sc_ipv }, [0, 0, 1, 1], ndcMin);
93+
coreMapLocation(_sc_v3, 0, 0, ndcZ, NDC, WORLD, { mat4PVInv: _sc_ipv }, [0, 0, 1, 1], ndcMin);
9494
return [_sc_v3[0], _sc_v3[1], _sc_v3[2]];
9595
}
9696

0 commit comments

Comments
 (0)