Processing Importing 3D model using loadShape()

Viewed 53

I'm trying to import a 3D model of a space shuttle but processing is giving me a really hard time doing this for some reason. I watched examples and even opened the .OBJ file on ym computer and it renders nicely but processing doesn't want to open it. The code snippet is really simple as shown below:

PShape rocket;

int windowSize = 1000; // size of square window


void setup() {
  size(1000, 1000, P3D);
  rocket = loadShape("space-shuttle.obj");
}

void draw() {
  background(100);
  shape(rocket);
}

I made sure I added the file to the data folder and also tried with a .svg in 2D which worked but I need the 3D model for my project. The error that I get is below. Any help would be appreciated! I am using processing 4.0. I had also tried with earlier versions but nothing happened


The file "space-shuttle.obj" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
java.lang.NullPointerException: Cannot invoke "java.io.BufferedReader.readLine()" because "reader" is null
    at processing.core.PShapeOBJ.parseOBJ(PShapeOBJ.java:168)
    at processing.core.PShapeOBJ.<init>(PShapeOBJ.java:40)
    at processing.core.PShapeOBJ.<init>(PShapeOBJ.java:27)
    at processing.opengl.PGraphics3D.loadShapeImpl(PGraphics3D.java:128)
    at processing.opengl.PGraphicsOpenGL.loadShape(PGraphicsOpenGL.java:3382)
    at processing.core.PApplet.loadShape(PApplet.java:11254)
    at simulation.setup(simulation.java:30)
    at processing.core.PApplet.handleDraw(PApplet.java:2142)
    at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:825)
    at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
    at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
    at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
    at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:782)
    at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
    at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:453)
    at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
    at java.base/java.util.TimerThread.mainLoop(Timer.java:566)
    at java.base/java.util.TimerThread.run(Timer.java:516)
1 Answers

Shuttle object is here:https://sketchfab.com/3d-models/space-shuttle-ff4b00b7ebb24fdd98fb96b08f2c43c9

The following source code should work:

PShape rocket;

float ry;

void setup() {
  size(500, 500, P3D);
  rocket = loadShape("space-shuttle.obj");
}

void draw() {
  background(200);
  translate(width/2, height/2, 350);
  rotateZ(PI);
  rotateY(ry);
  shape(rocket);
  ry += 0.02;
}

The .mtl file was not included with the original download, but may be added with the following code:

newmtl Default
illum 2
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.533333 0.533333 0.533333
Ks 0.100000 0.100000 0.100000
Ni 1.000000
d 1.000000
map_Kd ShuttleDiffuseMap.jpg

Files in the 'data' folder should look like this:

enter image description here

Related