|
@@ -52,7 +52,6 @@ Here we implement only the C++ interface (Assimp::Exporter).
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_NO_EXPORT
|
|
#ifndef ASSIMP_BUILD_NO_EXPORT
|
|
|
|
|
|
-#include "DefaultIOSystem.h"
|
|
|
|
#include "BlobIOSystem.h"
|
|
#include "BlobIOSystem.h"
|
|
#include "SceneCombiner.h"
|
|
#include "SceneCombiner.h"
|
|
#include "BaseProcess.h"
|
|
#include "BaseProcess.h"
|
|
@@ -64,11 +63,12 @@ Here we implement only the C++ interface (Assimp::Exporter).
|
|
#include "Exceptional.h"
|
|
#include "Exceptional.h"
|
|
#include "ScenePrivate.h"
|
|
#include "ScenePrivate.h"
|
|
#include <memory>
|
|
#include <memory>
|
|
|
|
+
|
|
|
|
+#include <assimp/DefaultIOSystem.h>
|
|
#include <assimp/Exporter.hpp>
|
|
#include <assimp/Exporter.hpp>
|
|
#include <assimp/mesh.h>
|
|
#include <assimp/mesh.h>
|
|
#include <assimp/postprocess.h>
|
|
#include <assimp/postprocess.h>
|
|
#include <assimp/scene.h>
|
|
#include <assimp/scene.h>
|
|
-#include <memory>
|
|
|
|
|
|
|
|
namespace Assimp {
|
|
namespace Assimp {
|
|
|
|
|
|
@@ -201,65 +201,48 @@ public:
|
|
std::vector<Exporter::ExportFormatEntry> mExporters;
|
|
std::vector<Exporter::ExportFormatEntry> mExporters;
|
|
};
|
|
};
|
|
|
|
|
|
-
|
|
|
|
} // end of namespace Assimp
|
|
} // end of namespace Assimp
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
using namespace Assimp;
|
|
using namespace Assimp;
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
Exporter :: Exporter()
|
|
Exporter :: Exporter()
|
|
-: pimpl(new ExporterPimpl())
|
|
|
|
-{
|
|
|
|
|
|
+: pimpl(new ExporterPimpl()) {
|
|
|
|
+ // empty
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-Exporter :: ~Exporter()
|
|
|
|
-{
|
|
|
|
|
|
+Exporter::~Exporter() {
|
|
FreeBlob();
|
|
FreeBlob();
|
|
|
|
|
|
delete pimpl;
|
|
delete pimpl;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-void Exporter :: SetIOHandler( IOSystem* pIOHandler)
|
|
|
|
-{
|
|
|
|
|
|
+void Exporter::SetIOHandler( IOSystem* pIOHandler) {
|
|
pimpl->mIsDefaultIOHandler = !pIOHandler;
|
|
pimpl->mIsDefaultIOHandler = !pIOHandler;
|
|
pimpl->mIOSystem.reset(pIOHandler);
|
|
pimpl->mIOSystem.reset(pIOHandler);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-IOSystem* Exporter :: GetIOHandler() const
|
|
|
|
-{
|
|
|
|
|
|
+IOSystem* Exporter::GetIOHandler() const {
|
|
return pimpl->mIOSystem.get();
|
|
return pimpl->mIOSystem.get();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-bool Exporter :: IsDefaultIOHandler() const
|
|
|
|
-{
|
|
|
|
|
|
+bool Exporter::IsDefaultIOHandler() const {
|
|
return pimpl->mIsDefaultIOHandler;
|
|
return pimpl->mIsDefaultIOHandler;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-const aiExportDataBlob* Exporter :: ExportToBlob( const aiScene* pScene, const char* pFormatId, unsigned int, const ExportProperties* pProperties)
|
|
|
|
-{
|
|
|
|
|
|
+const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const char* pFormatId,
|
|
|
|
+ unsigned int, const ExportProperties* pProperties ) {
|
|
if (pimpl->blob) {
|
|
if (pimpl->blob) {
|
|
delete pimpl->blob;
|
|
delete pimpl->blob;
|
|
pimpl->blob = NULL;
|
|
pimpl->blob = NULL;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
std::shared_ptr<IOSystem> old = pimpl->mIOSystem;
|
|
std::shared_ptr<IOSystem> old = pimpl->mIOSystem;
|
|
-
|
|
|
|
BlobIOSystem* blobio = new BlobIOSystem();
|
|
BlobIOSystem* blobio = new BlobIOSystem();
|
|
pimpl->mIOSystem = std::shared_ptr<IOSystem>( blobio );
|
|
pimpl->mIOSystem = std::shared_ptr<IOSystem>( blobio );
|
|
|
|
|
|
@@ -274,10 +257,8 @@ const aiExportDataBlob* Exporter :: ExportToBlob( const aiScene* pScene, const
|
|
return pimpl->blob;
|
|
return pimpl->blob;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-bool IsVerboseFormat(const aiMesh* mesh)
|
|
|
|
-{
|
|
|
|
|
|
+bool IsVerboseFormat(const aiMesh* mesh) {
|
|
// avoid slow vector<bool> specialization
|
|
// avoid slow vector<bool> specialization
|
|
std::vector<unsigned int> seen(mesh->mNumVertices,0);
|
|
std::vector<unsigned int> seen(mesh->mNumVertices,0);
|
|
for(unsigned int i = 0; i < mesh->mNumFaces; ++i) {
|
|
for(unsigned int i = 0; i < mesh->mNumFaces; ++i) {
|
|
@@ -292,10 +273,8 @@ bool IsVerboseFormat(const aiMesh* mesh)
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-bool IsVerboseFormat(const aiScene* pScene)
|
|
|
|
-{
|
|
|
|
|
|
+bool IsVerboseFormat(const aiScene* pScene) {
|
|
for(unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
|
|
for(unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
|
|
if(!IsVerboseFormat(pScene->mMeshes[i])) {
|
|
if(!IsVerboseFormat(pScene->mMeshes[i])) {
|
|
return false;
|
|
return false;
|
|
@@ -304,10 +283,8 @@ bool IsVerboseFormat(const aiScene* pScene)
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const char* pPath, unsigned int pPreprocessing, const ExportProperties* pProperties)
|
|
|
|
-{
|
|
|
|
|
|
+aiReturn Exporter::Export( const aiScene* pScene, const char* pFormatId, const char* pPath, unsigned int pPreprocessing, const ExportProperties* pProperties) {
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
|
// when they create scenes from scratch, users will likely create them not in verbose
|
|
// when they create scenes from scratch, users will likely create them not in verbose
|
|
@@ -320,9 +297,7 @@ aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const
|
|
for (size_t i = 0; i < pimpl->mExporters.size(); ++i) {
|
|
for (size_t i = 0; i < pimpl->mExporters.size(); ++i) {
|
|
const Exporter::ExportFormatEntry& exp = pimpl->mExporters[i];
|
|
const Exporter::ExportFormatEntry& exp = pimpl->mExporters[i];
|
|
if (!strcmp(exp.mDescription.id,pFormatId)) {
|
|
if (!strcmp(exp.mDescription.id,pFormatId)) {
|
|
-
|
|
|
|
try {
|
|
try {
|
|
-
|
|
|
|
// Always create a full copy of the scene. We might optimize this one day,
|
|
// Always create a full copy of the scene. We might optimize this one day,
|
|
// but for now it is the most pragmatic way.
|
|
// but for now it is the most pragmatic way.
|
|
aiScene* scenecopy_tmp = NULL;
|
|
aiScene* scenecopy_tmp = NULL;
|
|
@@ -341,18 +316,17 @@ aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const
|
|
? (priv->mPPStepsApplied & ~nonIdempotentSteps)
|
|
? (priv->mPPStepsApplied & ~nonIdempotentSteps)
|
|
: 0u);
|
|
: 0u);
|
|
|
|
|
|
- // If no extra postprocessing was specified, and we obtained this scene from an
|
|
|
|
|
|
+ // If no extra post-processing was specified, and we obtained this scene from an
|
|
// Assimp importer, apply the reverse steps automatically.
|
|
// Assimp importer, apply the reverse steps automatically.
|
|
// TODO: either drop this, or document it. Otherwise it is just a bad surprise.
|
|
// TODO: either drop this, or document it. Otherwise it is just a bad surprise.
|
|
//if (!pPreprocessing && priv) {
|
|
//if (!pPreprocessing && priv) {
|
|
// pp |= (nonIdempotentSteps & priv->mPPStepsApplied);
|
|
// pp |= (nonIdempotentSteps & priv->mPPStepsApplied);
|
|
//}
|
|
//}
|
|
|
|
|
|
- // If the input scene is not in verbose format, but there is at least postprocessing step that relies on it,
|
|
|
|
|
|
+ // If the input scene is not in verbose format, but there is at least post-processing step that relies on it,
|
|
// we need to run the MakeVerboseFormat step first.
|
|
// we need to run the MakeVerboseFormat step first.
|
|
bool must_join_again = false;
|
|
bool must_join_again = false;
|
|
if (!is_verbose_format) {
|
|
if (!is_verbose_format) {
|
|
-
|
|
|
|
bool verbosify = false;
|
|
bool verbosify = false;
|
|
for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) {
|
|
for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) {
|
|
BaseProcess* const p = pimpl->mPostProcessingSteps[a];
|
|
BaseProcess* const p = pimpl->mPostProcessingSteps[a];
|
|
@@ -423,8 +397,7 @@ aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const
|
|
|
|
|
|
ExportProperties emptyProperties; // Never pass NULL ExportProperties so Exporters don't have to worry.
|
|
ExportProperties emptyProperties; // Never pass NULL ExportProperties so Exporters don't have to worry.
|
|
exp.mExportFunction(pPath,pimpl->mIOSystem.get(),scenecopy.get(), pProperties ? pProperties : &emptyProperties);
|
|
exp.mExportFunction(pPath,pimpl->mIOSystem.get(),scenecopy.get(), pProperties ? pProperties : &emptyProperties);
|
|
- }
|
|
|
|
- catch (DeadlyExportError& err) {
|
|
|
|
|
|
+ } catch (DeadlyExportError& err) {
|
|
pimpl->mError = err.what();
|
|
pimpl->mError = err.what();
|
|
return AI_FAILURE;
|
|
return AI_FAILURE;
|
|
}
|
|
}
|
|
@@ -437,64 +410,53 @@ aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const
|
|
return AI_FAILURE;
|
|
return AI_FAILURE;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-const char* Exporter :: GetErrorString() const
|
|
|
|
-{
|
|
|
|
|
|
+const char* Exporter::GetErrorString() const {
|
|
return pimpl->mError.c_str();
|
|
return pimpl->mError.c_str();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-void Exporter :: FreeBlob( )
|
|
|
|
-{
|
|
|
|
|
|
+void Exporter::FreeBlob() {
|
|
delete pimpl->blob;
|
|
delete pimpl->blob;
|
|
pimpl->blob = NULL;
|
|
pimpl->blob = NULL;
|
|
|
|
|
|
pimpl->mError = "";
|
|
pimpl->mError = "";
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-const aiExportDataBlob* Exporter :: GetBlob() const
|
|
|
|
-{
|
|
|
|
|
|
+const aiExportDataBlob* Exporter::GetBlob() const {
|
|
return pimpl->blob;
|
|
return pimpl->blob;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-const aiExportDataBlob* Exporter :: GetOrphanedBlob() const
|
|
|
|
-{
|
|
|
|
|
|
+const aiExportDataBlob* Exporter::GetOrphanedBlob() const {
|
|
const aiExportDataBlob* tmp = pimpl->blob;
|
|
const aiExportDataBlob* tmp = pimpl->blob;
|
|
pimpl->blob = NULL;
|
|
pimpl->blob = NULL;
|
|
return tmp;
|
|
return tmp;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-size_t Exporter :: GetExportFormatCount() const
|
|
|
|
-{
|
|
|
|
|
|
+size_t Exporter::GetExportFormatCount() const {
|
|
return pimpl->mExporters.size();
|
|
return pimpl->mExporters.size();
|
|
}
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-const aiExportFormatDesc* Exporter :: GetExportFormatDescription( size_t pIndex ) const
|
|
|
|
-{
|
|
|
|
- if (pIndex >= GetExportFormatCount()) {
|
|
|
|
|
|
+const aiExportFormatDesc* Exporter::GetExportFormatDescription( size_t index ) const {
|
|
|
|
+ if (index >= GetExportFormatCount()) {
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
// Return from static storage if the requested index is built-in.
|
|
// Return from static storage if the requested index is built-in.
|
|
- if (pIndex < sizeof(gExporters) / sizeof(gExporters[0])) {
|
|
|
|
- return &gExporters[pIndex].mDescription;
|
|
|
|
|
|
+ if (index < sizeof(gExporters) / sizeof(gExporters[0])) {
|
|
|
|
+ return &gExporters[index].mDescription;
|
|
}
|
|
}
|
|
|
|
|
|
- return &pimpl->mExporters[pIndex].mDescription;
|
|
|
|
|
|
+ return &pimpl->mExporters[index].mDescription;
|
|
}
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-aiReturn Exporter :: RegisterExporter(const ExportFormatEntry& desc)
|
|
|
|
-{
|
|
|
|
|
|
+aiReturn Exporter::RegisterExporter(const ExportFormatEntry& desc) {
|
|
for(const ExportFormatEntry& e : pimpl->mExporters) {
|
|
for(const ExportFormatEntry& e : pimpl->mExporters) {
|
|
if (!strcmp(e.mDescription.id,desc.mDescription.id)) {
|
|
if (!strcmp(e.mDescription.id,desc.mDescription.id)) {
|
|
return aiReturn_FAILURE;
|
|
return aiReturn_FAILURE;
|
|
@@ -505,10 +467,8 @@ aiReturn Exporter :: RegisterExporter(const ExportFormatEntry& desc)
|
|
return aiReturn_SUCCESS;
|
|
return aiReturn_SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-void Exporter :: UnregisterExporter(const char* id)
|
|
|
|
-{
|
|
|
|
|
|
+void Exporter::UnregisterExporter(const char* id) {
|
|
for(std::vector<ExportFormatEntry>::iterator it = pimpl->mExporters.begin(); it != pimpl->mExporters.end(); ++it) {
|
|
for(std::vector<ExportFormatEntry>::iterator it = pimpl->mExporters.begin(); it != pimpl->mExporters.end(); ++it) {
|
|
if (!strcmp((*it).mDescription.id,id)) {
|
|
if (!strcmp((*it).mDescription.id,id)) {
|
|
pimpl->mExporters.erase(it);
|
|
pimpl->mExporters.erase(it);
|
|
@@ -517,29 +477,30 @@ void Exporter :: UnregisterExporter(const char* id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-ExportProperties :: ExportProperties() {}
|
|
|
|
|
|
+// ------------------------------------------------------------------------------------------------
|
|
|
|
+ExportProperties::ExportProperties() {
|
|
|
|
+ // empty
|
|
|
|
+}
|
|
|
|
|
|
|
|
+// ------------------------------------------------------------------------------------------------
|
|
ExportProperties::ExportProperties(const ExportProperties &other)
|
|
ExportProperties::ExportProperties(const ExportProperties &other)
|
|
- : mIntProperties(other.mIntProperties),
|
|
|
|
- mFloatProperties(other.mFloatProperties),
|
|
|
|
- mStringProperties(other.mStringProperties),
|
|
|
|
- mMatrixProperties(other.mMatrixProperties)
|
|
|
|
-{
|
|
|
|
-
|
|
|
|
|
|
+: mIntProperties(other.mIntProperties)
|
|
|
|
+, mFloatProperties(other.mFloatProperties)
|
|
|
|
+, mStringProperties(other.mStringProperties)
|
|
|
|
+, mMatrixProperties(other.mMatrixProperties) {
|
|
|
|
+ // empty
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
// Set a configuration property
|
|
// Set a configuration property
|
|
-bool ExportProperties :: SetPropertyInteger(const char* szName, int iValue)
|
|
|
|
-{
|
|
|
|
|
|
+bool ExportProperties::SetPropertyInteger(const char* szName, int iValue) {
|
|
return SetGenericProperty<int>(mIntProperties, szName,iValue);
|
|
return SetGenericProperty<int>(mIntProperties, szName,iValue);
|
|
}
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
// Set a configuration property
|
|
// Set a configuration property
|
|
-bool ExportProperties :: SetPropertyFloat(const char* szName, ai_real iValue)
|
|
|
|
-{
|
|
|
|
|
|
+bool ExportProperties::SetPropertyFloat(const char* szName, ai_real iValue) {
|
|
return SetGenericProperty<ai_real>(mFloatProperties, szName,iValue);
|
|
return SetGenericProperty<ai_real>(mFloatProperties, szName,iValue);
|
|
}
|
|
}
|
|
|
|
|