Three.js: THREE.OBJLoader2 is not a constructor

Created on 2 Nov 2017  路  12Comments  路  Source: mrdoob/three.js

Description of the problem

OBJLoader2 appears to be an empty object. When you create a new instance with

var objLoader = new THREE.OBJLoader2();

I get the error THREE.OBJLoader2 is not a constructor

http://jsfiddle.net/dm3mg5qs/1/

Three.js version
  • [ ] Dev
  • [x] r88
  • [ ] ...
Browser
  • [ ] All of them
  • [x] Chrome (Version 61.0.3163.100 (Official Build) (64-bit))
  • [ ] Firefox
  • [ ] Internet Explorer
OS
  • [ ] All of them
  • [ ] Windows
  • [x] macOS
  • [ ] Linux
  • [ ] Android
  • [ ] iOS

Most helpful comment

Sorry if this looked like a help request, I genuinely thought I'd come across a bug. OBJLoader2 in r87 didn't depend on LoaderSupport.js and there is no mention of it in the docs https://threejs.org/docs/#examples/loaders/OBJLoader2

All 12 comments

You have to add additional imports to your fiddle. Besides, the signature of loadMtl() was not correct.

Updated fiddle: https://jsfiddle.net/dm3mg5qs/4/

Also have a look at this example: https://threejs.org/examples/webgl_loader_obj2.html

Ok cool, thanks. There is no mention of the additional import requirements or any mention of loadMtl in the docs https://threejs.org/docs/#examples/loaders/OBJLoader2

Should I create a new issue for that?

@steveg3003 Nothing under the Examples header in the docs is included in three.js by default, it's not just OBJLoader2.

Please take a note of this

This form is for three.js bug reports and feature requests only.
This is NOT a help site. Do not ask help questions here.
If you need help, please use stackoverflow.

But even on stack overflow you should not tag this three.js since it's just a javascript issue - you're trying to construct something that is undefined.

Sorry if this looked like a help request, I genuinely thought I'd come across a bug. OBJLoader2 in r87 didn't depend on LoaderSupport.js and there is no mention of it in the docs https://threejs.org/docs/#examples/loaders/OBJLoader2

Oh, I missed that LoaderSupport is now also required... that would IMO be worth documenting, or at least throwing a user-friendly error about the need for it.

Is the idea to use LoaderSupport in lots of loaders? At the moment only OBJLoader2 is using it, if this isn't going to change I'd suggest moving it into the same file to prevent this kind of confusion.

Or at least throw a warning if the files is not found (and ideally fail gracefully) as @donmccurdy suggests. FBXLoader does this for NurbsCurve:

https://github.com/mrdoob/three.js/blob/05d67e9fb68e19adb17400d32e4964f1debd52cd/examples/js/loaders/FBXLoader.js#L1350-L1355

@looeee Yes the loader support should/will be implemented by all loaders2.
And may be it should be put in src folder (?)

The goal of LoaderSupport, if i fully understand, is to allow Workers, with an Orchestrator on top, for loaders.

The differents class inside should be, IMO, splitted in differents files to allow their port on others part of the library !

I will add a user friendly error. Documentation for OBJLoader2 mentions the dependence to THREE.LoaderSupport, but the text does explicitly state the it needs to be imported. Some polishing is required, I guess.

@Itee and @looeee especially the THREE.LoaderSupport.Builder and THREE.LoaderSupport.WorkerSupport can be re-used by other loaders in the future. The functionality is independent of OBJ loading and can be commonly used by other loaders if desired.
Please see https://github.com/mrdoob/three.js/pull/12048 for more background info.

I am trying to access the files on github for the loader support but it seems to be missing. Was it deleted at some point for a reason?

link:
https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/LoaderSupport.js

link found from source section at:
https://threejs.org/docs/index.html#examples/en/loaders/LoaderSupport

LoaderSupport has been removed. The loader was refactored some time ago. Please stick to the current example code: https://threejs.org/examples/webgl_loader_obj2

link found from source section at:

The docs will be updated with the next release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

filharvey picture filharvey  路  3Comments

zsitro picture zsitro  路  3Comments

boyravikumar picture boyravikumar  路  3Comments

clawconduce picture clawconduce  路  3Comments

Bandit picture Bandit  路  3Comments