Jump to content

Create a container mesh


3Dlove
 Share

Recommended Posts

Hello everybody :-)

 

I would like to create a mesh containing several meshes.

 

Because, currently, I use a loop to generate meshes, 100 meshes for instance, just in order to create a wall.

And if I want clone this wall, it's impossible because I have to clone the all 100 meshes.

 

1- And the Meshes Tree is ugly with these 100 meshes, is it possible to not show a mesh in the Meshes Tree ?

 

2- Is it possible to create a mesh which contains other meshes ?

 

 

Here is my example, I simplify it with grey and green materials, but in my project, I have materials more complex.

http://www.babylonjs-playground.com/#SFWRR#1

 

Thanks for your help :)

Link to comment
Share on other sites

Sure meshes can be parented to a designated parent.  When cloning of the parent, the children are also done.

childMesh.parent = parentMesh;

If you are just building "bricks", 100 meshes is probably not the way to go.  There is overhead for each mesh every frame.  Unless you also have 100 materials, think the overhead should be less with 100 sub-meshes. 

 

You might want 1 mesh with 100 sub-meshes. You could still create the 100 Meshes use createPlane, assign all the materials, & relative positions.  When ready merge the meshes.  Search merge meshes or look in doc, I do not have it in my code base to give an example.  

Link to comment
Share on other sites

Okay for parent and childrens :)

 

I tried to use createInstance in order to have better performances

 

here is my updated example : http://www.babylonjs-playground.com/#SFWRR#2

 

but with createInstance, the merging isn't working I believe.

Without, that work but there is a problem with materials, just the 1st used material is applicated to the merged mesh.

 

 

In fact, I would like to create a wall with metal bars and windows, the thing is that I don't know the width's wall because it's dynamic, the width can be 50, and 100 in another case. The height is constant.

So I have just 2 materials (window and bar), but many replicated windows and bars.

 

Tell me if I'm not really understandable ;)

Link to comment
Share on other sites

Hi again, 3D!

  I am off-topic, but, why merge?  Trying to get performance up?

 

And why all the computeWorldMatrix?  You're trying to take over the world, aren't you?  ;)

 

I made another: http://www.babylonjs-playground.com/#SFWRR#3  I turned-off the merging and the computes... and the debug layer... just to see if any of it was necessary.  Seems to work fine without those things.  But I think 3DLove has a bigger plan in mind.

 

One way to solve your dynamic wall size... is to use PERCENT.  For example, no matter the wall length, your first window begins 18% from the left edge.  Your first window occupies the location 18-22% (it is 4% wide). 

etc, etc.

 

When you work in percentages (of dynamic wall size), it all scales perfectly... in theory.  :)

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