3

I'm trying to load a fairly complex .obj file into three.js. Here's the code:

    // Load obj file
    var loader = new THREE.OBJMTLLoader();
    loader.load('MQ-9.obj', 'MQ-9.mtl', function(object) {
            scene.add(object);
    });

The MQ-9.mtl file refers to three images that are used on various places of the object (which is an MQ-9 Predator drone). I can load the object fine but its all black. The images don't appear to be loading. What am I doing wrong?

WestLangley
  • 102,557
  • 10
  • 276
  • 276
Frank Miller
  • 499
  • 1
  • 7
  • 19
  • 2
    Do you have console errors? Do you have lights in the scene? Are you sure you are rendering after all assets load? Can you provide a link to a live example? – WestLangley May 27 '14 at 02:37
  • Thanks for the reply. No console errors. I think I have lights. The other elements are visible. Its just the object that is not getting a texture. I'm definitely rendering, other things are showing up. All the other elements were created using base shapes, not loaded. I'll try to upload the code to a live server... – Frank Miller May 27 '14 at 04:11
  • I wish there was a way to add a screenshot – Frank Miller May 27 '14 at 05:29
  • Your suggestion about lights worked. I inserted an ambient and the surface images appeared. Thx! – Frank Miller May 27 '14 at 05:40

1 Answers1

1

If you load a model and it renders black, there can be several possible causes, some of which include problems with your model. Make sure you have no console errors.

Other than that, the two most common causes are:

  1. a lack of lights in the scene

  2. rendering the scene before all assets load

three.js r.67

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • Thanks West for the suggestions. I will say, I'm getting some load errors now. Two of the images appear to be loading but one is not. I'm getting a bunch of these errors: "THREE.OBJMTLLoader: Unhandled line 1374/1867/2272" This seems to go to an if statement in the loader code OBJMTLLoader.js:347. This appears to be an if statement that switches on the type of line it encounters in one of the files. It looks like there may be a line type in this particular obj file (or mtl i spose) that the loader is not understanding. – Frank Miller May 27 '14 at 15:43
  • There appear to be some lines (in the .obj file) that are continuing on the next line. Here's and example. The first line looks like this: f 1370/1863/2268 1366/1864/2269 1412/1865/2270 1411/1866/2271 and the second looks like this: 1374/1867/2272. Maybe the loader code is having trouble with the continuation line? – Frank Miller May 27 '14 at 15:51
  • OK, so each of the long lines ends with a backslash and then the last set of numbers is on the next line. This appears to be a bug in the loader code to me? These are "f" lines in the .obj file. – Frank Miller May 27 '14 at 16:02
  • Please make a new post with your new issue if you can't track it down yourself. three.js does not support quads -- only triangles. – WestLangley May 27 '14 at 16:34
  • That looks more like an issue with your file than the loader. You should not have a line like that appear with no definition. What are you exporting? That looks like a mesh with 5 different attributes if i'm reading this correctly? Can you link a portion of your obj? – pailhead May 28 '14 at 08:12