I am currently exploring three.js and facing a challenge in positioning and manipulating a plane object to overlay the surface of a sphere (or any object), mimicking its shape. My goal is to enable movement of the plane on the surface at a later stage.
To achieve this, I have positioned the plane in front of the sphere and iterated through its vertices by casting rays towards the sphere to detect intersections. Despite my attempts to adjust the z position of these vertices based on collision results, I have not been able to achieve the desired outcome. I would greatly appreciate guidance on how to make this work or suggestions for alternative methods.
Here is an example of how I am trying to modify the vertices (with a visible offset of 1 from the sphere's surface):
planeMesh.geometry.vertices[vertexIndex].z = collisionResults[0].distance - 1;
Prior to rendering, I ensure the following settings are in place:
planeMesh.geometry.verticesNeedUpdate = true;
planeMesh.geometry.normalsNeedUpdate = true;
You can view where I am with a fiddle linked below. In my current setup, when casting rays in the z direction, I am unable to detect collisions with the sphere, preventing me from adjusting the plane as intended.
http://jsfiddle.net/stokewoggle/vuezL/
For better visualization, you can rotate the camera around the scene using the left and right arrows (works best in Chrome) to observe the plane's shape. I have made the sphere transparent for improved visibility of the plane.
EDIT: Fiddle has been updated and description mistake corrected.