• Content count

  • Joined

  • Last visited

  1. I had to do both. Implementation of moveAllFromScene is the following. I prefer that this is implemented by the framework in the near future so that any internal changes in the scene object like addition or removal of assets properties will be taken care of as well. import 'babylonjs' export class AssetContainerEx extends BABYLON.AssetContainer { constructor(scene: BABYLON.Scene) { super(scene); } moveAllFromScene(): void { Array.prototype.push.apply(this.actionManagers, this.scene._actionManagers); Array.prototype.push.apply(this.animations, this.scene.animations); Array.prototype.push.apply(this.cameras, this.scene.cameras); Array.prototype.push.apply(this.geometries, this.scene.getGeometries()); Array.prototype.push.apply(this.lensFlareSystems, this.scene.lensFlareSystems); Array.prototype.push.apply(this.lights, this.scene.lights); Array.prototype.push.apply(this.materials, this.scene.materials); Array.prototype.push.apply(this.meshes, this.scene.meshes); Array.prototype.push.apply(this.morphTargetManagers, this.scene.morphTargetManagers); Array.prototype.push.apply(this.multiMaterials, this.scene.multiMaterials); Array.prototype.push.apply(this.skeletons, this.scene.skeletons); Array.prototype.push.apply(this.particleSystems, this.scene.particleSystems); Array.prototype.push.apply(this.sounds, this.scene.mainSoundTrack.soundCollection); Array.prototype.push.apply(this.transformNodes, this.scene.transformNodes); this.removeAllFromScene(); } }
  2. My codes are all in typescript as I know little javascript. Unfortunately the playground takes only javascript. That said though, @brianzinn has wrote nice sample code: http://playground.babylonjs.com/#JA1ND3#48 that illustrates similar situation. Notice how he created only a single object of scene and vr object and iterates each scene container and loads them into the scene object. If you are using VR headset, this is the only way to switch scenes afaik. Doing otherwise will result in the scene rendered incorrectly in the vr headset. What I am trying to do is similar to this except that I don't use screen loader, I programmatically create the assets. I agreed with your statements that switching scene is a complex op, that's why I'd rather avoid using AssetContainer, but currently this is the only options I can think of. So far the approach I describe above (to juggle the assets using the containers) seem to work. But there is this weird thing about how the .cameras properties not showing up in the scene - I am still trying to figure out the root cause.
  3. @trevordev thanks for the input. In that case, then I think we should add into 3.2 release the helper method called something like AssetContainer.moveAllFromScene which does the steps I described. I think many users will benefit from this. In retrospect, perhaps the better approach is not to expose the AssetContainer at all. The root issue is that the current BABYLON.Scene and its vr helper object can only be used as singleton (even if you intend to create multiple scenes), otherwise you will see rendering problem inside the VR headset. A high-level abstraction of Scene concept that internally manages its assets as user switches scenes would be a cleaner approach, imo. Another approach is not to make vr helper associated with scene but rather make it explicitly global entity.
  4. I wonder if the following approach will work (not ideal, but a bit more manageable) 1. Create all the needed assets (meshes, cameras, lights) as usual into the scene object. 2. Enumerate all asset array properties of the scene object like scene.camera, scene.lights, scene.animations, etc) and manually copy them into the corresponding array properties in the asset container object. (Question: does the asset container has all of the asset array properties of the scene object ? if not this approach won't work) 3. call assetContainer.removeAllFromScene() I guess, this will cleanly 'move' all the assets from the scene object to the container object. Any comments ?
  5. It seems to me that there is no direct way to create asset (light, camera, meshes etc) and add it into the asset container. What I am trying to do is the create the assets programmatically (not using load scene) into an container without polluting the scene object itself. The typical code fragment to create/add an asset into a container looks like the following: scene: BABYLON.Scene; assets: BABYLON.AssetContainer; ... let camera = new BABYLON.FreeCamera(... , scene); scene.removeCamera(camera); assets.cameras.push(camera); Basically it has to be done in 3 steps: 1. create/add the asset into scene (all existing api to create mesh takes the scene object) 2. remove asset from scene 3. add the asset to container This is true for all other asset types like light, meshes, animations etc. Is there an easier to do this (like doing in 1 step?) Please advise. Thanks
  6. BABYLON.AssetContainer usage

    thanks @brianzinn. I am looking into the sample codes now. @Deltakosh you guys are awesome!
  7. Looks like the AssetContainer is now included in alpha4, but I can't find much docs on how to use it. Could someone please post codes to the bjs playground that show the usage ? I am planning to use this for switching scenes reliably in vr mode. Thanks
  8. @deltakosh, is the container included in 3.2-alpha2 ?
  9. @deltakosh good to hear and thanks for the fix. Btw, when is the eta for 3.2 release ?
  10. @brianzinn, thanks for the confirming this is a known issue. I guess I can work around it by creating my own virtual session objects which is based on single babylonjs.session object. But look forward to the fix in 3.2.!
  11. Well I remembered Deltakosh mentioned this but I am not using full screen UI though. It won't even render properly in any scene. The first scene with button works just fine but as soon as I switched to the second scene, I am seeing double vision.
  12. I have a test app with 2 sessions which I can switch back and forth by clicking a button (thanks to the new UI). The rendering of both sessions works as expected in the browser (non-vr), but not quite when I go into the vr mode. When viewing in vr headset (using wmr odyssey), I am seeing double vision when switching session. I am guessing this has something to do with VRExperienceHelper which is created per scene object (via Scene.CreateDefaultVRExperience()). Probably it's not safe to create more than one instances of the vr helper object ? But then what should you do when you have multiple session objects ? Please advise, thanks.
  13. @deltakosh, thanks for the answer. Do I need to worry about calling engine.stopRenderLoop() when switching scene ? Let's say I have 3 scene objects: scene1, scene2, scene3 and want to render them in that order. Then should the following samples work ? engine.runRenderLoop(() => {scene1.render();}); ... engine.runRenderLoop(() => {scene2.render();}); ... engine.runRenderLoop(() => {scene3.render();});
  14. Another related questions: Is it possible to have 2 different canvases, each with its own scene, and render both scenes at the same time ?
  15. Hello, I have newbie questions: If I have multiple scenes in my app, I wonder if we should keep 1 global singleton BABYLON.Engine object which alternates between scene objects or having one engine object for each scene. I did try the latter (1 engine per 1 scene) which seems to work, but I don't know if this is the proper/efficient use of the engine object. Also, what's the most appropriate way/api to use to switch between scenes ? Do I need to manually dispose the scene object if it's no longer used ? Is BJS smart enough to garbage-collect those unused objects ? Thanks.