jps0611

Possible to createInstance of group with children?

Recommended Posts

Howdy,

Is it possible to create a group that contains a few meshes and then create instances of that group which includes the child meshes? How might one go about doing so? Thus far my attempts to create an instance of the group on creates the transform node but no children.

Thanks!

JPS

Screen Shot 2018-02-12 at 10.09.20 PM.png

Share this post


Link to post
Share on other sites

Hiya JPS, sorry for the slow replies.

https://www.babylonjs-playground.com/#11XV5X#6

I built a little groupInstance() function (lines 41-58).  Works ok, it seems.  Called from lines 61 and 64.

It does it's best to build low-budget instances of groups.  Look it over... holler if you have comments or questions.

PS: I'm far from a pro coder, so, be patient and stay tuned.  Others may have better ideas... soon.  :)

Share this post


Link to post
Share on other sites

My pleasure.  :) We should probably have a built-into-BJS function that does this FOR US, eh? 

Whenever the framework needs to create MANY mesh with one command, the naming of those mesh is a little difficult.  And without naming the generated mesh, scene.getMeshByName() doesn't do so well at FINDING the generated mesh. 

Most BJS functions that generate mesh... "impose" a name onto the generated mesh.  I guess that works, as long as users know the naming-format of the imposed name.

I dunno if these are the real reasons why a groupInstance() function isn't yet core-installed... but maybe.  *shrug*  Thoughts? 

Perhaps not used often enough to warrant core-ifying such a thing.

Share this post


Link to post
Share on other sites

Your solution is awesome @Wingnut.  Interestingly, while investing your solution I discovered I was able to get the children pulled into the created instance. I think I may have had a bug in my code wherein I was only looking at the object in memory...not in the scene. When I've got some time tonight I'll whip up a playground to illustrate. 

Share this post


Link to post
Share on other sites

*nod*.  If you use parent.clone(), the children get installed.  (note: there is a doNotCloneChildren flag... available in the clone() parameters)

If you use parent.createInstance(), the children are left behind.

Soooo... my "clone the parent" method can be extremely streamlined...

https://www.babylonjs-playground.com/#11XV5X#8

No func needed. 

Thanks for teaching me stuff, Jps!  :)  I should read the BabylonJS docs someday, perhaps.  heh.

Sorry if I sent you on a "wild goose chase" (mis-direction).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.