From c40b7670166952bf813577044d2954f2125a8ef5 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 15 Feb 2012 18:28:08 +0100 Subject: [PATCH 1/6] Matrix to Quaternion conversion precision fix. See below links for reasoning, but in short, avoid sqrt and division of small values. It's also possible to normalize the quaternion after the conversion, but better precision is preferable. http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/ethan.htm --- include/assimp/quaternion.inl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/assimp/quaternion.inl b/include/assimp/quaternion.inl index b6394b8a3..9113848b8 100644 --- a/include/assimp/quaternion.inl +++ b/include/assimp/quaternion.inl @@ -69,12 +69,12 @@ bool aiQuaterniont::operator!= (const aiQuaterniont& o) const template inline aiQuaterniont::aiQuaterniont( const aiMatrix3x3t &pRotMatrix) { - TReal t = 1 + pRotMatrix.a1 + pRotMatrix.b2 + pRotMatrix.c3; + TReal t = pRotMatrix.a1 + pRotMatrix.b2 + pRotMatrix.c3; // large enough - if( t > static_cast(0.001)) + if( t > static_cast(0)) { - TReal s = sqrt( t) * static_cast(2.0); + TReal s = sqrt(1 + t) * static_cast(2.0); x = (pRotMatrix.c2 - pRotMatrix.b3) / s; y = (pRotMatrix.a3 - pRotMatrix.c1) / s; z = (pRotMatrix.b1 - pRotMatrix.a2) / s; From 771d804c46783da8427c557e7f4c6e48284768e4 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 16 Mar 2012 12:02:53 +0100 Subject: [PATCH 2/6] ColladaParser: Tolerate empty data arrays and controller weights. --- code/ColladaParser.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/code/ColladaParser.cpp b/code/ColladaParser.cpp index 41aaee320..2f7787b62 100644 --- a/code/ColladaParser.cpp +++ b/code/ColladaParser.cpp @@ -599,7 +599,7 @@ void ColladaParser::ReadControllerWeights( Collada::Controller& pController) if( mReader->getNodeType() == irr::io::EXN_ELEMENT) { // Input channels for weight data. Two possible semantics: "JOINT" and "WEIGHT" - if( IsElement( "input")) + if( IsElement( "input") && vertexCount > 0 ) { InputChannel channel; @@ -628,7 +628,7 @@ void ColladaParser::ReadControllerWeights( Collada::Controller& pController) if( !mReader->isEmptyElement()) SkipElement(); } - else if( IsElement( "vcount")) + else if( IsElement( "vcount") && vertexCount > 0 ) { // read weight count per vertex const char* text = GetTextContent(); @@ -648,7 +648,7 @@ void ColladaParser::ReadControllerWeights( Collada::Controller& pController) // reserve weight count pController.mWeights.resize( numWeights); } - else if( IsElement( "v")) + else if( IsElement( "v") && vertexCount > 0 ) { // read JointIndex - WeightIndex pairs const char* text = GetTextContent(); @@ -1656,6 +1656,7 @@ void ColladaParser::ReadDataArray() std::string id = mReader->getAttributeValue( indexID); int indexCount = GetAttribute( "count"); unsigned int count = (unsigned int) mReader->getAttributeValueAsInt( indexCount); + if (count == 0) { return; } // some exporters write empty data arrays with count="0" const char* content = TestTextContent(); // read values and store inside an array in the data library From 24927ff4cc0f15ca1555d09d69d29283d79bf9ca Mon Sep 17 00:00:00 2001 From: Rodrigo Benenson Date: Thu, 29 Nov 2012 19:06:26 +0100 Subject: [PATCH 3/6] fixed sample.py --- port/PyAssimp/sample.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/port/PyAssimp/sample.py b/port/PyAssimp/sample.py index 3788bd065..20cebcd36 100755 --- a/port/PyAssimp/sample.py +++ b/port/PyAssimp/sample.py @@ -5,8 +5,7 @@ This module demonstrates the functionality of PyAssimp. """ - -import pyassimp +import pyassimp.core as pyassimp import os, sys #get a model out of assimp's test-data if none is provided on the command line @@ -22,6 +21,8 @@ def recur_node(node,level = 0): def main(filename=None): filename = filename or DEFAULT_MODEL + + print "Reading model", filename scene = pyassimp.load(filename) #the model we load @@ -45,21 +46,23 @@ def main(filename=None): print " material id:", mesh.materialindex+1 print " vertices:", len(mesh.vertices) print " first 3 verts:", mesh.vertices[:3] - if mesh.normals: + if len(mesh.normals) > 0: print " first 3 normals:", mesh.normals[:3] else: print " no normals" print " colors:", len(mesh.colors) tc = mesh.texturecoords - if tc: + if len(tc) >= 4: print " texture-coords 1:", len(tc[0]), "first3:", tc[0][:3] print " texture-coords 2:", len(tc[1]), "first3:", tc[1][:3] print " texture-coords 3:", len(tc[2]), "first3:", tc[2][:3] print " texture-coords 4:", len(tc[3]), "first3:", tc[3][:3] - else: + elif len(tc) == 0: print " no texture coordinates" + else: + print " tc is an unexpected number of elements (expect 4, got", len(tc), ")" print " uv-component-count:", len(mesh.numuvcomponents) - print " faces:", len(mesh.faces), "first:", [f.indices for f in mesh.faces[:3]] + print " faces:", len(mesh.faces), "first:", [f for f in mesh.faces[:3]] print " bones:", len(mesh.bones), "first:", [str(b) for b in mesh.bones[:3]] print @@ -81,5 +84,7 @@ def main(filename=None): # Finally release the model pyassimp.release(scene) + print "Finished parsing the model." + if __name__ == "__main__": main(sys.argv[1] if len(sys.argv)>1 else None) From c883967735ccb8462dd4797465f9ed3bbdfcf249 Mon Sep 17 00:00:00 2001 From: Rodrigo Benenson Date: Thu, 29 Nov 2012 19:07:56 +0100 Subject: [PATCH 4/6] Fixed pyassimp core.py --- port/PyAssimp/pyassimp/core.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/port/PyAssimp/pyassimp/core.py b/port/PyAssimp/pyassimp/core.py index 731dcd5a3..877272b1c 100644 --- a/port/PyAssimp/pyassimp/core.py +++ b/port/PyAssimp/pyassimp/core.py @@ -293,11 +293,9 @@ def release(scene): def _finalize_texture(tex, target): setattr(target, "achformathint", tex.achFormatHint) - data = numpy.array([make_tuple(getattr(tex, pcData)[i]) for i in range(tex.mWidth * tex.mHeight)]) + data = numpy.array([make_tuple(getattr(tex, "pcData")[i]) for i in range(tex.mWidth * tex.mHeight)]) setattr(target, "data", data) - - def _finalize_mesh(mesh, target): """ Building of meshes is a bit specific. From 7b253016b73abc696e2cb6ac95b44b6bb8f3f59e Mon Sep 17 00:00:00 2001 From: Rodrigo Benenson Date: Fri, 7 Dec 2012 21:57:39 +0100 Subject: [PATCH 5/6] Fixing compilation on gcc 4.5.2 --- code/IFCUtil.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/IFCUtil.cpp b/code/IFCUtil.cpp index 96877f934..17149906f 100644 --- a/code/IFCUtil.cpp +++ b/code/IFCUtil.cpp @@ -142,8 +142,8 @@ void TempMesh::RemoveDegenerates() bool drop = false; size_t inor = 0; - std::vector::const_iterator vit = verts.begin(); - for (std::vector::const_iterator it = vertcnt.begin(); it != vertcnt.end(); ++inor) { + std::vector::iterator vit = verts.begin(); + for (std::vector::iterator it = vertcnt.begin(); it != vertcnt.end(); ++inor) { const unsigned int pcount = *it; if (normals[inor].SquareLength() < 1e-5f) { From cc88a3a0de80538c6d54bcfb38565ac5f7f91b1f Mon Sep 17 00:00:00 2001 From: kimmi Date: Mon, 7 Jan 2013 21:05:53 +0000 Subject: [PATCH 6/6] update : add displacement map support to obj-material importer. this feature is supported by some special exporters. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1347 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/ObjFileData.h | 1 + code/ObjFileImporter.cpp | 3 +++ code/ObjFileMtlImporter.cpp | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/code/ObjFileData.h b/code/ObjFileData.h index 51a2088f1..59c39d48c 100644 --- a/code/ObjFileData.h +++ b/code/ObjFileData.h @@ -159,6 +159,7 @@ struct Material aiString textureBump; aiString textureSpecularity; aiString textureOpacity; + aiString textureDisp; //! Ambient color aiColor3D ambient; diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index eb1d4098f..84b8df5b2 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -556,6 +556,9 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc if ( 0 != pCurrentMaterial->textureBump.length ) mat->AddProperty( &pCurrentMaterial->textureBump, AI_MATKEY_TEXTURE_HEIGHT(0)); + if ( 0 != pCurrentMaterial->textureDisp.length ) + mat->AddProperty( &pCurrentMaterial->textureDisp, AI_MATKEY_TEXTURE_DISPLACEMENT(0) ); + if ( 0 != pCurrentMaterial->textureOpacity.length ) mat->AddProperty( &pCurrentMaterial->textureOpacity, AI_MATKEY_TEXTURE_OPACITY(0)); diff --git a/code/ObjFileMtlImporter.cpp b/code/ObjFileMtlImporter.cpp index db7e947d6..2c63592a0 100644 --- a/code/ObjFileMtlImporter.cpp +++ b/code/ObjFileMtlImporter.cpp @@ -279,6 +279,10 @@ void ObjFileMtlImporter::getTexture() else if (!ASSIMP_strincmp(&(*m_DataIt),"map_bump",8) || !ASSIMP_strincmp(&(*m_DataIt),"bump",4)) out = & m_pModel->m_pCurrentMaterial->textureBump; + // Displacement texture + else if (!ASSIMP_strincmp(&(*m_DataIt),"disp",4)) + out = &m_pModel->m_pCurrentMaterial->textureDisp; + // Specularity scaling (glossiness) else if (!ASSIMP_strincmp(&(*m_DataIt),"map_ns",6)) out = & m_pModel->m_pCurrentMaterial->textureSpecularity;