I’m currently looking into scene loading again and after looking through the source code on github I now have a few questions:
First: The implementation of both pc.app.scenes.loadSceneHierarchy and pc.app.scenes.loadSceneSettings suggests that we need to pass a SceneRegistryItem in order to load the hierarchy or the settings respectively. But actually we need to pass the url of the SceneRegistryItem instead. Passing the object itself will result in an error and the scene cannot be loaded. Here I’m just confused as to why that is?
Second: I also stumbled upon pc.app.scenes.loadScene which I didn’t know about until now. When we currently change to a different scene, we always do something like this:
var oldHierarchy = pc.app.root.children[0];
var scene = pc.app.scenes.find(sceneName);
pc.app.scenes.loadSceneSettings(scene.url, (err) => {
if (!err) {
pc.app.scenes.loadSceneHierarchy(scene.url, (err, parent: pc.Entity) => {
if (!err) {
oldHierarchy.destroy();
} else {
console.error(err);
}
})
}
});
Is this interchangeable, can I just change the code to something like the following to make sure that the new scene is fully loaded?
var oldHierarchy = pc.app.root.children[0];
var scene = pc.app.scenes.find(sceneName);
pc.app.scenes.loadScene(scene.url, (err) => {
if (!err) {
oldHierarchy.destroy();
} else {
console.error(err);
}
});
I’m asking because the description of this function specifically says that this is an internal function, but doesn’t describe it as a private function.
Actually that’s a good question. I’ve been using myself app.scenes.loadScene() for a while. The comment indeed points that this is an internal method, though I feel that’s an older comment?
I think there has been a motion to move most of the scene loading methods from pc.Application to the pc.SceneRegistry.
Master is showing 1.40.0-dev release where there’s a refactor on the API.
1.39.X release (which is what we are on now) is still expecting an URL to the scene JSON file.
Do not use loadScene if possible. It was made public for engine only users and requires private API usage to work correctly. The new API in 1.40.0 will allow you to preload and cache scene JSON data to avoid further HTTP requests on calls to loadSceneHiearchary and loadSceneSettings.
Ok, so it’s best if we keep out current process of loading a new scene, right? Will we have to do the scene caching manually, or will it be handled automatically?
And as for the next release, we will have to change our parameters as soon as 1.40 is released? Will this release break our current system, or will it be backwards compatible for a little while?