It’s GeomEnums.NT_uint8
, as mentioned on this manual page.
You could instead use a custom vertex format with a 4-component float column for vertex colors, but this will take up more memory.
On a side note, I strongly recommend the use of memoryviews instead of the interface you’re using right now.
EDIT
If you want to use floats, you can convert the vertex format after filling the vertex data to GeomVertexFormat.get_v3c4
:
vertex_rgbas = np.array([[0, 0, 0, 1], ]*len(vertices))
vertformat = GeomVertexFormat()
arrayformat = GeomVertexArrayFormat()
arrayformat.add_column(InternalName.get_vertex(), 3, GeomEnums.NT_float32, GeomEnums.C_point)
arrayformat.add_column(InternalName.get_color(), 4, GeomEnums.NT_float32, GeomEnums.C_color)
vertformat.add_array(arrayformat)
vertformat = GeomVertexFormat.register_format(vertformat)
vertexdata = GeomVertexData(name, vertformat, Geom.UHStatic)
vertexdata.unclean_set_num_rows(len(vertices))
view = memoryview(vertexdata.modify_array(0)).cast("B").cast("f")
view[:] = np.hstack((vertices, vertex_rgbas)).astype(np.float32)
vertexdata.format = GeomVertexFormat.get_v3c4()
Alternatively, if you prefer to use 8-bit integers to fill the data directly and you don’t mind splitting the format into 2 columns, the following should be fast too (presuming the color is the same for all vertices):
vertformat = GeomVertexFormat()
arrayformat = GeomVertexArrayFormat()
arrayformat.add_column(InternalName.get_vertex(), 3, GeomEnums.NT_float32, GeomEnums.C_point)
vertformat.add_array(arrayformat)
arrayformat = GeomVertexArrayFormat()
arrayformat.add_column(InternalName.get_color(), 4, GeomEnums.NT_uint8, GeomEnums.C_color)
vertformat.add_array(arrayformat)
vertformat = GeomVertexFormat.register_format(vertformat)
vertexdata = GeomVertexData(name, vertformat, Geom.UHStatic)
vertexdata.unclean_set_num_rows(len(vertices))
pos_view = memoryview(vertexdata.modify_array(0)).cast("B").cast("f")
pos_view[:] = vertices
vertexdata = vertexdata.set_color((0, 0, 0, 1))
Your final choice is to interleave the position data with the color data (in the [0, 255]
integer range) somehow (in pure Python struct
can be used for this).