Skip to content

Commit

Permalink
fix: 🐛 fix visible behind camera frustum (#178)
Browse files Browse the repository at this point in the history
this should fix html still being visible, when object is behind camera frustum
  • Loading branch information
dennemark committed Nov 26, 2021
1 parent 53a6d21 commit f057c71
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/customComponents/Html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ function isObjectBehindCamera(el: AbstractMesh, camera: Camera) {

const planes = Frustum.GetPlanes(camera.getTransformationMatrix());
const center = el.absolutePosition;
const insideFrustum = planes.findIndex(x => x.dotCoordinate(center) < 0) === -1 ? false : true; // taken from : https://forum.babylonjs.com/t/check-if-vector3-is-in-frustum/8652/3
const outsideFrustum = planes.findIndex(x => x.dotCoordinate(center) < 0) === -1 ? false : true; // taken from : https://forum.babylonjs.com/t/check-if-vector3-is-in-frustum/8652/3

return !insideFrustum;
return outsideFrustum;
}

function isObjectVisible(el: AbstractMesh, camera: Camera, occlude: AbstractMesh[]) {
Expand Down Expand Up @@ -249,7 +249,7 @@ const Html = forwardRef(
node.computeWorldMatrix(true)
const vec = transform ? oldPosition.current : calculatePosition(node, camera)

el.style.display = node.isEnabled(true) ? 'block' : 'none'
el.style.display = (visible.current && node.isEnabled(true)) ? 'block' : 'none'

if ( (isNaN(vec[0]) === false) && (
transform ||
Expand Down

0 comments on commit f057c71

Please sign in to comment.