A 3D Wavefront obj file viewer for HTML5 written in JavaScript
|
|
hace 12 años | |
|---|---|---|
| obj | hace 12 años | |
| script | hace 12 años | |
| LICENSE | hace 12 años | |
| README.md | hace 12 años | |
| index.html | hace 12 años |
Just include the ObJS.js in your project, create a ObJS object, and initalize its canvas.
myObJS = new ObJS();
myObJS.initCanvas(canvas);
Where
Then you can load any obj model by calling
myObJS.load(file);
Where
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.
To rotate the object, just call
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).
To zoom in or out the object, call the method
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);
Where
myObJS.colorElement(keyword, color);
Where
myObJS.setAlpha(percent);
Where
myObJS.setRotationSpeed(value);
Where
myObJS.setZoomSpeed(value);
Where