JCPalmer Posted March 3, 2016 Share Posted March 3, 2016 I am kind of tired of people using the inferior SceneLoader.Load() over SceneLoader.Append() and hearing about all their avoidable problems. Every time I mention Append(), I get at most a "well, I'll think about trying it". Append() came about because @Vousk-prod. wanted to have multiple .babylon files, and was doing all these back flips. I looked at the source, and saw all I had to do is change the name of the Load() function to Append, switch the engine arg for a scene arg, then make a 1 line wrapper for Load. public static Load(rootUrl: string, sceneFilename: any, engine: Engine, onsuccess?: (scene: Scene) => void, progressCallBack?: any, onerror?: (scene: Scene) => void): void { SceneLoader.Append(rootUrl, sceneFilename, new Scene(engine), onsuccess, progressCallBack, onerror); } /** * Append a scene * @param rootUrl a string that defines the root url for scene and resources * @param sceneFilename a string that defines the name of the scene file. can start with "data:" following by the stringified version of the scene * @param scene is the instance of BABYLON.Scene to append to */ public static Append(rootUrl: string, sceneFilename: any, scene: Scene, onsuccess?: (scene: Scene) => void, progressCallBack?: any, onerror?: (scene: Scene) => void): void { ... } So when you call Load(), you are Appending. Creating a scene outside of the Load call means you do not need to add your render loop in the callback. All the scope problems for your scene variable are also gone. Having more than one .babylon is just 2 simple Appends. Callbacks are also stupid, and do not scale. As soon as you have more than 1 .babylon, they become a nightmare. Just do all your Append()'s & ImportMesh()'s, then have all your post load code below inside a blocking executeWhenReady function. var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); var scene = new BABYLON.Scene(engine); BABYLON.SceneLoader.Append("./", "scene.babylon", scene); BABYLON.SceneLoader.ImportMesh(["moe","larry","curly"], "./", "meshes.babylon", scene); scene.executeWhenReady(function () { // Attach camera to canvas inputs scene.activeCamera.attachControl(canvas); // Once the scene is loaded, register a render loop engine.runRenderLoop(function() { scene.render(); }); // any post load code grabbing all stuff using scene lookups var skeleton = scene.getSkeletonByName("myskelname"); var material = scene.getMaterialByName("mymaterial"); var camera = scene.getCameraByName("polaroid"); var bone = scene.getBoneByName("funny"); var light = scene.getLightByName("spot"); var node = scene.getNodeByName("node"); var mesh = scene.getMeshByName("cube"); var sound = scene.getSoundByName("talking"); var flare = scene.getLensFlareSystemByName("flare"); }); Problems with callbacks for ImportMesh that reference the mesh as mesh[0] are also fixed. Usually, the problem is either [0] is the wrong mesh or there wasn't anything actually loaded. Specifying by name in a executeWhenReady should either get the right mesh, or drive home the problem that nothing was done quicker. Might be a good idea to add optional logging capability to Append (and therefore Load) and ImportMesh to list what actually got done. Load must die! Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 3, 2016 Share Posted March 3, 2016 I agree with that. I find this more convenient than Append Load. Perhaps a name change as: - NewScene() (Load() current) - AddScene() (Append() current) would be good or replace Append() on the Load() function. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 3, 2016 Share Posted March 3, 2016 Sorry no breaking changes... I completely agree on JCP point. But for compat reason we have to keep Load alive Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted March 3, 2016 Share Posted March 3, 2016 I agree with DK, we got to keep Load for compat. To address JCP smart request (advise people to preferably use Append) we could simply mention it in the doc, and maybe add a "deprecated" comment in the src. Boz and webGLmmk 2 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted March 4, 2016 Author Share Posted March 4, 2016 Adding a depreciated message to the browser console was what I wanted. This is consistent with other discouraged features. I just threw that "load must die" crack in at the end as sort of a call to action. I thought DK was referring to name changes dad72 added. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 4, 2016 Share Posted March 4, 2016 yes, I was not thinking breaking changes to avoided when I say this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.