ModelCache

Description

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts

The ModelCache API manages model cache resources.

Properties

Name Type Summary
numTotal number

Total number of total resources. Read-only.

numCached number

Total number of cached resource. Read-only.

sizeTotal number

Size in bytes of all resources. Read-only.

sizeCached number

Size in bytes of all cached resources. Read-only.

numGlobalQueriesPending number

Total number of global queries pending (across all resource cache managers). Read-only.

numGlobalQueriesLoading number

Total number of global queries loading (across all resource cache managers). Read-only.

Methods

Name Return Value Summary
getResourceList Array.<string>

Gets the URLs of all resources in the cache.

prefetch ResourceObject

Prefetches a resource.

updateTotalSize None

Deprecated: This function is deprecated and will be removed.

Signals

Name Summary
dirty

Triggered when the cache content has changed.

Method Details

(static) getResourceList( ) → {Array.<string>}
Returns: The URLs of all resources in the cache.

Gets the URLs of all resources in the cache.

Example

Report cached resources.

// Replace AnimationCache with MaterialCache, ModelCache, SoundCache, or TextureCache as appropriate.

var cachedResources = AnimationCache.getResourceList();
print("Cached resources: " + JSON.stringify(cachedResources));
(static) prefetch( url ) → {ResourceObject}
Returns: A resource object.

Prefetches a resource.

Parameters

Name Type Description
url string

The URL of the resource to prefetch.

Example

Prefetch a resource and wait until it has loaded.

// Replace AnimationCache with MaterialCache, ModelCache, SoundCache, or TextureCache as appropriate.
// TextureCache has its own version of this function.

var resourceURL = "https://apidocs.overte.org/examples/Silly%20Dancing.fbx";
var resourceObject = AnimationCache.prefetch(resourceURL);

function checkIfResourceLoaded(state) {
    if (state === Resource.State.FINISHED) {
        print("Resource loaded and ready.");
    } else if (state === Resource.State.FAILED) {
        print("Resource not loaded.");
    }
}

// Resource may have already been loaded.
print("Resource state: " + resourceObject.state);
checkIfResourceLoaded(resourceObject.state);

// Resource may still be loading.
resourceObject.stateChanged.connect(function (state) {
    print("Resource state changed to: " + state);
    checkIfResourceLoaded(state);
});
(static) updateTotalSize( deltaSize )

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Description
deltaSize number

Delta size.

Signal Details

dirty( )
Returns: Signal

Triggered when the cache content has changed.