The LoadingStates enum tells the state of the resource loading of the objects currently rendered.
There may be cases when the rendering of the DMU cannot be done with all the objects rendered.
The InfiniteEngineInterface features a complex algorithm to render the maximum relevant triangles
given a budget of triangles and memory.
This algorithm is triggered to download and render some geometries and is referred as the "resource loader".
The LoadingStates is the status of "resource loader".
It tells if the "resource loader" is loading, if all geometries have been
loaded, or if the loading was stopped due to memory/triangles limitations.
This information is retrieved on the InfiniteEngineInterface InfiniteEngineInterface.getResourceLoadingState.
This is not to be confused with the loading of the DMU itself that is retrieved on the DataSessionInterface.
This value is only relevant when the DMU has been loaded, and part instances are being rendered (DataSessionInterfaceSignal.DMULoadingSuccess signal
has been received).
/** * Sample to illustrate getting the loading state (updating, ok, out of budget) of the InfiniteEngineInterface. */ import { InfiniteEngineInterface, LoadingStates } from'generated_files/documentation/appinfiniteapi';
// created previously letlInfiniteEngine : InfiniteEngineInterface; // gets the loading state of the resource controller when the DMU has been loaded constlLoadingState : LoadingStates = lInfiniteEngine.getResourceLoadingState(); // and output its value console.log('current loading state ' + lLoadingState);
If promises are available, you may wait for the data loading to complete :
/** * Sample to illustrate the asynchronous screenshot procedure of the InfiniteEngineInterface. */ import { InfiniteEngineInterface, LoadingStates, Vector3, InfiniteImageInterface, ScreenshotType, AsyncDataLoadedResult, AsyncResultReason, AsyncScreenshotResult } from'generated_files/documentation/appinfiniteapi';
// We try to make a screenshot when all data is loaded
// the div to render the 3D display letlView3D: HTMLElement;
// created previously, should receive the image data to be displayed to the user (or ask for a download maybe ?) letlImageData : HTMLImageElement;
// created previously the position of the camera for the screenshot letlCameraLocation : Vector3;
// created previously the camera center of interest letlCenterOfInterest : Vector3;
// created previously the 3D engine letlInfiniteEngine: InfiniteEngineInterface;
consttakeScreenshot = async () : Promise<void> => { // bind the 3D rendering to the div (should have been done earlier :) ) lInfiniteEngine.setView(lView3D);
// we will make screenshot of 1024x1024 lInfiniteEngine.setFixedResolution(1024, 1024, 1);
// go to the expected position / location lInfiniteEngine.getCameraManager().setCameraLocation(lCameraLocation); lInfiniteEngine.getCameraManager().lookAt(lCenterOfInterest, 0);
// What to do when all data is loaded ? constlDataLoaded : AsyncDataLoadedResult = awaitlInfiniteEngine.asyncWaitForDataLoaded(); if (lDataLoaded.reason !== AsyncResultReason.ARR_Success || lDataLoaded.value === undefined) { // this is an error that should not happen (perhaps the engine interface has been destroyed ?) console.log('screenshot procedure failed for some reason'); return; } constlDataLoadedState : LoadingStates = lDataLoaded.value.newLoadingState; switch (lDataLoadedState) { caseLoadingStates.S_Loading: // this is an unexpected error console.log('unexpected error'); return; caseLoadingStates.S_OutOfBudget: // some fancy message console.log('Taking a screenshot without everything loaded'); // but we still make a screenshot :) break; default: break; } constlScreenshot : AsyncScreenshotResult = awaitlInfiniteEngine.asyncScreenshot(ScreenshotType.ST_Color, true, 'image/jpeg', 0.95); if (lScreenshot.reason !== AsyncResultReason.ARR_Success || lScreenshot.value === undefined) { // this is an error that may happen (perhaps the engine interface has been destroyed ?, or bad inputs ?) console.log('screenshot procedure failed for some reason'); return; } // What to do when screenshot is ready ?
// the image result constlInfiniteImage : InfiniteImageInterface = lScreenshot.value;
// is the image valid ? and base64 encoded ? if ((lInfiniteImage.width === 0) || (!lInfiniteImage.data) || (!lInfiniteImage.base64)) { console.log('Unexpected screenshot error, aborting'); return; }
// create the data url in base64 // even if we did not get the expected format, we still get the result constlDataUrl : string = 'data:' + lInfiniteImage.format + ';base64,' + lInfiniteImage.data;
// resize the image markup lImageData.width = lInfiniteImage.width; lImageData.height = lInfiniteImage.height; // and set data lImageData.src = lDataUrl;
// we get back to the size of the 3d view but this is up to the application needs lInfiniteEngine.unsetFixedResolution(); };
takeScreenshot();
Please make sure the destination browser supports promises before using async calls.
The LoadingStates enum tells the state of the resource loading of the objects currently rendered.
There may be cases when the rendering of the DMU cannot be done with all the objects rendered. The InfiniteEngineInterface features a complex algorithm to render the maximum relevant triangles given a budget of triangles and memory. This algorithm is triggered to download and render some geometries and is referred as the "resource loader".
The LoadingStates is the status of "resource loader". It tells if the "resource loader" is loading, if all geometries have been loaded, or if the loading was stopped due to memory/triangles limitations. This information is retrieved on the InfiniteEngineInterface InfiniteEngineInterface.getResourceLoadingState.
This is not to be confused with the loading of the DMU itself that is retrieved on the DataSessionInterface. This value is only relevant when the DMU has been loaded, and
part instancesare being rendered (DataSessionInterfaceSignal.DMULoadingSuccess signal has been received).If promises are available, you may wait for the data loading to complete :
Please make sure the destination browser supports promises before using async calls.
See
InfiniteEngineInterface.getResourceLoadingState