Z
Z
zeni1agent2018-12-30 23:39:27
JavaScript
zeni1agent, 2018-12-30 23:39:27

How to change background color in three.js using dat.GUI?

i have a code

var option_default = function() {
this.colr_scene = '#C8C7C7';
};
var option_array = new option_default();  
var opt_none ;   
var gui = new dat.GUI({ autoPlace: false }); 
var action_colr_scene = gui.addColor(option_array_ise, 'colr_scene');

action_colr_scene.onChange(function(opt_none){renderer.setClearColor.color.setHex(opt_none.replace("#", "0x"));});

var renderer = new THREE.WebGLRenderer();
renderer.setClearColor (0xC8C7C7 );

The problem is that I can't seem to change the color in setClearColor
I tried all possible methods
When I try to change
var cotl2 = '0xC8C7C7' ;
  renderer.setClearColor (cotl2 );

the background color disappears, becomes the default
No errors occur, only a new yellow window
THREE.Color: Unknown color 0xC8C7C7
alert(renderer.setClearColor);
gives me
function(){
[][][]background.setClearColor.apply(background, arguments);
[][]}

who doesn't know how to change the color parameter in setClearColor
Because I'm running out of ideas

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
zeni1agent, 2019-01-01
@zeni1agent

I found this solution to the problem

action_colr_scene.onChange( function (opt_none) {
 scene.background.setHex(opt_none.replace("#", "0x"));  
} );
 scene.background = new THREE.Color(0xff00ff);

A
Artem Andreev, 2018-12-30
@Pibodi

And the color should not be specified in hex by any chance? #000000 - in this format

V
Vitaly Stolyarov, 2019-12-31
@Ni55aN

See documentation . setClearColor can only take a Color object

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question