I’m attempting to get the camera to appear at the center of the model I have. I tried the UniversalCamera and the others also aren’t appearing here is my code:
const createScene = () => {
const scene = new BABYLON.Scene(engine);
const camera = new BABYLON.UniversalCamera("camera", new BABYLON.Vector3(0, 0, 0), scene);
camera.attachControl(canvas, true);
const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1,0), scene);
const box = BABYLON.MeshBuilder.CreateBox("box", {}, scene);
return scene;
}
I’m sure I’m doing something wrong but can’t figure out how to set it. I tried changing the coordinates on new BABYLON.Vector3(0, 0, 0) but that didn’t help. Any idea what I’m doing wrong?
So you are using the model viewer and running some code to initialize the scene right?
Let me ping @RaananW who is the architect of our viewer as I believe there might some race condition where the viewer is using its own camera setup overwriting your change in the process
Yes, the viewer works a bit differently. It creates its own scene, camera and lights based on a configuration object (as opposed to a playground scene where you create everything you need).
After the viewer is created you can get access to the scene the viewer created and do whatever you want, but if you want to stay model-agnostic, you should use the configuration and let the viewer do its magic.