# Combining Meshes / SubMeshes

## Recommended Posts

I'm trying to wrap my head around submeshes so that I can built something similar to BABYLON.Mesh.MergeMeshes, but maintain separation via sub-meshes and materials via mutlimaterial

In this PG, http://www.babylonjs-playground.com/#28EUMN#21, I cannot seem to comprehend the relationship of indexStart and indexCount

The same goes for this PG, http://www.babylonjs-playground.com/#1FSS3J - how do I color both faces of the Y axis?

##### Share on other sites

Let's imagine you have 30 indices (10 faces).

IndexStart for the global object = 0

IndexCount for the gobal object = 30

Now let's say you want to create a submesh for face 1 to 3:

indexStart = 3 (index 0, 1 and 2 are for the first face)

indexCount = 3 * 3 (3 faces)

Does it makes sense?

##### Share on other sites

Somewhat. In the 2nd PG example, how would I go about making the positive Y face(s) green as well? I think this would help clear it up for me.

I expected this to work:

`var submesh1 = new BABYLON.SubMesh(0, 0, verticesCount, 0, 12, box);var submesh2 = new BABYLON.SubMesh(1, 0, verticesCount, 12, 12, box);var submesh3 = new BABYLON.SubMesh(2, 0, verticesCount, 24, 12, box);`

24 vertices & 36 indices total

Scratch that, I copied from another PG example and didn't notice it was using emissiveColor. It does show it working as expected now that it's diffuseColor: http://www.babylonjs-playground.com/#1FSS3J#1

The sphere one was tricky to me because of the numbers it used. I understand now the numbers depend on the segments used in the sphere. Here's a PG with even numbers! http://www.babylonjs-playground.com/#28EUMN#22

Thanks for helping me clear this up!

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.