From ed9204ab1b754d3ff7a786bfdb8e4007166c0afa Mon Sep 17 00:00:00 2001 From: attila-barsi Date: Mon, 24 Mar 2014 11:46:36 +0100 Subject: [PATCH 01/14] Initial version for FBX layered textures. Fixed assert during parsing UDP3DSMAX. --- code/FBXConverter.cpp | 111 +++++++++++++++++++++++++++++++++++++++++- code/FBXDocument.cpp | 5 +- code/FBXDocument.h | 72 ++++++++++++++++++++++++++- code/FBXMaterial.cpp | 75 +++++++++++++++++++++++++--- 4 files changed, 251 insertions(+), 12 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index d08dc3dce..9f2b70b7f 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -23,7 +23,7 @@ following conditions are met: derived from this software without specific prior written permission of the assimp team. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT @@ -766,6 +766,7 @@ private: // find user defined properties (3ds Max) data->Set(index++, "UserProperties", aiString(PropertyGet(props, "UDP3DSMAX", ""))); + unparsedProperties.erase("UDP3DSMAX"); // preserve the info that a node was marked as Null node in the original file. data->Set(index++, "IsNull", model.IsNull() ? true : false); @@ -1439,6 +1440,7 @@ private: // texture assignments SetTextureProperties(out_mat,material.Textures()); + SetTextureProperties(out_mat,material.LayeredTextures()); return static_cast(materials.size() - 1); } @@ -1538,6 +1540,99 @@ private: out_mat->AddProperty(&uvIndex,1,_AI_MATKEY_UVWSRC_BASE,target,0); } + // ------------------------------------------------------------------------------------------------ + void TrySetTextureProperties(aiMaterial* out_mat, const LayeredTextureMap& layeredTextures, + const std::string& propName, + aiTextureType target) + { + LayeredTextureMap::const_iterator it = layeredTextures.find(propName); + if(it == layeredTextures.end()) { + return; + } + + const Texture* const tex = (*it).second->getTexture(); + + aiString path; + path.Set(tex->RelativeFilename()); + + out_mat->AddProperty(&path,_AI_MATKEY_TEXTURE_BASE,target,0); + + aiUVTransform uvTrafo; + // XXX handle all kinds of UV transformations + uvTrafo.mScaling = tex->UVScaling(); + uvTrafo.mTranslation = tex->UVTranslation(); + out_mat->AddProperty(&uvTrafo,1,_AI_MATKEY_UVTRANSFORM_BASE,target,0); + + const PropertyTable& props = tex->Props(); + + int uvIndex = 0; + + bool ok; + const std::string& uvSet = PropertyGet(props,"UVSet",ok); + if(ok) { + // "default" is the name which usually appears in the FbxFileTexture template + if(uvSet != "default" && uvSet.length()) { + // this is a bit awkward - we need to find a mesh that uses this + // material and scan its UV channels for the given UV name because + // assimp references UV channels by index, not by name. + + // XXX: the case that UV channels may appear in different orders + // in meshes is unhandled. A possible solution would be to sort + // the UV channels alphabetically, but this would have the side + // effect that the primary (first) UV channel would sometimes + // be moved, causing trouble when users read only the first + // UV channel and ignore UV channel assignments altogether. + + const unsigned int matIndex = static_cast(std::distance(materials.begin(), + std::find(materials.begin(),materials.end(),out_mat) + )); + + uvIndex = -1; + BOOST_FOREACH(const MeshMap::value_type& v,meshes_converted) { + const MeshGeometry* const mesh = dynamic_cast (v.first); + if(!mesh) { + continue; + } + + const MatIndexArray& mats = mesh->GetMaterialIndices(); + if(std::find(mats.begin(),mats.end(),matIndex) == mats.end()) { + continue; + } + + int index = -1; + for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { + if(mesh->GetTextureCoords(i).empty()) { + break; + } + const std::string& name = mesh->GetTextureCoordChannelName(i); + if(name == uvSet) { + index = static_cast(i); + break; + } + } + if(index == -1) { + FBXImporter::LogWarn("did not find UV channel named " + uvSet + " in a mesh using this material"); + continue; + } + + if(uvIndex == -1) { + uvIndex = index; + } + else { + FBXImporter::LogWarn("the UV channel named " + uvSet + + " appears at different positions in meshes, results will be wrong"); + } + } + + if(uvIndex == -1) { + FBXImporter::LogWarn("failed to resolve UV channel " + uvSet + ", using first UV channel"); + uvIndex = 0; + } + } + } + + out_mat->AddProperty(&uvIndex,1,_AI_MATKEY_UVWSRC_BASE,target,0); + } // ------------------------------------------------------------------------------------------------ void SetTextureProperties(aiMaterial* out_mat, const TextureMap& textures) @@ -1554,6 +1649,20 @@ private: TrySetTextureProperties(out_mat, textures, "ShininessExponent", aiTextureType_SHININESS); } + // ------------------------------------------------------------------------------------------------ + void SetTextureProperties(aiMaterial* out_mat, const LayeredTextureMap& layeredTextures) + { + TrySetTextureProperties(out_mat, layeredTextures, "DiffuseColor", aiTextureType_DIFFUSE); + TrySetTextureProperties(out_mat, layeredTextures, "AmbientColor", aiTextureType_AMBIENT); + TrySetTextureProperties(out_mat, layeredTextures, "EmissiveColor", aiTextureType_EMISSIVE); + TrySetTextureProperties(out_mat, layeredTextures, "SpecularColor", aiTextureType_SPECULAR); + TrySetTextureProperties(out_mat, layeredTextures, "TransparentColor", aiTextureType_OPACITY); + TrySetTextureProperties(out_mat, layeredTextures, "ReflectionColor", aiTextureType_REFLECTION); + TrySetTextureProperties(out_mat, layeredTextures, "DisplacementColor", aiTextureType_DISPLACEMENT); + TrySetTextureProperties(out_mat, layeredTextures, "NormalMap", aiTextureType_NORMALS); + TrySetTextureProperties(out_mat, layeredTextures, "Bump", aiTextureType_HEIGHT); + TrySetTextureProperties(out_mat, layeredTextures, "ShininessExponent", aiTextureType_SHININESS); + } // ------------------------------------------------------------------------------------------------ diff --git a/code/FBXDocument.cpp b/code/FBXDocument.cpp index cff52e542..404a8d6e2 100644 --- a/code/FBXDocument.cpp +++ b/code/FBXDocument.cpp @@ -14,7 +14,7 @@ following conditions are met: following disclaimer. * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the + copyright notice, this list of conditions and the* following disclaimer in the documentation and/or other materials provided with the distribution. @@ -176,6 +176,9 @@ const Object* LazyObject::Get(bool dieOnError) else if (!strncmp(obtype,"Texture",length)) { object.reset(new Texture(id,element,doc,name)); } + else if (!strncmp(obtype,"LayeredTexture",length)) { + object.reset(new LayeredTexture(id,element,doc,name)); + } else if (!strncmp(obtype,"AnimationStack",length)) { object.reset(new AnimationStack(id,element,name,doc)); } diff --git a/code/FBXDocument.h b/code/FBXDocument.h index 9b7d5e3ec..9dd5c79dd 100644 --- a/code/FBXDocument.h +++ b/code/FBXDocument.h @@ -516,8 +516,6 @@ private: boost::shared_ptr props; }; - - /** DOM class for generic FBX textures */ class Texture : public Object { @@ -576,8 +574,73 @@ private: unsigned int crop[4]; }; +/** DOM class for layered FBX textures */ +class LayeredTexture : public Object +{ +public: + + LayeredTexture(uint64_t id, const Element& element, const Document& doc, const std::string& name); + ~LayeredTexture(); + + //Can only be called after construction of the layered texture object due to construction flag. + void fillTexture(const Document& doc); + + enum BlendMode + { + BlendMode_Translucent, + BlendMode_Additive, + BlendMode_Modulate, + BlendMode_Modulate2, + BlendMode_Over, + BlendMode_Normal, + BlendMode_Dissolve, + BlendMode_Darken, + BlendMode_ColorBurn, + BlendMode_LinearBurn, + BlendMode_DarkerColor, + BlendMode_Lighten, + BlendMode_Screen, + BlendMode_ColorDodge, + BlendMode_LinearDodge, + BlendMode_LighterColor, + BlendMode_SoftLight, + BlendMode_HardLight, + BlendMode_VividLight, + BlendMode_LinearLight, + BlendMode_PinLight, + BlendMode_HardMix, + BlendMode_Difference, + BlendMode_Exclusion, + BlendMode_Subtract, + BlendMode_Divide, + BlendMode_Hue, + BlendMode_Saturation, + BlendMode_Color, + BlendMode_Luminosity, + BlendMode_Overlay, + BlendMode_BlendModeCount + }; + + const Texture* getTexture() const + { + return texture; + } + BlendMode GetBlendMode() + { + return blendMode; + } + float Alpha() + { + return alpha; + } +private: + const Texture* texture; + BlendMode blendMode; + float alpha; +}; typedef std::fbx_unordered_map TextureMap; +typedef std::fbx_unordered_map LayeredTextureMap; /** DOM class for generic FBX materials */ @@ -607,6 +670,10 @@ public: return textures; } + const LayeredTextureMap& LayeredTextures() const { + return layeredTextures; + } + private: std::string shading; @@ -614,6 +681,7 @@ private: boost::shared_ptr props; TextureMap textures; + LayeredTextureMap layeredTextures; }; diff --git a/code/FBXMaterial.cpp b/code/FBXMaterial.cpp index 1a5d7d443..a5e2a1169 100644 --- a/code/FBXMaterial.cpp +++ b/code/FBXMaterial.cpp @@ -110,16 +110,29 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con const Texture* const tex = dynamic_cast(ob); if(!tex) { - DOMWarning("source object for texture link is not a texture, ignoring",&element); - continue; + const LayeredTexture* const layeredTexture = dynamic_cast(ob); + if(!layeredTexture) { + DOMWarning("source object for texture link is not a texture or layered texture, ignoring",&element); + continue; + } + const std::string& prop = con->PropertyName(); + if (layeredTextures.find(prop) != layeredTextures.end()) { + DOMWarning("duplicate layered texture link: " + prop,&element); + } + + layeredTextures[prop] = layeredTexture; + ((LayeredTexture*)layeredTexture)->fillTexture(doc); + } + else + { + const std::string& prop = con->PropertyName(); + if (textures.find(prop) != textures.end()) { + DOMWarning("duplicate texture link: " + prop,&element); + } + + textures[prop] = tex; } - const std::string& prop = con->PropertyName(); - if (textures.find(prop) != textures.end()) { - DOMWarning("duplicate texture link: " + prop,&element); - } - - textures[prop] = tex; } } @@ -194,6 +207,52 @@ Texture::~Texture() } +LayeredTexture::LayeredTexture(uint64_t id, const Element& element, const Document& doc, const std::string& name) +: Object(id,element,name) +,texture(0) +,blendMode(BlendMode_Modulate) +,alpha(1) +{ + const Scope& sc = GetRequiredScope(element); + + const Element* const BlendModes = sc["BlendModes"]; + const Element* const Alphas = sc["Alphas"]; + + + if(BlendModes!=0) + { + blendMode = (BlendMode)ParseTokenAsInt(GetRequiredToken(*BlendModes,0)); + } + if(Alphas!=0) + { + alpha = ParseTokenAsFloat(GetRequiredToken(*Alphas,0)); + } +} + +LayeredTexture::~LayeredTexture() +{ + +} + +void LayeredTexture::fillTexture(const Document& doc) +{ + const std::vector& conns = doc.GetConnectionsByDestinationSequenced(ID()); + for(size_t i = 0; i < conns.size();++i) + { + const Connection* con = conns.at(i); + + const Object* const ob = con->SourceObject(); + if(!ob) { + DOMWarning("failed to read source object for texture link, ignoring",&element); + continue; + } + + const Texture* const tex = dynamic_cast(ob); + + texture = tex; + } +} + } //!FBX } //!Assimp From 2e3b602c0b894101675de3343ee940d3985530d2 Mon Sep 17 00:00:00 2001 From: DoubleLee Date: Wed, 26 Mar 2014 16:44:49 -0500 Subject: [PATCH 02/14] Aspect Ratio fix, and comment about field of view. --- code/FBXConverter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index d08dc3dce..4df579b31 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -378,10 +378,11 @@ private: out_camera->mName.Set(FixNodeName(model.Name())); - out_camera->mAspect = cam.AspectWidth(); + out_camera->mAspect = cam.AspectWidth() / cam.AspectHeight(); out_camera->mPosition = cam.Position(); out_camera->mLookAt = cam.InterestPosition() - out_camera->mPosition; + // BUG HERE cam.FieldOfView() returns 1.0f every time. 1.0f is default value. out_camera->mHorizontalFOV = AI_DEG_TO_RAD(cam.FieldOfView()); } From f9d5852ef937c5f8b905d29b37831441f3db0dfb Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 27 Mar 2014 19:19:25 +0100 Subject: [PATCH 03/14] bugfix: - add global namespace statement to sqrt. refactoring: - include cmath instead of math.h in c++ API. Signed-off-by: Kim Kulling --- include/assimp/matrix4x4.inl | 7 ++++++- include/assimp/vector2.h | 6 +++++- include/assimp/vector3.h | 7 +++++-- include/assimp/vector3.inl | 3 ++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/assimp/matrix4x4.inl b/include/assimp/matrix4x4.inl index 15edbf4ab..589129b10 100644 --- a/include/assimp/matrix4x4.inl +++ b/include/assimp/matrix4x4.inl @@ -53,7 +53,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include + +#ifdef __cplusplus +# include +#else +# include +#endif // ---------------------------------------------------------------------------------------- template diff --git a/include/assimp/vector2.h b/include/assimp/vector2.h index 46165ad54..f5e4b7c5e 100644 --- a/include/assimp/vector2.h +++ b/include/assimp/vector2.h @@ -44,7 +44,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AI_VECTOR2D_H_INC #define AI_VECTOR2D_H_INC -#include +#ifdef __cplusplus +# include +#else +# include +#endif #include "./Compiler/pushpack1.h" diff --git a/include/assimp/vector3.h b/include/assimp/vector3.h index cbdee264d..7b5269c9c 100644 --- a/include/assimp/vector3.h +++ b/include/assimp/vector3.h @@ -44,8 +44,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AI_VECTOR3D_H_INC #define AI_VECTOR3D_H_INC -#include - +#ifdef __cplusplus +# include +#else +# include +#endif #include "./Compiler/pushpack1.h" diff --git a/include/assimp/vector3.inl b/include/assimp/vector3.inl index c03437980..63c91480a 100644 --- a/include/assimp/vector3.inl +++ b/include/assimp/vector3.inl @@ -90,7 +90,7 @@ AI_FORCE_INLINE TReal aiVector3t::SquareLength() const { // ------------------------------------------------------------------------------------------------ template AI_FORCE_INLINE TReal aiVector3t::Length() const { - return sqrt( SquareLength()); + return ::sqrt( SquareLength()); } // ------------------------------------------------------------------------------------------------ template @@ -207,6 +207,7 @@ AI_FORCE_INLINE aiVector3t operator - ( const aiVector3t& v) { return aiVector3t( -v.x, -v.y, -v.z); } +// ------------------------------------------------------------------------------------------------ #endif // __cplusplus #endif // AI_VECTOR3D_INL_INC From 38de6a658d030c62629247924b0f26eb884ac8d2 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 27 Mar 2014 20:33:08 +0100 Subject: [PATCH 04/14] bugfix: - fix redundant checks against nullptr ( see https://github.com/assimp/assimp/issues/241 ). Signed-off-by: Kim Kulling --- code/Q3BSPFileData.h | 101 ++++++++++++++++--------------------- code/Q3BSPFileImporter.cpp | 74 +++++++++++---------------- include/assimp/metadata.h | 17 ++++--- 3 files changed, 84 insertions(+), 108 deletions(-) diff --git a/code/Q3BSPFileData.h b/code/Q3BSPFileData.h index 82881c861..452f83122 100644 --- a/code/Q3BSPFileData.h +++ b/code/Q3BSPFileData.h @@ -42,10 +42,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -namespace Assimp -{ -namespace Q3BSP -{ +namespace Assimp { +namespace Q3BSP { static const unsigned int CE_BSP_LIGHTMAPWIDTH = 128; static const unsigned int CE_BSP_LIGHTMAPHEIGHT = 128; @@ -54,8 +52,7 @@ static const unsigned int CE_BSP_LIGHTMAPSIZE = 128*128*3; ///< = 128( width ) * static const int VERION_Q3LEVEL = 46; ///< Supported version. /// Geometric type enumeration -enum Q3BSPGeoType -{ +enum Q3BSPGeoType { Polygon = 1, Patch, TriangleMesh, @@ -63,25 +60,23 @@ enum Q3BSPGeoType }; /// Integer vector. -struct ceVec3i -{ +struct ceVec3i { int x, y, z; ceVec3i(): x( 0 ), y( 0 ), z( 0 ) { /* empty */ } ceVec3i( int iX, int iY=0, int iZ=0) : x( iX ), y( iY ), z( iZ ) { /* empty */ } }; -/// Fileheader -struct sQ3BSPHeader -{ - char strID[ 4 ]; //!< Should be "IBSP" - int iVersion; //!< 46 for standard levels +/// the file header +struct sQ3BSPHeader { + char strID[ 4 ]; ///< Should be "IBSP" + int iVersion; ///< 46 for standard levels }; -/// Descripes an entry. +/// Describes an entry. struct sQ3BSPLump { - int iOffset; ///< Offset from startpointer of file - int iSize; ///< Size fo part + int iOffset; ///< Offset from start pointer of file + int iSize; ///< Size of part }; struct vec2f @@ -108,47 +103,42 @@ struct sQ3BSPVertex struct sQ3BSPFace { int iTextureID; ///< Index in texture array - int iEffect; ///< Index in effectarray (-1 = no effect) + int iEffect; ///< Index in effect array (-1 = no effect) int iType; ///< 1=Polygon, 2=Patch, 3=Mesh, 4=Billboard int iVertexIndex; ///< Start index of polygon int iNumOfVerts; ///< Number of vertices int iFaceVertexIndex; ///< Index of first mesh vertex - int iNumOfFaceVerts; ///< Anzahl der Meshvertices - int iLightmapID; ///< Index to the lightmap array - int iLMapCorner[ 2 ]; ///< Die Ecke der Lightmap in der Textur - int iLMapSize[ 2 ]; ///< Size of the lightmap stored on the texture - vec3f vLMapPos; ///< 3D-Ursprung der Lightmap - vec3f vLMapVecs[ 2 ]; ///< 3D-s-t-Vektoren - vec3f vNormal; ///< Polygonnormale + int iNumOfFaceVerts; ///< number of mesh vertices + int iLightmapID; ///< Index to the light-map array + int iLMapCorner[ 2 ]; ///< edge of the light-map in texture + int iLMapSize[ 2 ]; ///< Size of the light-map stored on the texture + vec3f vLMapPos; ///< 3D origin of the light-map + vec3f vLMapVecs[ 2 ]; ///< 3D-s-t-vectors + vec3f vNormal; ///< Polygon normals int patchWidth, patchHeight; ///< bezier patch }; /// A quake3 texture name. -struct sQ3BSPTexture -{ - char strName[ 64 ]; ///< Name of the texture without extention +struct sQ3BSPTexture { + char strName[ 64 ]; ///< Name of the texture without extension int iFlags; ///< Not used int iContents; ///< Not used }; -/// A lightmap of the level, size 128 x 128, RGB components. -struct sQ3BSPLightmap -{ +/// A light-map of the level, size 128 x 128, RGB components. +struct sQ3BSPLightmap { unsigned char bLMapData[ CE_BSP_LIGHTMAPSIZE ]; - sQ3BSPLightmap() - { - memset(bLMapData, 0, CE_BSP_LIGHTMAPSIZE ); + sQ3BSPLightmap() { + ::memset(bLMapData, 0, CE_BSP_LIGHTMAPSIZE ); } }; -struct SubPatch -{ +struct SubPatch { std::vector indices; int lightmapID; }; -enum eLumps -{ +enum eLumps { kEntities = 0, kTextures, kPlanes, @@ -169,8 +159,7 @@ enum eLumps kMaxLumps }; -struct Q3BSPModel -{ +struct Q3BSPModel { std::vector m_Data; std::vector m_Lumps; std::vector m_Vertices; @@ -195,24 +184,22 @@ struct Q3BSPModel // empty } - ~Q3BSPModel() - { - for ( unsigned int i=0; i &supportedExtensions) { + supportedExtensions.push_back( ".jpg" ); + supportedExtensions.push_back( ".png" ); + supportedExtensions.push_back( ".tga" ); +} + using namespace Q3BSP; // ------------------------------------------------------------------------------------------------ @@ -86,7 +91,7 @@ static void createKey( int id1, int id2, std::string &rKey ) } // ------------------------------------------------------------------------------------------------ -// Local function to extract the texture ids from a material keyname. +// Local function to extract the texture ids from a material key-name. static void extractIds( const std::string &rKey, int &rId1, int &rId2 ) { rId1 = -1; @@ -146,24 +151,16 @@ Q3BSPFileImporter::Q3BSPFileImporter() : // ------------------------------------------------------------------------------------------------ // Destructor. -Q3BSPFileImporter::~Q3BSPFileImporter() -{ - // For lint +Q3BSPFileImporter::~Q3BSPFileImporter() { m_pCurrentMesh = NULL; m_pCurrentFace = NULL; // Clear face-to-material map - for ( FaceMap::iterator it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); - ++it ) - { - const std::string matName = (*it).first; - if ( matName.empty() ) - { - continue; + for ( FaceMap::iterator it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); ++it ) { + const std::string &matName = it->first; + if ( !matName.empty() ) { + delete it->second; } - - std::vector *pCurFaceArray = (*it).second; - delete pCurFaceArray; } m_MaterialLookupMap.clear(); } @@ -566,7 +563,7 @@ size_t Q3BSPFileImporter::countFaces( const std::vector &rAr } // ------------------------------------------------------------------------------------------------ -// Counts the number of triangles in a Q3-facearray. +// Counts the number of triangles in a Q3-face-array. size_t Q3BSPFileImporter::countTriangles( const std::vector &rArray ) const { size_t numTriangles = 0; @@ -617,16 +614,11 @@ void Q3BSPFileImporter::createMaterialMap( const Q3BSP::Q3BSPModel *pModel ) // Returns the next face. aiFace *Q3BSPFileImporter::getNextFace( aiMesh *pMesh, unsigned int &rFaceIdx ) { - aiFace *pFace = NULL; - if ( rFaceIdx < pMesh->mNumFaces ) - { + aiFace *pFace( NULL ); + if ( rFaceIdx < pMesh->mNumFaces ) { pFace = &pMesh->mFaces[ rFaceIdx ]; rFaceIdx++; } - else - { - pFace = NULL; - } return pFace; } @@ -634,34 +626,30 @@ aiFace *Q3BSPFileImporter::getNextFace( aiMesh *pMesh, unsigned int &rFaceIdx ) // ------------------------------------------------------------------------------------------------ // Imports a texture file. bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pModel, - Q3BSP::Q3BSPZipArchive *pArchive, aiScene* /*pScene*/, - aiMaterial *pMatHelper, int textureId ) -{ - std::vector supportedExtensions; - supportedExtensions.push_back( ".jpg" ); - supportedExtensions.push_back( ".png" ); - supportedExtensions.push_back( ".tga" ); - if ( NULL == pArchive || NULL == pArchive || NULL == pMatHelper ) - { + Q3BSP::Q3BSPZipArchive *pArchive, aiScene*, + aiMaterial *pMatHelper, int textureId ) { + if ( NULL == pArchive || NULL == pArchive || NULL == pMatHelper ) { return false; } - if ( textureId < 0 || textureId >= static_cast( pModel->m_Textures.size() ) ) - { + if ( textureId < 0 || textureId >= static_cast( pModel->m_Textures.size() ) ) { return false; } bool res = true; sQ3BSPTexture *pTexture = pModel->m_Textures[ textureId ]; - if ( NULL == pTexture ) - return false; + if ( !pTexture ) { + return false; + } + std::vector supportedExtensions; + supportedExtensions.push_back( ".jpg" ); + supportedExtensions.push_back( ".png" ); + supportedExtensions.push_back( ".tga" ); std::string textureName, ext; - if ( expandFile( pArchive, pTexture->strName, supportedExtensions, textureName, ext ) ) - { + if ( expandFile( pArchive, pTexture->strName, supportedExtensions, textureName, ext ) ) { IOStream *pTextureStream = pArchive->Open( textureName.c_str() ); - if ( NULL != pTextureStream ) - { + if ( !pTextureStream ) { size_t texSize = pTextureStream->FileSize(); aiTexture *pTexture = new aiTexture; pTexture->mHeight = 0; @@ -685,9 +673,7 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pMode pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) ); mTextures.push_back( pTexture ); - } - else - { + } else { // If it doesn't exist in the archive, it is probably just a reference to an external file. // We'll leave it up to the user to figure out which extension the file has. aiString name; diff --git a/include/assimp/metadata.h b/include/assimp/metadata.h index f69f73ae2..ac55d2395 100644 --- a/include/assimp/metadata.h +++ b/include/assimp/metadata.h @@ -141,8 +141,8 @@ struct aiMetadata /** Destructor */ ~aiMetadata() { - if (mKeys) - delete [] mKeys; + delete[] mKeys; + mKeys = NULL; if (mValues) { // Delete each metadata entry @@ -177,8 +177,8 @@ struct aiMetadata // Delete the metadata array delete [] mValues; + mValues = NULL; } - } @@ -206,8 +206,9 @@ struct aiMetadata // Return false if the output data type does // not match the found value's data type - if (GetAiType(value) != mValues[index].mType) - return false; + if ( GetAiType( value ) != mValues[ index ].mType ) { + return false; + } // Otherwise, output the found value and // return true @@ -226,10 +227,12 @@ struct aiMetadata } template - inline bool Get( const std::string& key, T& value ) - { return Get(aiString(key), value); } + inline bool Get( const std::string& key, T& value ) { + return Get(aiString(key), value); + } #endif // __cplusplus + }; #endif // __AI_METADATA_H_INC__ From 4f36e85bd89f3ab769614125523447e18839b5d3 Mon Sep 17 00:00:00 2001 From: attila-barsi Date: Mon, 31 Mar 2014 10:30:04 +0200 Subject: [PATCH 05/14] Added required changes to doc and protection from nullptr. --- code/FBXConverter.cpp | 132 +++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 9f2b70b7f..a68be8ac5 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -23,7 +23,7 @@ following conditions are met: derived from this software without specific prior written permission of the assimp team. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT @@ -1457,87 +1457,89 @@ private: } const Texture* const tex = (*it).second; - - aiString path; - path.Set(tex->RelativeFilename()); + if(tex !=0 ) + { + aiString path; + path.Set(tex->RelativeFilename()); - out_mat->AddProperty(&path,_AI_MATKEY_TEXTURE_BASE,target,0); + out_mat->AddProperty(&path,_AI_MATKEY_TEXTURE_BASE,target,0); - aiUVTransform uvTrafo; - // XXX handle all kinds of UV transformations - uvTrafo.mScaling = tex->UVScaling(); - uvTrafo.mTranslation = tex->UVTranslation(); - out_mat->AddProperty(&uvTrafo,1,_AI_MATKEY_UVTRANSFORM_BASE,target,0); + aiUVTransform uvTrafo; + // XXX handle all kinds of UV transformations + uvTrafo.mScaling = tex->UVScaling(); + uvTrafo.mTranslation = tex->UVTranslation(); + out_mat->AddProperty(&uvTrafo,1,_AI_MATKEY_UVTRANSFORM_BASE,target,0); - const PropertyTable& props = tex->Props(); + const PropertyTable& props = tex->Props(); - int uvIndex = 0; + int uvIndex = 0; - bool ok; - const std::string& uvSet = PropertyGet(props,"UVSet",ok); - if(ok) { - // "default" is the name which usually appears in the FbxFileTexture template - if(uvSet != "default" && uvSet.length()) { - // this is a bit awkward - we need to find a mesh that uses this - // material and scan its UV channels for the given UV name because - // assimp references UV channels by index, not by name. + bool ok; + const std::string& uvSet = PropertyGet(props,"UVSet",ok); + if(ok) { + // "default" is the name which usually appears in the FbxFileTexture template + if(uvSet != "default" && uvSet.length()) { + // this is a bit awkward - we need to find a mesh that uses this + // material and scan its UV channels for the given UV name because + // assimp references UV channels by index, not by name. - // XXX: the case that UV channels may appear in different orders - // in meshes is unhandled. A possible solution would be to sort - // the UV channels alphabetically, but this would have the side - // effect that the primary (first) UV channel would sometimes - // be moved, causing trouble when users read only the first - // UV channel and ignore UV channel assignments altogether. + // XXX: the case that UV channels may appear in different orders + // in meshes is unhandled. A possible solution would be to sort + // the UV channels alphabetically, but this would have the side + // effect that the primary (first) UV channel would sometimes + // be moved, causing trouble when users read only the first + // UV channel and ignore UV channel assignments altogether. - const unsigned int matIndex = static_cast(std::distance(materials.begin(), - std::find(materials.begin(),materials.end(),out_mat) - )); + const unsigned int matIndex = static_cast(std::distance(materials.begin(), + std::find(materials.begin(),materials.end(),out_mat) + )); - uvIndex = -1; - BOOST_FOREACH(const MeshMap::value_type& v,meshes_converted) { - const MeshGeometry* const mesh = dynamic_cast (v.first); - if(!mesh) { - continue; - } - - const MatIndexArray& mats = mesh->GetMaterialIndices(); - if(std::find(mats.begin(),mats.end(),matIndex) == mats.end()) { - continue; - } - - int index = -1; - for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { - if(mesh->GetTextureCoords(i).empty()) { - break; + uvIndex = -1; + BOOST_FOREACH(const MeshMap::value_type& v,meshes_converted) { + const MeshGeometry* const mesh = dynamic_cast (v.first); + if(!mesh) { + continue; } - const std::string& name = mesh->GetTextureCoordChannelName(i); - if(name == uvSet) { - index = static_cast(i); - break; + + const MatIndexArray& mats = mesh->GetMaterialIndices(); + if(std::find(mats.begin(),mats.end(),matIndex) == mats.end()) { + continue; + } + + int index = -1; + for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { + if(mesh->GetTextureCoords(i).empty()) { + break; + } + const std::string& name = mesh->GetTextureCoordChannelName(i); + if(name == uvSet) { + index = static_cast(i); + break; + } + } + if(index == -1) { + FBXImporter::LogWarn("did not find UV channel named " + uvSet + " in a mesh using this material"); + continue; + } + + if(uvIndex == -1) { + uvIndex = index; + } + else { + FBXImporter::LogWarn("the UV channel named " + uvSet + + " appears at different positions in meshes, results will be wrong"); } - } - if(index == -1) { - FBXImporter::LogWarn("did not find UV channel named " + uvSet + " in a mesh using this material"); - continue; } if(uvIndex == -1) { - uvIndex = index; + FBXImporter::LogWarn("failed to resolve UV channel " + uvSet + ", using first UV channel"); + uvIndex = 0; } - else { - FBXImporter::LogWarn("the UV channel named " + uvSet + - " appears at different positions in meshes, results will be wrong"); - } - } - - if(uvIndex == -1) { - FBXImporter::LogWarn("failed to resolve UV channel " + uvSet + ", using first UV channel"); - uvIndex = 0; } } - } - out_mat->AddProperty(&uvIndex,1,_AI_MATKEY_UVWSRC_BASE,target,0); + out_mat->AddProperty(&uvIndex,1,_AI_MATKEY_UVWSRC_BASE,target,0); + } } // ------------------------------------------------------------------------------------------------ From da1c9e8434001cc9ef429c0ef96b31fd0e320e33 Mon Sep 17 00:00:00 2001 From: jmas-ogawa Date: Mon, 14 Apr 2014 23:04:36 +0900 Subject: [PATCH 06/14] Fixed half-width from the full-width double quotes. --- port/iOS/IPHONEOS_ARM64_TOOLCHAIN.cmake | 4 ++-- port/iOS/IPHONEOS_ARMV6_TOOLCHAIN.cmake | 4 ++-- port/iOS/IPHONEOS_ARMV7S_TOOLCHAIN.cmake | 6 +++--- port/iOS/IPHONEOS_ARMV7_TOOLCHAIN.cmake | 4 ++-- port/iOS/IPHONEOS_I386_TOOLCHAIN.cmake | 6 +++--- port/iOS/IPHONEOS_X86_64_TOOLCHAIN.cmake | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/port/iOS/IPHONEOS_ARM64_TOOLCHAIN.cmake b/port/iOS/IPHONEOS_ARM64_TOOLCHAIN.cmake index 3cefaf9be..bd7199cc5 100644 --- a/port/iOS/IPHONEOS_ARM64_TOOLCHAIN.cmake +++ b/port/iOS/IPHONEOS_ARM64_TOOLCHAIN.cmake @@ -2,9 +2,9 @@ INCLUDE(CMakeForceCompiler) SET (CMAKE_CROSSCOMPILING TRUE) SET (CMAKE_SYSTEM_NAME "Darwin") -SET (CMAKE_SYSTEM_PROCESSOR "arm64”) +SET (CMAKE_SYSTEM_PROCESSOR "arm64") -SET (SDKVER “7.1”) +SET (SDKVER "7.1") SET (DEVROOT "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain") SET (SDKROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk") SET (CC "${DEVROOT}/usr/bin/llvm-gcc") diff --git a/port/iOS/IPHONEOS_ARMV6_TOOLCHAIN.cmake b/port/iOS/IPHONEOS_ARMV6_TOOLCHAIN.cmake index f72569f94..5ec416322 100644 --- a/port/iOS/IPHONEOS_ARMV6_TOOLCHAIN.cmake +++ b/port/iOS/IPHONEOS_ARMV6_TOOLCHAIN.cmake @@ -4,10 +4,10 @@ SET (CMAKE_CROSSCOMPILING TRUE) SET (CMAKE_SYSTEM_NAME "Darwin") SET (CMAKE_SYSTEM_PROCESSOR "armv6") -SET (SDKVER “7.1”) +SET (SDKVER "7.1") SET (DEVROOT "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain") SET (SDKROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk") -SET (CC "${DEVROOT}/usr/bin/clang”) +SET (CC "${DEVROOT}/usr/bin/clang") SET (CXX "${DEVROOT}/usr/bin/clang++") CMAKE_FORCE_C_COMPILER (${CC} LLVM) diff --git a/port/iOS/IPHONEOS_ARMV7S_TOOLCHAIN.cmake b/port/iOS/IPHONEOS_ARMV7S_TOOLCHAIN.cmake index dcf39e644..f11519aa4 100644 --- a/port/iOS/IPHONEOS_ARMV7S_TOOLCHAIN.cmake +++ b/port/iOS/IPHONEOS_ARMV7S_TOOLCHAIN.cmake @@ -2,12 +2,12 @@ INCLUDE(CMakeForceCompiler) SET (CMAKE_CROSSCOMPILING TRUE) SET (CMAKE_SYSTEM_NAME "Darwin") -SET (CMAKE_SYSTEM_PROCESSOR "armv7s”) +SET (CMAKE_SYSTEM_PROCESSOR "armv7s") -SET (SDKVER “7.1”) +SET (SDKVER "7.1") SET (DEVROOT "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain") SET (SDKROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk") -SET (CC "${DEVROOT}/usr/bin/clang”) +SET (CC "${DEVROOT}/usr/bin/clang") SET (CXX "${DEVROOT}/usr/bin/clang++") CMAKE_FORCE_C_COMPILER (${CC} LLVM) diff --git a/port/iOS/IPHONEOS_ARMV7_TOOLCHAIN.cmake b/port/iOS/IPHONEOS_ARMV7_TOOLCHAIN.cmake index 06aa24a00..b7f196c0f 100644 --- a/port/iOS/IPHONEOS_ARMV7_TOOLCHAIN.cmake +++ b/port/iOS/IPHONEOS_ARMV7_TOOLCHAIN.cmake @@ -4,10 +4,10 @@ SET (CMAKE_CROSSCOMPILING TRUE) SET (CMAKE_SYSTEM_NAME "Darwin") SET (CMAKE_SYSTEM_PROCESSOR "armv7") -SET (SDKVER “7.1”) +SET (SDKVER "7.1") SET (DEVROOT "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain") SET (SDKROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk") -SET (CC "${DEVROOT}/usr/bin/clang”) +SET (CC "${DEVROOT}/usr/bin/clang") SET (CXX "${DEVROOT}/usr/bin/clang++") CMAKE_FORCE_C_COMPILER (${CC} LLVM) diff --git a/port/iOS/IPHONEOS_I386_TOOLCHAIN.cmake b/port/iOS/IPHONEOS_I386_TOOLCHAIN.cmake index 22d564c95..22178bb87 100644 --- a/port/iOS/IPHONEOS_I386_TOOLCHAIN.cmake +++ b/port/iOS/IPHONEOS_I386_TOOLCHAIN.cmake @@ -2,13 +2,13 @@ INCLUDE(CMakeForceCompiler) SET (CMAKE_CROSSCOMPILING TRUE) SET (CMAKE_SYSTEM_NAME "Darwin") -SET (CMAKE_SYSTEM_PROCESSOR “i386”) +SET (CMAKE_SYSTEM_PROCESSOR "i386") -SET (SDKVER “7.1”) +SET (SDKVER "7.1") SET (DEVROOT "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain") SET (SDKROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVER}.sdk") -SET (CC "${DEVROOT}/usr/bin/clang”) +SET (CC "${DEVROOT}/usr/bin/clang") SET (CXX "${DEVROOT}/usr/bin/clang++") CMAKE_FORCE_C_COMPILER (${CC} LLVM) diff --git a/port/iOS/IPHONEOS_X86_64_TOOLCHAIN.cmake b/port/iOS/IPHONEOS_X86_64_TOOLCHAIN.cmake index 80ef8e003..3c69ecdb3 100644 --- a/port/iOS/IPHONEOS_X86_64_TOOLCHAIN.cmake +++ b/port/iOS/IPHONEOS_X86_64_TOOLCHAIN.cmake @@ -2,13 +2,13 @@ INCLUDE(CMakeForceCompiler) SET (CMAKE_CROSSCOMPILING TRUE) SET (CMAKE_SYSTEM_NAME "Darwin") -SET (CMAKE_SYSTEM_PROCESSOR “x86_64”) +SET (CMAKE_SYSTEM_PROCESSOR "x86_64") -SET (SDKVER “7.1”) +SET (SDKVER "7.1") SET (DEVROOT "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain") SET (SDKROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVER}.sdk") -SET (CC "${DEVROOT}/usr/bin/clang”) +SET (CC "${DEVROOT}/usr/bin/clang") SET (CXX "${DEVROOT}/usr/bin/clang++") CMAKE_FORCE_C_COMPILER (${CC} LLVM) From 73e6908c362cabade4c471b69bc4af4f4249f35c Mon Sep 17 00:00:00 2001 From: Peter LaValle Date: Tue, 15 Apr 2014 15:10:48 +0100 Subject: [PATCH 07/14] fixed " ... " typo The XML tags did not match. Mismatched tags confuse XML parser kits. So I fixed the tags to match. --- tools/assimp_cmd/WriteDumb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/assimp_cmd/WriteDumb.cpp b/tools/assimp_cmd/WriteDumb.cpp index c12ebdd06..d33a83f64 100644 --- a/tools/assimp_cmd/WriteDumb.cpp +++ b/tools/assimp_cmd/WriteDumb.cpp @@ -1258,7 +1258,7 @@ void WriteDump(const aiScene* scene, FILE* out, const char* src, const char* cmd mesh->mColors[a][n].a); } } - fprintf(out,"\t\t\n"); + fprintf(out,"\t\t\n"); } fprintf(out,"\t\n"); } From aae01c47ad4d41df73617302ba0e1e1c4f036de7 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 21 Apr 2014 16:18:14 +0200 Subject: [PATCH 08/14] bugfix: fix compiler warnings for gcc-4.8.1. --- code/BlenderBMesh.cpp | 4 ++-- code/BlenderScene.cpp | 9 +-------- code/BlenderTessellator.cpp | 6 +++--- code/IFCGeometry.cpp | 2 -- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/code/BlenderBMesh.cpp b/code/BlenderBMesh.cpp index 83ccd37fb..0e517f4c8 100644 --- a/code/BlenderBMesh.cpp +++ b/code/BlenderBMesh.cpp @@ -109,11 +109,11 @@ void BlenderBMeshConverter::AssertValidMesh( ) // ------------------------------------------------------------------------------------------------ void BlenderBMeshConverter::AssertValidSizes( ) { - if ( BMesh->totpoly != BMesh->mpoly.size( ) ) + if ( BMesh->totpoly != static_cast( BMesh->mpoly.size( ) ) ) { ThrowException( "BMesh poly array has incorrect size" ); } - if ( BMesh->totloop != BMesh->mloop.size( ) ) + if ( BMesh->totloop != static_cast( BMesh->mloop.size( ) ) ) { ThrowException( "BMesh loop array has incorrect size" ); } diff --git a/code/BlenderScene.cpp b/code/BlenderScene.cpp index 77b9f5f66..16f889c72 100644 --- a/code/BlenderScene.cpp +++ b/code/BlenderScene.cpp @@ -251,10 +251,7 @@ template <> void Structure :: Convert ( const int initial_pos = db.reader->GetCurrentPos(); std::pair todo = std::make_pair(&dest, initial_pos); - - Base* saved_prev = NULL; - - while(true) { + for ( ;; ) { Base& cur_dest = *todo.first; db.reader->SetCurrentPos(todo.second); @@ -265,10 +262,6 @@ template <> void Structure :: Convert ( ReadFieldPtr(cur_dest.object,"*object",db); - // just record the offset of the blob data and allocate storage. - // Does _not_ invoke Convert() recursively. - const int old = db.reader->GetCurrentPos(); - // the return value of ReadFieldPtr indicates whether the object // was already cached. In this case, we don't need to resolve // it again. diff --git a/code/BlenderTessellator.cpp b/code/BlenderTessellator.cpp index 150183519..ffe794951 100644 --- a/code/BlenderTessellator.cpp +++ b/code/BlenderTessellator.cpp @@ -51,11 +51,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "BlenderBMesh.h" #include "BlenderTessellator.h" -#define BLEND_TESS_MAGIC ( 0x83ed9ac3 ) +static const unsigned int BLEND_TESS_MAGIC = 0x83ed9ac3; #if ASSIMP_BLEND_WITH_GLU_TESSELLATE -namespace Assimp +namspace Assimp { template< > const std::string LogFunctions< BlenderTessellatorGL >::log_prefix = "BLEND_TESS_GL: "; } @@ -382,7 +382,7 @@ inline PointP2T& BlenderTessellatorP2T::GetActualPointStructure( p2t::Point& poi { unsigned int pointOffset = OffsetOf( PointP2T, point2D ); PointP2T& pointStruct = *reinterpret_cast< PointP2T* >( reinterpret_cast< char* >( &point ) - pointOffset ); - if ( pointStruct.magic != BLEND_TESS_MAGIC ) + if ( pointStruct.magic != static_cast( BLEND_TESS_MAGIC ) ) { ThrowException( "Point returned by poly2tri was probably not one of ours. This indicates we need a new way to store vertex information" ); } diff --git a/code/IFCGeometry.cpp b/code/IFCGeometry.cpp index 693db0f11..210370d90 100644 --- a/code/IFCGeometry.cpp +++ b/code/IFCGeometry.cpp @@ -325,8 +325,6 @@ void ProcessSweptDiskSolid(const IfcSweptDiskSolid solid, TempMesh& result, Conv IFCImporter::LogError("failed to convert Directrix curve (IfcSweptDiskSolid)"); return; } - - const std::vector& in = result.verts; const unsigned int cnt_segments = 16; const IfcFloat deltaAngle = AI_MATH_TWO_PI/cnt_segments; From 0e624054066fdf2befe79036d73d7ebc519f22a5 Mon Sep 17 00:00:00 2001 From: xantares Date: Mon, 21 Apr 2014 21:36:33 +0200 Subject: [PATCH 09/14] use standard BUILD_SHARED_LIB option. Install dll to /bin (mingw) --- CMakeLists.txt | 4 +--- code/CMakeLists.txt | 18 +++++++----------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index afe0cea9b..ec5820265 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,9 +53,7 @@ SET( ASSIMP_BIN_INSTALL_DIR "bin" CACHE PATH SET(ASSIMP_DEBUG_POSTFIX "d" CACHE STRING "Debug Postfitx for lib, samples and tools") # Allow the user to build a static library -SET ( ASSIMP_BUILD_STATIC_LIB OFF CACHE BOOL - "Build a static (.a) version of the library" -) +option ( BUILD_SHARED_LIB "Build a shared version of the library" ON ) # Generate a pkg-config .pc for the Assimp library. CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/assimp.pc.in" "${PROJECT_BINARY_DIR}/assimp.pc" @ONLY ) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 9d4f39cf2..29ed3ccff 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -681,15 +681,7 @@ SET( assimp_src ADD_MSVC_PRECOMPILED_HEADER("AssimpPCH.h" "AssimpPCH.cpp" assimp_src) -IF ( ASSIMP_BUILD_STATIC_LIB ) - ADD_LIBRARY( assimp STATIC - ${assimp_src} - ) -ELSE ( ASSIMP_BUILD_STATIC_LIB ) - ADD_LIBRARY( assimp SHARED - ${assimp_src} - ) -ENDIF ( ASSIMP_BUILD_STATIC_LIB ) +ADD_LIBRARY( assimp ${assimp_src} ) SET_PROPERTY(TARGET assimp PROPERTY DEBUG_POSTFIX ${ASSIMP_DEBUG_POSTFIX}) @@ -713,7 +705,11 @@ else (UNZIP_FOUND) INCLUDE_DIRECTORIES("../contrib/unzip") endif (UNZIP_FOUND) -INSTALL( TARGETS assimp DESTINATION ${ASSIMP_LIB_INSTALL_DIR} COMPONENT ${LIBASSIMP_COMPONENT}) +INSTALL( TARGETS assimp + LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR} + COMPONENT ${LIBASSIMP_COMPONENT}) INSTALL( FILES ${PUBLIC_HEADERS} DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR}/assimp COMPONENT assimp-dev) INSTALL( FILES ${COMPILER_HEADERS} DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR}/assimp/Compiler COMPONENT assimp-dev) @@ -726,4 +722,4 @@ if(MSVC AND ASSIMP_INSTALL_PDB) DESTINATION ${ASSIMP_LIB_INSTALL_DIR} CONFIGURATIONS RelWithDebInfo ) -endif () \ No newline at end of file +endif () From f48c8ecccefbf9ac652c1d2940cb9219c3315252 Mon Sep 17 00:00:00 2001 From: xantares Date: Mon, 21 Apr 2014 21:58:29 +0200 Subject: [PATCH 10/14] Fix for issue #177 with mingw --- include/assimp/types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/assimp/types.h b/include/assimp/types.h index 604591402..cbbf8fff5 100644 --- a/include/assimp/types.h +++ b/include/assimp/types.h @@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define AI_TYPES_H_INC // Some runtime headers +#include #include #include #include From 8699021f178f244cc0cd87d5fbfeef60f5c43ac3 Mon Sep 17 00:00:00 2001 From: tszirr Date: Mon, 21 Apr 2014 22:40:48 +0200 Subject: [PATCH 11/14] fix: OptimizeMeshes w/o SplitLargeMeshes was disabled due to obscure max_verts = 0 assignment --- code/OptimizeMeshes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/OptimizeMeshes.cpp b/code/OptimizeMeshes.cpp index 3f5f84b99..937a678a6 100644 --- a/code/OptimizeMeshes.cpp +++ b/code/OptimizeMeshes.cpp @@ -74,7 +74,7 @@ bool OptimizeMeshesProcess::IsActive( unsigned int pFlags) const // That's a serious design flaw, consider redesign. if( 0 != (pFlags & aiProcess_OptimizeMeshes) ) { pts = (0 != (pFlags & aiProcess_SortByPType)); - max_verts = (0 != (pFlags & aiProcess_SplitLargeMeshes)) ? 0xdeadbeef : 0; + max_verts = (0 != (pFlags & aiProcess_SplitLargeMeshes)) ? 0xdeadbeef : max_verts; return true; } return false; From 0a01da72426732c3baf11d38f6613483d131e50b Mon Sep 17 00:00:00 2001 From: tszirr Date: Mon, 21 Apr 2014 22:52:50 +0200 Subject: [PATCH 12/14] fix: optimize meshes when vertex & primitive format final --- code/PostStepRegistry.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/PostStepRegistry.cpp b/code/PostStepRegistry.cpp index 3fdbeb257..b6ad6157d 100644 --- a/code/PostStepRegistry.cpp +++ b/code/PostStepRegistry.cpp @@ -145,9 +145,6 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out) #if (!defined ASSIMP_BUILD_NO_OPTIMIZEGRAPH_PROCESS) out.push_back( new OptimizeGraphProcess()); #endif -#if (!defined ASSIMP_BUILD_NO_OPTIMIZEMESHES_PROCESS) - out.push_back( new OptimizeMeshesProcess()); -#endif #if (!defined ASSIMP_BUILD_NO_FINDDEGENERATES_PROCESS) out.push_back( new FindDegeneratesProcess()); #endif @@ -169,6 +166,9 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out) #if (!defined ASSIMP_BUILD_NO_FINDINVALIDDATA_PROCESS) out.push_back( new FindInvalidDataProcess()); #endif +#if (!defined ASSIMP_BUILD_NO_OPTIMIZEMESHES_PROCESS) + out.push_back( new OptimizeMeshesProcess()); +#endif #if (!defined ASSIMP_BUILD_NO_FIXINFACINGNORMALS_PROCESS) out.push_back( new FixInfacingNormalsProcess()); #endif From 25c2dd58de975c968a31f1f3aa67534da961637d Mon Sep 17 00:00:00 2001 From: tszirr Date: Mon, 21 Apr 2014 23:12:51 +0200 Subject: [PATCH 13/14] fix: smoothed normal qnan handling & more stable smoothed normals for imprecise geometry w/ long thin faces --- code/GenVertexNormalsProcess.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/code/GenVertexNormalsProcess.cpp b/code/GenVertexNormalsProcess.cpp index 605ca7833..b278afb87 100644 --- a/code/GenVertexNormalsProcess.cpp +++ b/code/GenVertexNormalsProcess.cpp @@ -142,7 +142,7 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int const aiVector3D* pV1 = &pMesh->mVertices[face.mIndices[0]]; const aiVector3D* pV2 = &pMesh->mVertices[face.mIndices[1]]; const aiVector3D* pV3 = &pMesh->mVertices[face.mIndices[face.mNumIndices-1]]; - const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).Normalize(); + const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)); for (unsigned int i = 0;i < face.mNumIndices;++i) { pMesh->mNormals[face.mIndices[i]] = vNor; @@ -209,18 +209,19 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int // Get all vertices that share this one ... vertexFinder->FindPositions( pMesh->mVertices[i] , posEpsilon, verticesFound); + aiVector3D vr = pMesh->mNormals[i]; + float vrlen = vr.Length(); + aiVector3D pcNor; for (unsigned int a = 0; a < verticesFound.size(); ++a) { - const aiVector3D& v = pMesh->mNormals[verticesFound[a]]; + aiVector3D v = pMesh->mNormals[verticesFound[a]]; // check whether the angle between the two normals is not too large // HACK: if v.x is qnan the dot product will become qnan, too // therefore the comparison against fLimit should be false // in every case. - if (v * pMesh->mNormals[i] < fLimit) - continue; - - pcNor += v; + if (v * vr >= fLimit * vrlen * v.Length()) + pcNor += v; } pcNew[i] = pcNor.Normalize(); } From 51cb2c042c571b5ed6070d49b75a42ebca92179a Mon Sep 17 00:00:00 2001 From: tszirr Date: Mon, 21 Apr 2014 23:20:34 +0200 Subject: [PATCH 14/14] fix: want to add if NOT qnan --- code/GenVertexNormalsProcess.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/code/GenVertexNormalsProcess.cpp b/code/GenVertexNormalsProcess.cpp index 605ca7833..a659350fc 100644 --- a/code/GenVertexNormalsProcess.cpp +++ b/code/GenVertexNormalsProcess.cpp @@ -217,10 +217,8 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int // HACK: if v.x is qnan the dot product will become qnan, too // therefore the comparison against fLimit should be false // in every case. - if (v * pMesh->mNormals[i] < fLimit) - continue; - - pcNor += v; + if (v * pMesh->mNormals[i] >= fLimit) + pcNor += v; } pcNew[i] = pcNor.Normalize(); }