I’m loading a number of objects into the scene and want to frame the camera so that all are in view. In theory I thought I could check this by camera.isInFrustum(mesh) or mesh.isOccluded, assuming that if it is not in frustum, but occluded, it is safe to skip for my check.
However, isOccluded never gets updated, and all my attempts to ignore occlusion and check whether the object is in the frustum even if it is occluded have failes as well.
public frameMeshes = (meshes: BABYLON.AbstractMesh[]) => {
if (meshes === undefined) {
meshes = this._scene.meshes;
}
let maxLoops: number = 40;
for (let index = 0; index < maxLoops; index++) {
let allInFrustrum: boolean = true;
for (let index = 0; index < meshes.length; index++) {
const element = meshes[index];
// check if mesh is either visible in frustum OR is occluded (and thus not visible, but technically "in view")
allInFrustrum =
allInFrustrum &&
(this._camera.isCompletelyInFrustum(element) ||
element.isOccluded);
console.log(
`${element.name} ${this._camera.isInFrustum(element)} ${
element.isOccluded
}`
);
}
// move camera here depending on if everything is in view
};
Problem: this._camera.isCompletelyInFrustum(element)
only shows true for non-occluded meshes, meshes behind this always return false. element.isOccluded
always returns false, regardless.
I played with changing occlusionmethods etc but to no avail. Is it something obvious I’m missing?
Thanks!