I tried to use dat.GUI in the following three.js example.
I just did the following code changes to add a GUI to adjust mesh opacity.
var loader=new THREE.VTKLoader();
loader.load ("models/vtk/bunny.vtk", function(geom){
var mesh = new THREE.Mesh(geom, material );
mesh.doubleSided=true;
mesh.position.setY(-0.09);
scene.add( mesh );
var gui = new dat.GUI();
var view = this;
view.Opacity = 0.2;
var maingui = gui.addFolder('Main');
var opacity = maingui.add(view, 'Opacity', 0, 1);
opacity.onChange( function(value) {
mesh.material.opacity = value;
});
maingui.open();
animate();
Now, once I click the opacity slider the mouse is just following the slider. I am not able to come out of the mouse click.
GUI is another very useful tool that we can use to learn about Three. js as it allows us to quickly add a very basic user interface which allows us to interact with our 3d scene and the objects within it.
GUI. A lightweight graphical user interface for changing variables in JavaScript.
Three. js uses WebGL which is JavaScript API used for rendering interactive 3D and 2D graphics in web browsers without using any plugins. With the use of WebGL, Three. js enables your browser to render smooth 3D animation and being cross-browser it provides immense leverage of multi-dimensional objects across the web.
Three. js is a powerful library for creating three-dimensional models and games. With just a few lines of JavaScript, you can create anything from simple 3D patterns to photorealistic, real-time scenes. You can build simple and complex 3D geometrics, animate and move objects through a lifelike scene, and more.
Move the controls init block after the renderer init block, and change this line:
controls = new THREE.TrackballControls( camera );
to this:
controls = new THREE.TrackballControls( camera, renderer.domElement );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With