1

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

JoLi
  • 33
  • 5

1 Answers1

1

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.

George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • Oh yeah,I should have added that. The missing mtl file is not an issue. Also, where I got the cirno model from, didn't include the cirno_low.mtl file or any mtl file – JoLi Jul 08 '22 at 10:21
  • If you don't have the mtl file, simply comment out the `mtllib` and `usemtl` using the `#` symbol in front of those lines (see example above) and it should work (it did for me). " mtl file is not an issue" really depends on the program parsing the obj. Some 3d editors/viewers may be more forgiving (ignoring the missing mtl), others won't. The other thing to double check is that you allow Processing enough RAM (e.g. `Processing > File > Preferences ... > Increase maximum available memory to > 2048 MB` (or higher if you can). – George Profenza Jul 08 '22 at 10:49
  • I've updated the answer with the note above on increasing RAM, loading large obj files, tools for simplifying mesh and pointint out that currently, in your repo rock.obj is not a valid .obj file (but a text file with a donwload link). – George Profenza Jul 08 '22 at 10:58
  • The link in the file is intentional, as I don't want to break the license of the files for the rock, of course, locally I have the downloaded real and valid rock.obj and rockTexture.png file The cirno model & texture is there because they have the Creative Commons License, that's why I have 2 License files in the repo btw, even with max RAM set to 16GB (half of my system RAM), it still doesn't work :( commenting out the references to the mtl file fixed the error of processing not finding it, but that's it, still no rocks are displayed – JoLi Jul 08 '22 at 19:28
  • Without access to rock.obj I can't really advise on why that model would not work. The easier you make it for others to replicate you issues, the more likely you'll get (accurate) contributions. The fact that the cerno model loads without errors is positive. The same approach (opening rock.obj, double checking that .mtl / texture references are valid) didn't work ? Does rock.obj load/display correctly in other programs (Blender for example) ? – George Profenza Jul 08 '22 at 19:42
  • Yes, it works fine in blender, also, it works fine if I load it with exactly the same code inside the constructor of `Star`, but that is obviously very inefficient and makes the whole game lag even on my PC – JoLi Jul 08 '22 at 20:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/246287/discussion-between-george-profenza-and-joli). – George Profenza Jul 08 '22 at 21:03