Type Alias: LoadModularScene()
LoadModularScene = (
shortCode
,isAutosave?
,disableAutoZoom?
,isFav?
,config?
) =>Promise
<void
>
Loads a saved modular scene state with complete product initialization.
This function provides comprehensive scene loading functionality, handling everything from product fetching to configuration validation. It serves as the programmatic equivalent of the modular scene loading UI, but with additional control over the loading process.
Key Features:
- Automatic Product Loading: Detects and loads any missing products from JSON files or API
- Localization Support: Translates all product data based on current locale settings
- Asset Management: Loads 3D models, textures, and 2D images for each product
- Configuration Validation: Validates and auto-corrects invalid configuration codes
- State Restoration: Fully restores selected options from configuration codes
- Business Logic: Applies all constraints and rules during loading
- History Tracking: Maintains selection history for undo/redo functionality
- Loading State Management: Updates UI loading state through Redux dispatches
Loading Process:
- Clears current scene and selections
- Loads scene data (from shortcode or config)
- Identifies required products
- Fetches missing products and assets
- Validates configuration codes
- Restores all selections
- Updates scene with proper positioning
- Applies camera settings (unless disabled)
Parameters
shortCode
Nullable
<string
>
The unique identifier of the saved scene to load.
Pass null
when loading from autosave.
isAutosave?
boolean
Set to true
to load from the autosaved state instead
of a specific shortcode. Default is false
.
disableAutoZoom?
boolean
When true
, prevents the camera from automatically
zooming to fit the loaded scene. Useful when you want
to maintain the current camera position. Default is false
.
isFav?
boolean
Indicates whether this scene is being loaded from the user's
favorites. This affects how the loaded state is tracked. Default is false
.
config?
ModularSavedState
The complete configuration object for autosave scenarios.
Required when isAutosave
is true
, ignored otherwise.
Returns
Promise
<void
>
A Promise that resolves to void
when the scene has been fully loaded with all
products, assets, and configurations properly initialized. The Promise
will reject if any critical step in the loading process fails.
Throws
"No modular product loaded" - When called without an active modular product
Throws
"Either shortCode or config (with isAutosave) must be provided" - When missing required parameters
Throws
"Scene with shortcode {shortCode} not found" - When the specified scene doesn't exist
Throws
"Failed to load layout:" - When scene processing fails due to any error during loading
Throws
Various product loading errors - When required products cannot be fetched
Examples
// Load a specific saved scene
try {
await window.mimeeqApp.actions.loadModularState('F95SNI');
console.log('Scene loaded successfully');
} catch (error) {
console.error('Failed to load scene:', error);
}
// Load a scene from favorites without auto-zoom
await window.mimeeqApp.actions.loadModularState('F95SNI', false, true, true);
// Load from autosave with a configuration object
const autosaveConfig = await getAutosaveConfig(); // Your method to get config
await window.mimeeqApp.actions.loadModularState(null, true, false, false, autosaveConfig);
// Implement a custom scene selector with loading states
const sceneSelector = document.getElementById('scene-selector');
const loadButton = document.getElementById('load-btn');
loadButton.addEventListener('click', async () => {
const selectedScene = sceneSelector.value;
const loadingSpinner = document.getElementById('loading');
try {
loadingSpinner.style.display = 'block';
loadButton.disabled = true;
// Load without auto-zoom to preserve user's view
await window.mimeeqApp.actions.loadModularState(selectedScene, false, true);
// Update UI to show success
showSuccessMessage('Scene loaded successfully!');
} catch (error) {
// Handle specific error cases
if (error.message.includes('not found')) {
alert('This scene no longer exists');
} else {
alert('Failed to load the scene. Please try again.');
}
} finally {
loadingSpinner.style.display = 'none';
loadButton.disabled = false;
}
});
Note
The function returns early without error if the scene payload has no product elements, after clearing the loading state.