diff --git a/.travis.sh b/.travis.sh index 397e75077..fb42bd40d 100755 --- a/.travis.sh +++ b/.travis.sh @@ -46,7 +46,7 @@ if [ "$TRAVIS_OS_NAME" = "linux" ]; then if [ $ANALYZE = "ON" ] ; then if [ "$CC" = "clang" ]; then scan-build cmake -G "Unix Makefiles" -DBUILD_SHARED_LIBS=OFF -DASSIMP_BUILD_TESTS=OFF - scan-build --status-bugs make -j2 -v + scan-build --status-bugs make -j2 else cppcheck --version generate \ diff --git a/code/BaseImporter.cpp b/code/BaseImporter.cpp index 09b32e3ae..b9b9eeb71 100644 --- a/code/BaseImporter.cpp +++ b/code/BaseImporter.cpp @@ -89,12 +89,12 @@ aiScene* BaseImporter::ReadFile(const Importer* pImp, const std::string& pFile, FileSystemFilter filter(pFile,pIOHandler); // create a scene object to hold the data - ScopeGuard sc(new aiScene()); + std::unique_ptr sc(new aiScene()); // dispatch importing try { - InternReadFile( pFile, sc, &filter); + InternReadFile( pFile, sc.get(), &filter); } catch( const std::exception& err ) { // extract error description @@ -104,8 +104,7 @@ aiScene* BaseImporter::ReadFile(const Importer* pImp, const std::string& pFile, } // return what we gathered from the import. - sc.dismiss(); - return sc; + return sc.release(); } // ------------------------------------------------------------------------------------------------ diff --git a/code/BaseImporter.h b/code/BaseImporter.h index cee54c1ad..b424d2f83 100644 --- a/code/BaseImporter.h +++ b/code/BaseImporter.h @@ -65,42 +65,6 @@ class IOStream; #define AI_MAKE_MAGIC(string) ((uint32_t)((string[0] << 24) + \ (string[1] << 16) + (string[2] << 8) + string[3])) -// --------------------------------------------------------------------------- -template -struct ScopeGuard -{ - explicit ScopeGuard(T* obj) : obj(obj), mdismiss() {} - ~ScopeGuard () throw() { - if (!mdismiss) { - delete obj; - } - obj = NULL; - } - - T* dismiss() { - mdismiss=true; - return obj; - } - - operator T*() { - return obj; - } - - T* operator -> () { - return obj; - } - -private: - // no copying allowed. - ScopeGuard(); - ScopeGuard( const ScopeGuard & ); - ScopeGuard &operator = ( const ScopeGuard & ); - - T* obj; - bool mdismiss; -}; - - // --------------------------------------------------------------------------- /** FOR IMPORTER PLUGINS ONLY: The BaseImporter defines a common interface diff --git a/code/BlenderLoader.cpp b/code/BlenderLoader.cpp index 6d4c97cbf..824954f56 100644 --- a/code/BlenderLoader.cpp +++ b/code/BlenderLoader.cpp @@ -1148,7 +1148,7 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co // ------------------------------------------------------------------------------------------------ aiCamera* BlenderImporter::ConvertCamera(const Scene& /*in*/, const Object* obj, const Camera* cam, ConversionData& /*conv_data*/) { - ScopeGuard out(new aiCamera()); + std::unique_ptr out(new aiCamera()); out->mName = obj->id.name+2; out->mPosition = aiVector3D(0.f, 0.f, 0.f); out->mUp = aiVector3D(0.f, 1.f, 0.f); @@ -1159,13 +1159,13 @@ aiCamera* BlenderImporter::ConvertCamera(const Scene& /*in*/, const Object* obj, out->mClipPlaneNear = cam->clipsta; out->mClipPlaneFar = cam->clipend; - return out.dismiss(); + return out.release(); } // ------------------------------------------------------------------------------------------------ aiLight* BlenderImporter::ConvertLight(const Scene& /*in*/, const Object* obj, const Lamp* lamp, ConversionData& /*conv_data*/) { - ScopeGuard out(new aiLight()); + std::unique_ptr out(new aiLight()); out->mName = obj->id.name+2; switch (lamp->type) @@ -1203,7 +1203,7 @@ aiLight* BlenderImporter::ConvertLight(const Scene& /*in*/, const Object* obj, c out->mColorAmbient = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy; out->mColorSpecular = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy; out->mColorDiffuse = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy; - return out.dismiss(); + return out.release(); } // ------------------------------------------------------------------------------------------------ @@ -1221,7 +1221,7 @@ aiNode* BlenderImporter::ConvertNode(const Scene& in, const Object* obj, Convers ++it; } - ScopeGuard node(new aiNode(obj->id.name+2)); // skip over the name prefix 'OB' + std::unique_ptr node(new aiNode(obj->id.name+2)); // skip over the name prefix 'OB' if (obj->data) { switch (obj->type) { @@ -1305,14 +1305,14 @@ aiNode* BlenderImporter::ConvertNode(const Scene& in, const Object* obj, Convers aiNode** nd = node->mChildren = new aiNode*[node->mNumChildren](); for (const Object* nobj :children) { *nd = ConvertNode(in,nobj,conv_data,node->mTransformation * parentTransform); - (*nd++)->mParent = node; + (*nd++)->mParent = node.get(); } } // apply modifiers modifier_cache->ApplyModifiers(*node,conv_data,in,*obj); - return node.dismiss(); + return node.release(); } #endif // ASSIMP_BUILD_NO_BLEND_IMPORTER diff --git a/code/C4DImporter.cpp b/code/C4DImporter.cpp index 39514f6b8..1344f32fb 100644 --- a/code/C4DImporter.cpp +++ b/code/C4DImporter.cpp @@ -185,11 +185,11 @@ void C4DImporter::InternReadFile( const std::string& pFile, if(mesh->mMaterialIndex >= mat_count) { ++mat_count; - ScopeGuard def_material(new aiMaterial()); + std::unique_ptr def_material(new aiMaterial()); const aiString name(AI_DEFAULT_MATERIAL_NAME); def_material->AddProperty(&name, AI_MATKEY_NAME); - materials.push_back(def_material.dismiss()); + materials.push_back(def_material.release()); break; } } @@ -412,7 +412,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) const CPolygon* polys = polyObject->GetPolygonR(); ai_assert(polys != NULL); - ScopeGuard mesh(new aiMesh()); + std::unique_ptr mesh(new aiMesh()); mesh->mNumFaces = static_cast(polyCount); aiFace* face = mesh->mFaces = new aiFace[mesh->mNumFaces](); @@ -616,7 +616,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) } mesh->mMaterialIndex = ResolveMaterial(polyObject); - return mesh.dismiss(); + return mesh.release(); } diff --git a/code/D3MFImporter.cpp b/code/D3MFImporter.cpp index 2fcfefa6d..3d1846d21 100644 --- a/code/D3MFImporter.cpp +++ b/code/D3MFImporter.cpp @@ -106,7 +106,7 @@ public: private: aiNode* ReadObject(aiScene* scene) { - ScopeGuard node(new aiNode()); + std::unique_ptr node(new aiNode()); std::vector meshIds; @@ -146,7 +146,7 @@ private: std::copy(meshIds.begin(), meshIds.end(), node->mMeshes); - return node.dismiss(); + return node.release(); } diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index a5e44a607..ea911b270 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -2744,10 +2744,10 @@ aiNodeAnim* Converter::GenerateRotationNodeAnim( const std::string& name, double& max_time, double& min_time ) { - ScopeGuard na( new aiNodeAnim() ); + std::unique_ptr na( new aiNodeAnim() ); na->mNodeName.Set( name ); - ConvertRotationKeys( na, curves, layer_map, start, stop, max_time, min_time, target.RotationOrder() ); + ConvertRotationKeys( na.get(), curves, layer_map, start, stop, max_time, min_time, target.RotationOrder() ); // dummy scaling key na->mScalingKeys = new aiVectorKey[ 1 ]; @@ -2763,7 +2763,7 @@ aiNodeAnim* Converter::GenerateRotationNodeAnim( const std::string& name, na->mPositionKeys[ 0 ].mTime = 0.; na->mPositionKeys[ 0 ].mValue = aiVector3D(); - return na.dismiss(); + return na.release(); } aiNodeAnim* Converter::GenerateScalingNodeAnim( const std::string& name, @@ -2774,10 +2774,10 @@ aiNodeAnim* Converter::GenerateScalingNodeAnim( const std::string& name, double& max_time, double& min_time ) { - ScopeGuard na( new aiNodeAnim() ); + std::unique_ptr na( new aiNodeAnim() ); na->mNodeName.Set( name ); - ConvertScaleKeys( na, curves, layer_map, start, stop, max_time, min_time ); + ConvertScaleKeys( na.get(), curves, layer_map, start, stop, max_time, min_time ); // dummy rotation key na->mRotationKeys = new aiQuatKey[ 1 ]; @@ -2793,7 +2793,7 @@ aiNodeAnim* Converter::GenerateScalingNodeAnim( const std::string& name, na->mPositionKeys[ 0 ].mTime = 0.; na->mPositionKeys[ 0 ].mValue = aiVector3D(); - return na.dismiss(); + return na.release(); } @@ -2806,10 +2806,10 @@ aiNodeAnim* Converter::GenerateTranslationNodeAnim( const std::string& name, double& min_time, bool inverse ) { - ScopeGuard na( new aiNodeAnim() ); + std::unique_ptr na( new aiNodeAnim() ); na->mNodeName.Set( name ); - ConvertTranslationKeys( na, curves, layer_map, start, stop, max_time, min_time ); + ConvertTranslationKeys( na.get(), curves, layer_map, start, stop, max_time, min_time ); if ( inverse ) { for ( unsigned int i = 0; i < na->mNumPositionKeys; ++i ) { @@ -2831,7 +2831,7 @@ aiNodeAnim* Converter::GenerateTranslationNodeAnim( const std::string& name, na->mRotationKeys[ 0 ].mTime = 0.; na->mRotationKeys[ 0 ].mValue = aiQuaternion(); - return na.dismiss(); + return na.release(); } aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name, @@ -2845,7 +2845,7 @@ aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name, bool reverse_order ) { - ScopeGuard na( new aiNodeAnim() ); + std::unique_ptr na( new aiNodeAnim() ); na->mNodeName.Set( name ); const PropertyTable& props = target.Props(); @@ -2917,7 +2917,7 @@ aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name, // which requires all of rotation, scaling and translation // to be set. if ( chain[ TransformationComp_Scaling ] != iter_end ) { - ConvertScaleKeys( na, ( *chain[ TransformationComp_Scaling ] ).second, + ConvertScaleKeys( na.get(), ( *chain[ TransformationComp_Scaling ] ).second, layer_map, start, stop, max_time, @@ -2933,7 +2933,7 @@ aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name, } if ( chain[ TransformationComp_Rotation ] != iter_end ) { - ConvertRotationKeys( na, ( *chain[ TransformationComp_Rotation ] ).second, + ConvertRotationKeys( na.get(), ( *chain[ TransformationComp_Rotation ] ).second, layer_map, start, stop, max_time, @@ -2951,7 +2951,7 @@ aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name, } if ( chain[ TransformationComp_Translation ] != iter_end ) { - ConvertTranslationKeys( na, ( *chain[ TransformationComp_Translation ] ).second, + ConvertTranslationKeys( na.get(), ( *chain[ TransformationComp_Translation ] ).second, layer_map, start, stop, max_time, @@ -2967,7 +2967,7 @@ aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name, } } - return na.dismiss(); + return na.release(); } Converter::KeyFrameListList Converter::GetKeyframeList( const std::vector& nodes, int64_t start, int64_t stop ) diff --git a/code/MD3Loader.cpp b/code/MD3Loader.cpp index f6a3a85dd..11a6e56dd 100644 --- a/code/MD3Loader.cpp +++ b/code/MD3Loader.cpp @@ -1018,11 +1018,11 @@ void MD3Importer::InternReadFile( const std::string& pFile, // Convert the normal vector to uncompressed float3 format aiVector3D& nor = pcMesh->mNormals[iCurrent]; - LatLngNormalToVec3(pcVertices[pcTriangles->INDEXES[c]].NORMAL,(ai_real*)&nor); + LatLngNormalToVec3(pcVertices[index].NORMAL,(ai_real*)&nor); // Read texture coordinates - pcMesh->mTextureCoords[0][iCurrent].x = pcUVs[ pcTriangles->INDEXES[c]].U; - pcMesh->mTextureCoords[0][iCurrent].y = 1.0f-pcUVs[ pcTriangles->INDEXES[c]].V; + pcMesh->mTextureCoords[0][iCurrent].x = pcUVs[index].U; + pcMesh->mTextureCoords[0][iCurrent].y = 1.0f-pcUVs[index].V; } // Flip face order if necessary if (!shader || shader->cull == Q3Shader::CULL_CW) { diff --git a/code/STLLoader.cpp b/code/STLLoader.cpp index ab2dcf36e..be4c7584d 100644 --- a/code/STLLoader.cpp +++ b/code/STLLoader.cpp @@ -58,6 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; namespace { + static const aiImporterDesc desc = { "Stereolithography (STL) Importer", "", @@ -505,6 +506,12 @@ bool STLImporter::LoadBinaryFile() // now copy faces addFacesToMesh(pMesh); + // add all created meshes to the single node + pScene->mRootNode->mNumMeshes = pScene->mNumMeshes; + pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes]; + for (unsigned int i = 0; i < pScene->mNumMeshes; i++) + pScene->mRootNode->mMeshes[i] = i; + if (bIsMaterialise && !pMesh->mColors[0]) { // use the color as diffuse material color diff --git a/code/XGLLoader.cpp b/code/XGLLoader.cpp index df33229a6..8ef91afac 100644 --- a/code/XGLLoader.cpp +++ b/code/XGLLoader.cpp @@ -359,7 +359,7 @@ void XGLImporter::ReadLighting(TempScope& scope) // ------------------------------------------------------------------------------------------------ aiLight* XGLImporter::ReadDirectionalLight() { - ScopeGuard l(new aiLight()); + std::unique_ptr l(new aiLight()); l->mType = aiLightSource_DIRECTIONAL; while (ReadElementUpToClosing("directionallight")) { @@ -374,13 +374,13 @@ aiLight* XGLImporter::ReadDirectionalLight() l->mColorSpecular = ReadCol3(); } } - return l.dismiss(); + return l.release(); } // ------------------------------------------------------------------------------------------------ aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* closetag) { - ScopeGuard nd(new aiNode()); + std::unique_ptr nd(new aiNode()); std::vector children; std::vector meshes; @@ -463,11 +463,11 @@ aiNode* XGLImporter::ReadObject(TempScope& scope, bool skipFirst, const char* cl nd->mChildren = new aiNode*[nd->mNumChildren](); for(unsigned int i = 0; i < nd->mNumChildren; ++i) { nd->mChildren[i] = children[i]; - children[i]->mParent = nd; + children[i]->mParent = nd.get(); } } - return nd.dismiss(); + return nd.release(); } // ------------------------------------------------------------------------------------------------ @@ -539,7 +539,7 @@ aiMatrix4x4 XGLImporter::ReadTrafo() // ------------------------------------------------------------------------------------------------ aiMesh* XGLImporter::ToOutputMesh(const TempMaterialMesh& m) { - ScopeGuard mesh(new aiMesh()); + std::unique_ptr mesh(new aiMesh()); mesh->mNumVertices = static_cast(m.positions.size()); mesh->mVertices = new aiVector3D[mesh->mNumVertices]; @@ -576,7 +576,7 @@ aiMesh* XGLImporter::ToOutputMesh(const TempMaterialMesh& m) mesh->mPrimitiveTypes = m.pflags; mesh->mMaterialIndex = m.matid; - return mesh.dismiss(); + return mesh.release(); } // ------------------------------------------------------------------------------------------------ @@ -745,7 +745,7 @@ void XGLImporter::ReadMaterial(TempScope& scope) { const unsigned int mat_id = ReadIDAttr(); - ScopeGuard mat(new aiMaterial()); + std::unique_ptr mat(new aiMaterial()); while (ReadElementUpToClosing("mat")) { const std::string& s = GetElementName(); if (s == "amb") { @@ -774,8 +774,8 @@ void XGLImporter::ReadMaterial(TempScope& scope) } } - scope.materials[mat_id] = mat; - scope.materials_linear.push_back(mat.dismiss()); + scope.materials[mat_id] = mat.get(); + scope.materials_linear.push_back(mat.release()); } diff --git a/contrib/zip/src/miniz.h b/contrib/zip/src/miniz.h index 8428e6ce0..b8e4cf230 100644 --- a/contrib/zip/src/miniz.h +++ b/contrib/zip/src/miniz.h @@ -3807,9 +3807,7 @@ mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_ind status = TINFL_STATUS_FAILED; else if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) file_crc32 = (mz_uint32)mz_crc32(file_crc32, (const mz_uint8 *)pRead_buf, (size_t)file_stat.m_comp_size); - cur_file_ofs += file_stat.m_comp_size; out_buf_ofs += file_stat.m_comp_size; - comp_remaining = 0; } else { @@ -4688,7 +4686,6 @@ mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive * return MZ_FALSE; } - cur_src_file_ofs += n; cur_dst_file_ofs += n; } pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);