2

I'm trying to import 3d objects in Processing from .obj files found on the web. I've seen that there are several ways to import objs into the scene.

I'm using PShape in this example and an obj file found here. I've started from the Examples>Basic>Shape>LoadDisplayObJ sample in which textures work.

I was able to import the obj file using the loadShape function but no textures and colors were displayed. Am I missing something? Should I import the .mtl file as well?

Here is the code:

PShape house;

float ry;

public void setup() {
  size(640, 360, P3D);

  house = loadShape("huts/huts.obj");
}

public void draw() {
  background(100);
  lights();

  translate(width/3, height/3, 0); 
  //rotateX(QUARTER_PI * 1.0);            
  rotateZ(-PI );

  rotateY(map(mouseX, mouseY, width, 2.5, -2.5));

  //rotateY(ry);
  pushMatrix();
  translate(1500,-400,0);
  shape(house);
  popMatrix();
 }
UserK
  • 884
  • 3
  • 17
  • 40
  • 2
    The specific obj file does not seem to come with the .mtl files referenced in it. Is that correct? If loadShape should normally load materials just fine, it simply doesn't work because the mtl files are missing. – Bart Mar 06 '13 at 22:45

1 Answers1

2

Yes, you have the import that file too, and if you have something like .jpg that will be your texture.

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
Dmx Dmx
  • 36
  • 2
  • import processing.opengl.*; import saito.objloader.*; import peasy.*; int detail = 70; color bg= #ffffff; PeasyCam cam; OBJModel model; void setup() {size(1000 , 600 , OPENGL); model = new OBJModel (this, "mol3.obj"); cam = new PeasyCam(this, 700); model.scale(0.3); model.translateToCenter(); noStroke(); smooth(); } void draw() {lights(); background(200);smooth(); model.draw(); } void lights() { int w=170, m=-422, p=+422; ambientLight(w,w,w); directionalLight(w, w, w, m, m, m); directionalLight(w, w, w, p, p, p); directionalLight(w, w, w, m, m, p); directionalLight(w, w, w, p, p, m); } – Dmx Dmx Dec 27 '13 at 23:17
  • the mol3.obj is in data folder ...there i have 3 files..the mol3.obj ...the mol3.mtl ..and mol3.jpg – Dmx Dmx Dec 27 '13 at 23:18