簡體   English   中英

Threejs十六進制顏色差異

[英]Threejs hex color difference

創建材料時,我使用的是十六進制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;
});

請注意,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;
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM