Camera position set after loading new model

I tried the same model import from doc exmaple : https://www.babylonjs-playground.com/#1GFIVU#2
however, my camera seems zoom too much on target, here is my code:

    }
    appendModels(path:string,fileName:string | File,onSuccess?:()=>any){
        SceneLoader.Append(path,fileName,this.scene,(a)=>{
            onSuccess?onSuccess():
            console.log('finished');
            if(a.meshes.length){
                // const worlExtends = a.getWorldExtends();
                // let center = worlExtends.min.add(worlExtends.max).divideInPlace(Vector3.Zero());
                (a.activeCamera as SuportedCamera).addBehavior(new AutoRotationBehavior());
 
                a.createDefaultEnvironment({
                    createGround: true,
                    createSkybox: true,
                    enableGroundMirror: true,
                    groundMirrorSizeRatio: 0.2
                });
                // (a.activeCamera as SuportedCamera).setTarget(new Vector3(worlExtends.max._x+worlExtends.min._x,worlExtends.max._y+worlExtends.min._y,worlExtends.max._z+worlExtends.min._z))
        
            }
        },(data)=>{
            console.log('onProgrocee',data);
        },(err)=>{
            console.log('onError',err);
        })
    }

my question is: is there a better way to set camera position to center model after every Append or Load Action

I recommend taking a look into the Framing Behavior Camera Behaviors | Babylon.js Documentation (babylonjs.com)

1 Like

I checked the camera behaviors, but i dont think that is what i need. when i use @babylonjs/viwer to show models, it always position the model in front of camera with appropriate distance, however if i build the scene by self, the camera is either too close or too far from the model. my purpose was to build a lib like @babylonjs/viwer, that display models , I’m looking for a universal way to adjust models,lights and camera position, after the model loaded. or … I dont know, I’m new to 3d :smiling_face_with_tear:

btw, Framing Behavior not work in my build, I use Typescript in my project, so what i did was import FramingBehavior from ‘@babylonjs/core’ and then

      scene.activeCamera?.addBehavior(new FramingBehavior())
        scene.activeCamera?.addBehavior(new AutoRotationBehavior())

after the scene init.
AutoRotationBehavior is working fine, but i didnt see the FramingBehavior,

So FramingBehavior is not being exposed by @babylonjs/core? Which version are you using?
Pinging @RaananW to take a look when he can

i’ll look into that, but this could have been caused by many different issues.

What version of core are you using? can you share the project you are using? Is the activeCamera actually defined? what kind of camera is it?

Also - what version of @babylonjs/core are you using?

Hey Raanan, I put my questions together in this repo:
https://github.com/mxm-web-develop/workspace/tree/babylonQuestion
Thanks for your response again

replied in the other thread - the project is 404, i can’t seem to see the code.