JohnK Posted May 29, 2015 Share Posted May 29, 2015 Sorry folks here I am again doing strange things and getting strange (to me) results. What follows are descriptions of: what I am trying to do; how I am trying to do it; the issues that arise; the code I am trying with demo in playground; other thoughts and attempts; why I am trying to do it (for those interested in why I do these weird things); I fully expect that those who get as far as 2 will tell me I am going about it the wrong way and I should be doing X, Y, Z not A, B, C to achieve 1. In which case I will do X, Y and Z. 1 What I am trying to do I create two scenes, sceneA and sceneB, using the same engine and canvas but containing different meshes. I start by viewing sceneA. At some point I want to swap from sceneA to sceneB transferring some but not all meshes from sceneA to sceneB and then viewing sceneB. Thanks to RanaanW I can export a scene from one program and then read from it a saved mesh into a different program. I want the above to happen within one program (webpage). 2 How I am trying to do it. Basically create meshes in sceneA and then sceneB and render sceneA. Then on swap push the required meshes from sceneA to sceneB.meshes;stop rendering sceneAstart rendering sceneB 3 The issues that arise In sceneA I create a blue box and a green box. In sceneB I create a red box. When I push two boxes into sceneB.meshes the materials of the two boxes are transferred. green and blue boxes from sceneA added to red box of sceneB However when I only push one box into scenB.meshes the material of the box picks up the red material from sceneB only green box from sceneA added to red box of sceneB The other issue is that in both cases I can move the camera in sceneB but only the red box originally created in sceneB responds to the camera movement. 4 The code I am trying with demo in playgroundfunction onswap() { sceneB.meshes.push(box0); sceneB.meshes.push(box1); engine.stopRenderLoop(); // Register new render loop to repeatedly render the sceneB engine.runRenderLoop(function () { sceneB.render(); });}In the playground the swap is carried out by clicking on the 'Frames Per Second' counter. ***********************************************WARNING ***************************************************After clicking on the fps counter YOU MUST REFRESH the webpage before RUNning it again.Any major changes you might make should be saved before RUNning.************************************************WARNING ***************************************************//click playground fpLabel to switch scenesdocument.getElementById('fpsLabel').addEventListener("click", function () { sceneB.meshes.push(box0); sceneB.meshes.push(box1); engine.stopRenderLoop(); // Register new render loop to repeatedly render the sceneB engine.runRenderLoop(function () { sceneB.render(); });}, false);The demo 5 Other thoughts and attempts I have tried transferring sceneA.materials to sceneB.materials but perhaps I got this wrong. I have thought about reading the data from a mesh including type (box, sphere, cylinder etc), position, rotation, material etc and then using BABYLON.Mesh.Create....... to reconstruct the mesh in sceneB but if there is a lazy way of doing it, like using sceneB.meshes then I am all for it. 6 Why I am trying to do it I am at the beginning of a project that is attempting to do the following. In sceneA construct a 'model' using basic BJS elements (Think children's building blocks). When the model is completed switch to sceneB and add the finished model to sceneB. The basic thinking is that sceneA is a model construction site and sceneB is where the models are combined to make scene. For example in the construction site you could build different dwellings, benches, fences, trees etc that can then be added to the main scene. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 29, 2015 Share Posted May 29, 2015 Hello, this is crystal clear. I like that! So if you want to transfer a mesh, you also have to transfer mesh.material Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 29, 2015 Share Posted May 29, 2015 But if you just want construction site, why not creating your mesh with mesh.setEnabled(false) ? Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 29, 2015 Author Share Posted May 29, 2015 But if you just want construction site, why not creating your mesh with mesh.setEnabled(false) ? because I did not know it existed and now I do I am still ignorant of what it does or why it helps. I only found BJS two weeks ago and as much as I love it I am still learning and while I can find things I recognise like scene.meshes and say to myself that is just an array of the meshes for the scene and so I will try pushing my meshes into it I am still at a loss at the inner workings and how many of the methods can be used. By the way I have gathered and believe you are the (a) creator of BJS and as I said I love it and the help you get on this forum. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 29, 2015 Share Posted May 29, 2015 so yes the best idea for you would be to use setEnabled. when a mesh is disabled it does not cost any perf so this could do the work for you:) JohnK 1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 30, 2015 Author Share Posted May 30, 2015 I think I understand what you are suggesting. Instead of swapping between sceneA and sceneB have just one scene which is displaying either the construction site or the model site. To switch from the construction site to the model site - for each mesh not wanted in the model site use mesh.setEnabled(false) and apply mesh.setEnabled(true) to the meshes in the model site that were not wanted in the construction site. Can see the advantages of this, though I can see it would produce some other issues I would need to address but could perhaps be overcome using instances. I'll give this a try. Quote Link to comment Share on other sites More sharing options...
Temechon Posted May 30, 2015 Share Posted May 30, 2015 Like this: http://www.babylonjs-playground.com/#16MOW9 Good luck 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.