guanglei

what's the difference between mesh and submesh

Recommended Posts

I'm reading the source code, and I'm a bit confused about the difference between mesh and submesh.

So when I call `Mesh.createGround` I created a Mesh(with transform matrix, geometry and material), right? But what is submesh for?

Is that when I set the parent mesh (`groundMesh.parent = sphereMesh`, eg), the groundMesh became a submesh? I'm not sure.

Share this post


Link to post
Share on other sites
3 hours ago, guanglei said:

Is that when I set the parent mesh (`groundMesh.parent = sphereMesh`, eg), the groundMesh became a submesh?

I would say no - by setting the sphereMesh as the parent groundMesh of you have linked the two meshes as parent-child. Now when the parent moves/rotates the child will also move/rotate.  In this case, if you move the sphere (ie: sphere.position.x += 2) then the child mesh (ground) will move with it.

Since you are asking about creating ground - submesh can be used for multi materials.  Here are good links to show what submeshes are:
https://www.eternalcoding.com/?p=283
https://doc.babylonjs.com/features/materials (scroll down to "More Than One Material on a Mesh" for Playground samples)
https://makina-corpus.com/blog/metier/2014/how-to-use-multimaterials-with-a-tiled-ground-in-babylonjs

Share this post


Link to post
Share on other sites

A mesh has 1 to n submeshes, which divide its vertex data to n parts. This is useful for many cases (from collision to Octree, to MultiMatrials and co).

When you create a ground mesh, a mesh is being created, and inside of this mesh, a new submesh is created. 

You can see from the signature:

constructor(public materialIndex: number, public verticesStart: number, public verticesCount: number, public indexStart: number, public indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox: boolean = true);

It is receiving information (index-data) of existing vertex data, but has no internal information of its own.

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.