Alphawolf88
Alphawolf88

Reputation: 35

PlaneGeometry and Directional Light

I've a problem with lightning and the plane geometry. While creating the plane geometry with certain heightdata, it doesn't seem to me, that the directional light affect the mesh. There is still the same color overall :(

var geometry: THREE.PlaneGeometry
   = new THREE.PlaneGeometry(1000, 1000, 199, 199);

for (var i = 0, l = geometry.vertices.length; i < l; i++)
    geometry.vertices[i].z = this._heightmap.data[i];

var mesh = new THREE.Mesh(geometry, 
    new THREE.MeshLambertMaterial({ color: 0x1AAD2B }));

mesh.applyMatrix(new THREE.Matrix4().makeRotationX(- Math.PI / 2));

this.screen.get("Scene").add(mesh);

var light = new THREE.DirectionalLight(0xffffff, 1);

light.position.set(0.8, 0.5, 1);
light.position.normalize();
this.screen.get("Scene").add(light);

http://s14.directupload.net/images/130703/jsfx9tr3.png

Must i create my own shader or is it a queston of options i need to perform?

Kind Regards Christian

Upvotes: 1

Views: 782

Answers (1)

WestLangley
WestLangley

Reputation: 104783

You didn't change the vertex normals; they are all ( 0, 1, 0 ).

Also, when you modify the vertices of a quad, the four vertices are most likely no longer planar. This will cause you all sorts of problems. ( google non-planar quads. )

You can avoid these problems by triangulating the PlaneGeometry first:

THREE.GeometryUtils.triangulateQuads( geometry );

Be advised that this function recomputes vertex normals. Have a look at the source so you understand what it is doing.

EDIT: three.js no longer supports quads; PlaneGeometry is now triangulated.

three.js r.66

Upvotes: 1

Related Questions