In three.js I load a displacement map like this
// ADD MAP
const loader = new THREE.TextureLoader();
const height = loader.load(GAME_CONTEXT.height_map_link);
const texture = loader.load(GAME_CONTEXT.texture_map_link);
const normal = loader.load(GAME_CONTEXT.normal_map_link);
const map_geometry = new THREE.PlaneBufferGeometry(GAME_CONTEXT.width, GAME_CONTEXT.height, 64, 64);
const map_material = new THREE.MeshStandardMaterial({
color:'orange',
//side: THREE.DoubleSide,
map:texture,
displacementMap: height,
displacementScale: GAME_CONTEXT.scale,
normalMap : normal
//alphaMap: alpha,
//transparent:true
});
const map_plane = new THREE.Mesh(map_geometry, map_material);
map_plane.position.x += GAME_CONTEXT.width/2;
map_plane.position.y += GAME_CONTEXT.height/2;
scene.add( map_plane );
map_geometry.computeVertexNormals();
map_geometry.computeTangents();
var normals = map_geometry.attributes.normal.array;
for(var i1 = 0, l1 = normals.length; i1 < l1; i1 += 3){
var n = new THREE.Vector3(normals[i1], normals[i1+1], normals[i1+2]);
console.log(n);
}
The map loads, but I am now trying to get the normals at each position on the map. Or simply calculate it at any abstract (x,y) position. I am looking through the normals, but they are all (0,0,1). How can I get the actual normals?