Loading GLTF camera data to a ArcRotateCamera in Orthographic mode?

Hi everyone,

Sorry if this has been asked before, I’m struggling to find any examples online of our use case.

We want to load in a camera that is defined in a GLTF/GLB file, our scene by default uses an ArcRotateCamera in Orthographic mode. The GLTF data we load into the scene defines the camera in the following structure:

"nodes": [
 {
  "name": "Camera",
  "camera": 0
 },
 { ... }
],

...

"cameras": [
  {
    "type": "orthographic",
    "orthographic": {
      "xmag": 4095.000000,
      "ymag": 2219.225830,
      "znear":   0.000000,
      "zfar": 5067.582031
    }
  }
 ],

So far, we’ve been able to load in the above camera from the GLB/GLTF, but it defaults to a FreeCamera. I’m not sure how we would apply the above data so that our ArcCamera presents the model correctly to the above info.

Can anyone point me in the right direction? I’m looking at using the onCameraLoadedObservable to detect when models have a camera. But I’m not sure how to convert the information to an ArcRotate Camera in Ortho mode.

I’ve created a small playground to try and get things working with an example file but no luck so far https://playground.babylonjs.com/#3CGBLF#20

Thanks for any help/guidance :slight_smile:

pinging @bghgary

1 Like

The code does this.

That’s the mapping between glTF properties and what Babylon expects for ortho cameras.

2 Likes

Thanks for your help @bghgary and @Deltakosh, that’s great! Just what I needed :slight_smile:

2 Likes