Threejs十六进制色差

时间:2016-01-31 19:32:00

标签: javascript three.js

创建材料时,我使用的是十六进制0x205081,如下所示:

material = new THREE.MeshBasicMaterial({color: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 个答案:

答案 0 :(得分: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;
});