New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QUAD_STRIP as child shape draws extra lines #4656

Closed
jeremydouglass opened this Issue Sep 9, 2016 · 1 comment

Comments

Projects
None yet
3 participants
@jeremydouglass
Contributor

jeremydouglass commented Sep 9, 2016

QUAD_STRIP when used as a child shape draws extra lines -- this can be observed in the P3D renderer, in Processing 3.2.1

  • The first child draws extra lines from each odd numbered vertex (except the last) towards the origin 0,0,0.
  • The second child draws those extra lines to the n-3 vertex on the first child.
  • The third child draws those extra lines to the n-3 vertex on the second child.
  • etc. etc.

The demo sketch adds some interface and a text label to make the bugs easier to see.

/**
 * QUAD_STRIP extra lines bug
 * Processing 3.2.1
 * 2016-09-07 Jeremy Douglass
 * <a href="https://forum.processing.org/two/discussion/17876/0/" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/17876/0/</a>
 * 
 * When child QUAD_STRIPs are added to a PShape, even closed shapes,
 * sets extra lines are rendered from child as follows
 * 
 * -  Three extra lines the same color as background
 *    are drawn from first child vertex 1,3,5...n-3 to origin (0,0,0)
 * -  Three extra lines are drawn from second child vertex 1,3,5...n-3
 *    to first child vertex n-3. These lines are gradient from
 *    child2 color to child1 color, and from child2 stroke to 0.
 * -  Three extra lines are drawn from third child to second child...
 * -  Three extra lines are drawn from fourth child to third child... etc.
 *
 * The extra lines are always rendered, but are most visible when
 * each child shape is separate and nothing is overdrawing (e.g. noFill).
 */

PShape group;
PShape red;
PShape green;
PShape blue;

int translatex = 0;
int translatey = 0;

color RED = color(255,0,0,255);
color GREEN = color(0,255,0,255);
color BLUE = color(0,0,255,255);
color GREYA = color(255,255,255,16);

void setup() {
  size(400, 400, P3D); 
  group = createShape(GROUP);
  red   = makeChild(GREYA,RED,80);
  green = makeChild(GREYA,GREEN,40);
  blue  = makeChild(GREYA,BLUE,0);
  group.addChild(red);
  group.addChild(green);
  group.addChild(blue);
}

void draw(){
  background(0);
  camera(100, 50, 200, 0, 0, 0, 0, 1, 0);
  text("0,0,0",0,0,0);
  shape(group,-translatex, -translatey);
  stroke(255);
}

PShape makeChild(color fill_, color stroke_, float offset_){
  PShape shape_ = createShape();
  shape_.beginShape(QUAD_STRIP);
  shape_.stroke(stroke_);
  shape_.strokeWeight(5);
  shape_.noFill();
  //// example quad data copied from <a href="https://processing.org/reference/beginShape_.html" target="_blank" rel="nofollow">https://processing.org/reference/beginShape_.html</a>
  shape_.vertex(30, 10, offset_); /// v1 - line from here to previous child v5
  shape_.vertex(30, 75, offset_); 
  shape_.vertex(50, 20, offset_); /// v3 - line from here to previous child v5
  shape_.vertex(50, 75, offset_);
  shape_.vertex(65, 10, offset_); /// v5 - line from here to previous child v5
  shape_.vertex(65, 75, offset_); 
  shape_.vertex(85, 20, offset_);
  shape_.vertex(85, 75, offset_);
  shape_.endShape(CLOSE);
  return shape_;
}

/* *** INTERFACE *** */

void mouseDragged(){
  // translate(60 * mouseX/width, 60 * mouseY/height);
  translatex = 30 - 60 * mouseX/width;
  translatey = 30 - 60 * mouseY/height;
  updateShapes();
}
void updateShapes(){
  group.removeChild(2);
  group.removeChild(1);
  group.removeChild(0);
  group.addChild( makeChild(GREYA,RED,80 + translatex) );
  group.addChild( makeChild(GREYA,GREEN,40) );
  group.addChild( makeChild(GREYA,BLUE,0 - translatex) );
}

In a forum thread, koogs reported seeing this bug arise between Processing 3.0b7 (no bug) and 3.1.1 (bug).

@benfry benfry added the opengl label Sep 9, 2016

@codeanticode codeanticode self-assigned this Oct 6, 2016

@codeanticode

This comment has been minimized.

Show comment
Hide comment
@codeanticode

codeanticode Oct 6, 2016

Member

thanks for your report, the bug was caused by a small error in the edge closing code, which affected any quad strips, not only those in PShapes. So, I'm surprised it didn't come up earlier.

Member

codeanticode commented Oct 6, 2016

thanks for your report, the bug was caused by a small error in the edge closing code, which affected any quad strips, not only those in PShapes. So, I'm surprised it didn't come up earlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment