Enumeration LoadingStates

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
let lInfiniteEngine : InfiniteEngineInterface;
// gets the loading state of the resource controller when the DMU has been loaded
const lLoadingState : 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
let lView3D: HTMLElement;

// created previously, should receive the image data to be displayed to the user (or ask for a download maybe ?)
let lImageData : HTMLImageElement;

// created previously the position of the camera for the screenshot
let lCameraLocation : Vector3;

// created previously the camera center of interest
let lCenterOfInterest : Vector3;

// created previously the 3D engine
let lInfiniteEngine: InfiniteEngineInterface;

const takeScreenshot = 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 ?
const lDataLoaded : AsyncDataLoadedResult = await lInfiniteEngine.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;
}
const lDataLoadedState : LoadingStates = lDataLoaded.value.newLoadingState;
switch (lDataLoadedState)
{
case LoadingStates.S_Loading:
// this is an unexpected error
console.log('unexpected error');
return;
case LoadingStates.S_OutOfBudget:
// some fancy message
console.log('Taking a screenshot without everything loaded');
// but we still make a screenshot :)
break;
default:
break;
}
const lScreenshot : AsyncScreenshotResult = await lInfiniteEngine.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
const lInfiniteImage : 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
const lDataUrl : 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.
3D Rendering

Enumeration Members

Enumeration Members

S_AllLoaded: 2

The "resource loader" has loaded all required resources.

S_Loading: 1

The "resource loader" is loading resources.

S_OutOfBudget: 3

The "resource loader" could not load all resources, it will not do anything more.