Jump to content

Strange results when Transferring Meshes Between Scene


JohnK
 Share

Recommended Posts

Sorry folks here I am again doing strange things and getting strange (to me) results.

 

What follows are descriptions of:

 

  1. what I am trying to do;
  2. how I am trying to do it;
  3. the issues that arise;
  4. the code I am trying with demo in playground;
  5. other thoughts and attempts;
  6. 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 sceneA

start 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.

 

gb2.JPG   green and blue boxes from sceneA added to red box of sceneB gbr1.JPG

 

However when I only push one box into scenB.meshes the material of the box picks up the red material from sceneB

 

gb2.JPG   only green box from sceneA added to red box of sceneB rr1.JPG

 

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 playground

function 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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...