diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 8668d4e6b..40840759b 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -669,6 +669,8 @@ SET( PostProcessing_SRCS PostProcessing/MakeVerboseFormat.h PostProcessing/ScaleProcess.cpp PostProcessing/ScaleProcess.h + PostProcessing/GenBoundingBoxesProcess.cpp + PostProcessing/GenBoundingBoxesProcess.h ) SOURCE_GROUP( PostProcessing FILES ${PostProcessing_SRCS}) diff --git a/code/Common/BaseProcess.cpp b/code/Common/BaseProcess.cpp index 18872c369..e247be418 100644 --- a/code/Common/BaseProcess.cpp +++ b/code/Common/BaseProcess.cpp @@ -89,7 +89,7 @@ void BaseProcess::ExecuteOnScene( Importer* pImp) // and kill the partially imported data delete pImp->Pimpl()->mScene; - pImp->Pimpl()->mScene = NULL; + pImp->Pimpl()->mScene = nullptr; } } diff --git a/code/Common/PostStepRegistry.cpp b/code/Common/PostStepRegistry.cpp index c08963817..ef58f8ddf 100644 --- a/code/Common/PostStepRegistry.cpp +++ b/code/Common/PostStepRegistry.cpp @@ -131,6 +131,10 @@ corresponding preprocessor flag to selectively disable steps. #if (!defined ASSIMP_BUILD_NO_GLOBALSCALE_PROCESS) # include "PostProcessing/ScaleProcess.h" #endif +#if (!defined ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS) +# include "PostProcessing/GenBoundingBoxesProcess.h" +#endif + namespace Assimp { @@ -246,6 +250,9 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out) #if (!defined ASSIMP_BUILD_NO_IMPROVECACHELOCALITY_PROCESS) out.push_back( new ImproveCacheLocalityProcess()); #endif +#if (!defined ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS) + out.push_back(new GenBoundingBoxesProcess); +#endif } } diff --git a/code/PostProcessing/GenBoundingBoxesProcess.h b/code/PostProcessing/GenBoundingBoxesProcess.h index 433144e8e..4b43c82a4 100644 --- a/code/PostProcessing/GenBoundingBoxesProcess.h +++ b/code/PostProcessing/GenBoundingBoxesProcess.h @@ -39,23 +39,38 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ +/** @file Defines a post-processing step to generate Axis-aligned bounding + * volumes for all meshes. + */ + #pragma once #ifndef AI_GENBOUNDINGBOXESPROCESS_H_INC #define AI_GENBOUNDINGBOXESPROCESS_H_INC +#ifndef ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS + #include "Common/BaseProcess.h" namespace Assimp { -class GenBoundingBoxesProcess : public BaseProcess { +/** Post-processing process to find axis-aligned bounding volumes for amm meshes + * used in a scene + */ +class ASSIMP_API GenBoundingBoxesProcess : public BaseProcess { public: + /// The class constructor. GenBoundingBoxesProcess(); + /// The class destructor. ~GenBoundingBoxesProcess(); + /// Will return true, if aiProcess_GenBoundingBoxes is defined. bool IsActive(unsigned int pFlags) const override; + /// The execution callback. void Execute(aiScene* pScene) override; }; } // Namespace Assimp +#endif // #ifndef ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS + #endif // AI_GENBOUNDINGBOXESPROCESS_H_INC diff --git a/code/PostProcessing/SplitLargeMeshes.h b/code/PostProcessing/SplitLargeMeshes.h index f683663b8..3f90576ea 100644 --- a/code/PostProcessing/SplitLargeMeshes.h +++ b/code/PostProcessing/SplitLargeMeshes.h @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2019, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -40,7 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ -/** @file Defines a post processing step to split large meshes into submeshes +/** @file Defines a post processing step to split large meshes into sub-meshes */ #ifndef AI_SPLITLARGEMESHES_H_INC #define AI_SPLITLARGEMESHES_H_INC @@ -51,10 +50,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +// Forward declarations class SplitLargeMeshesTest; -namespace Assimp -{ +namespace Assimp { class SplitLargeMeshesProcess_Triangle; class SplitLargeMeshesProcess_Vertex; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4db319725..737a34610 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -161,6 +161,7 @@ SET( POST_PROCESSES unit/utTargetAnimation.cpp unit/utSortByPType.cpp unit/utSceneCombiner.cpp + unit/utGenBoundingBoxesProcess.cpp ) SOURCE_GROUP( UnitTests\\Compiler FILES unit/CCompilerTest.c ) diff --git a/test/models/PLY/cube_test.ply b/test/models/PLY/cube_test.ply index 194798cf0..eef7cd426 100644 --- a/test/models/PLY/cube_test.ply +++ b/test/models/PLY/cube_test.ply @@ -1,6 +1,6 @@ ply format ascii 1.0 -comment Created by Open Asset Import Library - http://assimp.sf.net (v4.1.3945266037) +comment Created by Open Asset Import Library - http://assimp.sf.net (v4.1.649942190) element vertex 8 property float x property float y diff --git a/test/unit/utGenBoundingBoxesProcess.cpp b/test/unit/utGenBoundingBoxesProcess.cpp new file mode 100644 index 000000000..a26edb7e3 --- /dev/null +++ b/test/unit/utGenBoundingBoxesProcess.cpp @@ -0,0 +1,88 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (assimp) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2019, assimp team + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the following +conditions are met: + +* Redistributions of source code must retain the above +copyright notice, this list of conditions and the +following disclaimer. + +* Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the +following disclaimer in the documentation and/or other +materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its +contributors may be used to endorse or promote products +derived from this software without specific prior +written permission of the assimp team. + +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 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--------------------------------------------------------------------------- +*/ +#include "UnitTestPCH.h" + +#include "PostProcessing/GenBoundingBoxesProcess.h" +#include +#include + +using namespace Assimp; + +class utGenBoundingBoxesProcess : public ::testing::Test { +public: + void SetUp() override { + mProcess = new GenBoundingBoxesProcess; + mMesh = new aiMesh(); + mMesh->mNumVertices = 100; + mMesh->mVertices = new aiVector3D[100]; + for (unsigned int i = 0; i < 100; ++i) { + mMesh->mVertices[i] = aiVector3D(i, i, i); + } + mScene = new aiScene(); + mScene->mNumMeshes = 1; + mScene->mMeshes = new aiMesh*[1]; + mScene->mMeshes[0] = mMesh; + } + + void TearDown() override { + delete mProcess; + delete mScene; + } + +protected: + GenBoundingBoxesProcess *mProcess; + aiMesh *mMesh; + aiScene* mScene; +}; + +TEST_F(utGenBoundingBoxesProcess, executeTest) { + mProcess->Execute(mScene); + + aiMesh* mesh = mScene->mMeshes[0]; + EXPECT_NE(nullptr, mesh); + EXPECT_EQ(0, mesh->mAABB.mMin.x); + EXPECT_EQ(0, mesh->mAABB.mMin.y); + EXPECT_EQ(0, mesh->mAABB.mMin.z); + + EXPECT_EQ(99, mesh->mAABB.mMax.x); + EXPECT_EQ(99, mesh->mAABB.mMax.y); + EXPECT_EQ(99, mesh->mAABB.mMax.z); +}