p5.tree 0.0.2 → 0.0.4

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/dist/p5.tree.js CHANGED
@@ -3,16 +3,16 @@
3
3
 
4
4
  /**
5
5
  * @file Adds Tree rendering functions to the p5 prototype.
6
- * @version 0.0.2
6
+ * @version 0.0.4
7
7
  * @author JP Charalambos
8
8
  * @license GPL-3.0-only
9
9
  *
10
10
  * @description
11
- * A p5.js WEBGL addon for shader development and space transformations.
11
+ * A p5.js 3D addon for matrix queries, shader workflows, and space transformations.
12
12
  *
13
13
  * Camera path recording/playback section.
14
14
  *
15
- * Requires WEBGL (p5.Camera).
15
+ * Requires 3D renderer (p5.Camera).
16
16
  *
17
17
  * Camera API:
18
18
  * camera.path : p5.Camera[]
@@ -39,7 +39,7 @@
39
39
  const CONST = value => ({ value, writable: false, enumerable: true, configurable: false });
40
40
 
41
41
  Object.defineProperties(p5.Tree, {
42
- VERSION: CONST('0.0.2'),
42
+ VERSION: CONST('0.0.4'),
43
43
 
44
44
  NONE: CONST(0),
45
45
 
@@ -49,6 +49,7 @@
49
49
  NDC: CONST('NDC'),
50
50
  SCREEN: CONST('SCREEN'),
51
51
  MODEL: CONST('MODEL'),
52
+ OBJECT: CONST('MODEL'), // alias of MODEL (shader terminology)
52
53
 
53
54
  // Points and vectors
54
55
  ORIGIN: CONST(Object.freeze([0, 0, 0])),
@@ -69,9 +70,6 @@
69
70
  Z: CONST(1 << 4),
70
71
  _Z: CONST(1 << 5),
71
72
  LABELS: CONST(1 << 6),
72
-
73
- DOTS: CONST(0),
74
- SOLID: CONST(1),
75
73
 
76
74
  // bullsEye
77
75
  CIRCLE: CONST(0),
@@ -100,13 +98,13 @@
100
98
 
101
99
  /**
102
100
  * @private
103
- * Returns the WEBGL renderer or undefined.
104
- * @param {p5} pInst
105
- * @returns {p5.RendererGL|undefined}
101
+ * Returns the active 3D renderer (WEBGL or WEBGPU) or undefined.
102
+ * @param {p5} pInst - The p5 instance.
103
+ * @returns {p5.Renderer3D|undefined} The active 3D renderer if available.
106
104
  */
107
- const _rendererGL = function (pInst) {
108
- const r = pInst._renderer;
109
- return r instanceof p5.RendererGL ? r : undefined;
105
+ const _renderer3D = function (pInst) {
106
+ const r = pInst?._renderer;
107
+ return r instanceof p5.Renderer3D ? r : undefined;
110
108
  };
111
109
 
112
110
  // ---------------------------------------------------------------------------
@@ -219,34 +217,34 @@
219
217
  * Returns the current projection matrix (immutable copy).
220
218
  * @returns {p5.Matrix}
221
219
  */
222
- p5.RendererGL.prototype.pMatrix = function () {
220
+ p5.Renderer3D.prototype.pMatrix = function () {
223
221
  return this.states.uPMatrix.clone();
224
222
  };
225
223
 
226
224
  /**
227
225
  * Returns the current projection matrix (immutable copy).
228
- * Requires WEBGL.
226
+ * Requires 3D renderer.
229
227
  * @returns {p5.Matrix}
230
228
  */
231
229
  fn.pMatrix = function () {
232
- return _rendererGL(this).pMatrix();
230
+ return _renderer3D(this).pMatrix();
233
231
  };
234
232
 
235
233
  /**
236
234
  * Returns the current model matrix (immutable copy).
237
235
  * @returns {p5.Matrix}
238
236
  */
239
- p5.RendererGL.prototype.mMatrix = function () {
237
+ p5.Renderer3D.prototype.mMatrix = function () {
240
238
  return this.states.uModelMatrix.clone();
241
239
  };
242
240
 
243
241
  /**
244
242
  * Returns the current model matrix (immutable copy).
245
- * Requires WEBGL.
243
+ * Requires 3D renderer.
246
244
  * @returns {p5.Matrix}
247
245
  */
248
246
  fn.mMatrix = function () {
249
- return _rendererGL(this).mMatrix();
247
+ return _renderer3D(this).mMatrix();
250
248
  };
251
249
 
252
250
  /**
@@ -270,46 +268,46 @@
270
268
  * Prefers the renderer cached view matrix when available.
271
269
  * @returns {p5.Matrix}
272
270
  */
273
- p5.RendererGL.prototype.vMatrix = function () {
271
+ p5.Renderer3D.prototype.vMatrix = function () {
274
272
  return (this.states.uViewMatrix || this.states.curCamera.cameraMatrix).clone();
275
273
  };
276
274
 
277
275
  /**
278
276
  * Returns the current view matrix (world -> camera) (immutable copy).
279
- * Requires WEBGL.
277
+ * Requires 3D renderer.
280
278
  * @returns {p5.Matrix}
281
279
  */
282
280
  fn.vMatrix = function () {
283
- return _rendererGL(this).vMatrix();
281
+ return _renderer3D(this).vMatrix();
284
282
  };
285
283
 
286
284
  /**
287
285
  * Returns the current eye matrix (camera -> world) (immutable).
288
286
  * @returns {p5.Matrix}
289
287
  */
290
- p5.RendererGL.prototype.eMatrix = function () {
288
+ p5.Renderer3D.prototype.eMatrix = function () {
291
289
  return _invert(this.states.uViewMatrix || this.states.curCamera.cameraMatrix);
292
290
  };
293
291
 
294
292
  /**
295
293
  * Returns the current eye matrix (camera -> world) (immutable).
296
- * Requires WEBGL.
294
+ * Requires 3D renderer.
297
295
  * @returns {p5.Matrix}
298
296
  */
299
297
  fn.eMatrix = function () {
300
- return _rendererGL(this).eMatrix();
298
+ return _renderer3D(this).eMatrix();
301
299
  };
302
300
 
303
301
  /**
304
302
  * lMatrix({ from, to }):
305
- * Position transform (mat4) mapping points from `from` space to `to` space.
303
+ * Location transform (mat4) mapping points from `from` space to `to` space.
306
304
  * treegl semantics: to^-1 * from.
307
305
  * @param {object} [opts]
308
306
  * @param {p5.Matrix} [opts.from=new p5.Matrix()] Source frame matrix.
309
307
  * @param {p5.Matrix} [opts.to=this.eMatrix()] Target frame matrix.
310
308
  * @returns {p5.Matrix}
311
309
  */
312
- p5.RendererGL.prototype.lMatrix = function ({
310
+ p5.Renderer3D.prototype.lMatrix = function ({
313
311
  from = new p5.Matrix(4),
314
312
  to = this.eMatrix()
315
313
  } = {}) {
@@ -318,15 +316,15 @@
318
316
 
319
317
  /**
320
318
  * lMatrix({ from, to }):
321
- * Position transform (mat4) mapping points from `from` space to `to` space.
322
- * Requires WEBGL.
319
+ * Location transform (mat4) mapping points from `from` space to `to` space.
320
+ * Requires 3D renderer.
323
321
  * @param {object} [opts]
324
322
  * @param {p5.Matrix} [opts.from]
325
323
  * @param {p5.Matrix} [opts.to]
326
324
  * @returns {p5.Matrix}
327
325
  */
328
326
  fn.lMatrix = function (opts = {}) {
329
- return _rendererGL(this).lMatrix(opts);
327
+ return _renderer3D(this).lMatrix(opts);
330
328
  };
331
329
 
332
330
  /**
@@ -340,7 +338,7 @@
340
338
  * @param {p5.Matrix} [opts.matrix] Precomputed mat4 override.
341
339
  * @returns {p5.Matrix} mat3
342
340
  */
343
- p5.RendererGL.prototype.dMatrix = function ({
341
+ p5.Renderer3D.prototype.dMatrix = function ({
344
342
  from = new p5.Matrix(4),
345
343
  to = this.eMatrix(),
346
344
  matrix
@@ -358,7 +356,7 @@
358
356
  /**
359
357
  * dMatrix({ from, to, matrix }):
360
358
  * Direction transform (mat3) mapping vectors from `from` space to `to` space.
361
- * Requires WEBGL.
359
+ * Requires 3D renderer.
362
360
  * @param {object} [opts]
363
361
  * @param {p5.Matrix} [opts.from]
364
362
  * @param {p5.Matrix} [opts.to]
@@ -366,7 +364,7 @@
366
364
  * @returns {p5.Matrix} mat3
367
365
  */
368
366
  fn.dMatrix = function (opts = {}) {
369
- return _rendererGL(this).dMatrix(opts);
367
+ return _renderer3D(this).dMatrix(opts);
370
368
  };
371
369
 
372
370
  /**
@@ -377,7 +375,7 @@
377
375
  * @param {p5.Matrix} [opts.mMatrix=this.mMatrix()] Model matrix.
378
376
  * @returns {p5.Matrix}
379
377
  */
380
- p5.RendererGL.prototype.mvMatrix = function ({
378
+ p5.Renderer3D.prototype.mvMatrix = function ({
381
379
  vMatrix = this.vMatrix(),
382
380
  mMatrix
383
381
  } = {}) {
@@ -387,14 +385,14 @@
387
385
  /**
388
386
  * mvMatrix({ vMatrix, mMatrix }):
389
387
  * ModelView matrix (mat4) = M * V (p5-v2 convention).
390
- * Requires WEBGL.
388
+ * Requires 3D renderer.
391
389
  * @param {object} [opts]
392
390
  * @param {p5.Matrix} [opts.vMatrix]
393
391
  * @param {p5.Matrix} [opts.mMatrix]
394
392
  * @returns {p5.Matrix}
395
393
  */
396
394
  fn.mvMatrix = function (opts = {}) {
397
- return _rendererGL(this).mvMatrix(opts);
395
+ return _renderer3D(this).mvMatrix(opts);
398
396
  };
399
397
 
400
398
  /**
@@ -406,7 +404,7 @@
406
404
  * @param {p5.Matrix} [opts.mvMatrix=this.mvMatrix({ mMatrix, vMatrix })] Optional MV matrix override.
407
405
  * @returns {p5.Matrix} mat3
408
406
  */
409
- p5.RendererGL.prototype.nMatrix = function ({
407
+ p5.Renderer3D.prototype.nMatrix = function ({
410
408
  vMatrix,
411
409
  mMatrix,
412
410
  mvMatrix = this.mvMatrix({ mMatrix, vMatrix })
@@ -417,7 +415,7 @@
417
415
  /**
418
416
  * nMatrix({ vMatrix, mMatrix, mvMatrix }):
419
417
  * Normal matrix (mat3) = inverseTranspose(linear_part(MV)).
420
- * Requires WEBGL.
418
+ * Requires 3D renderer.
421
419
  * @param {object} [opts]
422
420
  * @param {p5.Matrix} [opts.vMatrix]
423
421
  * @param {p5.Matrix} [opts.mMatrix]
@@ -425,7 +423,7 @@
425
423
  * @returns {p5.Matrix} mat3
426
424
  */
427
425
  fn.nMatrix = function (opts = {}) {
428
- return _rendererGL(this).nMatrix(opts);
426
+ return _renderer3D(this).nMatrix(opts);
429
427
  };
430
428
 
431
429
  /**
@@ -438,7 +436,7 @@
438
436
  * @param {p5.Matrix} [opts.mvMatrix=this.mvMatrix({ mMatrix, vMatrix })] Optional MV matrix override.
439
437
  * @returns {p5.Matrix}
440
438
  */
441
- p5.RendererGL.prototype.pmvMatrix = function ({
439
+ p5.Renderer3D.prototype.pmvMatrix = function ({
442
440
  pMatrix = this.pMatrix(),
443
441
  vMatrix,
444
442
  mMatrix,
@@ -450,7 +448,7 @@
450
448
  /**
451
449
  * pmvMatrix({ pMatrix, vMatrix, mMatrix, mvMatrix }):
452
450
  * PMV (mat4) = M * V * P (p5-v2 convention).
453
- * Requires WEBGL.
451
+ * Requires 3D renderer.
454
452
  * @param {object} [opts]
455
453
  * @param {p5.Matrix} [opts.pMatrix]
456
454
  * @param {p5.Matrix} [opts.vMatrix]
@@ -459,7 +457,7 @@
459
457
  * @returns {p5.Matrix}
460
458
  */
461
459
  fn.pmvMatrix = function (opts = {}) {
462
- return _rendererGL(this).pmvMatrix(opts);
460
+ return _renderer3D(this).pmvMatrix(opts);
463
461
  };
464
462
 
465
463
  /**
@@ -470,7 +468,7 @@
470
468
  * @param {p5.Matrix} [opts.vMatrix=this.vMatrix()] View matrix.
471
469
  * @returns {p5.Matrix}
472
470
  */
473
- p5.RendererGL.prototype.pvMatrix = function ({
471
+ p5.Renderer3D.prototype.pvMatrix = function ({
474
472
  pMatrix = this.pMatrix(),
475
473
  vMatrix
476
474
  } = {}) {
@@ -480,14 +478,14 @@
480
478
  /**
481
479
  * pvMatrix({ pMatrix, vMatrix }):
482
480
  * PV (mat4) = V * P (p5-v2 convention).
483
- * Requires WEBGL.
481
+ * Requires 3D renderer.
484
482
  * @param {object} [opts]
485
483
  * @param {p5.Matrix} [opts.pMatrix]
486
484
  * @param {p5.Matrix} [opts.vMatrix]
487
485
  * @returns {p5.Matrix}
488
486
  */
489
487
  fn.pvMatrix = function (opts = {}) {
490
- return _rendererGL(this).pvMatrix(opts);
488
+ return _renderer3D(this).pvMatrix(opts);
491
489
  };
492
490
 
493
491
  /**
@@ -499,7 +497,7 @@
499
497
  * @param {p5.Matrix} [opts.pvMatrix=this.pvMatrix({ pMatrix, vMatrix })] Optional PV matrix override.
500
498
  * @returns {p5.Matrix}
501
499
  */
502
- p5.RendererGL.prototype.ipvMatrix = function ({
500
+ p5.Renderer3D.prototype.ipvMatrix = function ({
503
501
  pMatrix,
504
502
  vMatrix,
505
503
  pvMatrix = this.pvMatrix({ pMatrix, vMatrix })
@@ -509,12 +507,12 @@
509
507
 
510
508
  /**
511
509
  * ipvMatrix({ pMatrix, vMatrix, pvMatrix }):
512
- * Inverse(PV) (mat4). Requires WEBGL.
510
+ * Inverse(PV) (mat4). Requires 3D renderer.
513
511
  * @param {object} [opts]
514
512
  * @returns {p5.Matrix}
515
513
  */
516
514
  fn.ipvMatrix = function (opts = {}) {
517
- return _rendererGL(this).ipvMatrix(opts);
515
+ return _renderer3D(this).ipvMatrix(opts);
518
516
  };
519
517
 
520
518
  // ---------------------------------------------------------------------------
@@ -533,17 +531,17 @@
533
531
  * Returns true if the current projection is orthographic.
534
532
  * @returns {boolean}
535
533
  */
536
- p5.RendererGL.prototype.isOrtho = function () {
534
+ p5.Renderer3D.prototype.isOrtho = function () {
537
535
  return this.pMatrix().isOrtho();
538
536
  };
539
537
 
540
538
  /**
541
539
  * Returns true if the current projection is orthographic.
542
- * Requires WEBGL.
540
+ * Requires 3D renderer.
543
541
  * @returns {boolean}
544
542
  */
545
543
  fn.isOrtho = function () {
546
- return _rendererGL(this).isOrtho();
544
+ return _renderer3D(this).isOrtho();
547
545
  };
548
546
 
549
547
  /**
@@ -604,7 +602,7 @@
604
602
  * Near plane distance for the current projection.
605
603
  * @returns {number}
606
604
  */
607
- p5.RendererGL.prototype.nPlane = function () {
605
+ p5.Renderer3D.prototype.nPlane = function () {
608
606
  return this.pMatrix().nPlane();
609
607
  };
610
608
 
@@ -612,7 +610,7 @@
612
610
  * Far plane distance for the current projection.
613
611
  * @returns {number}
614
612
  */
615
- p5.RendererGL.prototype.fPlane = function () {
613
+ p5.Renderer3D.prototype.fPlane = function () {
616
614
  return this.pMatrix().fPlane();
617
615
  };
618
616
 
@@ -620,7 +618,7 @@
620
618
  * Left plane for the current projection.
621
619
  * @returns {number}
622
620
  */
623
- p5.RendererGL.prototype.lPlane = function () {
621
+ p5.Renderer3D.prototype.lPlane = function () {
624
622
  return this.pMatrix().lPlane();
625
623
  };
626
624
 
@@ -628,7 +626,7 @@
628
626
  * Right plane for the current projection.
629
627
  * @returns {number}
630
628
  */
631
- p5.RendererGL.prototype.rPlane = function () {
629
+ p5.Renderer3D.prototype.rPlane = function () {
632
630
  return this.pMatrix().rPlane();
633
631
  };
634
632
 
@@ -636,7 +634,7 @@
636
634
  * Top plane for the current projection.
637
635
  * @returns {number}
638
636
  */
639
- p5.RendererGL.prototype.tPlane = function () {
637
+ p5.Renderer3D.prototype.tPlane = function () {
640
638
  return this.pMatrix().tPlane();
641
639
  };
642
640
 
@@ -644,62 +642,62 @@
644
642
  * Bottom plane for the current projection.
645
643
  * @returns {number}
646
644
  */
647
- p5.RendererGL.prototype.bPlane = function () {
645
+ p5.Renderer3D.prototype.bPlane = function () {
648
646
  return this.pMatrix().bPlane();
649
647
  };
650
648
 
651
649
  /**
652
650
  * Near plane distance for the current projection.
653
- * Requires WEBGL.
651
+ * Requires 3D renderer.
654
652
  * @returns {number}
655
653
  */
656
654
  fn.nPlane = function () {
657
- return _rendererGL(this).nPlane();
655
+ return _renderer3D(this).nPlane();
658
656
  };
659
657
 
660
658
  /**
661
659
  * Far plane distance for the current projection.
662
- * Requires WEBGL.
660
+ * Requires 3D renderer.
663
661
  * @returns {number}
664
662
  */
665
663
  fn.fPlane = function () {
666
- return _rendererGL(this).fPlane();
664
+ return _renderer3D(this).fPlane();
667
665
  };
668
666
 
669
667
  /**
670
668
  * Left plane for the current projection.
671
- * Requires WEBGL.
669
+ * Requires 3D renderer.
672
670
  * @returns {number}
673
671
  */
674
672
  fn.lPlane = function () {
675
- return _rendererGL(this).lPlane();
673
+ return _renderer3D(this).lPlane();
676
674
  };
677
675
 
678
676
  /**
679
677
  * Right plane for the current projection.
680
- * Requires WEBGL.
678
+ * Requires 3D renderer.
681
679
  * @returns {number}
682
680
  */
683
681
  fn.rPlane = function () {
684
- return _rendererGL(this).rPlane();
682
+ return _renderer3D(this).rPlane();
685
683
  };
686
684
 
687
685
  /**
688
686
  * Top plane for the current projection.
689
- * Requires WEBGL.
687
+ * Requires 3D renderer.
690
688
  * @returns {number}
691
689
  */
692
690
  fn.tPlane = function () {
693
- return _rendererGL(this).tPlane();
691
+ return _renderer3D(this).tPlane();
694
692
  };
695
693
 
696
694
  /**
697
695
  * Bottom plane for the current projection.
698
- * Requires WEBGL.
696
+ * Requires 3D renderer.
699
697
  * @returns {number}
700
698
  */
701
699
  fn.bPlane = function () {
702
- return _rendererGL(this).bPlane();
700
+ return _renderer3D(this).bPlane();
703
701
  };
704
702
 
705
703
  /**
@@ -730,7 +728,7 @@
730
728
  * Vertical field of view (radians) of the current projection.
731
729
  * @returns {number|undefined}
732
730
  */
733
- p5.RendererGL.prototype.fov = function () {
731
+ p5.Renderer3D.prototype.fov = function () {
734
732
  return this.pMatrix().fov();
735
733
  };
736
734
 
@@ -738,26 +736,26 @@
738
736
  * Horizontal field of view (radians) of the current projection.
739
737
  * @returns {number|undefined}
740
738
  */
741
- p5.RendererGL.prototype.hfov = function () {
739
+ p5.Renderer3D.prototype.hfov = function () {
742
740
  return this.pMatrix().hfov();
743
741
  };
744
742
 
745
743
  /**
746
744
  * Vertical field of view (radians) of the current projection.
747
- * Requires WEBGL.
745
+ * Requires 3D renderer.
748
746
  * @returns {number|undefined}
749
747
  */
750
748
  fn.fov = function () {
751
- return _rendererGL(this).fov();
749
+ return _renderer3D(this).fov();
752
750
  };
753
751
 
754
752
  /**
755
753
  * Horizontal field of view (radians) of the current projection.
756
- * Requires WEBGL.
754
+ * Requires 3D renderer.
757
755
  * @returns {number|undefined}
758
756
  */
759
757
  fn.hfov = function () {
760
- return _rendererGL(this).hfov();
758
+ return _renderer3D(this).hfov();
761
759
  };
762
760
 
763
761
  // --- private keys (shared internal state across protos) ---
@@ -1340,7 +1338,7 @@
1340
1338
 
1341
1339
  /*
1342
1340
  // treegl approach:
1343
- p5.RendererGL.prototype.beginHUD = function () {
1341
+ p5.Renderer3D.prototype.beginHUD = function () {
1344
1342
  if (this._hudActive === true) return;
1345
1343
  const p = this._pInst;
1346
1344
  const gl = this.drawingContext;
@@ -1377,7 +1375,7 @@
1377
1375
  this._hudActive = true;
1378
1376
  };
1379
1377
 
1380
- p5.RendererGL.prototype.endHUD = function () {
1378
+ p5.Renderer3D.prototype.endHUD = function () {
1381
1379
  if (this._hudActive !== true) return;
1382
1380
  const p = this._pInst;
1383
1381
  const gl = this.drawingContext;
@@ -1398,46 +1396,54 @@
1398
1396
  };
1399
1397
  */
1400
1398
 
1401
- p5.RendererGL.prototype.beginHUD = function () {
1399
+ p5.Renderer3D.prototype.beginHUD = function () {
1402
1400
  if (this._hudActive === true) return;
1403
1401
  const p = this._pInst;
1404
- if (!p) return;
1405
- const gl = this.drawingContext;
1406
1402
  const states = this.states;
1407
- if (!gl || !states) return;
1408
- p.push(); // isolate all subsequent HUD drawing from caller state
1403
+ if (!p || !states) return;
1404
+ p.push();
1409
1405
  p.resetShader();
1410
- // Ensure HUD space does NOT inherit the user's current model transforms
1411
- // (e.g. push()/translate()
1412
1406
  p.resetMatrix();
1413
- // ---------------------
1414
- // --- HUD setup ---
1415
1407
  this._hudPrevCam = states.curCamera;
1416
- this._hudDepthWasEnabled = gl.isEnabled(gl.DEPTH_TEST);
1417
- gl.flush();
1418
- gl.disable(gl.DEPTH_TEST);
1408
+ this._hudDepthMode = undefined;
1409
+ this._hudDepthWasEnabled = undefined;
1410
+ if (typeof this.clearDepth === 'function') {
1411
+ this.flushDraw?.();
1412
+ this.clearDepth(1);
1413
+ this._hudDepthMode = 'clearDepth';
1414
+ } else {
1415
+ const gl = this.drawingContext;
1416
+ if (gl && typeof gl.isEnabled === 'function' && gl.DEPTH_TEST !== undefined) {
1417
+ this._hudDepthWasEnabled = gl.isEnabled(gl.DEPTH_TEST);
1418
+ gl.flush?.();
1419
+ gl.disable(gl.DEPTH_TEST);
1420
+ this._hudDepthMode = 'depthTestToggle';
1421
+ }
1422
+ }
1419
1423
  if (this._hudCam === undefined) this._hudCam = p.createCamera();
1420
1424
  const z = 1e6;
1421
- // HUD coordinates: x in [0, width], y in [0, height]
1422
1425
  this._hudCam.ortho(0, p.width, -p.height, 0, -z, z);
1423
- // this._hudCam.ortho(0, p.width, 0, -p.height, -z, z); // <- flipped
1424
1426
  this._hudCam.camera(0, 0, 1, 0, 0, 0, 0, 1, 0);
1425
1427
  p.setCamera(this._hudCam);
1426
1428
  this._hudActive = true;
1427
1429
  };
1428
1430
 
1429
- p5.RendererGL.prototype.endHUD = function () {
1431
+ p5.Renderer3D.prototype.endHUD = function () {
1430
1432
  if (this._hudActive !== true) return;
1431
1433
  const p = this._pInst;
1432
- const gl = this.drawingContext;
1433
- const states = this.states;
1434
- if (p === undefined || gl === undefined || states === undefined) return;
1435
- gl.flush();
1436
- this._hudDepthWasEnabled ? gl.enable(gl.DEPTH_TEST) : gl.disable(gl.DEPTH_TEST);
1437
- p.pop(); // calls: this.pop(this._rendererState);
1434
+ if (!p) return;
1435
+ if (this._hudDepthMode === 'depthTestToggle') {
1436
+ const gl = this.drawingContext;
1437
+ if (gl && gl.DEPTH_TEST !== undefined) {
1438
+ gl.flush?.();
1439
+ this._hudDepthWasEnabled ? gl.enable(gl.DEPTH_TEST) : gl.disable(gl.DEPTH_TEST);
1440
+ }
1441
+ }
1442
+ p.pop();
1438
1443
  this._hudPrevCam !== undefined && p.setCamera(this._hudPrevCam);
1439
1444
  this._hudPrevCam = undefined;
1440
1445
  this._hudDepthWasEnabled = undefined;
1446
+ this._hudDepthMode = undefined;
1441
1447
  this._hudActive = false;
1442
1448
  };
1443
1449
 
@@ -1445,7 +1451,7 @@
1445
1451
  // Space transforms: mapLocation / mapDirection
1446
1452
  // ---------------------------------------------------------------------------
1447
1453
 
1448
- p5.RendererGL.prototype._parseTransformArgs = function (defaultMainArg, ...args) {
1454
+ p5.Renderer3D.prototype._parseTransformArgs = function (defaultMainArg, ...args) {
1449
1455
  let mainArg = defaultMainArg;
1450
1456
  const options = {};
1451
1457
  for (const arg of args) {
@@ -1463,7 +1469,7 @@
1463
1469
  // ---------------------------------------------------------------------------
1464
1470
 
1465
1471
  fn.mapLocation = function (...args) {
1466
- return _rendererGL(this)?.mapLocation(...args);
1472
+ return _renderer3D(this)?.mapLocation(...args);
1467
1473
  };
1468
1474
 
1469
1475
  /**
@@ -1480,12 +1486,12 @@
1480
1486
  * @param {p5.Matrix} [opts.ipvMatrix]
1481
1487
  * @returns {p5.Vector}
1482
1488
  */
1483
- p5.RendererGL.prototype.mapLocation = function (...args) {
1489
+ p5.Renderer3D.prototype.mapLocation = function (...args) {
1484
1490
  const { mainArg, options } = this._parseTransformArgs(p5.Tree.ORIGIN, ...args);
1485
1491
  return this._location(mainArg, options);
1486
1492
  };
1487
1493
 
1488
- p5.RendererGL.prototype._location = function (
1494
+ p5.Renderer3D.prototype._location = function (
1489
1495
  point = p5.Tree.ORIGIN,
1490
1496
  {
1491
1497
  from = p5.Tree.EYE,
@@ -1507,25 +1513,25 @@
1507
1513
  to = this.mMatrix({ eMatrix });
1508
1514
  }
1509
1515
  if ((from == p5.Tree.WORLD) && (to == p5.Tree.SCREEN)) {
1510
- return this._worldToScreenPosition({ point, pMatrix, vMatrix, pvMatrix });
1516
+ return this._worldToScreenLocation({ point, pMatrix, vMatrix, pvMatrix });
1511
1517
  }
1512
1518
  if ((from == p5.Tree.SCREEN) && (to == p5.Tree.WORLD)) {
1513
- return this._screenToWorldPosition({ point, pMatrix, vMatrix, pvMatrix, ipvMatrix });
1519
+ return this._screenToWorldLocation({ point, pMatrix, vMatrix, pvMatrix, ipvMatrix });
1514
1520
  }
1515
1521
  if (from == p5.Tree.SCREEN && to == p5.Tree.NDC) {
1516
- return this._screenToNDCPosition(point);
1522
+ return this._screenToNDCLocation(point);
1517
1523
  }
1518
1524
  if (from == p5.Tree.NDC && to == p5.Tree.SCREEN) {
1519
- return this._ndcToScreenPosition(point);
1525
+ return this._ndcToScreenLocation(point);
1520
1526
  }
1521
1527
  if (from == p5.Tree.WORLD && to == p5.Tree.NDC) {
1522
- return this._screenToNDCPosition(
1523
- this._worldToScreenPosition({ point, pMatrix, vMatrix, pvMatrix })
1528
+ return this._screenToNDCLocation(
1529
+ this._worldToScreenLocation({ point, pMatrix, vMatrix, pvMatrix })
1524
1530
  );
1525
1531
  }
1526
1532
  if (from == p5.Tree.NDC && to == p5.Tree.WORLD) {
1527
- return this._screenToWorldPosition({
1528
- point: this._ndcToScreenPosition(point),
1533
+ return this._screenToWorldLocation({
1534
+ point: this._ndcToScreenLocation(point),
1529
1535
  pMatrix,
1530
1536
  vMatrix,
1531
1537
  pvMatrix,
@@ -1537,8 +1543,8 @@
1537
1543
  ? (vMatrix ?? this.vMatrix())
1538
1544
  : to.copy().invert(to)
1539
1545
  ).mult4(
1540
- this._screenToWorldPosition({
1541
- point: this._ndcToScreenPosition(point),
1546
+ this._screenToWorldLocation({
1547
+ point: this._ndcToScreenLocation(point),
1542
1548
  pMatrix,
1543
1549
  vMatrix,
1544
1550
  pvMatrix,
@@ -1547,8 +1553,8 @@
1547
1553
  );
1548
1554
  }
1549
1555
  if ((from instanceof p5.Matrix || from == p5.Tree.EYE) && to == p5.Tree.NDC) {
1550
- return this._screenToNDCPosition(
1551
- this._worldToScreenPosition({
1556
+ return this._screenToNDCLocation(
1557
+ this._worldToScreenLocation({
1552
1558
  point: (from == p5.Tree.EYE
1553
1559
  ? (eMatrix ?? this.eMatrix())
1554
1560
  : from
@@ -1579,11 +1585,11 @@
1579
1585
  ? (vMatrix ?? this.vMatrix())
1580
1586
  : to.copy().invert(to)
1581
1587
  ).mult4(
1582
- this._screenToWorldPosition({ point, pMatrix, vMatrix, pvMatrix, ipvMatrix })
1588
+ this._screenToWorldLocation({ point, pMatrix, vMatrix, pvMatrix, ipvMatrix })
1583
1589
  );
1584
1590
  }
1585
1591
  if ((from instanceof p5.Matrix || from == p5.Tree.EYE) && to == p5.Tree.SCREEN) {
1586
- return this._worldToScreenPosition({
1592
+ return this._worldToScreenLocation({
1587
1593
  point: (from == p5.Tree.EYE
1588
1594
  ? (eMatrix ?? this.eMatrix())
1589
1595
  : from
@@ -1603,7 +1609,7 @@
1603
1609
  return point;
1604
1610
  };
1605
1611
 
1606
- p5.RendererGL.prototype._ndcToScreenPosition = function (point) {
1612
+ p5.Renderer3D.prototype._ndcToScreenLocation = function (point) {
1607
1613
  return new p5.Vector(
1608
1614
  p5.prototype.map(point.x, -1, 1, 0, this.width),
1609
1615
  p5.prototype.map(point.y, -1, 1, 0, this.height),
@@ -1611,7 +1617,7 @@
1611
1617
  );
1612
1618
  };
1613
1619
 
1614
- p5.RendererGL.prototype._screenToNDCPosition = function (point) {
1620
+ p5.Renderer3D.prototype._screenToNDCLocation = function (point) {
1615
1621
  return new p5.Vector(
1616
1622
  p5.prototype.map(point.x, 0, this.width, -1, 1),
1617
1623
  p5.prototype.map(point.y, 0, this.height, -1, 1),
@@ -1619,7 +1625,7 @@
1619
1625
  );
1620
1626
  };
1621
1627
 
1622
- p5.RendererGL.prototype._worldToScreenPosition = function ({
1628
+ p5.Renderer3D.prototype._worldToScreenLocation = function ({
1623
1629
  point = new p5.Vector(0, 0, 0.5),
1624
1630
  pMatrix,
1625
1631
  vMatrix,
@@ -1642,7 +1648,7 @@
1642
1648
  return new p5.Vector(target[0], target[1], target[2]);
1643
1649
  };
1644
1650
 
1645
- p5.RendererGL.prototype._screenToWorldPosition = function ({
1651
+ p5.Renderer3D.prototype._screenToWorldLocation = function ({
1646
1652
  point = new p5.Vector(this.width / 2, this.height / 2, 0.5),
1647
1653
  pMatrix,
1648
1654
  vMatrix,
@@ -1672,7 +1678,7 @@
1672
1678
  // ---------------------------------------------------------------------------
1673
1679
 
1674
1680
  fn.mapDirection = function (...args) {
1675
- return _rendererGL(this)?.mapDirection(...args);
1681
+ return _renderer3D(this)?.mapDirection(...args);
1676
1682
  };
1677
1683
 
1678
1684
  /**
@@ -1687,12 +1693,12 @@
1687
1693
  * @param {p5.Matrix} [opts.pMatrix]
1688
1694
  * @returns {p5.Vector}
1689
1695
  */
1690
- p5.RendererGL.prototype.mapDirection = function (...args) {
1696
+ p5.Renderer3D.prototype.mapDirection = function (...args) {
1691
1697
  const { mainArg, options } = this._parseTransformArgs(p5.Tree._k, ...args);
1692
1698
  return this._direction(mainArg, options);
1693
1699
  };
1694
1700
 
1695
- p5.RendererGL.prototype._direction = function (
1701
+ p5.Renderer3D.prototype._direction = function (
1696
1702
  vector = p5.Tree._k,
1697
1703
  {
1698
1704
  from = p5.Tree.EYE,
@@ -1786,7 +1792,7 @@
1786
1792
  return vector;
1787
1793
  };
1788
1794
 
1789
- p5.RendererGL.prototype._worldToScreenDirection = function (vector, pMatrix) {
1795
+ p5.Renderer3D.prototype._worldToScreenDirection = function (vector, pMatrix) {
1790
1796
  pMatrix = pMatrix ?? this.pMatrix();
1791
1797
  const eyeVector = this._direction(vector, { from: p5.Tree.WORLD, to: p5.Tree.EYE });
1792
1798
  let dx = eyeVector.x;
@@ -1807,7 +1813,7 @@
1807
1813
  return new p5.Vector(dx, dy, dz);
1808
1814
  };
1809
1815
 
1810
- p5.RendererGL.prototype._screenToWorldDirection = function (vector, pMatrix) {
1816
+ p5.Renderer3D.prototype._screenToWorldDirection = function (vector, pMatrix) {
1811
1817
  pMatrix = pMatrix ?? this.pMatrix();
1812
1818
 
1813
1819
  let dx = vector.x;
@@ -1831,11 +1837,11 @@
1831
1837
  return this._direction(new p5.Vector(dx, dy, dz), { from: p5.Tree.EYE, to: p5.Tree.WORLD });
1832
1838
  };
1833
1839
 
1834
- p5.RendererGL.prototype._ndcToScreenDirection = function (vector) {
1840
+ p5.Renderer3D.prototype._ndcToScreenDirection = function (vector) {
1835
1841
  return new p5.Vector(this.width * vector.x / 2, this.height * vector.y / 2, vector.z / 2);
1836
1842
  };
1837
1843
 
1838
- p5.RendererGL.prototype._screenToNDCDirection = function (vector) {
1844
+ p5.Renderer3D.prototype._screenToNDCDirection = function (vector) {
1839
1845
  return new p5.Vector(2 * vector.x / this.width, 2 * vector.y / this.height, 2 * vector.z);
1840
1846
  };
1841
1847
 
@@ -1852,13 +1858,13 @@
1852
1858
  * - In orthographic projection, the ratio is constant.
1853
1859
  * - In perspective projection, the ratio depends on eye-space depth.
1854
1860
  *
1855
- * Requires WEBGL.
1861
+ * Requires 3D renderer.
1856
1862
  *
1857
1863
  * @param {p5.Vector|number[]} [point=p5.Tree.ORIGIN] World-space point.
1858
1864
  * @returns {number|undefined} World units per pixel at the given point.
1859
1865
  */
1860
1866
  fn.pixelRatio = function (point) {
1861
- return _rendererGL(this)?.pixelRatio(point);
1867
+ return _renderer3D(this)?.pixelRatio(point);
1862
1868
  };
1863
1869
 
1864
1870
  /**
@@ -1866,7 +1872,7 @@
1866
1872
  * @param {p5.Vector|number[]} [point=p5.Tree.ORIGIN]
1867
1873
  * @returns {number}
1868
1874
  */
1869
- p5.RendererGL.prototype.pixelRatio = function (point = p5.Tree.ORIGIN) {
1875
+ p5.Renderer3D.prototype.pixelRatio = function (point = p5.Tree.ORIGIN) {
1870
1876
  return this.isOrtho()
1871
1877
  ? Math.abs(this.tPlane() - this.bPlane()) / this.height
1872
1878
  : 2 * Math.abs(
@@ -1899,27 +1905,27 @@
1899
1905
 
1900
1906
  /**
1901
1907
  * Returns a pointer position in *pixel* coordinates from an arbitrary (x, y) pair.
1902
- * Delegates to the WEBGL renderer.
1908
+ * Delegates to the active 3D renderer.
1903
1909
  *
1904
1910
  * Accepts parameters in any order:
1905
1911
  * - `number, number` → pointerX, pointerY
1906
1912
  * - optional `boolean` → `flip`
1907
1913
  *
1908
1914
  * @param {...(number|boolean)} args
1909
- * @returns {number[]|undefined} `[x, y]` in pixels, or undefined if not in WEBGL.
1915
+ * @returns {number[]|undefined} `[x, y]` in pixels, or undefined if no 3D renderer is active.
1910
1916
  */
1911
1917
  fn.pointerPosition = function (...args) {
1912
- return _rendererGL(this)?.pointerPosition(...args);
1918
+ return _renderer3D(this)?.pointerPosition(...args);
1913
1919
  };
1914
1920
 
1915
1921
  /**
1916
1922
  * Returns the canvas resolution in *pixel* coordinates.
1917
- * Delegates to the WEBGL renderer.
1923
+ * Delegates to the active 3D renderer.
1918
1924
  *
1919
- * @returns {number[]|undefined} `[width, height]` in pixels, or undefined if not in WEBGL.
1925
+ * @returns {number[]|undefined} `[width, height]` in pixels, or undefined if no 3D renderer is active.
1920
1926
  */
1921
1927
  fn.resolution = function () {
1922
- return _rendererGL(this)?.resolution();
1928
+ return _renderer3D(this)?.resolution();
1923
1929
  };
1924
1930
 
1925
1931
  /**
@@ -1932,7 +1938,7 @@
1932
1938
  * @param {...(number|boolean)} args
1933
1939
  * @returns {number[]} `[x, y]` in pixels (includes pixelDensity scaling).
1934
1940
  */
1935
- p5.RendererGL.prototype.pointerPosition = function (...args) {
1941
+ p5.Renderer3D.prototype.pointerPosition = function (...args) {
1936
1942
  let pointerX;
1937
1943
  let pointerY;
1938
1944
  let flip = true;
@@ -1952,7 +1958,7 @@
1952
1958
  * Returns the canvas resolution in *pixel* coordinates.
1953
1959
  * @returns {number[]} `[width, height]` in pixels (includes pixelDensity scaling).
1954
1960
  */
1955
- p5.RendererGL.prototype.resolution = function () {
1961
+ p5.Renderer3D.prototype.resolution = function () {
1956
1962
  const pd = this.pixelDensity();
1957
1963
  return [pd * this.width, pd * this.height];
1958
1964
  };
@@ -1962,11 +1968,51 @@
1962
1968
  // -------------------------------------------------------------------------
1963
1969
 
1964
1970
  fn.axes = function (opts) {
1965
- _rendererGL(this)?.axes(opts);
1971
+ _renderer3D(this)?.axes(opts);
1966
1972
  return this;
1967
1973
  };
1968
1974
 
1969
- p5.RendererGL.prototype.axes = function ({
1975
+ /**
1976
+ * Draws 3D reference axes (X, Y, Z) centered at the origin in model space,
1977
+ * using the current stroke settings.
1978
+ *
1979
+ * Each axis can be enabled independently using bitwise flags, and optional
1980
+ * axis labels (X, Y, Z) can be rendered near the positive ends.
1981
+ *
1982
+ * @method axes
1983
+ * @for p5.Renderer3D
1984
+ * @param {Object} [opts] Axes options.
1985
+ * @param {Number} [opts.size=100] Length of each axis in world units.
1986
+ * @param {Array<String>} [opts.colors=['Red','Lime','DodgerBlue']]
1987
+ * Stroke colors for X, Y, and Z axes respectively.
1988
+ * @param {Number} [opts.bits=p5.Tree.LABELS | p5.Tree.X | p5.Tree.Y | p5.Tree.Z]
1989
+ * Bitmask controlling which axes and labels are drawn.
1990
+ *
1991
+ * @example
1992
+ * function draw() {
1993
+ * background(30);
1994
+ * orbitControl();
1995
+ * axes({ size: 300 });
1996
+ * }
1997
+ *
1998
+ * @example
1999
+ * // Draw only X and Z axes, no labels
2000
+ * axes({
2001
+ * size: 200,
2002
+ * bits: p5.Tree.X | p5.Tree.Z
2003
+ * });
2004
+ *
2005
+ * @example
2006
+ * // Draw full axes in both positive and negative directions
2007
+ * axes({
2008
+ * size: 150,
2009
+ * bits: p5.Tree.X | p5.Tree._X |
2010
+ * p5.Tree.Y | p5.Tree._Y |
2011
+ * p5.Tree.Z | p5.Tree._Z |
2012
+ * p5.Tree.LABELS
2013
+ * });
2014
+ */
2015
+ p5.Renderer3D.prototype.axes = function ({
1970
2016
  size = 100,
1971
2017
  colors = ['Red', 'Lime', 'DodgerBlue'],
1972
2018
  bits = p5.Tree.LABELS | p5.Tree.X | p5.Tree.Y | p5.Tree.Z
@@ -2011,51 +2057,40 @@
2011
2057
  };
2012
2058
 
2013
2059
  fn.grid = function (opts) {
2014
- _rendererGL(this)?.grid(opts);
2060
+ _renderer3D(this)?.grid(opts);
2015
2061
  return this;
2016
2062
  };
2017
2063
 
2018
- p5.RendererGL.prototype.grid = function ({
2064
+ /**
2065
+ * Draws a simple X/Y reference grid on the Z=0 plane in the current model space.
2066
+ *
2067
+ * The grid is centered at the origin and spans from `-size` to `+size` on both X and Y.
2068
+ * It draws `subdivisions + 1` lines in each direction (including the borders).
2069
+ *
2070
+ * @method grid
2071
+ * @for p5.Renderer3D
2072
+ * @param {Object} [opts] Grid options.
2073
+ * @param {Number} [opts.size=100] Half-extent of the grid in world units.
2074
+ * @param {Number} [opts.subdivisions=10] Number of subdivisions per side (must be >= 1).
2075
+ * @example
2076
+ * function draw() {
2077
+ * background(30);
2078
+ * orbitControl();
2079
+ * grid({ size: 300, subdivisions: 20 });
2080
+ * }
2081
+ */
2082
+ p5.Renderer3D.prototype.grid = function ({
2019
2083
  size = 100,
2020
- subdivisions = 10,
2021
- style = p5.Tree.SOLID,
2022
- weight = 1,
2023
- minorSubdivisions = 5
2084
+ subdivisions = 10
2024
2085
  } = {}) {
2025
2086
  const p = this._pInst;
2026
- if (!p) return;
2087
+ if (!p) return;
2088
+ subdivisions = Math.max(1, subdivisions);
2027
2089
  p.push();
2028
- if (style === p5.Tree.DOTS) {
2029
- let posi = 0;
2030
- let posj = 0;
2031
- p.strokeWeight(weight * 2);
2032
- p.beginShape(p.POINTS);
2033
- for (let i = 0; i <= subdivisions; ++i) {
2034
- posi = size * (2.0 * i / subdivisions - 1.0);
2035
- for (let j = 0; j <= subdivisions; ++j) {
2036
- posj = size * (2.0 * j / subdivisions - 1.0);
2037
- p.vertex(posi, posj, 0);
2038
- }
2039
- }
2040
- p.endShape();
2041
- const internalSub = Math.max(1, minorSubdivisions | 0);
2042
- const subSubdivisions = subdivisions * internalSub;
2043
- p.strokeWeight(weight);
2044
- p.beginShape(p.POINTS);
2045
- for (let i = 0; i <= subSubdivisions; ++i) {
2046
- posi = size * (2.0 * i / subSubdivisions - 1.0);
2047
- for (let j = 0; j <= subSubdivisions; ++j) {
2048
- posj = size * (2.0 * j / subSubdivisions - 1.0);
2049
- ((i % internalSub) !== 0 || (j % internalSub) !== 0) && p.vertex(posi, posj, 0);
2050
- }
2051
- }
2052
- p.endShape();
2053
- } else {
2054
- for (let i = 0; i <= subdivisions; ++i) {
2055
- const pos = size * (2.0 * i / subdivisions - 1.0);
2056
- p.line(pos, -size, 0, pos, +size, 0);
2057
- p.line(-size, pos, 0, size, pos, 0);
2058
- }
2090
+ for (let i = 0; i <= subdivisions; ++i) {
2091
+ const pos = size * (2.0 * i / subdivisions - 1.0);
2092
+ p.line(pos, -size, 0, pos, +size, 0);
2093
+ p.line(-size, pos, 0, +size, pos, 0);
2059
2094
  }
2060
2095
  p.pop();
2061
2096
  };
@@ -2071,7 +2106,7 @@
2071
2106
  * `p5.Tree.SCREEN`. In that case, `size` is interpreted in *world units* and
2072
2107
  * converted to pixels using `pixelRatio()` at the corresponding world point.
2073
2108
  *
2074
- * Requires WEBGL.
2109
+ * Requires 3D renderer.
2075
2110
  *
2076
2111
  * @param {object} [opts]
2077
2112
  * @param {p5.Matrix} [opts.mMatrix] Model-space matrix origin to compute (x, y) from.
@@ -2086,7 +2121,7 @@
2086
2121
  * @returns {boolean|undefined}
2087
2122
  */
2088
2123
  fn.mousePicking = function (opts) {
2089
- return _rendererGL(this)?.mousePicking(opts);
2124
+ return _renderer3D(this)?.mousePicking(opts);
2090
2125
  };
2091
2126
 
2092
2127
  /**
@@ -2096,16 +2131,16 @@
2096
2131
  * `p5.Tree.SCREEN`. In that case, `size` is interpreted in *world units* and
2097
2132
  * converted to pixels using `pixelRatio()` at the corresponding world point.
2098
2133
  *
2099
- * Requires WEBGL.
2134
+ * Requires 3D renderer.
2100
2135
  *
2101
2136
  * @param {...any} args
2102
2137
  * @returns {boolean|undefined}
2103
2138
  */
2104
2139
  fn.pointerPicking = function (...args) {
2105
- return _rendererGL(this)?.pointerPicking(...args);
2140
+ return _renderer3D(this)?.pointerPicking(...args);
2106
2141
  };
2107
2142
 
2108
- p5.RendererGL.prototype.mousePicking = function ({
2143
+ p5.Renderer3D.prototype.mousePicking = function ({
2109
2144
  mMatrix = this.mMatrix(),
2110
2145
  x,
2111
2146
  y,
@@ -2131,7 +2166,7 @@
2131
2166
  * @param {...any} args
2132
2167
  * @returns {boolean}
2133
2168
  */
2134
- p5.RendererGL.prototype.pointerPicking = function (...args) {
2169
+ p5.Renderer3D.prototype.pointerPicking = function (...args) {
2135
2170
  let pointerX;
2136
2171
  let pointerY;
2137
2172
  const config = {};
@@ -2193,7 +2228,7 @@
2193
2228
  * @param {number} [opts.radius=100] Radius in current space.
2194
2229
  * @param {number} [opts.detail=50] Segment count.
2195
2230
  */
2196
- p5.RendererGL.prototype._circle = function ({
2231
+ p5.Renderer3D.prototype._circle = function ({
2197
2232
  filled = false,
2198
2233
  x = this.width / 2,
2199
2234
  y = this.height / 2,
@@ -2245,11 +2280,11 @@
2245
2280
  * @param {p5.Matrix} [opts.pvMatrix] Projection-view matrix override.
2246
2281
  */
2247
2282
  fn.cross = function (opts) {
2248
- _rendererGL(this)?.cross(opts);
2283
+ _renderer3D(this)?.cross(opts);
2249
2284
  return this;
2250
2285
  };
2251
2286
 
2252
- p5.RendererGL.prototype.cross = function ({
2287
+ p5.Renderer3D.prototype.cross = function ({
2253
2288
  mMatrix = this.mMatrix(),
2254
2289
  x,
2255
2290
  y,
@@ -2298,11 +2333,11 @@
2298
2333
  * @param {p5.Matrix} [opts.pvMatrix] Projection-view matrix override.
2299
2334
  */
2300
2335
  fn.bullsEye = function (opts) {
2301
- _rendererGL(this)?.bullsEye(opts);
2336
+ _renderer3D(this)?.bullsEye(opts);
2302
2337
  return this;
2303
2338
  };
2304
2339
 
2305
- p5.RendererGL.prototype.bullsEye = function ({
2340
+ p5.Renderer3D.prototype.bullsEye = function ({
2306
2341
  mMatrix = this.mMatrix(),
2307
2342
  x,
2308
2343
  y,
@@ -2349,22 +2384,22 @@
2349
2384
  // ---------------------------------------------------------------------------
2350
2385
 
2351
2386
  fn.viewFrustum = function (opts) {
2352
- _rendererGL(this)?.viewFrustum(opts);
2387
+ _renderer3D(this)?.viewFrustum(opts);
2353
2388
  return this;
2354
2389
  };
2355
2390
 
2356
2391
  /**
2357
- * Displays a view frustum, either from a pg (p5.Graphics / p5.RendererGL) or from eMatrix/pMatrix.
2392
+ * Displays a view frustum, either from a pg (p5.Graphics / p5.Renderer3D) or from eMatrix/pMatrix.
2358
2393
  *
2359
2394
  * @param {Object} [opts]
2360
2395
  * @param {p5.Matrix} [opts.vMatrix=this.vMatrix()] desired view matrix (world -> this eye) for drawing the frustum.
2361
- * @param {p5.RendererGL|p5.Graphics} [opts.pg] renderer/pg whose frustum is to be displayed.
2396
+ * @param {p5.Renderer3D|p5.Graphics} [opts.pg] renderer/pg whose frustum is to be displayed.
2362
2397
  * @param {p5.Matrix} [opts.eMatrix=pg?.eMatrix()] eye matrix defining frustum pose (eye -> world).
2363
2398
  * @param {p5.Matrix} [opts.pMatrix=pg?.pMatrix()] projection matrix defining frustum projection.
2364
2399
  * @param {number} [opts.bits=p5.Tree.NEAR|p5.Tree.FAR] bitmask (NEAR/FAR/BODY/APEX).
2365
2400
  * @param {Function|false|null} [opts.viewer=...] callback drawn at the frustum origin (in frustum space).
2366
2401
  */
2367
- p5.RendererGL.prototype.viewFrustum = function ({
2402
+ p5.Renderer3D.prototype.viewFrustum = function ({
2368
2403
  vMatrix = this.vMatrix(),
2369
2404
  pg,
2370
2405
  eMatrix = pg?.eMatrix(),
@@ -2495,7 +2530,7 @@
2495
2530
  * @returns {number} One of p5.Tree.VISIBLE, p5.Tree.INVISIBLE, p5.Tree.SEMIVISIBLE.
2496
2531
  */
2497
2532
  fn.visibility = function (...args) {
2498
- return _rendererGL(this).visibility(...args);
2533
+ return _renderer3D(this).visibility(...args);
2499
2534
  };
2500
2535
 
2501
2536
  /**
@@ -2503,7 +2538,7 @@
2503
2538
  * @returns {Object}
2504
2539
  */
2505
2540
  fn.bounds = function (opts = {}) {
2506
- return _rendererGL(this).bounds(opts);
2541
+ return _renderer3D(this).bounds(opts);
2507
2542
  };
2508
2543
 
2509
2544
  /**
@@ -2511,7 +2546,7 @@
2511
2546
  * @returns {number}
2512
2547
  */
2513
2548
  fn.distanceToBound = function (...args) {
2514
- return _rendererGL(this).distanceToBound(...args);
2549
+ return _renderer3D(this).distanceToBound(...args);
2515
2550
  };
2516
2551
 
2517
2552
  /**
@@ -2523,7 +2558,7 @@
2523
2558
  *
2524
2559
  * @private
2525
2560
  */
2526
- p5.RendererGL.prototype._parseVisibilityArgs = function (...args) {
2561
+ p5.Renderer3D.prototype._parseVisibilityArgs = function (...args) {
2527
2562
  let corner1;
2528
2563
  let corner2;
2529
2564
  let center;
@@ -2592,7 +2627,7 @@
2592
2627
  * @param {Object} [opts.bounds] Frustum plane equations (defaults to this.bounds()).
2593
2628
  * @returns {number} One of p5.Tree.VISIBLE, p5.Tree.INVISIBLE, p5.Tree.SEMIVISIBLE.
2594
2629
  */
2595
- p5.RendererGL.prototype.visibility = function (...args) {
2630
+ p5.Renderer3D.prototype.visibility = function (...args) {
2596
2631
  const { corner1, corner2, center, radius, bounds } = this._parseVisibilityArgs(...args);
2597
2632
  const b = bounds ?? this.bounds();
2598
2633
  return center ? (radius ? this._ballVisibility(center, radius, b) : this._pointVisibility(center, b))
@@ -2600,7 +2635,7 @@
2600
2635
  : (console.error('[p5.tree] visibility: could not parse query.'), p5.Tree.INVISIBLE));
2601
2636
  };
2602
2637
 
2603
- p5.RendererGL.prototype._pointVisibility = function (point, bounds = this.bounds()) {
2638
+ p5.Renderer3D.prototype._pointVisibility = function (point, bounds = this.bounds()) {
2604
2639
  for (const key in bounds) {
2605
2640
  const d = this.distanceToBound(point, key, bounds);
2606
2641
  if (d > 0) return p5.Tree.INVISIBLE;
@@ -2609,7 +2644,7 @@
2609
2644
  return p5.Tree.VISIBLE;
2610
2645
  };
2611
2646
 
2612
- p5.RendererGL.prototype._ballVisibility = function (center, radius, bounds = this.bounds()) {
2647
+ p5.Renderer3D.prototype._ballVisibility = function (center, radius, bounds = this.bounds()) {
2613
2648
  let allInForAllPlanes = true;
2614
2649
  for (const key in bounds) {
2615
2650
  const d = this.distanceToBound(center, key, bounds);
@@ -2619,7 +2654,7 @@
2619
2654
  return allInForAllPlanes ? p5.Tree.VISIBLE : p5.Tree.SEMIVISIBLE;
2620
2655
  };
2621
2656
 
2622
- p5.RendererGL.prototype._boxVisibility = function (corner1, corner2, bounds = this.bounds()) {
2657
+ p5.Renderer3D.prototype._boxVisibility = function (corner1, corner2, bounds = this.bounds()) {
2623
2658
  const asVec3 = v =>
2624
2659
  v instanceof p5.Vector ? v : new p5.Vector(v?.[0] ?? 0, v?.[1] ?? 0, v?.[2] ?? 0);
2625
2660
  corner1 = asVec3(corner1);
@@ -2654,7 +2689,7 @@
2654
2689
  * @param {p5.Matrix} [opts.eMatrix] Eye matrix (eye -> world).
2655
2690
  * @returns {Object} Object keyed by p5.Tree.LEFT/RIGHT/NEAR/FAR/TOP/BOTTOM.
2656
2691
  */
2657
- p5.RendererGL.prototype.bounds = function ({
2692
+ p5.Renderer3D.prototype.bounds = function ({
2658
2693
  vMatrix,
2659
2694
  eMatrix
2660
2695
  } = {}) {
@@ -2726,7 +2761,7 @@
2726
2761
  * @param {Object} [bounds] Plane equations (defaults to this.bounds()).
2727
2762
  * @returns {number}
2728
2763
  */
2729
- p5.RendererGL.prototype.distanceToBound = function (...args) {
2764
+ p5.Renderer3D.prototype.distanceToBound = function (...args) {
2730
2765
  let point;
2731
2766
  let key;
2732
2767
  let bounds = this.bounds();