@@ -520,6 +520,93 @@ function primitives3D(p5, fn){
520
520
return this . _renderer . endGeometry ( ) ;
521
521
} ;
522
522
523
+
524
+ /**
525
+ * Sets the stroke rendering mode to balance performance and visual features when drawing lines.
526
+ *
527
+ * `strokeMode()` offers two modes:
528
+ *
529
+ * - `SIMPLE`: Optimizes for speed by disabling caps, joins, and stroke color features.
530
+ * Use this mode for faster line rendering when these visual details are unnecessary.
531
+ * - `FULL`: Enables caps, joins, and stroke color for lines.
532
+ * This mode provides enhanced visuals but may reduce performance due to additional processing.
533
+ *
534
+ * Choose the mode that best suits your application's needs to either improve rendering speed or enhance visual quality.
535
+ *
536
+ * @method strokeMode
537
+ * @param {string } mode - The stroke mode to set. Possible values are:
538
+ * - `'SIMPLE'`: Fast rendering without caps, joins, or stroke color.
539
+ * - `'FULL'`: Detailed rendering with caps, joins, and stroke color.
540
+ *
541
+ * @example
542
+ * <div>
543
+ * <code>
544
+ * function setup() {
545
+ * createCanvas(300, 300, WEBGL);
546
+ *
547
+ * describe('A sphere with red stroke and a red, wavy line on a gray background.');
548
+ * }
549
+ *
550
+ * function draw() {
551
+ * background(128);
552
+ * strokeMode(FULL); // Enables detailed rendering with caps, joins, and stroke color.
553
+ * push();
554
+ * strokeWeight(1);
555
+ * translate(0, -50, 0);
556
+ * sphere(50);
557
+ * pop();
558
+ *
559
+ * noFill();
560
+ * strokeWeight(15);
561
+ * beginShape();
562
+ * vertex(-150, 100);
563
+ * stroke('red');
564
+ * bezierVertex(-50, -100, 30, 300, 130, 50);
565
+ * endShape();
566
+ * }
567
+ * </code>
568
+ * </div>
569
+ *
570
+ * <div>
571
+ * <code>
572
+ * function setup() {
573
+ * createCanvas(300, 300, WEBGL);
574
+ *
575
+ * describe('A sphere with red stroke and a wavy line without full curve decorations without caps and color on a gray background.');
576
+ * }
577
+ *
578
+ * function draw() {
579
+ * background(128);
580
+ * strokeMode(SIMPLE); // Enables simple rendering without caps, joins, and stroke color.
581
+ * push();
582
+ * strokeWeight(1);
583
+ * translate(0, -50, 0);
584
+ * sphere(50);
585
+ * pop();
586
+ *
587
+ * noFill();
588
+ * strokeWeight(15);
589
+ * beginShape();
590
+ * vertex(-150, 100);
591
+ * stroke('red');
592
+ * bezierVertex(-50, -100, 30, 300, 130, 50);
593
+ * endShape();
594
+ * }
595
+ * </code>
596
+ * </div>
597
+ */
598
+
599
+ fn . strokeMode = function ( mode ) {
600
+ if ( mode === undefined ) {
601
+ return this . _renderer . _simpleLines ? constants . SIMPLE : constants . FULL ;
602
+ } else if ( mode === constants . SIMPLE ) {
603
+ this . _renderer . _simpleLines = true ;
604
+ } else if ( mode === constants . FULL ) {
605
+ this . _renderer . _simpleLines = false ;
606
+ } else {
607
+ throw Error ( 'no such parameter' ) ;
608
+ }
609
+ }
523
610
/**
524
611
* Creates a custom <a href="#/p5.Geometry">p5.Geometry</a> object from
525
612
* simpler 3D shapes.
@@ -2109,7 +2196,7 @@ function primitives3D(p5, fn){
2109
2196
this . faces = [ [ 0 , 1 , 2 ] ] ;
2110
2197
this . uvs = [ 0 , 0 , 1 , 0 , 1 , 1 ] ;
2111
2198
} ;
2112
- const triGeom = new Geometry ( 1 , 1 , _triangle ) ;
2199
+ const triGeom = new Geometry ( 1 , 1 , _triangle , this ) ;
2113
2200
triGeom . _edgesToVertices ( ) ;
2114
2201
triGeom . computeNormals ( ) ;
2115
2202
triGeom . gid = gid ;
@@ -2245,7 +2332,7 @@ function primitives3D(p5, fn){
2245
2332
}
2246
2333
} ;
2247
2334
2248
- const arcGeom = new Geometry ( detail , 1 , _arc ) ;
2335
+ const arcGeom = new Geometry ( detail , 1 , _arc , this ) ;
2249
2336
arcGeom . computeNormals ( ) ;
2250
2337
2251
2338
if ( detail <= 50 ) {
@@ -2308,7 +2395,7 @@ function primitives3D(p5, fn){
2308
2395
] ;
2309
2396
}
2310
2397
} ;
2311
- const rectGeom = new Geometry ( detailX , detailY , _rect ) ;
2398
+ const rectGeom = new Geometry ( detailX , detailY , _rect , this ) ;
2312
2399
rectGeom
2313
2400
. computeFaces ( )
2314
2401
. computeNormals ( )
@@ -2440,7 +2527,7 @@ function primitives3D(p5, fn){
2440
2527
this . uvs . push ( [ pctx , pcty ] ) ;
2441
2528
}
2442
2529
}
2443
- } ) ;
2530
+ } , this ) ;
2444
2531
2445
2532
quadGeom . faces = [ ] ;
2446
2533
for ( let y = 0 ; y < detailY - 1 ; y ++ ) {
@@ -3362,7 +3449,7 @@ function primitives3D(p5, fn){
3362
3449
}
3363
3450
}
3364
3451
} ;
3365
- const planeGeom = new Geometry ( detailX , detailY , _plane ) ;
3452
+ const planeGeom = new Geometry ( detailX , detailY , _plane , this ) ;
3366
3453
planeGeom . computeFaces ( ) . computeNormals ( ) ;
3367
3454
if ( detailX <= 1 && detailY <= 1 ) {
3368
3455
planeGeom . _makeTriangleEdges ( ) . _edgesToVertices ( ) ;
@@ -3442,7 +3529,7 @@ function primitives3D(p5, fn){
3442
3529
this . faces . push ( [ v + 2 , v + 1 , v + 3 ] ) ;
3443
3530
} ) ;
3444
3531
} ;
3445
- const boxGeom = new Geometry ( detailX , detailY , _box ) ;
3532
+ const boxGeom = new Geometry ( detailX , detailY , _box , this ) ;
3446
3533
boxGeom . computeNormals ( ) ;
3447
3534
if ( detailX <= 4 && detailY <= 4 ) {
3448
3535
boxGeom . _edgesToVertices ( ) ;
@@ -3498,7 +3585,7 @@ function primitives3D(p5, fn){
3498
3585
}
3499
3586
}
3500
3587
} ;
3501
- const ellipsoidGeom = new Geometry ( detailX , detailY , _ellipsoid ) ;
3588
+ const ellipsoidGeom = new Geometry ( detailX , detailY , _ellipsoid , this ) ;
3502
3589
ellipsoidGeom . computeFaces ( ) ;
3503
3590
if ( detailX <= 24 && detailY <= 24 ) {
3504
3591
ellipsoidGeom . _makeTriangleEdges ( ) . _edgesToVertices ( ) ;
@@ -3525,17 +3612,18 @@ function primitives3D(p5, fn){
3525
3612
) {
3526
3613
const gid = `cylinder|${ detailX } |${ detailY } |${ bottomCap } |${ topCap } ` ;
3527
3614
if ( ! this . geometryInHash ( gid ) ) {
3528
- const cylinderGeom = new p5 . Geometry ( detailX , detailY ) ;
3529
- _truncatedCone . call (
3530
- cylinderGeom ,
3531
- 1 ,
3532
- 1 ,
3533
- 1 ,
3534
- detailX ,
3535
- detailY ,
3536
- bottomCap ,
3537
- topCap
3538
- ) ;
3615
+ const cylinderGeom = new p5 . Geometry ( detailX , detailY , function ( ) {
3616
+ _truncatedCone . call (
3617
+ this ,
3618
+ 1 ,
3619
+ 1 ,
3620
+ 1 ,
3621
+ detailX ,
3622
+ detailY ,
3623
+ bottomCap ,
3624
+ topCap
3625
+ ) ;
3626
+ } , this ) ;
3539
3627
// normals are computed in call to _truncatedCone
3540
3628
if ( detailX <= 24 && detailY <= 16 ) {
3541
3629
cylinderGeom . _makeTriangleEdges ( ) . _edgesToVertices ( ) ;
@@ -3561,8 +3649,18 @@ function primitives3D(p5, fn){
3561
3649
) {
3562
3650
const gid = `cone|${ detailX } |${ detailY } |${ cap } ` ;
3563
3651
if ( ! this . geometryInHash ( gid ) ) {
3564
- const coneGeom = new Geometry ( detailX , detailY ) ;
3565
- _truncatedCone . call ( coneGeom , 1 , 0 , 1 , detailX , detailY , cap , false ) ;
3652
+ const coneGeom = new Geometry ( detailX , detailY , function ( ) {
3653
+ _truncatedCone . call (
3654
+ this ,
3655
+ 1 ,
3656
+ 0 ,
3657
+ 1 ,
3658
+ detailX ,
3659
+ detailY ,
3660
+ cap ,
3661
+ false
3662
+ ) ;
3663
+ } , this ) ;
3566
3664
if ( detailX <= 24 && detailY <= 16 ) {
3567
3665
coneGeom . _makeTriangleEdges ( ) . _edgesToVertices ( ) ;
3568
3666
} else if ( this . states . doStroke ) {
@@ -3624,7 +3722,7 @@ function primitives3D(p5, fn){
3624
3722
}
3625
3723
}
3626
3724
} ;
3627
- const torusGeom = new Geometry ( detailX , detailY , _torus ) ;
3725
+ const torusGeom = new Geometry ( detailX , detailY , _torus , this ) ;
3628
3726
torusGeom . computeFaces ( ) ;
3629
3727
if ( detailX <= 24 && detailY <= 16 ) {
3630
3728
torusGeom . _makeTriangleEdges ( ) . _edgesToVertices ( ) ;
0 commit comments