I made a low-poly model for our game, finished it around midnight and was looking for feedback from my friends. Taking pictures from every possible angle or even recording a short turntable animation were too much work for me as I had already been very tired. So I created a WebGL model viewer in three.js. This took me about an hour and propably much longer than the images would have but was so much more fun and exciting. Also my tiredness suddenly disappeared while working on the model viewer. It turned out pretty well and that is why I want to share this small tutorial on how to build a WebGL 3Dmodel viewer with three.js. Before you start, you have to gather some things which you’ll be working with:
Put the files in a folder and reference them in a simple HTML page as in the code snippet below. I also recommend you to set some styles for the background, so your character does not have to sit in an empty white void. I like empty dark voids, so I set the background to black. [color=rgb(98, 98, 98) !important]WebGL 3d model viewer using three.js – HTML[color=rgb(98, 98, 98) !important]XHTML
The code is pretty self-explanatory, so instead of explaining the different parts I have created comments. It may be easier to read if you paste it into an editor with syntax highlighting. [color=rgb(98, 98, 98) !important]WebGL 3D model viewer using three.js – JS[color=rgb(98, 98, 98) !important]JavaScript
Et voilà! Your in-browser model viewer is done and you can show off your great models to your friends. I recommend the Getting Started with Three.js article and thethree.js documentation if you want to dive deeper into WebGL. Kind regards, Manuel |