Hi all, just started using three.js yesterday. My main goal was to load up a model I had created in Blender which I eventually succeeded with. Very nice!!
To get there was a bit of a struggle, I want to go over this journey as I feel the documentation could have been better in regards to this particular task.
To begin with, the Getting Started page is confusing to an absolute newbie as it gives you a single three.js file before the actual installation documentation. It took me some time to understand that there was more to the library than just this file. Not to mention that the documentation encourages using files from the same master version. I don’t believe this part is so bad, but I’m just noting my experience with it. It confused me.
So with the master downloaded and the three.js file replaced, my next task was to get the GLTFLoader working. I am using Atom code editor for this, very simple HTML, CSS and JavaScript, so import statements were out of reach, instead the GLTFLoader would be referenced with script tags in HTML.
My problem here was that the Loading a 3D Model documentation shows to import “three/examples/jsm/GLTFLoader.js”, however, using the file led to this type error, “Uncaught TypeError: THREE.GLTFLoader is not a constructor”, which if you google has caused some confusion. I found that using the “three/examples/js/GLTFLoader.js” file instead, fixed this error for me and I could see my model.
It did take me around 3 hours to resolve this, as I am also learning JavaScript at the moment and didn’t understand where to find the console. Due to this, I was troubleshooting camera position and lighting first, this is suggested when you google “three.js GLTFLoader black screen”.
I understand that this post is a bit trivial, and that I may be wrong about several things in here, but I thought it was worth pointing out from a user experience point of view. I will definitely continue to use three.js.
Thanks for reading.