I’m trying to dynamically adjust a single side of a mesh’s face colour. The reason for this is I don’t want to regenerate the whole mesh. Most of my modelling/mesh adjustment technique has been to modify the base values (mostly vertices) of elements by tweening them for nice animations.
Now that I have a need to adjust the face colour I hit a bit of a snag. I’ve developing a picture frame that has dynamic details you can customise. In this case the user should be able to modify the bevel colour of a “mat” element:
The black stroke is the bevel element. The mesh itself is generated from an ExtrudedPolygon:
const horizontalStick = MeshBuilder.ExtrudePolygon('HS1', {
shape: standardShape,
depth: this.matDepth,
faceUV,
faceColors
});
My face colours are generated like so:
[
new Color4(1, 1, 1, 1),
colour == null ?
new Color4(0.75, 0.75, 0.75, 0.1) :
Color4.FromHexString(colour),
new Color4(1, 1, 1, 1)
]
This works well. Now when I want to dynamically adjust the colour, according to the docs I have to grab the vertice’s data, adjust it then re-set it:
let positions = mat.getVerticesData(VBuffer.ColorKind);
... (adjust the values here)...
mat.getVerticesData(VBuffer.ColorKind, positions)
When I log the positions I get a buffer of values:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
I’m assuming that’s a buffer representation of the face colours. I suspect I have to find the position that represents the black part of my frame (likely the 1’s in the buffer) and replace them with rgb values of my new colour?
The question is what positions within this buffer do I need to modify? Is there a more efficient way of doing this?