Change model.url in javascript in babylonjs viewer

Hi, I want to know , if there is any method to change the model.url in javascript in babylonjs viewer with the variable/function rather than to give string as path.
like model.url = variable/function
not model.url = “…/assets/path/file.glb”

Hi, I’m able to change the model via prop :model=“variable” (not model.url) … but it’s giving me error “importmesh of undefined from undefined version: undefined, exporter version: undefinedimportmesh has failed json parse”
Seems like it’s error of loaders (but i’m not confirmed about it)

The viewer instance has two functions you can use to load a new model initModel and loadModel , depends on the level of load-guaranty you require. You will need to use javascript for that, HTML alone will only let you load one predefined URL.

1 Like

@RaananW Thanks for your reply. I was using loadModel for model.url like this…

BabylonViewer.viewerManager
      .getViewerPromiseById("loading-demo")
      .then(function (viewer) {
        // this will resolve only after the viewer with this specific ID is initialized
        viewer.onEngineInitObservable.add(function (scene) {
          viewer.loadModel({
          //url must take some variable/function not string of path
           url:"../assets/file.glb", 
          });
        });
      }); 

Can you help me how can I use variable/function for url here? because I did not find anything related to this to dynamically change the model. It will be help for me in this regard. Thanks in advance :smiley:

2 Likes

Calling loadModel at a later time will re-init the viewer and will display the new model. Just keep a reference to the viewer (or get it again using the same function), and you can change the model loaded