From 0e9ff778c8d16d7c340bca66f58734ef4471b972 Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Sun, 8 Feb 2009 21:22:03 +0000 Subject: [PATCH] FIX: ptv transforms tangents and bitangents now corrrectly. FIX: Obj loader sets IOR material property now. Fixed spelling. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@336 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/ObjFileImporter.cpp | 5 +++- code/PretransformVertices.cpp | 40 +++++++++++++------------------ tools/assimp_view/assimp_view.cpp | 2 +- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 72c668026..8b3d3ff8f 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -446,7 +446,7 @@ void ObjFileImporter::createMaterial(const ObjFile::Model* pModel, const ObjFile break; default: sm = aiShadingMode_Gouraud; - DefaultLogger::get()->error("OBJ/MTL: Unexpected illumination model (0-3 recognized)"); + DefaultLogger::get()->error("OBJ/MTL: Unexpected illumination model (0-2 recognized)"); } mat->AddProperty( &sm, 1, AI_MATKEY_SHADING_MODEL); @@ -456,6 +456,9 @@ void ObjFileImporter::createMaterial(const ObjFile::Model* pModel, const ObjFile mat->AddProperty( &pCurrentMaterial->specular, 1, AI_MATKEY_COLOR_SPECULAR ); mat->AddProperty( &pCurrentMaterial->shineness, 1, AI_MATKEY_SHININESS ); + // Adding refraction index + mat->AddProperty( &pCurrentMaterial->ior, 1, AI_MATKEY_REFRACTI ); + // Adding textures if ( 0 != pCurrentMaterial->texture.length ) mat->AddProperty( &pCurrentMaterial->texture, AI_MATKEY_TEXTURE_DIFFUSE(0)); diff --git a/code/PretransformVertices.cpp b/code/PretransformVertices.cpp index 89450d77d..8764dec04 100644 --- a/code/PretransformVertices.cpp +++ b/code/PretransformVertices.cpp @@ -138,35 +138,29 @@ void CollectData( aiScene* pcScene, aiNode* pcNode, unsigned int iMat, { // copy positions, transform them to worldspace for (unsigned int n = 0; n < pcMesh->mNumVertices;++n) - { - pcMeshOut->mVertices[aiCurrent[AI_PTVS_VERTEX]+n] = - pcNode->mTransformation * pcMesh->mVertices[n]; - } - if (iVFormat & 0x2) - { - aiMatrix4x4 mWorldIT = pcNode->mTransformation; - mWorldIT.Inverse().Transpose(); + pcMeshOut->mVertices[aiCurrent[AI_PTVS_VERTEX]+n] = pcNode->mTransformation * pcMesh->mVertices[n]; + - // TODO: implement Inverse() for aiMatrix3x3 - aiMatrix3x3 m = aiMatrix3x3(mWorldIT); - + aiMatrix4x4 mWorldIT = pcNode->mTransformation; + mWorldIT.Inverse().Transpose(); + + // TODO: implement Inverse() for aiMatrix3x3 + aiMatrix3x3 m = aiMatrix3x3(mWorldIT); + + if (iVFormat & 0x2) + { // copy normals, transform them to worldspace - for (unsigned int n = 0; n < pcMesh->mNumVertices;++n) - { - pcMeshOut->mNormals[aiCurrent[AI_PTVS_VERTEX]+n] = - m * pcMesh->mNormals[n]; + for (unsigned int n = 0; n < pcMesh->mNumVertices;++n) { + pcMeshOut->mNormals[aiCurrent[AI_PTVS_VERTEX]+n] = m * pcMesh->mNormals[n]; } } if (iVFormat & 0x4) { - // copy tangents - memcpy(pcMeshOut->mTangents + aiCurrent[AI_PTVS_VERTEX], - pcMesh->mTangents, - pcMesh->mNumVertices * sizeof(aiVector3D)); - // copy bitangents - memcpy(pcMeshOut->mBitangents + aiCurrent[AI_PTVS_VERTEX], - pcMesh->mBitangents, - pcMesh->mNumVertices * sizeof(aiVector3D)); + // copy tangents and bitangents, transform them to worldspace + for (unsigned int n = 0; n < pcMesh->mNumVertices;++n) { + pcMeshOut->mTangents [aiCurrent[AI_PTVS_VERTEX]+n] = m * pcMesh->mTangents[n]; + pcMeshOut->mBitangents[aiCurrent[AI_PTVS_VERTEX]+n] = m * pcMesh->mBitangents[n]; + } } unsigned int p = 0; while (iVFormat & (0x100 << p)) diff --git a/tools/assimp_view/assimp_view.cpp b/tools/assimp_view/assimp_view.cpp index 9577234d8..d646f916f 100644 --- a/tools/assimp_view/assimp_view.cpp +++ b/tools/assimp_view/assimp_view.cpp @@ -147,7 +147,7 @@ DWORD WINAPI LoadThreadProc(LPVOID lpParameter) aiProcess_GenUVCoords | // convert spherical, cylindrical, box and planar mapping to proper UVs aiProcess_TransformUVCoords | // preprocess UV transformations (scaling, translation ...) aiProcess_FindInstances | // search for instanced meshes and remove them by references to one master -// aiProcess_PreTransformVertices | + aiProcess_PreTransformVertices | 0); // get the end time of zje operation, calculate delta t