Skip to main content

GltfAsset

Class

Represents a GLTF 3D Model.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Since Lens Scripting v176

Index

Example

// @input Asset.BitmojiModule bitmojiModule
// @input Asset.RemoteMediaModule remoteMediaModule
// @input Asset.Material pbrMaterialHolder

script.bitmojiModule.requestBitmoji3DResource(
function (bitmoji3DResource) {
script.remoteMediaModule.loadResourceAsGltfAsset(
bitmoji3DResource,
onDownloaded,
onFail
)
}
)

function onDownloaded (gltfAsset){
var root = scene.createSceneObject("BitmojiAvatar");
var gltfSettings = GltfSettings.create();
gltfSettings.convertMetersToCentimeters = true;
var avatar = gltfAsset.tryInstantiateWithSetting(root, script.pbrMaterialHolder, gltfSettings);
}

function onFail (e){
print(e);
}

Extends

Properties

extras

readonly extras: string

Since

Lens Scripting Version 176


name

name: string

The name of the Asset in Lens Studio.

Default Value

""

Inherited from

Asset.name


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Asset.uniqueIdentifier

Methods

getResourceFromExtras()

getResourceFromExtras(url): DynamicResource

Use this method to get a dynamic resource for the url from the gltf extras.

Parameters

ParameterType
urlstring

Returns

DynamicResource

Since

Lens Scripting Version 313


getStaticComposition()

getStaticComposition(): string

Returns a JSON string containing statistics about the glTF asset including: file size, triangle count, vertex count, mesh count, texture count, texture memory size, material count, animation count, and node count. Must be called after the asset has been instantiated with tryInstantiate, tryInstantiateAsync or tryInstantiateWithSetting, otherwise it returns null.

Returns

string

Since

Lens Scripting Version 340

Example

var info = gltfAsset.getStaticComposition();
if (info) {
var stats = JSON.parse(info);
print("Triangles: " + stats.triangleCount);
print("File size: " + stats.fileSizeBytes + " bytes");
}

getTypeName()

static getTypeName(): TypeName<GltfAsset>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<GltfAsset>

Since

Lens Scripting Version 176

Overrides

Asset.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Asset.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Asset.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Asset.isSame


tryInstantiate()

tryInstantiate(parent, material): SceneObject

Try instantiating an object from the GLTF asset.

Parameters

ParameterType
parentSceneObject
materialMaterial

Returns

SceneObject

Since

Lens Scripting Version 176


tryInstantiateAsync()

tryInstantiateAsync(parent, material, onSuccess, onFailure, onProgress, gltfSettings?): void

Asynchronously try instantiating an object from the GLTF asset. Useful to prevent frame drops when loading multiple assets simultaenously as to not block the the thread.

Parameters

ParameterType
parentSceneObject
materialMaterial
onSuccess(sceneObject) => void
onFailure(error) => void
onProgress(progress) => void
gltfSettings?GltfSettings

Returns

void

Since

Lens Scripting Version 300


tryInstantiateWithSetting()

tryInstantiateWithSetting(parent, material, gltfSettings): SceneObject

Try instantiating an object from the GLTF asset with supplied GltfSetting

Parameters

ParameterType
parentSceneObject
materialMaterial
gltfSettingsGltfSettings

Returns

SceneObject

Since

Lens Scripting Version 183