I’m trying to add vertex colors to a primitive box model which uses a StandardMaterial. I’ve set the mesh’s normals, UVs and the colors using Float32Arrays as per the mesh docs. The UVs and the normals are being applied correctly, however the vertex colors are not visible on the model. I’m setting all vertex colors to red (255, 0 ,0, 1), however the model is rendered like this:
DiffuseMapVertexColor is set to true on the standard material. Removing the diffuseMap texture has no effect.
Any advice would be appreciated.
Here is a link to a: barebones project
Here is my code:
ApplyTexture.prototype.initialize = function() {
//We scale the UVs so the image texture isn't distorted as the model scales
let scale = this.entity.localScale;
let uvs = [];
for (let i = 4; i < 6; i++) {
//Left, Right
uvs.push(0, scale.y);
uvs.push(0, 0);
uvs.push(scale.x, scale.y);
uvs.push(scale.x, 0);
}
for (let i = 0; i < 2; i++) {
//Top, Bottom
uvs.push(0, scale.x);
uvs.push(scale.z , scale.x);
uvs.push(0, 0);
uvs.push(scale.z , 0);
}
for (let i = 2; i < 4; i++) {
//Front, Back
uvs.push(0, scale.y);
uvs.push(0, 0);
uvs.push(scale.z , scale.y);
uvs.push(scale.z , 0);
}
let normals = [
//Left
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
//Right
0, 0, -1,
0, 0, -1,
0, 0, -1,
0, 0, -1,
//Top
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
//Bottom
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
//Front
1, 0, 0,
1, 0, 0,
1, 0, 0,
1, 0, 0,
//Back
-1, 0, 0,
-1, 0, 0,
-1, 0, 0,
-1, 0, 0
];
let colors = [];
for (let v = 0; v < 24; v++) {
colors.push(255, 0, 0, 1);
}
let mesh = this.entity.model.meshInstances[0].mesh;
mesh.setUvs(0, new Float32Array(uvs));
mesh.setNormals(new Float32Array(normals));
mesh.setColors(new Float32Array(colors));
mesh.update();
};