OBJLoader doesn't work

loaders
obj-loader

#1

I have included the three.js file in my HTML page, but I cannot seem to use OBJLoader?

I downloaded the master zip, and looked in the src folder but couldn’t find it in there either?


#2

All loaders are located here:

And need to be included separately to the main three.js file.


#3

Thanks.

Might be worthwhile updating the documentation to explain this.


#4

@paulcanning the documentation is a community project. If you feel that something is missing then please add it :slightly_smiling_face:

BTW each docs page has an “Edit” button in the top right.


#5

It’s strange that they are located in a different folder. Plus, I took a look at the code. I saw THREE.OBJLoader = (function() { ... }), which is very unfriendly to npm user who import code with CommonJS or ES6 import.


#6

@chenyong have a read through this issue thread:


#7

Seems we still need to wait for next release to have ES6 module support.


#8

If you’re using CommonJS, this should work fine:

var THREE = require ('three');
require('three/examples/js/loaders/OBJLoader');

var loader = new THREE.OBJLoader();

For ES6, yeah, there is no easy answer right now. Probably easiest to copy the files you need, add export lines, and make sure THREE is in the global namespace.


#9

Trying. Acutally in ClojureScript, but with CommonJS/ES6 modules support. I’m copying the files and modifying it.

Normally we dont use global variables like window.THREE, but turned our three.js prefers writing in this way?


#10

Well, files in examples/js/* depend on window.THREE anyway. I think it’s an eventual goal to change that…