TextureCache

Description

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

The TextureCache API manages texture 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.

prefetch ResourceObject

Prefetches a texture resource of specific type.

updateTotalSize None

Deprecated: This function is deprecated and will be removed.

Signals

Name Summary
dirty

Triggered when the cache content has changed.

spectatorCameraFramebufferReset

Deprecated: This signal is deprecated and will be removed.

Type Definitions

TextureType
Type: number

Describes the type of texture.

See also: Material and PBR Materials Guide.

ValueNameDescription
0DefaultBasic color.
1StrictBasic color. Quality never downgraded.
2AlbedoColor for PBR.
3NormalNormal map.
4BumpBump map.
5Specular or metallicMetallic or not.
6RoughnessRough or matte.
7GlossGloss or shine.
8EmissiveThe amount of light reflected.
9CubeCubic image for sky boxes.
10Occlusion or scatteringHow objects or human skin interact with light.
11LightmapLight map.
12UnusedTexture is not currently used.

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) prefetch( url, type, maxNumPixelsopt ) → {ResourceObject}
Returns: A resource object.

Prefetches a texture resource of specific type.

Parameters

Name Type Attributes Default Value Description
url string

The URL of the texture to prefetch.

type TextureCache.TextureType

The type of the texture.

maxNumPixels number <optional>
67108864

The maximum number of pixels to use for the image. If the texture has more than this number it is downscaled.

(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.

spectatorCameraFramebufferReset( )
Returns: Signal

Deprecated: This signal is deprecated and will be removed.