Jump to content

Best practices for changing facet color in custom mesh?


Recommended Posts


I've successfully created a custom mesh:

var vertexData = new BABYLON.VertexData();
// ... fill vertexData ...
var customMesh = new BABYLON.Mesh("custom", scene);

I want to change the color of some triangles in customMesh after it is created.

Which triangles to change is not known until run-time.

 What is the best practices to achieve this? Can I update only the affected part of the mesh data (like using glBufferSubData/glTexSubImage in GL)? 

Thank you very much!

Link to comment
Share on other sites

On 1/7/2017 at 0:50 AM, Deltakosh said:


I suggest using vertex colors: http://www.babylonjs-playground.com/#2KEX2Y


Thank you.

If I use vertex colors, like

sphere.setVerticesData(BABYLON.VertexBuffer.ColorKind, colors);

and I have set all vertex colors to red;

and then I want to change the color of only one vertex to green, 

do I still need to create the whole colors array again?

Is there any way to update only the single vertex to change? (Like using glBufferSubData instead of glBufferData in GL.)

Link to comment
Share on other sites

You don't need to create the color array again as it is passed as a reference.

You just need to change, in this same array, the values of the wanted elements and then call again the updateVerticesData with this same array.

color4Array[66] = 1.0;   // will give the 66/3 = 33 th vertex of the "indices" array
color4Array[67] = 1.0;   // color = (1, 1, 1, 1)
color4Array[68] = 1.0;
color4Array[69] = 1.0;
mesh.updateVerticesData(BABYLON.VertexBuffer.ColorKind, color4Array, false, false);
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.

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.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...