emllnd
emllnd

Reputation: 111

THREE.OBJLoader not working (TypeError)

I'm trying to make a HTML/Javascript application that would display an arbitrary 3d-model in the Wavefront .OBJ format. Right now I have a working app that can display spheres and planes and such. I tried incorporating the THREE.OBJLoader module into my code but it breaks things. I've figured out how to load it with my page and tested that it actually loads (I placed an alert in the end of my copy of THREE.OBJLoader and it displayed correctly).

The code I used to try to load the model is here:

var loader = new THREE.OBJLoader();
loader.load('3d/models/torus.obj', function ( object ) {
scene.add( object );
});

(It was copied from here: render OBJ file using THREE.OBJLoader. And yes, I read and tried the linked source code from MrDoob also ("Male02.obj" and so on).)

When I load my page with that code snippet, what I see is a blank screen (instead of a little scene with spheres that I had). Chrome Developer Tools displays an error after the line "var loader = new THREE.OBJLoader();".The error is the following: "Uncaught TypeError: undefined is not a function".

Any ideas on how to properly display a 3d model? Thanks in advance. I'll post more code as needed.

Upvotes: 4

Views: 8810

Answers (2)

emllnd
emllnd

Reputation: 111

Okay, I got it! The problem was the load order I had specified in HTML for my files. I was trying create a new loader before my program knew what a THREE.OBJLoader is. So I swapped the following lines in HTML:

<script src="../lib/objloader.js"></script>  <!-- when this was loaded last, code didn't work -->
<script src="../3d/3d.js"></script>

Upvotes: 0

bjorke
bjorke

Reputation: 3305

make sure you include the OBJLoader in a separate <script> tag -- it's not usually art of build/three.js (or three.min.js)

Upvotes: 1

Related Questions