Jump to content

Split mesh based on vertex colour or hide unwanted vertex colours


babbleon
 Share

Recommended Posts

Thank you @PsichiX,

I have a mesh which is exported from Blender. Separate faces have different vertex colours.

I would like to be able to click on any particular part and it will delete the vertices that have that particular vertex colour and then create a new mesh from the previously deleted vertices.

At the moment, when you click on it the selected vertices just get set to 0,0,0 and so are invisible.

Here's a PG: https://playground.babylonjs.com/#44X0M9#10

Link to comment
Share on other sites

It’s not that simple vertices share faces that are on separate colors.  You would need to do a flood fill algo basically and iterate over the points gather out the points that you need, mark the ones that are sharing faces,  pull the buffer out and the repair the other one.  I’ve tried to examine that it’s not simple and is very limited on scope.  Especially when it will be hard to establish the vertices that are a different because they are a border to anouther color region and won’t be the same color as initially looking for.

The better way is to have the mesh seperated already on inport. 

Link to comment
Share on other sites

I have altered the approach on this.

In short & in the absence of a better idea, I load a mesh and create x number of new meshes where x = number of unique vertex colours and set all vertex positions on each new mesh to 0 where they do not match the current vertex colour.

PG here: https://playground.babylonjs.com/#44X0M9#28

The problem I'm having is that the vertex positions taken from the original loaded mesh do not correctly update on each distinctVertexColours loop.

If you uncomment lines 72,73,74 and comment out 79,80,81 you will see the problem a bit more clearly.

Does anyone have any bright ideas as how to fix this?

Thank you.

 

Link to comment
Share on other sites

  • babbleon changed the title to Split mesh based on vertex colour or hide unwanted vertex colours

some remarks:

- line #91 is a duplicate of the applyToMesh API

- Not sure to understand what would be the expected result if I uncomment the lines your mentioned. Can you elaborate on that?

Link to comment
Share on other sites

Thank you @Deltakosh - problem is still there if I comment out #91, but good to know.

below is extract with comment about the bits of the loop

for (l = 0; l < colors.length; l += 4)
{
	if (colors[l + 0] == distinctVertexColours[k][0] && colors[l + 1] == distinctVertexColours[k][1] && colors[l + 2] == distinctVertexColours[k][2])
	{
		///sets vertices to 0 position if they have vertex colour in loop
		//positions[((l / 4) * 3) + 0] = 0;
		//positions[((l / 4) * 3) + 1] = 0;
		//positions[((l / 4) * 3) + 2] = 0;
	}
	else
	{
		///sets vertices to 0 position if they do not have vertex colour in loop
		positions[((l / 4) * 3) + 0] = 0;
		positions[((l / 4) * 3) + 1] = 0;
		positions[((l / 4) * 3) + 2] = 0;
	}
}

 

Link to comment
Share on other sites

ah, I see!

As it stands now - I would expect to see x number of meshes (5 or 6) from left to right:

  • 1st being the original mesh
  • 2nd is correct
  • 3rd with only faces of another vertex colour
  • and so on

Each of the new meshes would only have one single vertex colour and only be parts of the original mesh.

If you uncomment lines 72,73,74 and comment out 79,80,81 all it would do if instead of hiding all but the chosen vertex colour, it would hide all other. 

Hope I am explaining properly.

 

Link to comment
Share on other sites

Yes and no... I do not understand the necessity to do things outside of normal scope.

When you construct the mesh with vertex colors you are still having to go through and edit the mesh and set vertex colors, which takes just as much time as splitting the mesh up in your program.

This just adds a bunch more steps... you are basically making bjs do what you should have just done in your 3d program.


You could use this process though with this:
http://www.babylonjs-playground.com/#36TFT6#15
... like I said at that point you are just adding extra steps and making more work for yourself.

but ill go ahead and enable the stuff to this new process, cause its easier to say yes and just do it then bother with conversation especially when its specifically what you want.

I'm on it.

Link to comment
Share on other sites

Hi @Pryme8,

Simply put, it's something I then wont have to do in Blender.. a real pain if I have modifiers which I invariably do. Not an issue if I am doing one model, but if i am doing say 6 models per day then it all stacks up. Much better BJS does the work on import than me.

Thank you for agreeing to implement this.

Cheers,

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