Search code examples
autodesk-forgeautodesk-viewer

Autodesk Forge Viewer - How do I fire an event after model loading is complete?


How do I fire an event after model loading is complete?

I created the "basicSetting" function below.

function basicSetting(){
    viewer.setLightPreset(1);
    viewer.setQualityLevel(false, false);
    viewer.setGhosting(true);
    viewer.setGroundShadow(false);
    viewer.setGroundReflection(false);
    viewer.setEnvMapBackground(false);
    viewer.setProgressiveRendering(true);
}   

And I applied it to the "onDocumentLoadSuccess" function.

But it didn't work.

Help!


Solution

  • You can use the GEOMETRY_LOADED_EVENT as per this link and use it like this after you have initialised a viewer.

    In typescript (using forge-typings)

    this.viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, (x) => 
    { 
        basicSetting();
    }
    

    Or if you wanna be extra save and make sure the function is never called elsewhere, just remove it and place its contents in the event callback.

    this.viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, (x) => 
    { 
        this.viewer.setLightPreset(1);
        this.viewer.setQualityLevel(false, false);
        this.viewer.setGhosting(true);
        this.viewer.setGroundShadow(false);
        this.viewer.setGroundReflection(false);
        this.viewer.setEnvMapBackground(false);
        this.viewer.setProgressiveRendering(true);
    }
    

    Not sure in which languages you are developing but it should be pretty simular !