Jump to content

How to merge or append scenes and keep context? Append filter support?


kevzettler
 Share

Recommended Posts

I have an existing scene made in Babylon.js (scene1) I have a `.babylon` file (scene2) I want to append to scene1.  Before appending scene2 to scene1 I want to do some operations on the meshes of scene2.  `BABYLON.SceneLoader.Append` just immediately dumps everything from scene2 into the scope of scene1. This is not helpful. I have a lot of meshes in scene2 and scene1 with dynamic names so it's a lot of work to manually go through the merged array and look for the meshes that were in scene2.

I was hoping I could use `BABYLON.SceneLoader.Load` for this. Load scene2, iterate over the scene2 meshes, then manually add them to scene1. Maybe I've missed something but, it doesn't like there is straightforward support for this. Seems like `BABYLON.SceneLoader.Load` is designed to load an initial scene only.

Link to comment
Share on other sites

Hi kev :)

I'm not sure if this would be called a "hack" or not, but this is the approach that I would take using Blender (I assume 3DMax has a similar feature).

In Blender with the meshes of scene 1, I would create an Empty named "Scene1" and parent all the meshes in the scene to that Empty. Then repeat this with Scene2 but just change the name of the Empty to Scene2.

Now in code I can

var scen2 = scene.getMeshByName("Scene2");
var scen2Meshes = scene2.getChildren();

You can also get the meshes for Scene 1 this way.

cheers, gryff :)

 

Link to comment
Share on other sites

1 hour ago, kevzettler said:

Lots of my meshes are parented to an armature

Well @kevzettler : that kind of moves the goalposts a wee bit ;).

It might help if you could describe scenes 1 and 2 a little more. Do both scenes have armatures? How many armatures in each scene? Are there meshes not bound to the armatures(s) in one or both scenes? How many meshes are bound to the armatures?

And going back to your original post what do you mean by "dynamic names"? In fact what are you trying to accomplish?

Depending on your answers, it may require someone with better coding skills than gryff :o

cheers, gryff :)

Link to comment
Share on other sites

I would use the Blender option to freezeWorldMatrix for your static stuff.  You could then use that to detect your background meshes.  This is NOT a hack.  It's a hack not to freeze background geometry :P.

SceneLoader.Load is / was depreciated.  It is implemented as a wrapper of SceneLoader.Append anyway, so I am not aware of any thing Load can do that Append cannot.  You can avoid problems referencing the scene object defined Load, and messy callbacks that result with using more than 1 .babylon file.

You could also use importMesh and get the list of contained meshes in the callback.

Link to comment
Share on other sites

Quote

I would use the Blender option to freezeWorldMatrix for your static stuff.  You could then use that to detect your background meshes.  This is NOT a hack.  It's a hack not to freeze background geometry :P.

1

I should have clarified The static scenes are all manually created in Babylon at the moment. Appreciate the tip though.

Quote

You could also use importMesh and get the list of contained meshes in the callback.

This actually looks exactly what I need. A callback to tell what has been loaded is what I would expect here. Thanks @JCPalmer

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