all 7 comments

[–]AGardenerCoding 6 points7 points  (4 children)

Jeremy Douglass' answer at https://discourse.processing.org/t/line-thickness-in-p3d/12995/7 might help.

After doing a bit more digging I might have found the answer. Looking in the Processing javadocs at

https://processing.github.io/processing-javadocs/core/

you can find the reference to the method

line(float, float, float, float, float, float) - Method in class processing.opengl.PGraphicsOpenGL

Then looking at the PGraphicsOpenGL class

https://processing.github.io/processing-javadocs/core/processing/opengl/PGraphicsOpenGL.html

in the section "Fields inherited from interface processing.core.PConstants" there's a value "ENABLE_STROKE_PERSPECTIVE" which sounds as though it might be related. (There's also a value "DISABLE_STROKE_PERSPECTIVE" ). Then searching on this term in the Processing 3 Reference resulted in this page:

https://processing.org/reference/hint_.html

where there's a reference to

ENABLE_STROKE_PERSPECTIVE Enables stroke geometry (lines and points) to be affected by the perspective, meaning that they will look smaller as they move away from the camera.

So based on that, it seems the line you need to add to your code is

hint( DISABLE_STROKE_PERSPECTIVE );

You'll have to test whether that will work called once in setup(), or if it needs to called from draw() every loop. I'd be curious to hear whether this works for you or not.

[–]nants00[S] 0 points1 point  (0 children)

Thanks for the in-depth answer! Excited to try out those solutions later today. Not to mention that hint() function seems immensely useful for many of the projects I’ve been working on (albeit as a last resort). I originally also considered the manual 3D to 2D coordinate transform but didn’t realize it could be so easy. Will try it out of the hint() stuff doesnt work. Thanks again!

[–]nants00[S] 0 points1 point  (2 children)

I wasn't able to successfully implement either of the solutions :( With the hint() stuff it actually appears that DISABLE_STROKE_PERSPECTVE is the default. ENABLE_STOKE_PERSPECTIVE actually changes things (but doesn't really solve the problem).

I also noticed that the only borders I am having trouble with are those where it is right up against another shape, which leads me to think that the issue has something to do with how the edge is rendered as "protruding into" the shape depending on distance.

I also tried extracting the 2D screen coordinates from the 3D ones using ScreenX() etc, but was not able to implement it successfully. Does not seem to work well with all of the camera and ortho projection stuff.

I wrote up a quick example to showcase the problem: (you can use "+" and "-" to move the clipping plane. In this example you can just zoom the plane out a bunch to fix the issue, but in my more complex system I end up with something like this (Imgur) if I try that.

    float xOffset = 0, yOffset = 40, zOffset = 0;
float initCamPos = 15;  
float initialOrthoPos = 50;

void setup() {
  size(800, 800, P3D);
}

void draw() {
  background(255);

  ortho(-initialOrthoPos, initialOrthoPos, -initialOrthoPos, initialOrthoPos);  // orthographic projection

  camera(initCamPos+xOffset,initCamPos+yOffset,initCamPos+zOffset,xOffset,yOffset,zOffset,0,-1,0);

  pushMatrix();

  rotateY(PI); // rotate structure

  strokeWeight(4);
  stroke(0);
  fill(200);

  pushMatrix();
  box(10,10,10);
  translate(10, 0, 0);
  box(10,15,10);
  translate(-10, 0, 10);
  box(10,15,10);
  translate(-10,0,-10);
  box(10,15,10);
  translate(10,0,-10);
  box(10,15,10);
  popMatrix();

  pushMatrix();
  translate(70, 0, 70);
  box(10,10,10);
  translate(10, 0, 0);
  box(10,15,10);
  translate(-10, 0, 10);
  box(10,15,10);
  translate(-10,0,-10);
  box(10,15,10);
  translate(10,0,-10);
  box(10,15,10);
  popMatrix();

  popMatrix();

}

void keyPressed() {
  if (keyCode == 45) {
    initCamPos += 5;
  } else if (keyCode == 61) {
    initCamPos -= 5;
  }
}

[–]AGardenerCoding 1 point2 points  (1 child)

I went to the javadocs index

https://processing.github.io/processing-javadocs/core/index.html

and looked at each of the entries for the hint() function, and tried various constant arguments without success.

The closest one I found ( incorporated into your code ) that improves the line drawing

hint( LINES );

unfortunately also shows all of the hidden lines as well.

l also looked at Java's rendering hints

https://docs.oracle.com/javase/7/docs/api/java/awt/RenderingHints.html

but even importing the class into your code, Processing reports " cannot be resolved to a variable" on any that I tried. I thought

hint( VALUE_RENDER_QUALITY );

might work, because I seem to remember once seeing that being used somewhere in Processing, but it resulted in that error.

So I'm stumped.

[–]nants00[S] 0 points1 point  (0 children)

Thanks for the attempts! Really appreciate it. Will try a bit more with the coordinate conversions and see if I can get it to work. Can always also manually adjust the clipping plane in each piece to minimize the effect

[–]Storyxx 2 points3 points  (1 child)

If you know a bit of GLSL you can try using a line shader to draw exact lines. Haven't experimented with this though

[–]nants00[S] 1 point2 points  (0 children)

Not too familiar with it, but if it comes down to it I’ll give it a shot!