为什么网格的颜色没有改变(使用 three.js)?

Why color of mesh does not change (using three.js)?

我正在使用 three.js 创建一些对象:

    // it probably does not matter where geom1 or geom2 comes from
    var materials = [
        new THREE.MeshLambertMaterial( { opacity: 0.2, color: 0x000000, transparent:false, side: THREE.DoubleSide } ),
        new THREE.MeshBasicMaterial( { color: 0x445555, wireframe: true } )

    ];
    mesh2 = THREE.SceneUtils.createMultiMaterialObject(geom2,materials);

    var material = new THREE.MeshBasicMaterial( {color: 0xEEEEEB, transparent:false, side: THREE.DoubleSide } );
    mesh1 = new THREE.Mesh(geom1,material);
    mesh1.material.color.setHex( 0xEEEEEB );

正如您从代码中看到的那样,我尝试以两种方式创建材质。在这两种情况下,我给颜色参数赋予什么值都没有关系,颜色永远不会改变(它总是灰色的)。除非我调整不透明度,否则它当然会变暗或变亮。我在这里错过了什么?

在声明之外更新颜色后,设置 needsUpdate 参数

material.needsUpdate = true;

因为

new THREE.MeshLambertMaterial( {  color: 0x33cc33, side: THREE.DoubleSide } )

显示为 gray/shade 灰色您可能场景中没有任何灯光,添加一个尝试

scene.add(new THREE.AmbientLight(0xffffff))

或设置 LambertMaterial 的发光颜色

new THREE.MeshLambertMaterial({color: 0x33cc33, side: THREE.DoubleSide, emissive: 0x33cc33})

让它发出颜色