Display obj file in 3D

edited October 2017 in Library Questions

Hello all,

I am trying to use free 3D obj models from here

https://opengameart.org/art-search-advanced?keys=plane&title=&field_art_tags_tid_op=or&field_art_tags_tid=&name=&field_art_type_tid[]=10&field_art_type_tid[]=7273&field_art_licenses_tid[]=2&field_art_licenses_tid[]=3&field_art_licenses_tid[]=6&field_art_licenses_tid[]=5&field_art_licenses_tid[]=10310&field_art_licenses_tid[]=4&field_art_licenses_tid[]=8&field_art_licenses_tid[]=7&sort_by=count&sort_order=DESC&items_per_page=24&Collection=

but I always get this Unsupported formate: name.obj

please help...

Chrisir

PShape s1;

void setup() {

  size (900, 900);
  println (displayWidth); 
  println (displayHeight); 
  s1 = loadShape(  "ShuttleNew2.obj" );
}

void draw() {

  shape (s1, 333, 333);
}

Error I get:

1600
900
Unsupported format: ShuttleNew2.obj
Tagged:

Answers

  • Your link points to a list of mostly .blendBlender files. There is no file named ShuttleNew2.obj listed in the site search.

    Could you please give a specific example of a file that is causing you problems? No way to guess based on your link or code.

  • edited October 2017

    I haven't tried blender, only obj

    ok, I tried about 5 different obj

    https://opengameart.org/content/shuttle-2

    https://opengameart.org/content/hextraction-base-player-pod

    https://opengameart.org/content/low-poly-biplane

    new approach

    in fact instead of loadShape I tried saitoloader now but I haven't managed to apply the texture.

    I used this:

    https://opengameart.org/content/low-poly-biplane

    // see https : // github.com/taseenb/OBJLoader/
    
    // imports ================================================
    
    /** opengl **/
    // import processing.opengl.*;
    
    /** PeasyCam **/
    import peasy.*;
    
    // to display 
    import saito.objloader.*;
    
    // declare that we need a OBJModel and we'll be calling it "model"
    // OBJModel model;
    final int maxOBJModel = 1; 
    OBJModel[] model = new OBJModel[maxOBJModel];
    float rotX;
    float rotY;
    int [] Y_Correction = new int [maxOBJModel];
    
    PeasyCam cam1 ; 
    PImage imgDark;
    
    void setup() {
      size(800, 800, P3D);
    
    
      cam1 = new PeasyCam(this, 1110); 
      background(0); 
    
      model[0] = new OBJModel ( this, "biplane.obj", "relative", TRIANGLES);  // "cassini.obj", "relative", TRIANGLES);
    
      //model[0].setupGL();
    
      model[0].disableDebug();
    
      model[0].shapeMode(POLYGON);
    
      model[0].originalTexture();
    
    
      imgDark = loadImage ( "diffuse_512.jpg" ); 
      model[0].setTexture ( imgDark ) ; 
    
      model[0].scale(20);
      model[0].disableMaterial();
    
      model[0].enableTexture();
    
    
      noStroke();
      //  fill(255, 0, 0);
    }
    
    void draw() {
      background(0); 
    
      lights();
      model[0].draw();
    }
    
  • Hmm. The first line of your example obj file is

    mtllib ShuttleNew2.mtl
    

    ...that links to a materials file that doesn't exist, and doesn't seem to be part of the download you linked. If you comment out that line then the shape loads fine, although it is gray.

    import peasy.*;
    import peasy.org.apache.commons.math.*;
    import peasy.org.apache.commons.math.geometry.*;
    
    PeasyCam camera;
    PShape s;
    
    void setup() {
      size(400, 400, P3D);
      // The file "bot.obj" must be in the data folder
      // of the current sketch to load successfully
      s = loadShape("ShuttleNew2.obj");
      camera = new PeasyCam(this, 0, 0, 0, 50);
    }
    
    void draw() {
      background(204);
      // translate(width/2, height/2);
      scale(10);
      shape(s, 0, 0);
    }
    
  • edited October 2017

    Oh, see this old recent discussion about mtl loading being broken in 3.x -- might be relevant:

    Edit: ...although I just noticed that post is for Android Mode

  • Thank you!

    Apart from mtl, how would I apply a color or texture?

  • Unfortunately I am out of my depth there -- I don't do a lot of work with objs. Perhaps @codeanticode might now?

  • edited October 2017

    ah, thanks to you, I am making progress here.

    one of the mistakes I had was to use size() without P3D.... but the error message didn't show that...

    https://opengameart.org/content/low-poly-biplane

    This model comes now with its texture:

    // https : // opengameart.org/content/low-poly-biplane
    
    
    import peasy.*;
    //import peasy.org.apache.commons.math.*;
    //import peasy.org.apache.commons.math.geometry.*;
    
    PeasyCam camera;
    PShape s;
    
    void setup() {
      size(1400, 900, P3D);
    
      // The file must be in the data folder
      // of the current sketch to load successfully
      s = loadShape("biplane.obj"); 
    
      // apply its texture 
      PImage img1=loadImage("diffuse_512.png"); 
      s.setTexture(img1);
    
      s.scale(20);
      camera = new PeasyCam(this, 0, 0, 0, 50);
    
      background(0);
    }
    
    void draw() {
      background(0);
      lights();
      shape(s, 0, 0);
    }
    //
    
  • Another model - even more simple:

    // https : // opengameart.org/content/hextraction-base-player-pod
    
    import peasy.*;
    
    PeasyCam camera;
    PShape s;
    
    void setup() {
      size(1400, 900, P3D);
    
      // The file and all other data (extracted from the zip file) must be in the data folder
      // of the current sketch to load successfully
      s = loadShape("hextraction_pod.obj"); 
    
      camera = new PeasyCam(this, 0, 0, 0, 50);
    
      background(0);
    }
    
    void draw() {
      background(0);
      lights();
      shape(s, 0, 0);
    }
    //
    
  • great!

Sign In or Register to comment.