A 3D Wavefront obj file viewer for HTML5 written in JavaScript
|
|
před 12 roky | |
|---|---|---|
| obj | před 12 roky | |
| script | před 12 roky | |
| LICENSE | před 12 roky | |
| README.md | před 12 roky | |
| index.html | před 12 roky |
http://seavenois.com/jstricks/ObJS/
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.
You can rotate the object by dragging it with the mouse or your finger in a touch screen. Also, you can apply rotation programatically:
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 Set rotation speed).
You can move the object around by dragging it with the mouse while holding down the shift key. Also, you can move it programatically:
myObJS.moveHorizontal(-1); //Move to the left
myObJS.moveHorizontal(1); //Move right
myObJS.moveVertical(-1); //Move up
myObJS.moveVertical(1); //Move down
Note that the movement speed can be set (see Set movement speed).
Zoom in and out can be achieven with the mouse wheel, by pinching the mode if you are using a touch screen, or programatically:
myObJS.zoom(value);
value can be any float number, positive to zoom in, and negative to zoom out. 1 and -1 are a one step zoom in or out. Note that the zoom speed can be set (see Set 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.drawVertizes(true); //Draw vertizes
myObJS.drawVertizes(false); //Don't draw vertizes
myObJS.drawEdges(true); //Draw edges
myObJS.drawEdges(false); //Don't draw edges
myObJS.drawFaces(true); //Draw faces
myObJS.drawFaces(false); //Don't draw faces
myObJS.drawBackground(true); //Draw the background
myObJS.drawBackground(false); //Don't draw the background
myObJS.setVertizesColor(code); //Set the color for the vertizes
myObJS.setEdgesColor(code); //Set the color for the edges
myObJS.setFacesColor(code); //Set the color for the faces
myObJS.setBackgroundColor(code); //Set the background color
If a .mtl file is present in the same directory as the obj file, you can use the materials there to colorize the model (enabled by default).
myObJS.linkMaterial(true); //Use .mtl file
myObJS.linkMaterial(false); //Don't use .mtl file
Note that, when using .mtl files, faces with no material assigned will use the color defined by the user.
myObJS.setAlpha(percent);
myObJS.setRotationSpeed(value);
myObJS.setMovementSpeed(value);
myObJS.setZoomSpeed(value);