1
$\begingroup$

I'm trying to write a mesh exporter that can export vertex colors (color attributes). On the default cube, I've found the Blender counts 8 regular vertices wherein it stores 24 color attributes. showcase

I assume the attributes consider the faces in a separate context and a vertex shared between multiple faces as unique within that context. Shown by how painting on one corner will have the value appear three times in the color attributes list.

Vertices
1 1.0 1.0 1.0
2 1.0 1.0 -1.0
3 1.0 -1.0 1.0
4 1.0 -1.0 -1.0
5 -1.0 1.0 1.0
6 -1.0 1.0 -1.0
7 -1.0 -1.0 1.0
8 -1.0 -1.0 -1.0
Colour Attributes
1 [1.0, 1.0, 1.0, 1.0]
2 [1.0, 1.0, 1.0, 1.0]
3 [1.0, 1.0, 1.0, 1.0]
4 [1.0, 0.015996292233467102, 0.02732088789343834, 1.0]
5 [1.0, 1.0, 1.0, 1.0]
6 [1.0, 0.015996292233467102, 0.02732088789343834, 1.0]
7 [1.0, 1.0, 1.0, 1.0]
8 [1.0, 1.0, 1.0, 1.0]
9 [1.0, 1.0, 1.0, 1.0]
10 [1.0, 1.0, 1.0, 1.0]
11 [1.0, 1.0, 1.0, 1.0]
12 [1.0, 1.0, 1.0, 1.0]
13 [1.0, 1.0, 1.0, 1.0]
14 [1.0, 1.0, 1.0, 1.0]
15 [1.0, 1.0, 1.0, 1.0]
16 [1.0, 1.0, 1.0, 1.0]
17 [1.0, 1.0, 1.0, 1.0]
18 [1.0, 1.0, 1.0, 1.0]
19 [1.0, 0.015996292233467102, 0.02732088789343834, 1.0]
20 [1.0, 1.0, 1.0, 1.0]
21 [1.0, 1.0, 1.0, 1.0]
22 [1.0, 1.0, 1.0, 1.0]
23 [1.0, 1.0, 1.0, 1.0]
24 [1.0, 1.0, 1.0, 1.0]

What I want to know is how to map these different color attribute vertices to the main positional vertices.

$\endgroup$

2 Answers 2

1
$\begingroup$

Found it.
The MeshPolygon struct has a field called loop_indices. Each of these indices corresponds to the attribute index I described in my question. Indexing the Mesh.loops field with this same index will return a MeshLoop struct that has a vertex_index which will get you the positional vertex.

$\endgroup$
0
$\begingroup$

Vertex indices match data indices.

If I make a vector attribute creatively called "VectorAttribute" by converting some color attribute so I can recognise the values I previously painted and want to access it, it is apparently stored in object.data.attributes['VectorAttribute']. If I want to know the value of this attribute assigned to vertex with index 7, it's C.object.data.attributes['VectorAttribute'].data[7].vector. Console prints:

enter image description here

This matches my expected values.

I used functionality of MeasureIt add-on to visually confirm vertex indices:

enter image description here

$\endgroup$
1
  • $\begingroup$ I made some changes to the original question which will hopefully better show my problem $\endgroup$
    – Sef
    Commented Feb 23, 2023 at 15:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .