Fix the relative addressing for all types.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@919 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2007-09-07 08:57:15 +00:00
parent fb1d24d219
commit 04ed098fe8
2 changed files with 18 additions and 4 deletions

View File

@ -204,7 +204,7 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
// read in next vertex's data
u32 wlength = copyWord(vertexWord, pLinePtr, WORD_BUFFER_LENGTH, pBufEnd);
// this function will also convert obj's 1-based index to c++'s 0-based index
retrieveVertexIndices(vertexWord, Idx, vertexWord+wlength+1, vertexBuffer);
retrieveVertexIndices(vertexWord, Idx, vertexWord+wlength+1, vertexBuffer.size(), textureCoordBuffer.size(), normalsBuffer.size());
v.Pos = vertexBuffer[Idx[0]];
if ( -1 != Idx[1] )
v.TCoords = textureCoordBuffer[Idx[1]];
@ -693,7 +693,7 @@ const c8* COBJMeshFileLoader::goAndCopyNextWord(c8* outBuf, const c8* inBuf, u32
}
bool COBJMeshFileLoader::retrieveVertexIndices(c8* pVertexData, s32* pIdx, const c8* pBufEnd, const core::array<core::vector3df>& vbuffer)
bool COBJMeshFileLoader::retrieveVertexIndices(c8* pVertexData, s32* pIdx, const c8* pBufEnd, u32 vbsize, u32 vtsize, u32 vnsize)
{
c8 word[16] = "";
const c8* pChar = goFirstWord(pVertexData, pBufEnd);
@ -713,7 +713,21 @@ bool COBJMeshFileLoader::retrieveVertexIndices(c8* pVertexData, s32* pIdx, const
word[i] = '\0';
// if no number was found index will become 0 and later on -1 by decrement
if (word[0]=='-')
pIdx[idxType] = vbuffer.size()-core::strtol10(word+1,0);
{
pIdx[idxType] = -core::strtol10(word+1,0);
switch (idxType)
{
case 0:
pIdx[idxType] += vbsize;
break;
case 1:
pIdx[idxType] += vtsize;
break;
case 2:
pIdx[idxType] += vnsize;
break;
}
}
else
pIdx[idxType] = core::strtol10(word,0)-1;

View File

@ -86,7 +86,7 @@ private:
// reads and convert to integer the vertex indices in a line of obj file's face statement
// -1 for the index if it doesn't exist
// indices are changed to 0-based index instead of 1-based from the obj file
bool retrieveVertexIndices(c8* pVertexData, s32* Idx, const c8* pBufEnd, const core::array<core::vector3df>& vbuffer);
bool retrieveVertexIndices(c8* pVertexData, s32* Idx, const c8* pBufEnd, u32 vbsize, u32 vtsize, u32 vnsize);
void cleanUp();