After experimenting with a function that graphs a pair of arrays as a double-sided surface in threejs, I realized I was facing some issues. Despite my experience using threejs for a few weeks, custom shapes seemed to complicate things. I scoured the internet for solutions but found none that worked for me. Hence, I am reaching out here.
The two relevant code snippets are below, but the entire code can be accessed on JsFiddle.
var ambient = new THREE.AmbientLight( 0x444444 );
scene.add( ambient );
var spotLight = new THREE.DirectionalLight( 0xffffff );
spotLight.position.set( 0, 1, 1 ).normalize();
scene.add(spotLight);
and
function graph(array1, array2)
{
var particleCount = array1.length*array2.length,
particles = new THREE.Geometry(),
pMaterial = new THREE.MeshPhongMaterial({
side: THREE.DoubleSide,
shading: THREE.SmoothShading
});
// now create the individual particles
for (var p = 0; p < particleCount; p++) {
var row = (p%array1.length),
col = Math.floor(p/array1.length),
pX = 2*row - array1.length,
pY = 2*col - array2.length,
pZ = (array1[row])*(array2[col]),
particle = new THREE.Vector3(pX, pZ, pY);
// add it to the geometry
particles.vertices.push(particle);
if (row != 0 && col != 0)
{
particles.faces.push( new THREE.Face3( col * array1.length + row, col * array1.length + row - 1, (col - 1) * array1.length + row) );
particles.faces.push( new THREE.Face3( (col - 1) * array1.length + row, col * array1.length + row - 1, (col - 1) * array1.length + row - 1) );
}
}
// create the particle system
var particleSystem = new THREE.Mesh(
particles,
pMaterial);
// add it to the scene
scene.add(particleSystem);
onRenderFcts.push(function(){
var angle = Date.now()/10000 * Math.PI;
particleSystem.rotation.y = angle;
})
}
https://jsfiddle.net/6Lp74xdn/1/
Despite thorough testing, I'm stumped as to why the directional light is not illuminating the surface correctly.