diff --git a/CMakeLists.txt b/CMakeLists.txt index bc222f92e..ddc2c4cc1 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/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/CMakeLists.txt b/code/CMakeLists.txt index 8705429c2..561797942 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -693,15 +693,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}) @@ -725,7 +717,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) @@ -738,4 +734,4 @@ if(MSVC AND ASSIMP_INSTALL_PDB) DESTINATION ${ASSIMP_LIB_INSTALL_DIR} CONFIGURATIONS RelWithDebInfo ) -endif () \ No newline at end of file +endif () diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index e2b37e604..f623c3ae7 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 @@ -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()); } @@ -766,6 +767,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 +1441,7 @@ private: // texture assignments SetTextureProperties(out_mat,material.Textures()); + SetTextureProperties(out_mat,material.LayeredTextures()); return static_cast(materials.size() - 1); } @@ -1455,7 +1458,103 @@ private: } const Texture* const tex = (*it).second; - + if(tex !=0 ) + { + 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 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()); @@ -1489,7 +1588,7 @@ private: 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) { @@ -1538,7 +1637,6 @@ private: out_mat->AddProperty(&uvIndex,1,_AI_MATKEY_UVWSRC_BASE,target,0); } - // ------------------------------------------------------------------------------------------------ void SetTextureProperties(aiMaterial* out_mat, const TextureMap& textures) { @@ -1554,6 +1652,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 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(); } 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; 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; diff --git a/code/PostStepRegistry.cpp b/code/PostStepRegistry.cpp index 60d2a803f..5593a7f41 100644 --- a/code/PostStepRegistry.cpp +++ b/code/PostStepRegistry.cpp @@ -154,9 +154,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 @@ -178,6 +175,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 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/matrix4x4.inl b/include/assimp/matrix4x4.inl index 327f6f00c..2d30796ab 100644 --- a/include/assimp/matrix4x4.inl +++ b/include/assimp/matrix4x4.inl @@ -52,8 +52,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "quaternion.h" #include -#include -#include +#include + +#ifdef __cplusplus +# include +#else +# include +#endif // ---------------------------------------------------------------------------------------- template diff --git a/include/assimp/metadata.h b/include/assimp/metadata.h index ffb5edfda..a16b4062b 100644 --- a/include/assimp/metadata.h +++ b/include/assimp/metadata.h @@ -143,8 +143,8 @@ struct aiMetadata /** Destructor */ ~aiMetadata() { - if (mKeys) - delete [] mKeys; + delete[] mKeys; + mKeys = NULL; if (mValues) { // Delete each metadata entry @@ -179,8 +179,8 @@ struct aiMetadata // Delete the metadata array delete [] mValues; + mValues = NULL; } - } @@ -208,8 +208,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 @@ -228,10 +229,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__ diff --git a/include/assimp/types.h b/include/assimp/types.h index 7d31d2685..822490a45 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 diff --git a/include/assimp/vector2.h b/include/assimp/vector2.h index eaea4457d..d033e5a15 100644 --- a/include/assimp/vector2.h +++ b/include/assimp/vector2.h @@ -43,7 +43,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef AI_VECTOR2D_H_INC #define AI_VECTOR2D_H_INC - + +#ifdef __cplusplus +# include +#else +# include +#endif + #include "./Compiler/pushpack1.h" // ---------------------------------------------------------------------------------- diff --git a/include/assimp/vector3.h b/include/assimp/vector3.h index e0e683c62..9edaf5bf6 100644 --- a/include/assimp/vector3.h +++ b/include/assimp/vector3.h @@ -43,7 +43,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef AI_VECTOR3D_H_INC #define AI_VECTOR3D_H_INC - + +#ifdef __cplusplus +# include +#else +# include +#endif + #include "./Compiler/pushpack1.h" #ifdef __cplusplus diff --git a/include/assimp/vector3.inl b/include/assimp/vector3.inl index ae1e4ef03..93f317645 100644 --- a/include/assimp/vector3.inl +++ b/include/assimp/vector3.inl @@ -92,7 +92,7 @@ AI_FORCE_INLINE TReal aiVector3t::SquareLength() const { // ------------------------------------------------------------------------------------------------ template AI_FORCE_INLINE TReal aiVector3t::Length() const { - return sqrt( SquareLength()); + return ::sqrt( SquareLength()); } // ------------------------------------------------------------------------------------------------ template @@ -217,6 +217,7 @@ AI_FORCE_INLINE aiVector3t operator - ( const aiVector3t& v) { return aiVector3t( -v.x, -v.y, -v.z); } +// ------------------------------------------------------------------------------------------------ #endif // __cplusplus #endif // AI_VECTOR3D_INL_INC 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) 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"); }