Search code examples
javascriptcesiumjs

Cesium bind camera to model


I have put Cesium model

let modelMatrix = Transforms.eastNorthUpToFixedFrame(
  Cartesian3.fromDegrees(
    longitude,
    latitude,
    altitude
  )
);

let model = this.viewer.scene.primitives.add(Model.fromGltf({
    url : URL,
    modelMatrix : modelMatrix,
    minimumPixelSize : 1,
    maximumScale : 1
}));

And im going to change its position (model will fly) And I would like to know is there a way to bind camera to this model. Something like this:

let camera = this.viewer.camera.bindToModel(model, OPTIONS);

So when model will change its position - camera will also move. Thanks


Solution

  • The reason why my

    viewer.trackedEntity = myModel;
    

    did not focus camera on model, is that i used

    let myModel = viewer.scene.primitives.add(MODEL);
    viewer.trackedEntity = myModel;
    

    to add model on scence and focus on it. When i changed to

    let myModel = viewer.entities.add(MODEL_DESC);
    viewer.trackedEntity = myModel;
    

    My camera focused on model and follow it on position change, as i need. Thanks emackey for useful example Multipart CZML Demo that helped to solve my task