Extract function ColladaParser::CopyPrimitive

pull/414/head
Johannes Ebersold 2014-11-19 14:10:16 +01:00 committed by Wolfgang Herget
parent 70d2c8571b
commit 4ef244f672
2 changed files with 29 additions and 15 deletions

View File

@ -2132,11 +2132,26 @@ void ColladaParser::ReadPrimitives( Mesh* pMesh, std::vector<InputChannel>& pPer
// gather that number of vertices // gather that number of vertices
for( size_t b = 0; b < numPoints; b++) for( size_t b = 0; b < numPoints; b++)
{ {
CopyPrimitive(b, numOffsets, numPoints, perVertexOffset, pMesh, pPerIndexChannels, currentPrimitive, indices);
}
}
// if I ever get my hands on that guy who invented this steaming pile of indirection...
TestClosing( "p");
}
void ColladaParser::CopyPrimitive(size_t currentVertex, size_t numOffsets, size_t numPoints, size_t perVertexOffset, Mesh* pMesh, std::vector<InputChannel>& pPerIndexChannels, size_t currentPrimitive, const std::vector<size_t>& indices){
// don't overrun the boundaries of the index list
size_t maxIndexRequested = currentPrimitive * numOffsets * numPoints + (currentVertex + 1) * numOffsets - 1;
ai_assert(maxIndexRequested < indices.size());
// read all indices for this vertex. Yes, in a hacky local array // read all indices for this vertex. Yes, in a hacky local array
ai_assert(numOffsets < 20 && perVertexOffset < 20); ai_assert(numOffsets < 20 && perVertexOffset < 20);
size_t vindex[20]; size_t vindex[20];
for (size_t offsets = 0; offsets < numOffsets; ++offsets) for (size_t offsets = 0; offsets < numOffsets; ++offsets)
vindex[offsets] = indices[currentPrimitive * numOffsets * numPoints + b * numOffsets + offsets]; vindex[offsets] = indices[currentPrimitive * numOffsets * numPoints + currentVertex * numOffsets + offsets];
// extract per-vertex channels using the global per-vertex offset // extract per-vertex channels using the global per-vertex offset
for (std::vector<InputChannel>::iterator it = pMesh->mPerVertexData.begin(); it != pMesh->mPerVertexData.end(); ++it) for (std::vector<InputChannel>::iterator it = pMesh->mPerVertexData.begin(); it != pMesh->mPerVertexData.end(); ++it)
@ -2148,12 +2163,6 @@ void ColladaParser::ReadPrimitives( Mesh* pMesh, std::vector<InputChannel>& pPer
// store the vertex-data index for later assignment of bone vertex weights // store the vertex-data index for later assignment of bone vertex weights
pMesh->mFacePosIndices.push_back(vindex[perVertexOffset]); pMesh->mFacePosIndices.push_back(vindex[perVertexOffset]);
} }
}
// if I ever get my hands on that guy who invented this steaming pile of indirection...
TestClosing( "p");
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Extracts a single object from an input channel and stores it in the appropriate mesh data array // Extracts a single object from an input channel and stores it in the appropriate mesh data array

View File

@ -180,6 +180,11 @@ protected:
void ReadPrimitives( Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels, void ReadPrimitives( Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
size_t pNumPrimitives, const std::vector<size_t>& pVCount, Collada::PrimitiveType pPrimType); size_t pNumPrimitives, const std::vector<size_t>& pVCount, Collada::PrimitiveType pPrimType);
/** Copies the data for a single primitive into the mesh, based on the InputChannels */
void CopyPrimitive(size_t currentVertex, size_t numOffsets, size_t numPoints, size_t perVertexOffset,
Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
size_t currentPrimitive, const std::vector<size_t>& indices);
/** Extracts a single object from an input channel and stores it in the appropriate mesh data array */ /** Extracts a single object from an input channel and stores it in the appropriate mesh data array */
void ExtractDataObjectFromChannel( const Collada::InputChannel& pInput, size_t pLocalIndex, Collada::Mesh* pMesh); void ExtractDataObjectFromChannel( const Collada::InputChannel& pInput, size_t pLocalIndex, Collada::Mesh* pMesh);