Processing - loading obj File

Viewed 66

I've made a little game (https://github.com/JonLit/SpaceStarProcessing3D) and now want to convert it to 3D.

I've done some things with spheres in P3D before, so I'm not completely new to this.

But now I've encountered a weird problem:

If I load the obj File for the Star in the Constructor (which is a bad Idea), it works fine (but runs extremely slow, even lags on my i5-12600k), but if I load it in setup(), it doesn't work.

With the Debugger I saw that the loaded PShape doesn't have any vertices, but why?

Also, weirdly only when using the debugger I get these lines in the output:

RunnableTask.run(): A caught exception occured on thread main-Display-.x11_:0-1-EDT-1: RunnableTask[enqueued true[executed false, flushed false, thread[0x33a9822b, main-Display-.x11_:0-1-EDT-1]], tTotal 0 ms, tExec 0 ms, tQueue 0 ms, attachment null, throwable java.lang.RuntimeException: Waited 5000ms for: <364c201e, 7d976186>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.x11_:0-1-EDT-1>]
java.lang.RuntimeException: Waited 5000ms for: <364c201e, 7d976186>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.x11_:0-1-EDT-1>
    at jogamp.common.util.locks.RecursiveLockImpl01Unfairish.lock(RecursiveLockImpl01Unfairish.java:198)
    at jogamp.newt.WindowImpl$ResizableAction.run(WindowImpl.java:2159)
    at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:447)
    at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:2859)
    at jogamp.newt.WindowImpl.setResizable(WindowImpl.java:2195)
    at com.jogamp.newt.opengl.GLWindow.setResizable(GLWindow.java:371)
    at processing.opengl.PSurfaceJOGL.lambda$setResizable$5(PSurfaceJOGL.java:436)
    at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:125)
    at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:375)
DefaultEDT.run(): Caught exception occured on thread main-Display-.x11_:0-1-EDT-1: RunnableTask[enqueued false[executed true, flushed false, thread[0x33a9822b, main-Display-.x11_:0-1-EDT-1]], tTotal 5001 ms, tExec 5001 ms, tQueue 0 ms, attachment null, throwable java.lang.RuntimeException: Waited 5000ms for: <364c201e, 7d976186>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.x11_:0-1-EDT-1>]
java.lang.RuntimeException: Waited 5000ms for: <364c201e, 7d976186>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.x11_:0-1-EDT-1>
    at jogamp.common.util.locks.RecursiveLockImpl01Unfairish.lock(RecursiveLockImpl01Unfairish.java:198)
    at jogamp.newt.WindowImpl$ResizableAction.run(WindowImpl.java:2159)
    at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:447)
    at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:2859)
    at jogamp.newt.WindowImpl.setResizable(WindowImpl.java:2195)
    at com.jogamp.newt.opengl.GLWindow.setResizable(GLWindow.java:371)
    at processing.opengl.PSurfaceJOGL.lambda$setResizable$5(PSurfaceJOGL.java:436)
    at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:125)
    at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:375)

This happens both on my PC and Laptop with Processing 4.0b7 and 4.0b8

Here's the link: https://github.com/JonLit/SpaceStarProcessing3D I included the Cirno model and texture with it's license, but I'm not sure about the rock model and textures, so you'll have to get them yourselves, links are provided though

Edit: The missing mtl File for cirno is not the issue

1 Answers

I think the issue with your Cirno model is that you're missing the material file (cirno_low.mtl). The obj. file references it (if you open the .obj in a text editor):

# 
# Wavefront OBJ file
# Created in RealityCapture
# Engine version v1.0.3.4987
# 5050 vertices, 10000 faces
# 
mtllib cirno_low.mtl

g default
usemtl cirno_low_Material
...

Notice mtllib and usemtl.

I've commented out the material use like so:

# 
# Wavefront OBJ file
# Created in RealityCapture
# Engine version v1.0.3.4987
# 5050 vertices, 10000 faces
# 
# mtllib cirno_low.mtl

g default
# usemtl cirno_low_Material
...

and seems to load fine in Processing despite the high number of points and triangles:

a 3d scanned dense mesh of an anime looking toy doll rendered in gray without texture

This is the basic test sketch.

PShape mesh;

void setup(){
  size(900, 900, P3D);
  mesh = loadShape("cirno_low.obj");
}

void draw(){
  background(0);
  lights();
  translate(width * 0.5, height * 0.5, 0);
  rotateY(map(mouseX, 0, width, -PI, PI));
  rotateX(map(mouseY, 0, height, PI, -PI));
  scale(10);
  
  shape(mesh);
  
}

If you also add your .mtl file alonside the .obj and texture (which is already there), hopefully Processing will pick it up and display the model textured.

Update

Additionally if the model is large consider increasing the amount of RAM Processsing can use (e.g. Processing > File > Preferences ... > Increase maximum available memory to > 2048 MB).

If loading an .obj file takes too long in setup() the OpenGL thread will timeout and the sketch will crash. You can load in draw() in this case, but you should use a "debouncing" boolean variable to ensure you load the model only once, if the model wasn't already loaded:

PShape mesh;
boolean isMeshLoaded;

void setup(){
  size(900, 900, P3D);
  mesh = loadShape("cirno_low.obj");
}

void draw(){
  if(!isMeshLoaded){
    mesh = loadShape("cirno_low.obj");
    isMeshLoaded = true;

  }
  background(0);
  lights();
  translate(width * 0.5, height * 0.5, 0);
  rotateY(map(mouseX, 0, width, -PI, PI));
  rotateX(map(mouseY, 0, height, PI, -PI));
  scale(10);

  shape(mesh);

}

In general, for real-time graphics it's best to optimize / simplify mesh. (You can easily do that with opensource tools like Blender (and it's Decimate modifier) and MeshLab)

This could be rock.obj, but bare in mind, in your repo, this is simply a link to a download, not a valid .obj file.

Related