@@ -3,15 +3,17 @@ import { Scene } from "@babylonjs/core/scene";
33import { Observer } from "@babylonjs/core/Misc/observable" ;
44import { PointerInfo } from "@babylonjs/core/Events/pointerEvents" ;
55import { KeyboardInfo } from "@babylonjs/core/Events/keyboardEvents" ;
6+ import { LoadAssetContainerAsync } from "@babylonjs/core/Loading/sceneLoader" ;
7+ import { SceneLoaderFlags } from "@babylonjs/core/Loading/sceneLoaderFlags" ;
68import { IParticleSystem } from "@babylonjs/core/Particles/IParticleSystem" ;
79
810import { IScript } from "../script" ;
911
1012import { applyDecorators } from "../decorators/apply" ;
1113
12- import { isAnyParticleSystem , isNode , isScene } from "../tools/guards" ;
14+ import { isAnyParticleSystem , isMesh , isNode , isScene } from "../tools/guards" ;
1315
14- import { loadScene , SceneLoaderOptions , ScriptMap } from "./loader" ;
16+ import { ScriptMap } from "./loader" ;
1517
1618/**
1719 * Defines the cache of all
@@ -21,7 +23,7 @@ export const scriptAssetsCache = new Map<string, any>();
2123/**
2224 * @internal
2325 */
24- export async function _preloadScriptsAssets ( scene : Scene , rootUrl : string , scriptsMap : ScriptMap , options ?: SceneLoaderOptions ) {
26+ export async function _preloadScriptsAssets ( rootUrl : string , scene : Scene ) {
2527 const nodes = [ scene , ...scene . transformNodes , ...scene . meshes , ...scene . lights , ...scene . cameras ] ;
2628
2729 const scripts = nodes
@@ -61,9 +63,19 @@ export async function _preloadScriptsAssets(scene: Scene, rootUrl: string, scrip
6163 const filename = key . split ( "/" ) . pop ( ) ! ;
6264 const sceneFilename = filename . replace ( ".scene" , ".babylon" ) ;
6365
64- scriptAssetsCache . set ( key , "done" ) ;
66+ // Load asset container
67+ const container = await LoadAssetContainerAsync ( `${ rootUrl } ${ sceneFilename } ` , scene , {
68+ pluginExtension : ".babylon" ,
69+ } ) ;
6570
66- await loadScene ( rootUrl , sceneFilename , scene , scriptsMap , options ) ;
71+ // Ensure all meshes perform their delay state check
72+ if ( SceneLoaderFlags . ForceFullSceneLoadingForIncremental ) {
73+ scene . meshes . forEach ( ( m ) => isMesh ( m ) && m . _checkDelayState ( ) ) ;
74+ }
75+
76+ container . addAllToScene ( ) ;
77+
78+ scriptAssetsCache . set ( key , container ) ;
6779 } else {
6880 const response = await fetch ( `${ rootUrl } ${ key } ` ) ;
6981 const data = await response . json ( ) ;
0 commit comments