Skip to content

Commit d7de4bd

Browse files
committed
v0.0.28 panel: pre-allocate capturePose buffer for CameraTrack + button; add reset:false option to suppress reset
1 parent cd925b7 commit d7de4bd

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ const ui = createPanel(track, {
399399
color: 'white'
400400
})
401401

402+
// Suppress + button
403+
createPanel(track, { camera: null, x: 10, y: 10 })
404+
405+
// Suppress reset button (e.g. when keyframes are hardcoded and cannot be re-added)
406+
createPanel(track, { reset: false, x: 10, y: 10 })
407+
402408
// call every frame
403409
ui.tick()
404410
```
@@ -412,7 +418,8 @@ ui.tick()
412418
| `loop` | track.loop | Initial loop mode. |
413419
| `pingPong` | track.pingPong | Initial pingPong mode. |
414420
| `depth` | `0.5` | Initial + button depth [0..1]. |
415-
| `camera` | curCamera | Camera for + button. `null` suppresses it. |
421+
| `camera` | track.camera (CameraTrack), curCamera (PoseTrack) | Camera for + button. `null` suppresses it. |
422+
| `reset` | `true` | Show reset button. `false` suppresses it. |
416423
417424
Lifecycle hooks can be passed directly in opt:
418425
@@ -565,7 +572,7 @@ Both accept the same options object:
565572
# Utilities
566573
567574
```js
568-
p5.Tree.VERSION // '0.0.27'
575+
p5.Tree.VERSION // '0.0.28'
569576
```
570577
571578
**Visibility testing** — frustum culling against the current camera:
@@ -610,9 +617,9 @@ Latest:
610617
611618
Tagged:
612619
613-
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.27/dist/p5.tree.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.27/dist/p5.tree.js)
614-
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.27/dist/p5.tree.min.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.27/dist/p5.tree.min.js)
615-
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.27/dist/p5.tree.esm.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.27/dist/p5.tree.esm.js)
620+
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.28/dist/p5.tree.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.28/dist/p5.tree.js)
621+
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.28/dist/p5.tree.min.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.28/dist/p5.tree.min.js)
622+
* [https://cdn.jsdelivr.net/npm/p5.tree@0.0.28/dist/p5.tree.esm.js](https://cdn.jsdelivr.net/npm/p5.tree@0.0.28/dist/p5.tree.esm.js)
616623
617624
---
618625

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "p5.tree",
3-
"version": "0.0.27",
3+
"version": "0.0.28",
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",

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.27'),
15+
VERSION: CONST('0.0.28'),
1616
NONE: CONST(0),
1717

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

src/panel.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,17 @@ function _centerAtDepth(pInst, d) {
117117
* @param {p5.Camera|null} cam
118118
* @param {boolean} isCameraTrack
119119
* @param {p5} pInst
120+
* @param {boolean} showReset When false, w.reset is omitted and _createPanel
121+
* suppresses the reset button. Use when keyframes are immutable by design.
120122
* @returns {Object}
121123
*/
122-
function _wrapTrack(track, cam, isCameraTrack, pInst) {
124+
function _wrapTrack(track, cam, isCameraTrack, pInst, showReset) {
123125
const _snapOut = isCameraTrack
124126
? { eye:[0,0,0], center:[0,0,0], up:[0,1,0], fov:null, halfHeight:null }
125127
: { pos:[0,0,0], rot:[0,0,0,1], scl:[1,1,1] };
126128

127129
const _captureOut = { eye:[0,0,0], center:[0,0,0], up:[0,1,0], fov:null, halfHeight:null };
130+
const _addOut = { eye:[0,0,0], center:[0,0,0], up:[0,1,0], fov:null, halfHeight:null };
128131

129132
function _applySnap() {
130133
if (isCameraTrack && cam && track.keyframes.length > 0) cam.applyPose(track.eval(_snapOut));
@@ -150,8 +153,8 @@ function _wrapTrack(track, cam, isCameraTrack, pInst) {
150153
seek: (t) => { track.seek(t); _applySnap(); },
151154
time: () => track.time(),
152155
};
153-
if (typeof track.reset === 'function') w.reset = () => track.reset();
154-
if (typeof track.info === 'function') w.info = () => track.info();
156+
if (showReset && typeof track.reset === 'function') w.reset = () => track.reset();
157+
if (typeof track.info === 'function') w.info = () => track.info();
155158

156159
// Forward lib-space hook slots to the underlying track.
157160
// trackUI assigns w._onPlay / _onEnd / _onStop; track.play() fires track._onPlay.
@@ -172,7 +175,10 @@ function _wrapTrack(track, cam, isCameraTrack, pInst) {
172175

173176
if (cam !== null && typeof track.add === 'function') {
174177
if (isCameraTrack) {
175-
w.add = () => track.add(cam.capturePose());
178+
w.add = () => {
179+
cam.capturePose(_addOut);
180+
track.add(_addOut, { deduplicate: false });
181+
};
176182
} else {
177183
w.add = (d) => {
178184
const pos = _centerAtDepth(pInst, typeof d === 'number' ? d : 0.5) || [0,0,0];
@@ -215,8 +221,11 @@ export function installPanel(p5, fn) {
215221
* // PoseTrack — explicit camera override
216222
* createPanel(track, { camera: cam2, x: 10, y: 10 })
217223
*
218-
* // PoseTrack — suppress + button
224+
* // Suppress + button (camera: null)
219225
* createPanel(track, { camera: null, x: 10, y: 10 })
226+
*
227+
* // Suppress reset button
228+
* createPanel(track, { reset: false, x: 10, y: 10 })
220229
* ```
221230
*
222231
* **Param panel** (shader uniforms, scene parameters):
@@ -241,7 +250,10 @@ export function installPanel(p5, fn) {
241250
* Layout and behaviour options.
242251
* @param {p5.Camera|null} [opt.camera]
243252
* Track panels only. Override camera for + button.
244-
* null suppresses the + button. Defaults to curCamera.
253+
* null suppresses the + button. Defaults to track.camera for CameraTrack,
254+
* curCamera for PoseTrack.
255+
* @param {boolean} [opt.reset=true]
256+
* Track panels only. Set false to suppress the reset button.
245257
* @param {Object|Function} [opt.target]
246258
* Param panels only. Value sink: p5 shader, (name,val)=>..., or {set}.
247259
* @param {(HTMLElement|p5.Element)} [opt.parent]
@@ -264,10 +276,13 @@ export function installPanel(p5, fn) {
264276
if (typeof opt.onEnd === 'function') { track.onEnd = opt.onEnd; delete opt.onEnd; }
265277
if (typeof opt.onStop === 'function') { track.onStop = opt.onStop; delete opt.onStop; }
266278

279+
const showReset = opt.reset !== false;
280+
delete opt.reset;
281+
267282
// Resolve camera for + button.
268283
let cam;
269284
if ('camera' in opt) {
270-
cam = opt.camera === null ? null
285+
cam = opt.camera === null ? null
271286
: opt.camera instanceof p5.Camera ? opt.camera
272287
: (pInst._renderer?.states?.curCamera ?? null);
273288
} else if (isCameraTrack) {
@@ -280,7 +295,7 @@ export function installPanel(p5, fn) {
280295
// Depth slider not meaningful for camera tracks.
281296
if (isCameraTrack && !('depth' in opt)) opt.depth = false;
282297

283-
const panel = _createPanel(_wrapTrack(track, cam, isCameraTrack, pInst), opt);
298+
const panel = _createPanel(_wrapTrack(track, cam, isCameraTrack, pInst, showReset), opt);
284299
registerPlayer(pInst, { tick() { panel.tick(); return true; } });
285300
return panel;
286301
}

0 commit comments

Comments
 (0)