Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set the color the one object in three js with dat.GUI choose color

How to set a color with dat.gui in one object the Three js

I wanna choose the color with the dialog some like Box 3 in this example

How to make this?

like image 522
Cristian Avatar asked Oct 22 '25 01:10

Cristian


1 Answers

I make the following function to change the color with a chooser color

function cambiarColor( obj )
{
    var gui = new dat.GUI();


    var Configuracion=function(){
            this.color = "#ffae23";
    }
    var conf = new Configuracion();

    var controlador = gui.addColor( conf, 'color');
    controlador.onChange( function( colorValue  )
    {
      //the return value by the chooser is like as: #ffff so
      //remove the # and replace by 0x
      colorValue=colorValue.replace( '#','0x' );
      //create a Color
      var colorObject = new THREE.Color( colorValue ) ;
      //set the color in the object
      obj.material.color = colorObject;
    });
}
like image 119
Cristian Avatar answered Oct 23 '25 17:10

Cristian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!