0

I am trying to draw a cylinder with chocolate color 0xd2691e but when I use :

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

It doesn't change the color. And when I use

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

It does change color, but the color of the top face is the same as the sides, so it ends up like a blob without showing the cylinder 3D shape.

I checked this question and it does change the colors of faces randomly, but I would want simply some way to distinguish the colors of the top and the sides.

Community
  • 1
  • 1
hmghaly
  • 1,411
  • 3
  • 29
  • 47

1 Answers1

2

You should use the MeshLambertMaterial. Also, make sure the scene has a light otherwise it won't show up.

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 );
mrdoob
  • 19,334
  • 4
  • 63
  • 62