'How to add color definition in 'pygltflib' python library to 3D triangular mesh?

The following example generates a 3D object using arbitrary triangle definitions (vertices and connectivity matrix). https://gitlab.com/dodgyville/pygltflib#create-a-mesh-convert-to-bytes-convert-back-to-mesh

How can I set custom colors to the vertices?

Just like the same way as in this matlab library: https://www.mathworks.com/matlabcentral/fileexchange/109264-matlab2glb

Matlab example code with color definition for vertices:

example.POSITION = [0 0 0; 1 0 0; 1 1 0; 0 1 0; 0 0 1; 1 0 1; 1 1 1; 0 1 1]; 
example.indices = [1 4 2; 4 3 2; 3 7 2; 7 6 2; 3 4 7; 4 8 7; 8 5 7; 5 6 7; 5 2 6; 5 1 2; 1 5 4; 5 8 4];
example.COLOR_0 = [1 0 0; 0.5 0.5 0.5; 0.5 0.5 0.5; 0.5 0.5 0.5; 0.5 0.5 0.5; 0.5 0.5 0.5; 0 1 0; 0.5 0.5 0.5];
example.prop.material.pbrMetallicRoughness.baseColorFactor = [0.7 0.7 1 0.5];
example.prop.material.pbrMetallicRoughness.metallicFactor = 1;
example.prop.material.pbrMetallicRoughness.roughnessFactor = 0.1;
example.prop.material.alphaMode = 'BLEND';
example.prop.material.doubleSided = true;
write_glb('example.glb', example);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source