Struggling to determine the best method for checking if an Object3d is visible to the camera.
Imagine a sphere in the center of the screen with cubes randomly placed on its surface. I need a way to identify which cubes are visible (on the front half of the sphere) and which are hidden (on the back half) to the camera.
My research led me to the THREE.Raytracer class, but I suspect I may be overlooking something important.
Here is the code I'm working with on jsfiddle: jsfiddle. I've tried to make it clear.
This section of the fiddle may contain the problematic code:
var raycaster = new THREE.Raycaster();
var origin = camera.position, direction, intersects, rayGeometry = new THREE.Geometry(), g;
pointGroup.children.forEach(function(pointMesh) {
direction = pointMesh.position.clone();
// I SUSPECT THIS CALCULATION MAY BE INCORRECT - BUT NOT SURE HOW TO FIX IT
raycaster.set(origin, direction.sub(origin).normalize());
// if the pointMesh's position is on the back half of the globe, the ray should intersect with globe first and the hit the point as second target - because the cube is hidden behind the bigger sphere object
intersects = raycaster.intersectObject(pointMesh);
// this is always empty - should contain objects that are located on the back of the sphere ...
console.log(intersects);
});
Frustum Culling is not solving the issue as discussed in this stack overflow question: post1
Additional resources like post2 and post3 provide valuable insights but not directly applicable to my situation.
Appreciate any assistance you can offer!