Change the colors of a cube's faces

前端 未结 2 1867
孤独总比滥情好
孤独总比滥情好 2020-12-10 04:06

I actually found this question, but it says material.color doesn\'t exist. I need to know how to change the colors of the various faces of a cube I\'m drawing:<

2条回答
  •  我在风中等你
    2020-12-10 04:42

    Here is a fiddle for people who end up here and want to see this code working.

    I made a box and tied 3 colors to the faces:

    // colors
    red = new THREE.Color(1, 0, 0);
    green = new THREE.Color(0, 1, 0);
    blue = new THREE.Color(0, 0, 1);
    var colors = [red, green, blue];
    
    for (var i = 0; i < 3; i++) {
        geometry.faces[4 * i].color = colors[i];
        geometry.faces[4 * i + 1].color = colors[i];
        geometry.faces[4 * i + 2].color = colors[i];
        geometry.faces[4 * i + 3].color = colors[i];
    }
    

    The face colors are changed in the animate loop.


    Also check a related question here with a great answer demonstrating the use of material indices and groups on THREE.BufferGeometry instances.

提交回复
热议问题