2013-02-02 97 views

回答

4

我提出以下功能:使得以選配顏色

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; 
    }); 
} 
+0

@ CB4驚人的傢伙,檢查出版物日期;) –

+0

克里斯蒂安:哇,我真的很抱歉 - 完全錯過了!請接受我的道歉。再次上調 – cb4

+0

! :) – polyclick

1

有沒有必要做一個「新Three.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'); 
     //set the color in the object 
     obj.material.color.setHex(colorValue); 
    }); 
} 
1

實施three.js所色彩或色彩均勻,以dat.gui一個簡單的方法:

dat.GUI.prototype.addThreeColor=function(obj,varName){ 
    // threejs & dat.gui have color incompatible formats so we use a dummy data as target : 
    var dummy={}; 
    // set dummy initial value : 
    dummy[varName]=obj[varName].getStyle(); 
    return this.addColor(dummy,varName) 
     .onChange(function(colorValue ){ 
      //set color from result : 
      obj[varName].setStyle(colorValue); 
     }); 
}; 
dat.GUI.prototype.addThreeUniformColor=function(material,uniformName,label){ 
    return this.addThreeColor(material.uniforms[uniformName],"value").name(label||uniformName); 
};