2016-01-31 88 views
1

當創建我使用十六進制0x205081的材料,例如:Threejs六角色差

材料=新THREE.MeshBasicMaterial({顏色:0x205081,vertexColors:THREE.FaceColors});

在改變面部的幾種顏色之後,我嘗試將它們更改回原始顏色(0x205081),但它顯然比首次初始化時更暗,即使使用完全相同的十六進制代碼,我又缺少了什麼?

的差異可以在這個小提琴被注意到: http://jsfiddle.net/VsWb9/4805/

var camera, scene, renderer, geometry, material, mesh; 

init(); 
animate(); 

function init() { 

    scene = new THREE.Scene(); 

    camera = new THREE.PerspectiveCamera(50, window.innerWidth/window.innerHeight, 1, 10000); 
    camera.position.z = 500; 
    scene.add(camera); 

    geometry = new THREE.CubeGeometry(200, 200, 200); 
    material = new THREE.MeshBasicMaterial({color: 0x205081, vertexColors: THREE.FaceColors}); 

    mesh = new THREE.Mesh(geometry, material); 
    scene.add(mesh); 

    renderer = new THREE.CanvasRenderer(); 
    renderer.setSize(window.innerWidth, window.innerHeight); 

    document.body.appendChild(renderer.domElement); 

} 

function animate() { 

    requestAnimationFrame(animate); 
    render(); 

} 

function render() { 

    mesh.rotation.x += 0.01; 
    mesh.rotation.y += 0.02; 

    renderer.render(scene, camera); 

} 

$('input[type=button]').click(function() { 
     geometry.faces.map(function(f) { 
      f.color.setHex(0x205081); 
    }); 
    geometry.colorsNeedUpdate = true; 
}); 
+1

見http://stackoverflow.com/questions/27506997/superimposing-of-color/27737708#27737708,這是同一個問題。 – WestLangley

回答

1

小心MeshBasicMaterial的顏色是不一樣的面的顏色。

你想要的是這樣的:

var camera, scene, renderer, geometry, material, mesh; 

init(); 
animate(); 

function init() { 

    scene = new THREE.Scene(); 

    camera = new THREE.PerspectiveCamera(50, window.innerWidth/window.innerHeight, 1, 10000); 
    camera.position.z = 500; 
    scene.add(camera); 

    geometry = new THREE.CubeGeometry(200, 200, 200); 

    //Set material to white color so it doesn't conflict when applying actual face colors 
    material = new THREE.MeshBasicMaterial({color: 0xffffff, vertexColors: THREE.FaceColors}); 

    //Set your initial face colors like this, not with material 
    geometry.faces.map(function(f) { 
      f.color.setHex(0x205081); 
    }); 

    mesh = new THREE.Mesh(geometry, material); 
    scene.add(mesh); 

    renderer = new THREE.CanvasRenderer(); 
    renderer.setSize(window.innerWidth, window.innerHeight); 

    document.body.appendChild(renderer.domElement); 

} 

function animate() { 

    requestAnimationFrame(animate); 
    render(); 

} 

function render() { 

    mesh.rotation.x += 0.01; 
    mesh.rotation.y += 0.02; 

    renderer.render(scene, camera); 

} 

$('input[type=button]').click(function() { 
    geometry.faces.map(function(f) { 
      f.color.setHex(0x205081); 
    }); 
    geometry.colorsNeedUpdate = true; 
}); 
+1

它的行爲並不像預期的那樣,如果我在截圖中使用圖像顏色選擇器,它將返回#041941而不是#205081。 http://html-color-codes.info/colors-from-image/ – fabriciofreitag

+0

@onionfeelings這與現場的照明,陰影等有關嗎? –

+0

@LTTaylor我假設沒有,因爲我沒有設置任何東西,如果你用十六進制顏色選擇器測試屏幕截圖(例如:http://html-color-codes.info/colors-from-image/) 你'會看到由材質設置的顏色正確(#205081)和通過設置面部顏色設置的顏色實際上是#041941。 – fabriciofreitag