A 3D Wavefront obj file viewer for HTML5 written in JavaScript
|
|
%!s(int64=12) %!d(string=hai) anos | |
|---|---|---|
| obj | %!s(int64=12) %!d(string=hai) anos | |
| script | %!s(int64=12) %!d(string=hai) anos | |
| LICENSE | %!s(int64=12) %!d(string=hai) anos | |
| README.md | %!s(int64=12) %!d(string=hai) anos | |
| index.html | %!s(int64=12) %!d(string=hai) anos |
Just include the ObJS.js in your project, create a ObJS object, and initalize its canvas.
myObJS = new ObJS();
myObJS.initCanvas(canvas);
Then you can load any obj model by calling
myObJS.load(file);
If you want to clear the canvas, just call
myObJS.clear();
Note that the canvas is automatically cleared when a new object is loaded.
The model can be rotated and zoomed in and out with the mouse, but it can also be done programmatically.
myObJS.rotateX(-1); //Rotate along the X edge to the left
myObJS.rotateX(1); //Rotate along the X edge to the right
myObJS.rotateY(-1); //Rotate along the Y edge to the left
myObJS.rotateY(1); //Rotate along the Y edge to the right
Note that the rotation speed can be set (see Seting rotation speed).
myObJS.zoom("+"); //Zoom in
myObJS.zoom("-"); //Zoom out
Note that the zoom speed can be set (see Seting zoom speed).
You can change parameters such as the elements to draw, their color, transparency, rotation speed, zoom speed... in the script, but much of them can be changed on runtime, so you can use controls.
myObJS.drawElement(keyword, on);
myObJS.colorElement(keyword, color);
myObJS.setAlpha(percent);
myObJS.setRotationSpeed(value);
myObJS.setZoomSpeed(value);