Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 圆柱体的着色_Javascript_Three.js - Fatal编程技术网

Javascript 圆柱体的着色

Javascript 圆柱体的着色,javascript,three.js,Javascript,Three.js,我正在尝试绘制巧克力色0xd2691e的圆柱体,但使用时: var cylinder = new THREE.Mesh(new THREE.CylinderGeometry(100, 100, 100, 100, 50, false), new THREE.MeshNormalMaterial({ color: 0xd2691e })); 它不会改变颜色。当我使用 var cylinder = new THREE.Mesh(new THREE.CylinderGeometry(100, 100

我正在尝试绘制巧克力色0xd2691e的圆柱体,但使用时:

var cylinder = new THREE.Mesh(new THREE.CylinderGeometry(100, 100, 100, 100, 50, false), new THREE.MeshNormalMaterial({ color: 0xd2691e }));
它不会改变颜色。当我使用

var cylinder = new THREE.Mesh(new THREE.CylinderGeometry(100, 100, 100, 100, 50, false), new THREE.MeshBasicMaterial({ color: 0xd2691e }));
它确实会更改颜色,但顶面的颜色与侧面的颜色相同,因此它最终像一个水滴,而不显示圆柱体三维形状


我检查了,它确实随机改变了面颜色,但我只想用一些方法来区分顶部和侧面的颜色。

您应该使用
MeshLambertMaterial
。另外,确保场景有灯光,否则它不会显示

var scene = new THREE.Scene();

var cylinder = new THREE.Mesh(new THREE.CylinderGeometry(100, 100, 100, 100, 50, false), new THREE.MeshLambertMaterial({ color: 0xd2691e }));
scene.add( cylinder );

var light = new THREE.PointLight( 0xffffff );
light.position.z = 200;
scene.add( light );