I'm rendering a complex 3D mesh with Three.js (an iliac bone). Then I'm rendering some simple spheres along with this mesh to mark certain points on the surface (where muscles would attach):
The problem is, the mesh is quite thin in some areas, and the markers will stick out the back.
Assume that the marker coordinates are always closer to the front face of the mesh than the back face, and that the spheres always show more surface area / volume on the front of the mesh than on the back:
How could I hide the parts that extrude out the back without manually intervening for specific markers?
Edit: Here's a (naive?) way of how I might do it. I would like feedback on the feasibility of the idea, and (some pointers to writing) actual code to do it:
- for each marker sphere:
- find all faces of the mesh that intersect with the sphere
- compute all outward-facing normal vectors of those faces (vertex-normals? face-normals?)
- compute all distances from the center of the face to the center of the sphere
- add all those normal vectors, weighed by their respective distances
- given the (normalized?) result vector, hide the hemisphere pointing in that direction
I'm not sure how to code any of those steps. Nor am I sure if this is even a sensible approach.
phiStart
andphiLength
params: threejs.org/docs/#Reference/Extras.Geometries/SphereGeometry). Idea 2: Set an offset of the spheres on thenormal
depending on the sphere radius and bone thickness (you'll need that info) in the point where the sphere should be placed so it will not be visible on the other side. – B0Andrewbone.geometry.faces
. Then each face should havevertexNormals
. Take a look inVertexNormalsHelper
code. This should give you a good start: github.com/mrdoob/three.js/blob/master/src/extras/helpers/… – B0AndrewVertexNormalsHelper
to see what I can make of it. Thanks! – mhelvens