API reference
API reference
Select your platform
No SDKs available
No versions available

GLXFManager Class

Modifiers: final
GLXFManager is a class that manages the inflation of glXF files into Spatial SDK entities. It manages the full lifecycle of glXFs that are inflated, including deletion.
For more info on how to use glXFs, visit our docs.
Example of inflating a glXF file:
// ImmersiveActivity.kt(your Spatial SDK activity)
private fun loadGLXF() {
  activityScope.launch {
    glXFManager.inflateGLXF(Uri.parse("apk:///demoproject1.glxf"))
  }
}

Constructors

GLXFManager ( context )
Signature
constructor(context: Context)
Parameters
context: Context
  : the context of the GLXFManager, a.k.a. the Spatial activity object.

Properties

context : Context
[Get]
: the context of the GLXFManager, a.k.a. the Spatial activity object.
Signature
val context: Context

Functions

addReloadedGLXFUris ( toReloadUris , basePath )
Adds URIs that should be loaded using the local file system instead of the APK file system. This is used when hot reloading to reload GLXFs so that future GLXFs use the reloaded files. It is recommended not to use this unless you know what you're doing.
Parameters
toReloadUris: Set
  The URIs that have been reloaded and use the local file system instead of the APK file system.
basePath: File
  The base path of the reloaded files.
deleteGLXF ( glxfInfo )
Deletes root entity and all children. Removes references to the deleted GLXFInfo from the maps.
Example:
// ImmersiveActivity.kt(your Spatial SDK activity)
glXFManager.deleteGLXF(glXFInfo)

Signature
fun deleteGLXF(glxfInfo: GLXFInfo)
Parameters
glxfInfo: GLXFInfo
  The GLXFInfo to remove.
deleteGLXF ( entity )
Deletes the GLXFInfo the entity belongs to along with all other entities in that GLXFInfo.
Example:
// ImmersiveActivity.kt(your Spatial SDK activity)
// If you have a reference to the root entity but not the GLXFInfo
glXFManager.deleteGLXF(gltfxEntity)

Signature
fun deleteGLXF(entity: Entity)
Parameters
entity: Entity
  The entity associated with GLXF to remove.
deleteGLXFEntityAndGetDeletedChildren ( entity )
Deletes a GLXF entity and get the deleted children. This is used for handling the deletion of children entities when deleting a GLXF entity. It is recommended not to use this unless you know what you're doing.
Example:
// ImmersiveActivity.kt(your Spatial SDK activity)
val deletedChildren = glXFManager.deleteGLXFEntityAndGetDeletedChildren(gltfxEntity)
for (childEntity in deletedChildren) {
  // Do something with each deleted child entity
  println("Deleted child entity: $childEntity")
}

Signature
fun deleteGLXFEntityAndGetDeletedChildren(entity: Entity): Set<Entity>
Parameters
entity: Entity
  The entity to delete.
Returns
Set
  A set of deleted children entities.
getGLXFInfo ( keyName )
Returns the GLXFInfo object for the given keyName.
Example:
// ImmersiveActivity.kt(your Spatial SDK activity)
val glXFInfo = glXFManager.getGLXFInfo("myKey")

Signature
fun getGLXFInfo(keyName: String): GLXFInfo
Parameters
keyName: String
  The key name of the GLXFInfo object to retrieve.
Returns
  The GLXFInfo object associated with the given keyName.
getNestedGLXFInfo ( parentInfo , childName )
Gets the nested GLXFInfo for a given child name.
Example:
val myGLXFInfo = glXFManager.getGLXFInfo("myKey")
val myNestedGLXFInfo = glXFManager.getNestedGLXFInfo(myGLXFInfo, "childWithNestedGLXFName")

Signature
fun getNestedGLXFInfo(parentInfo: GLXFInfo, childName: String): GLXFInfo?
Parameters
parentInfo: GLXFInfo
  The parent GLXFInfo object.
childName: String
  The name of the child node.
Returns
  The nested GLXFInfo object, or null if not found.
getNestedGLXFInfo ( parentInfo , childNamePathList )
Gets the nested GLXFInfo for a given list of child names. The first name should be the highest level child name, with each subsequent name being a child of that nested GLXFInfo
val myGLXFInfo = glXFManager.getGLXFInfo("myKey")
val myNestedGLXFInfo = glXFManager.getNestedGLXFInfo(myGLXFInfo, listOf("childOfMyGLXFInfo", "childOf_childOfMyGLXFInfo"))

Signature
fun getNestedGLXFInfo(parentInfo: GLXFInfo, childNamePathList: List<String>): GLXFInfo?
Parameters
parentInfo: GLXFInfo
  The parent GLXFInfo object.
childNamePathList: List
  The list of child names.
Returns
  The nested GLXFInfo object, or null if not found.
hasGLXFInfoForUri ( uri )
Checks if there is a GLXFInfo object for a given URI. This is useful for checking if a glXF file is in use. It is used mostly for hot reloading glXFs.
// ImmersiveActivity.kt(your Spatial SDK activity)
val uri = Uri.parse("apk:///scenes/Composition.glxf")
if (glXFManager.hasGLXFInfoForUri(uri)) {
  // The GLXF has already been loaded
} else {
  // Need to load the GLXF
  activityScope.launch {
    glXFManager.inflateGLXF(uri)
  }
}

Signature
fun hasGLXFInfoForUri(uri: Uri): Boolean
Parameters
uri: Uri
  The URI to check.
Returns
Boolean
  True if a GLXFInfo object exists for the URI, false otherwise.
inflateComposition ( compositionName , assetFolderPath , rootEntity , keyName , onLoaded )
Parses the Composition glxf file and calls inflateGLXF, inflates a GLXF file into a GLXFInfo object, adds it to the map of GLXFInfo objects, and sets the GLXF component on the root entity of the GLXF file.
// ImmersiveActivity.kt(your Spatial SDK activity)
private fun loadGLXF() {
  activityScope.launch {
    glXFManager.inflateComposition("demoproject1", assetFolderPath = "subfolder") // Inflates Uri.parse("apk:///subfolder/demoproject1.glxf")
  }
}

Signature
suspend fun inflateComposition(compositionName: String, assetFolderPath: String = "scenes", rootEntity: Entity = Entity.createGlobal(), keyName: String? = null, onLoaded: (GLXFInfo) -> Unit = {}): GLXFInfo?
Parameters
compositionName: String
  The name of the composition to inflate.
assetFolderPath: String
  The folder path where the assets are stored.
rootEntity: Entity
  The root entity of the GLXF file.
keyName: String?
  The key name of the GLXFInfo object to create.
onLoaded: Function1
Returns
  The inflated GLXFInfo object, or null if the keyName already exists in the map.
inflateGLXF ( uri , rootEntity , keyName , onLoaded )
Inflates a GLXF file into a GLXFInfo object, adds it to the map of GLXFInfo objects, and sets the GLXF component on the root entity of the GLXF file.
// ImmersiveActivity.kt(your Spatial SDK activity)
private fun loadGLXF() {
  activityScope.launch {
    glXFManager.inflateGLXF(Uri.parse("apk:///demoproject1.glxf"), rootEntity = myEntity, keyName = "myKey")
  }
}

Signature
suspend fun inflateGLXF(uri: Uri, rootEntity: Entity = defaultCreateEntity(null), keyName: String? = null, onLoaded: (GLXFInfo) -> Unit = {}): GLXFInfo?
Parameters
uri: Uri
  The URI of the GLXF file to inflate.
rootEntity: Entity
  The root entity of the GLXF file.
keyName: String?
  The key name of the GLXFInfo object to create.
onLoaded: Function1
  The callback function to call after the GLXFInfo object is loaded.
Returns
  The inflated GLXFInfo object, or null if the keyName already exists in the map.
inflateGLXF ( uri , overrideCreateEntity , rootEntity , keyName , onLoaded )
Inflates a GLXF file into a GLXFInfo object, adds it to the map of GLXFInfo objects, and sets the GLXF component on the root entity of the GLXF file.
// ImmersiveActivity.kt(your Spatial SDK activity)
private fun loadGLXF() {
  val addCustomComponentMethod: (JSONObject?) -> Entity = { Entity.create(MyCustomComponent()) }
  activityScope.launch {
    glXFManager.inflateGLXF(Uri.parse("apk:///demoproject1.glxf"), overrideCreateEntity = addCustomComponentMethod)
  }
}

Parameters
uri: Uri
  The URI of the GLXF file to inflate.
overrideCreateEntity: Function1
  The function to create a new entity in the glXF, the JSONObject is the glXF node the entity represents, it will be null for the root node which has no glXF JSON associated with it.
rootEntity: Entity
  The root entity of the GLXF file.
keyName: String?
  The key name of the GLXFInfo object to create.
onLoaded: Function1
  The callback function to call after the GLXFInfo object is loaded.
Returns
  The inflated GLXFInfo object, or null if the keyName already exists in the map.
reloadGLXFsFromFile ( oldFileName , newFileName , meshManager )
Reloads GLXFs from a file. This is used for hot reloading glXFs. We recommend not using this unless you know what you're doing.
Signature
suspend fun reloadGLXFsFromFile(oldFileName: Uri, newFileName: Uri, meshManager: MeshManager): 
Parameters
oldFileName: Uri
  The old file name.
newFileName: Uri
  The new file name.
meshManager: MeshManager
  The mesh manager.
Returns
setDefaultCreateEntity ( overrideCreateEntity )
Developer can override the default entity creation function
Parameters
overrideCreateEntity: Function1
  The function to create a new entity in the glXF
setReloadType ( reloadType )
Developer can pick how GLXFs reload. The default reload type of GLXFManager is DELETE_AND_RECREATE_ENTITIES.
Example:
// ImmersiveActivity.kt(your Spatial SDK activity)
// Set reload type to keep existing entities when reloading
glXFManager.setReloadType(GLXFReloadType.KEEP_EXISTING_ENTITIES)
// Or set reload type to delete and recreate entities when reloading (default)
glXFManager.setReloadType(GLXFReloadType.DELETE_AND_RECREATE_ENTITIES)

Signature
fun setReloadType(reloadType: GLXFReloadType)
Parameters
reloadType: GLXFReloadType
  The type of reload to perform.
tryGetGLXFInfo ( keyName )
Returns the GLXFInfo object for the given keyName, or null if it doesn't exist.
Example:
// ImmersiveActivity.kt(your Spatial SDK activity)
val glXFInfo = glXFManager.getGLXFInfo("myKey") ?: return

Signature
fun tryGetGLXFInfo(keyName: String): GLXFInfo?
Parameters
keyName: String
  The key name of the GLXFInfo object to retrieve.
Returns
  The GLXFInfo object associated with the given keyName, or null if it doesn't exist.

Companion Object

Companion Object Functions

isSupportedGLXFExtension ( fileName )
Determine whether a file type can be loaded by GLXFManager into an inflated GLXFInfo
Signature
fun isSupportedGLXFExtension(fileName: String): Boolean
Parameters
fileName: String
Returns
Boolean
  true if the file name is a supported GLXF extension such as .glxf or .gltfx, false otherwise
Did you find this page helpful?