Hi there
I’m reading the Deindexer() code in ColladaRT. this function calls the ParseInputAndP() function to do something. I don’t understand what this function do?Could you please give me more explanation about the ParseInputAndP() function?Here’s its definition:

void ParseInputAndP(domInputLocalOffset_Array &input_array, domP * p, domPRef &newp, VertexSet & vertexset, domUint & vertexindex, domUint &maxoffset)
{
std::map<domElement*, domUint> offsetmap;
for (size_t j=0; j<input_array.getCount(); j++)
{
offsetmap[input_array[j]->getSource().getElement()] = input_array[j]->getOffset();
input_array[j]->setOffset(0); // reset all input's offset to 0 since all inputs use the same vertex index
}
domListOfUInts & value = p->getValue();
for (size_t j=0; j<value.getCount(); j=(size_t) (j+maxoffset+1))
{
VertexIndexes* vertex = new VertexIndexes();
std::map<domElement*, domUint>::iterator iter;
for (iter=offsetmap.begin(); iter!=offsetmap.end(); iter++)
{
vertex->SetIndex(iter->first, value[(size_t) (j+(iter->second))]);
}
std::pair<VertexSet::iterator,bool> result = vertexset.insert(vertex);
if (result.second)
{ // it is unique, not duplicate in set
// printf("vertex is unique
");
vertex->new_index = vertexindex;
newp->getValue().append(vertexindex);
vertexindex++;
} else
{ // it is not unique, duplicate found in set
// printf("vertex is not unique
");
VertexIndexes * match_vertex = *(result.first);
newp->getValue().append(match_vertex->new_index);
MergeVertex(match_vertex, vertex);
}
}
}

I think the part you’re confused about is where the “deindexer” conditioner (which isn’t appropriately named, since even after transformation you still end up with indexed geometry primitives) is trying to reuse vertices whenever possible.

Let’s say I have a geometric primitive consisting of positions and normals, and I use different indices for each. Also suppose I have triangle 1 that uses positions 0, 1, and 2, and a single normal 0. In Collada this gets written out as “0 0 1 0 2 0”, where each pair of numbers represents a logical “index”. Now let’s say I have triangle 2 that uses positions 2, 3, and 4, and normal 0 again. Now it looks like “0 0 1 0 2 0 2 0 3 0 4 0”. Note that the 3rd and 4th “indices” are the same (“2 0” and “2 0”). When you convert to unified indices, you don’t need to create separate vertices for them. You can create one new vertex containing the data for position 2 and normal 0, and reference it twice in your index list. So after you unify the indices, your index list could become “0 1 2 2 3 4”* instead of “0 1 2 3 4 5”, to maximize vertex reuse. That’s what it looks like the function is doing.

That might’ve just confused you more, but I hope it helps

Unfortunately, I think the deindexer writes the data out as “0 0 1 1 2 2 2 2 3 3 4 4” instead of the simpler “0 1 2 2 3 4” that I have above.

In your example, maxoffset is 4( Am I corect ? )
So why we add j by maxoffset?
Each <input> has an offset attribute, and maxoffset is the maximum of these offset values. maxoffset+1 gives you the stride of each index. In my example, maxoffset would be 1 (position is offset 0 and normal is offset 1), so the stride is 2. That’s why j is being incremented by maxoffset+1.

I also don’t understand the meaning of p in Collada DOM( What does p->getValue() do? )
p is of type domP, which represents the

element in the geometry. It’s just an array of indices. p->getValue will return the actual daeArray object.

Why do we use value[(size_t) (j+(iter->second))] here?
j is the beginning of the index in the array, and iter->second is going to be the offset within the index for a particular vertex component (0 for position, 1 for normal, etc). value[j+iter->second] will give you the value of the vertex component identified by iter->second of the jth index.