Asset Loading
rooomSpaces Viewer API asset loading for dynamic virtual environments. Import 3D models, meshes, and asset containers to enhance and customize virtual spaces.
loadAssetContainer
loadAssetContainer(rootUrl: string, filename: string, options?: object, [callback: Function])
Loads an asset container with multiple 3D objects, materials, and textures. This function is ideal for loading complete scenes or complex multi-part objects.
Parameters:
rootUrl: string- Base URL path for the scene and its resourcesfilename: string- Filename of the asset or "data:" string for inline contentoptions?: object- Optional loading configuration (see IImportMeshOptions)
Returns: Array of root mesh IDs from the imported asset container
// Load a furniture set asset container
api.loadAssetContainer(
'https://assets.example.com/furniture/',
'living-room-set.glb',
{
transform: {
position: [0, 0, 0],
rotation: [0, 0, 0],
scaling: [1, 1, 1]
},
cloneMaterials: true,
collider: true,
hidden: false
},
function(meshIds) {
console.log('Asset container loaded with meshes:', meshIds);
}
);importMesh
importMesh(rootUrl: string, filename: string, options?: object, [callback: Function])
Imports a single 3D mesh or model into the virtual space.
Parameters:
rootUrl: string- Base URL path for the mesh and its resourcesfilename: string- Filename of the mesh or "data:" string for inline contentoptions?: object- Optional import configuration (see IImportMeshOptions)
Returns: Unique ID of the imported root mesh
// Import a single product model
api.importMesh(
'https://products.example.com/models/',
'chair-modern.glb',
{
transform: {
position: [2, 0, -1],
rotation: [0, 45, 0],
scaling: [1.2, 1.2, 1.2]
},
playAnimation: true,
collider: true,
hidden: false
},
function(meshId) {
console.log('Mesh imported with ID:', meshId);
}
);Import Options Configuration
The options parameter supports the following configuration:
interface IImportMeshOptions {
meshNames?: string[]; // Specific mesh names to import
skeletonsEnabled?: boolean; // Enable skeletal animations
playAnimation?: string | boolean; // Auto-play animations
transform?: { // Initial transformation
position?: [number, number, number];
rotation?: [number, number, number];
scaling?: [number, number, number];
};
instanceTransforms?: object[]; // Multiple instance transforms
cloneMaterials?: boolean; // Clone materials for independent editing
doNotInstantiate?: boolean; // Load without instantiating
collider?: boolean; // Add collider to the imported mesh
hidden?: boolean; // Hide the imported mesh
}Performance Considerations
Optimization Tips:
- Load assets progressively based on user proximity or interaction
- Use
doNotInstantiate: truefor pre-loading without immediate display - Clone materials only when independent customization is needed
- Consider file size and complexity when loading multiple assets
Memory Management:
- Remove unused assets to free memory
- Use asset containers for related objects to optimize loading
- Monitor loading progress and provide user feedback