From 593484829b6c57c0b8c24a21ec91bed28d23e4aa Mon Sep 17 00:00:00 2001 From: Johannes Ebersold Date: Wed, 19 Nov 2014 14:30:18 +0100 Subject: [PATCH] Add Function ColladaParser::ReadPrimTriStrips. This does the index mangling for reading tristrips. --- code/ColladaParser.cpp | 20 +++++++++++++++++++- code/ColladaParser.h | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/code/ColladaParser.cpp b/code/ColladaParser.cpp index 2cdebef21..5268255eb 100644 --- a/code/ColladaParser.cpp +++ b/code/ColladaParser.cpp @@ -2122,6 +2122,10 @@ void ColladaParser::ReadPrimitives( Mesh* pMesh, std::vector& pPer for (size_t currentVertex = 0; currentVertex < numPoints; currentVertex++) CopyPrimitive(currentVertex, numOffsets, numPoints, perVertexOffset, pMesh, pPerIndexChannels, currentPrimitive, indices); break; + case Prim_TriStrips: + numPoints = 3; + ReadPrimTriStrips(numOffsets, perVertexOffset, pMesh, pPerIndexChannels, currentPrimitive, indices); + break; case Prim_Polylist: numPoints = pVCount[currentPrimitive]; for (size_t currentVertex = 0; currentVertex < numPoints; currentVertex++) @@ -2134,7 +2138,7 @@ void ColladaParser::ReadPrimitives( Mesh* pMesh, std::vector& pPer CopyPrimitive(currentVertex, numOffsets, numPoints, perVertexOffset, pMesh, pPerIndexChannels, currentPrimitive, indices); break; default: - // LineStrip and TriStrip not supported due to expected index unmangling + // LineStrip is not supported due to expected index unmangling ThrowException( "Unsupported primitive type."); break; } @@ -2171,6 +2175,20 @@ void ColladaParser::CopyPrimitive(size_t currentVertex, size_t numOffsets, size_ pMesh->mFacePosIndices.push_back(vindex[perVertexOffset]); } +void ColladaParser::ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Mesh* pMesh, std::vector& pPerIndexChannels, size_t currentPrimitive, const std::vector& indices){ + if (currentPrimitive % 2 != 0){ + //odd tristrip triangles need their indices mangled, to preserve winding direction + CopyPrimitive(1, numOffsets, 1, perVertexOffset, pMesh, pPerIndexChannels, currentPrimitive, indices); + CopyPrimitive(0, numOffsets, 1, perVertexOffset, pMesh, pPerIndexChannels, currentPrimitive, indices); + CopyPrimitive(2, numOffsets, 1, perVertexOffset, pMesh, pPerIndexChannels, currentPrimitive, indices); + } + else {//for non tristrips or even tristrip triangles + CopyPrimitive(0, numOffsets, 1, perVertexOffset, pMesh, pPerIndexChannels, currentPrimitive, indices); + CopyPrimitive(1, numOffsets, 1, perVertexOffset, pMesh, pPerIndexChannels, currentPrimitive, indices); + CopyPrimitive(2, numOffsets, 1, perVertexOffset, pMesh, pPerIndexChannels, currentPrimitive, indices); + } +} + // ------------------------------------------------------------------------------------------------ // Extracts a single object from an input channel and stores it in the appropriate mesh data array void ColladaParser::ExtractDataObjectFromChannel( const InputChannel& pInput, size_t pLocalIndex, Mesh* pMesh) diff --git a/code/ColladaParser.h b/code/ColladaParser.h index b93cf9145..9f0963345 100644 --- a/code/ColladaParser.h +++ b/code/ColladaParser.h @@ -185,6 +185,10 @@ protected: Collada::Mesh* pMesh, std::vector& pPerIndexChannels, size_t currentPrimitive, const std::vector& indices); + /** Reads one triangle of a tristrip into the mesh */ + void ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Collada::Mesh* pMesh, + std::vector& pPerIndexChannels, size_t currentPrimitive, const std::vector& indices); + /** 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);