freetoplay Posted August 25, 2018 Share Posted August 25, 2018 Is there a way to adjust the camera to assure that the mesh is always within the canvas, when using AssetManager to load the mesh? I have been having issues such as this: http://www.babylonjs-playground.com/#TT2BK1 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted August 25, 2018 Share Posted August 25, 2018 You can do some math and adjust camera.fov (and direction/target/alpha/beta). scene.activeCamera.fov = 2.5; I tried to see the bounding box to be able to programatically calculate the FOV, but maybe at least that camera property will help you get one step further. Once you have a bounding box, you can do some math to have that all in the camera frustum. Quote Link to comment Share on other sites More sharing options...
freetoplay Posted August 26, 2018 Author Share Posted August 26, 2018 Do you know where I can find the math required to have the mesh to be within the camera frustum? The thing is I want to display different models, without the need to manually position the camera for each one of them. Not sure if that is possible. Quote Link to comment Share on other sites More sharing options...
brianzinn Posted August 26, 2018 Share Posted August 26, 2018 Here is how you fit a plane exactly in the frustum - it's a playground from Jerome. That's the math for a plane. https://playground.babylonjs.com/#UJWGY4#1 What I've done is that once you get your bounding box then you can work backwards. I have done moving the camera backwards, so everything was in the frustum. Here's a PG that I did that moves the camera (based on http://www.html5gamedevs.com/topic/31367-solved-determine-camera-distance-to-make-mesh-fit/ ) : https://www.babylonjs-playground.com/#P6JAWE#11 Another option is to do isCompletelyInFrustum() - using mesh or camera, but again, you will need a bounding box... here is a PG that I made as well that explores that way. I think you could do scaling and keep the positions of both the same. https://playground.babylonjs.com/#050P3M I was going to make you a PG, but I don't know how to get the bounding box from your mesh without calculating it from position vectors manually. I think it might be a mesh._children[0] on the duck. There are some posts how to get the bounding box on groups of imported meshes - I think you are going to need that first. Anyway, as you can see - once you know how big the mesh is there are various ways to accomplish what you are after. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
freetoplay Posted August 26, 2018 Author Share Posted August 26, 2018 This seems to have worked perfectly, thank you so much! brianzinn 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.