Skip to content

Incorrect lines when applying a stroke to geometry built without initial stroke #6318

@davepagurek

Description

@davepagurek

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build Process
  • Unit Testing
  • Internalization
  • Friendly Errors
  • Other (specify if possible)

p5.js version

main branch

Web browser and version

Firefox 114

Operating System

MacOS 12.5.1

Steps to reproduce this

Steps:

  1. Set noStroke()
  2. Build some geometry using buildGeometry()
  3. Set stroke(0)
  4. Draw the geometry with model()

You end up with the fill triangles getting strokes rather than the contours passed in between beginShape() and endShape().

I'm not 100% sure if this should be considered a bug or not, but the result feels unexpected enough that I'm leaning towards treating it like one? Fixing this would mean always storing stroke info to p5.Geometry being built even if there is currently no stroke set, since one can add one back later, although this could lower performance when building the geometry. Maybe that's OK though since building geometry is a one-time upfront cost?

Snippet:

let geom

function setup() {
  createCanvas(300, 300, WEBGL);
  
  // Comment this out to make it work
  noStroke()
  geom = buildGeometry(() => {
    beginShape()
    for (let i = 0; i < 10; i++) {
      const angle = i/10 * TWO_PI
      vertex(100*cos(angle), 100*sin(angle))
    }
    beginContour()
    for (let i = 0; i < 10; i++) {
      const angle = -i/10 * TWO_PI
      vertex(20*cos(angle), 20*sin(angle))
    }
    endContour()
    endShape(CLOSE)
  })
}

function draw() {
  background('red')
  fill('white')
  stroke('black')
  model(geom)
}

With noStroke() before buildGeometry():
image

With a stroke in buildGeometry():
image

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Status

DONE! 🎉

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions