Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js + Threex + Javascript: "fromArray is not a function"?

I've really tried my best to solve this with my own research, but unfortunately I'm an absolute novice with three.js and javascript and I really need some help.

I am trying to import a model from threex (google threex -- I can't post another link) into my three.js scene. Unfortunately, when I add the code to do so as follows:

    var spaceship = null;
THREEx.SpaceShips.loadSpaceFighter03(function(object3d){
    scene.add(object3d)
    spaceship = object3d
})

I end up with a blank scene, and this error in my javascript console:

Uncaught TypeError: (intermediate value).fromArray is not a function.:8000/bower_components/threex.spaceships/examples/vendor/three.js/examples/js/loaders/MTLLoader.js:299

Which leads me to the (supposedly) offending line of code in MTLLoader.js (whatever that file is.)

params[ 'ambient' ] = new THREE.Color().fromArray( value );

I don't know what's happening, and I'm in a bit over my head I think. Does anybody know how to fix this?

I am working off of this tutorial: https://www.youtube.com/watch?v=vw5_YyM4hn8 (if it helps, the sample code for that segment of the tutorial is found here: https://github.com/jeromeetienne/flying-spaceship-minigame/blob/master/step1-01-naked-spaceship.html -- I can't see any problems -- I've so far tried to follow the steps very closely.)

Thanks in advance.

like image 229
spwoco Avatar asked Nov 10 '22 14:11

spwoco


1 Answers

This is a version incompatibility between current three.js and the code used from that threex. Threex is compatible with a version of three.js that is a year old.

When learning three.js, this has good advice: Learning WebGL and three.js

The version of three.js that threex uses can be seen in https://github.com/jeromeetienne/threex/tree/master/vendor

like image 171
2 revs Avatar answered Nov 14 '22 22:11

2 revs