zhutq Posted January 6, 2017 Share Posted January 6, 2017 Hi, I've successfully created a custom mesh: var vertexData = new BABYLON.VertexData(); // ... fill vertexData ... var customMesh = new BABYLON.Mesh("custom", scene); vertexData.applyToMesh(customMesh); 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! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 6, 2017 Share Posted January 6, 2017 Hello I suggest using vertex colors: http://www.babylonjs-playground.com/#2KEX2Y Quote Link to comment Share on other sites More sharing options...
zhutq Posted January 9, 2017 Author Share Posted January 9, 2017 On 1/7/2017 at 0:50 AM, Deltakosh said: Hello 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.) Quote Link to comment Share on other sites More sharing options...
jerome Posted January 9, 2017 Share Posted January 9, 2017 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.