Merge branch 'master' into dependabot/github_actions/actions/upload-artifact-4
commit
7afbe4257b
|
@ -137,7 +137,7 @@ IF (WIN32)
|
|||
ELSE()
|
||||
OPTION( ASSIMP_BUILD_ZLIB
|
||||
"Build your own zlib"
|
||||
ON
|
||||
OFF
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
|
|
@ -89,22 +89,27 @@ using namespace Assimp;
|
|||
|
||||
namespace Assimp {
|
||||
|
||||
void ExportScenePbrt (
|
||||
const char* pFile,
|
||||
IOSystem* pIOSystem,
|
||||
const aiScene* pScene,
|
||||
const ExportProperties* /*pProperties*/
|
||||
){
|
||||
void ExportScenePbrt(const char *pFile, IOSystem *pIOSystem, const aiScene *pScene,
|
||||
const ExportProperties *) {
|
||||
std::string path = DefaultIOSystem::absolutePath(std::string(pFile));
|
||||
std::string file = DefaultIOSystem::completeBaseName(std::string(pFile));
|
||||
|
||||
path = path + file + ".pbrt";
|
||||
// initialize the exporter
|
||||
PbrtExporter exporter(pScene, pIOSystem, path, file);
|
||||
}
|
||||
|
||||
} // end of namespace Assimp
|
||||
|
||||
// Constructor
|
||||
static void create_embedded_textures_folder(const aiScene *scene, IOSystem *pIOSystem) {
|
||||
if (scene->mNumTextures > 0) {
|
||||
if (!pIOSystem->Exists("textures")) {
|
||||
if (!pIOSystem->CreateDirectory("textures")) {
|
||||
throw DeadlyExportError("Could not create textures/ directory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PbrtExporter::PbrtExporter(
|
||||
const aiScene *pScene, IOSystem *pIOSystem,
|
||||
const std::string &path, const std::string &file) :
|
||||
|
@ -127,10 +132,10 @@ PbrtExporter::PbrtExporter(
|
|||
0.f, 0.f, 1.f, 0.f, //
|
||||
0.f, 0.f, 0.f, 1.f //
|
||||
) * mRootTransform;
|
||||
|
||||
// Export embedded textures.
|
||||
if (mScene->mNumTextures > 0)
|
||||
if (!mIOSystem->CreateDirectory("textures"))
|
||||
throw DeadlyExportError("Could not create textures/ directory.");
|
||||
create_embedded_textures_folder(mScene, mIOSystem);
|
||||
|
||||
for (unsigned int i = 0; i < mScene->mNumTextures; ++i) {
|
||||
aiTexture* tex = mScene->mTextures[i];
|
||||
std::string fn = CleanTextureFilename(tex->mFilename, false);
|
||||
|
@ -176,9 +181,6 @@ PbrtExporter::PbrtExporter(
|
|||
outfile->Write(mOutput.str().c_str(), mOutput.str().length(), 1);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
PbrtExporter::~PbrtExporter() = default;
|
||||
|
||||
void PbrtExporter::WriteMetaData() {
|
||||
mOutput << "#############################\n";
|
||||
mOutput << "# Scene metadata:\n";
|
||||
|
|
|
@ -70,15 +70,33 @@ class ExportProperties;
|
|||
// ---------------------------------------------------------------------
|
||||
/** Helper class to export a given scene to a Pbrt file. */
|
||||
// ---------------------------------------------------------------------
|
||||
class PbrtExporter
|
||||
{
|
||||
class PbrtExporter {
|
||||
public:
|
||||
/// Constructor for a specific scene to export
|
||||
PbrtExporter(const aiScene *pScene, IOSystem *pIOSystem,
|
||||
const std::string &path, const std::string &file);
|
||||
|
||||
/// Destructor
|
||||
virtual ~PbrtExporter();
|
||||
virtual ~PbrtExporter() = default;
|
||||
|
||||
private:
|
||||
aiMatrix4x4 GetNodeTransform(const aiString &name) const;
|
||||
static std::string TransformAsString(const aiMatrix4x4 &m);
|
||||
static std::string RemoveSuffix(std::string filename);
|
||||
std::string CleanTextureFilename(const aiString &f, bool rewriteExtension = true) const;
|
||||
void WriteMetaData();
|
||||
void WriteWorldDefinition();
|
||||
void WriteCameras();
|
||||
void WriteCamera(int i);
|
||||
void WriteLights();
|
||||
void WriteTextures();
|
||||
static bool TextureHasAlphaMask(const std::string &filename);
|
||||
void WriteMaterials();
|
||||
void WriteMaterial(int i);
|
||||
void WriteMesh(aiMesh *mesh);
|
||||
void WriteInstanceDefinition(int i);
|
||||
void WriteGeometricObjects(aiNode *node, aiMatrix4x4 parentTransform,
|
||||
std::map<int, int> &meshUses);
|
||||
|
||||
private:
|
||||
// the scene to export
|
||||
|
@ -96,39 +114,11 @@ private:
|
|||
/// Name of the file (without extension) where the scene will be exported
|
||||
const std::string mFile;
|
||||
|
||||
private:
|
||||
// A private set to keep track of which textures have been declared
|
||||
std::set<std::string> mTextureSet;
|
||||
|
||||
// Transform to apply to the root node and all root objects such as cameras, lights, etc.
|
||||
aiMatrix4x4 mRootTransform;
|
||||
|
||||
aiMatrix4x4 GetNodeTransform(const aiString& name) const;
|
||||
static std::string TransformAsString(const aiMatrix4x4& m);
|
||||
|
||||
static std::string RemoveSuffix(std::string filename);
|
||||
std::string CleanTextureFilename(const aiString &f, bool rewriteExtension = true) const;
|
||||
|
||||
void WriteMetaData();
|
||||
|
||||
void WriteWorldDefinition();
|
||||
|
||||
void WriteCameras();
|
||||
void WriteCamera(int i);
|
||||
|
||||
void WriteLights();
|
||||
|
||||
void WriteTextures();
|
||||
static bool TextureHasAlphaMask(const std::string &filename);
|
||||
|
||||
void WriteMaterials();
|
||||
void WriteMaterial(int i);
|
||||
|
||||
void WriteMesh(aiMesh* mesh);
|
||||
|
||||
void WriteInstanceDefinition(int i);
|
||||
void WriteGeometricObjects(aiNode* node, aiMatrix4x4 parentTransform,
|
||||
std::map<int, int> &meshUses);
|
||||
};
|
||||
|
||||
} // namespace Assimp
|
||||
|
|
|
@ -111,6 +111,9 @@ void Sweep::EdgeEvent(SweepContext& tcx, Edge* edge, Node* node)
|
|||
|
||||
void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangle, Point& point)
|
||||
{
|
||||
if (triangle == nullptr)
|
||||
return;
|
||||
|
||||
if (IsEdgeSideOfTriangle(*triangle, ep, eq)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public:
|
|||
* Create an instance of your derived class and assign it to an
|
||||
* #Assimp::Importer instance by calling Importer::SetIOHandler().
|
||||
*/
|
||||
IOSystem() AI_NO_EXCEPT;
|
||||
IOSystem() AI_NO_EXCEPT = default;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Virtual destructor.
|
||||
|
@ -105,7 +105,7 @@ public:
|
|||
* It is safe to be called from within DLL Assimp, we're constructed
|
||||
* on Assimp's heap.
|
||||
*/
|
||||
virtual ~IOSystem();
|
||||
virtual ~IOSystem() = default;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief For backward compatibility
|
||||
|
@ -236,12 +236,6 @@ private:
|
|||
std::vector<std::string> m_pathStack;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
AI_FORCE_INLINE IOSystem::IOSystem() AI_NO_EXCEPT = default;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
AI_FORCE_INLINE IOSystem::~IOSystem() = default;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// For compatibility, the interface of some functions taking a std::string was
|
||||
// changed to const char* to avoid crashes between binary incompatible STL
|
||||
|
|
|
@ -165,6 +165,7 @@ SET( IMPORTERS
|
|||
unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp
|
||||
unit/ImportExport/RAW/utRAWImportExport.cpp
|
||||
unit/ImportExport/Terragen/utTerragenImportExport.cpp
|
||||
unit/ImportExport/Pbrt/utPbrtImportExport.cpp
|
||||
)
|
||||
|
||||
SET( MATERIAL
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, 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 "AbstractImportExportBase.h"
|
||||
#include "UnitTestPCH.h"
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
class utPbrtImportExport : public AbstractImportExportBase {
|
||||
public:
|
||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||
bool exporterTest() override {
|
||||
Assimp::Importer importer;
|
||||
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OBJ/spider.obj", aiProcess_ValidateDataStructure);
|
||||
EXPECT_NE(scene, nullptr );
|
||||
|
||||
::Assimp::Exporter exporter;
|
||||
return AI_SUCCESS == exporter.Export(scene, "pbrt", ASSIMP_TEST_MODELS_DIR "/OBJ/spider_out.pbrt");
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||
|
||||
TEST_F(utPbrtImportExport, exportTest_Success) {
|
||||
EXPECT_TRUE(exporterTest());
|
||||
}
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_EXPORT
|
Loading…
Reference in New Issue