G4P ViewListener imported obj render problem

I’m getting a strange effect when trying to render stroke & fill on an imported obj, the stroke appears to only be rendered once at first frame , almost as an orthographic projection, this stroke rotates with the box as expected but is flat.

As a simple example, take the G4P_ViewListeners example file, import a simple .obj and set up some shading:

PShape box;
void settings() {
  size(600, 380, P2D);
}

void setup() {
  box = loadShape("data/"+"box.obj");
  box.setStroke(true);
  box.setStroke(color(42, 100, 138));
  box.setStrokeWeight(2.0f);
  box.setFill(color(50, 50, 50));

and replace the box(80) in the “ShowBox” tab with the pshape:

 v.beginDraw();
    //v.ambientLight(100, 100, 10);
    //v.directionalLight(255, 255, 0, 0.5f, 1, -2f);
    v.background(0);
    v.translate(v.width/2, v.height/2);
    v.rotateX(0.19f * a);
    v.rotateY(1.101f * a);
    v.rotateZ(1.357f * a);
    //v.fill(255, 200, 128);
    //v.stroke(255, 0, 0);
    //v.strokeWeight(4);
    v.shape(box);
    //v.box(80);
    a += delta;
    v.endDraw();

Could be this is not a problem with G4P as such but inherited from PGraphics… though I’ve been able to render stroke and fill on an imported obj when not using G4P.

Has anyone any ideas?

1 Like

The GView control uses a Processing PGraphic object as a buffer for the display. The buffer is either JAVA2D, P2D or P3D depending on what you passed as parameters when you created the control. So in your code above v is a PGraphics3D object.

You might try adding the line

v.hint(DISABLE_OPTIMIZED_STROKE);

after the background statement and see if that helps.

@quark
thanks for the suggestion, unfortunately that doesn’t seem to have helped :frowning:

Have you tried drawing the shape straight onto the screen, bypassing G4P. Any solution should be applied in the listener.

To be honest I don’t think the problem is with G4P because the GView control uses Processing drawing commands with Processing rendering modes.

Have found the solution, the sketch itself must be P3D in order for the stroke to be rendered correctly i.e :

void settings() {
  size(600, 380, P3D);
}

Cheers,
mala