draco
draco copied to clipboard
How to get all information of a single point? When should I use mapped_index?
Firstly I thought, when I add attributes with identity_mapping=true
, the i-th attribute is corresponding to i-th point, codes like:
GeometryAttribute va;
va.Init(GeometryAttribute::POSITION, nullptr, 3, DT_FLOAT32, false,
sizeof(float) * 3, 0);
auto pos_att_id_ = mesh.AddAttribute(va, true, vertexCount);
va.Init(GeometryAttribute::GENERIC, nullptr, 1, DT_INT32, false,
sizeof(int32_t) * 1, 0);
auto generic_att_id_ = mesh.AddAttribute(va, true, vertexCount);
// add other attributes and then fill them.
But I got broken triangles:
auto &face = mesh.face(draco::FaceIndex(id)); // here the index is wrong
auto posAttr = mesh.GetNamedAttribute(draco::GeometryAttribute::POSITION);
for (auto i = 0; i < 3; ++i) {
pIndices[i] = posAttr->mapped_index(face[i]).value(); // here get the correct index
}
Then I did a test:
for(auto i = 0;i < vertexCount;++i)
{
mesh.attribute(pos_att_id_)
->SetAttributeValue(AttributeValueIndex(i), &points[i]);
mesh.attribute(generic_att_id_)
->SetAttributeValue(AttributeValueIndex(i), &i);
}
// encode and decode...
for (auto i = 0;i < vertexCount;++i)
{
int index;
decGenericAttr->ConvertValue(AttributeValueIndex(i), &index);
float pos[3];
decPosAttr->ConvertValue(AttributeValueIndex(i), pos);
// here the value of pos is corresponding to the index-th point before encode
}
It seems only the value of face need mapped_index
? In general, when should I use mapped_index
/GetMappedValue
?
I would suggest always using mapped_index
. It will work even when the mapping is identity. When the mapping is identity PointIndex
should be equal to AttributeValueIndex
but that's something you would need to check / know whenever you access an attribute. Note that even when you set an attribute to identity mapping before encoding it doesn't mean that it will have identity mapping after decoding (in fact, it will most likely not have identity mapping).