Essentially, I’d like to prevent a camera from clipping through an object. I noticed that when a .gltf file is uploaded to the sandbox, the camera enables you to zoom extremely close to the surface without actually going through it. I’d just like to replicate this behavior.
The camera in the sandbox uses “framing behavior” to prevent it from getting too close. You can also adjust the radius limit to adjust how close and far away you can get from the object. I created a video on a lot of these mechanics here: https://www.youtube.com/watch?v=VSX8Y026MkQ Hope that helps!
If you use the framing behavior you can have it set based on the bounds of the object.
BABYLON.FramingBehavior.FitFrustumSidesMode : The camera is not allowed to zoom closer to the mesh than the point at which the adjusted bounding sphere touches the frustum sides
That’s one way to do it, otherwise, you can just play around with the lower radius limit setting it to something like 5.
If you have something more dynamic where you may have a variety of objects of similar size you can also create a box that will act as the “bounds” and use the framing behavior to zoom in on the box. Make the box invisible and make sure the imported mesh is in the center of the box. Now when the camera zoom in, it’ll stop when it reaches the bounds of the box.