Three.js - Como verificar se um objeto está visível para a câmera
Estou tendo dificuldades para descobrir qual é a melhor maneira de verificar se um Object3d está visível para os olhos da câmera.
Estou tendo uma esfera no meio da tela. Alguns cubos são adicionados aleatoriamente à sua superfície. O que eu precisaria é uma maneira de verificar quais cubos são visíveis (na metade frontal da esfera) e quais são invisíveis (na metade traseira da esfera) para os olhos da câmera.
O que encontrei até agora parece ser a direção certa - mas devo estar perdendo algo com a classe THREE.Raytracer.
Aqui está um violino do código que estou usando:jsfiddle. Eu tentei deixar o mais claro possível.
Esta parte do violino pode conter o código de buggy:
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 THINK THIS CALCULATION MIGHT BE WRONG - BUT DON'T KNOW HOW TO CORRECT 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);
});
O Frustum Culling não está funcionando como descrito nesta pergunta de estouro de pilha aqui:post1
Também issopost2 e istopost3 estão explicando o tópico realmente bom, mas não exatamente para esta situação.
Obrigado pela ajuda!