Jump to content

what's the difference between mesh and submesh


guanglei
 Share

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.

Link to comment
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

Link to comment
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.

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