Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue while using dat.GUI in a three.js example

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.

like image 549
George Neil Avatar asked Jul 03 '12 04:07

George Neil


People also ask

What is GUI in THREE js?

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.

What is dat GUI?

GUI. A lightweight graphical user interface for changing variables in JavaScript.

Why three Js is used?

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.

What can we do with three Js?

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.


1 Answers

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 );
like image 171
mrdoob Avatar answered Sep 21 '22 11:09

mrdoob