Skip to content

Commit

Permalink
Merge branch 'master' into step-import
Browse files Browse the repository at this point in the history
  • Loading branch information
kkulling committed Nov 16, 2018
2 parents 9e4aaaf + e6905b6 commit 4e5e6b5
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 105 deletions.
4 changes: 1 addition & 3 deletions code/DefaultProgressHandler.h
Expand Up @@ -52,9 +52,7 @@ namespace Assimp {

// ------------------------------------------------------------------------------------
/** @brief Internal default implementation of the #ProgressHandler interface. */
class DefaultProgressHandler
: public ProgressHandler {

class DefaultProgressHandler : public ProgressHandler {

virtual bool Update(float /*percentage*/) {
return false;
Expand Down
1 change: 1 addition & 0 deletions code/DropFaceNormalsProcess.cpp
Expand Up @@ -104,5 +104,6 @@ bool DropFaceNormalsProcess::DropMeshFaceNormals (aiMesh* pMesh) {
}

delete[] pMesh->mNormals;
pMesh->mNormals = nullptr;
return true;
}
122 changes: 76 additions & 46 deletions code/Exporter.cpp
Expand Up @@ -56,22 +56,22 @@ Here we implement only the C++ interface (Assimp::Exporter).

#include <assimp/BlobIOSystem.h>
#include <assimp/SceneCombiner.h>
#include "BaseProcess.h"
#include "Importer.h" // need this for GetPostProcessingStepInstanceList()
#include <assimp/DefaultIOSystem.h>
#include <assimp/Exporter.hpp>
#include <assimp/mesh.h>
#include <assimp/postprocess.h>
#include <assimp/scene.h>

#include "DefaultProgressHandler.h"
#include "BaseProcess.h"
#include "JoinVerticesProcess.h"
#include "MakeVerboseFormat.h"
#include "ConvertToLHProcess.h"
#include "PretransformVertices.h"
#include <assimp/Exceptional.h>
#include "ScenePrivate.h"
#include <memory>

#include <assimp/DefaultIOSystem.h>
#include <assimp/Exporter.hpp>
#include <assimp/mesh.h>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <memory>

namespace Assimp {

Expand Down Expand Up @@ -188,10 +188,14 @@ Exporter::ExportFormatEntry gExporters[] =
class ExporterPimpl {
public:
ExporterPimpl()
: blob()
, mIOSystem(new Assimp::DefaultIOSystem())
, mIsDefaultIOHandler(true)
{
: blob()
, mIOSystem(new Assimp::DefaultIOSystem())
, mIsDefaultIOHandler(true)
, mProgressHandler( nullptr )
, mIsDefaultProgressHandler( true )
, mPostProcessingSteps()
, mError()
, mExporters() {
GetPostProcessingStepInstanceList(mPostProcessingSteps);

// grab all built-in exporters
Expand All @@ -201,8 +205,7 @@ class ExporterPimpl {
}
}

~ExporterPimpl()
{
~ExporterPimpl() {
delete blob;

// Delete all post-processing plug-ins
Expand All @@ -216,6 +219,10 @@ class ExporterPimpl {
std::shared_ptr< Assimp::IOSystem > mIOSystem;
bool mIsDefaultIOHandler;

/** The progress handler */
ProgressHandler *mProgressHandler;
bool mIsDefaultProgressHandler;

/** Post processing steps we can apply at the imported data. */
std::vector< BaseProcess* > mPostProcessingSteps;

Expand All @@ -233,13 +240,16 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------
Exporter :: Exporter()
: pimpl(new ExporterPimpl()) {
// empty
pimpl->mProgressHandler = new DefaultProgressHandler();
}

// ------------------------------------------------------------------------------------------------
Exporter::~Exporter() {
FreeBlob();

if (pimpl->mIsDefaultProgressHandler) {
delete pimpl->mProgressHandler;
pimpl->mProgressHandler = nullptr;
}
delete pimpl;
}

Expand All @@ -259,12 +269,32 @@ bool Exporter::IsDefaultIOHandler() const {
return pimpl->mIsDefaultIOHandler;
}

// ------------------------------------------------------------------------------------------------
void Exporter::SetProgressHandler(ProgressHandler* pHandler) {
ai_assert(nullptr != pimpl);

if ( nullptr == pHandler) {
// Release pointer in the possession of the caller
pimpl->mProgressHandler = new DefaultProgressHandler();
pimpl->mIsDefaultProgressHandler = true;
return;
}

if (pimpl->mProgressHandler == pHandler) {
return;
}

delete pimpl->mProgressHandler;
pimpl->mProgressHandler = pHandler;
pimpl->mIsDefaultProgressHandler = false;
}

// ------------------------------------------------------------------------------------------------
const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const char* pFormatId,
unsigned int, const ExportProperties* /*pProperties*/ ) {
if (pimpl->blob) {
delete pimpl->blob;
pimpl->blob = NULL;
pimpl->blob = nullptr;
}

std::shared_ptr<IOSystem> old = pimpl->mIOSystem;
Expand All @@ -273,7 +303,7 @@ const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const cha

if (AI_SUCCESS != Export(pScene,pFormatId,blobio->GetMagicFileName())) {
pimpl->mIOSystem = old;
return NULL;
return nullptr;
}

pimpl->blob = blobio->GetBlobChain();
Expand All @@ -295,6 +325,7 @@ bool IsVerboseFormat(const aiMesh* mesh) {
}
}
}

return true;
}

Expand All @@ -305,6 +336,7 @@ bool IsVerboseFormat(const aiScene* pScene) {
return false;
}
}

return true;
}

Expand All @@ -319,16 +351,20 @@ aiReturn Exporter::Export( const aiScene* pScene, const char* pFormatId, const c
// meshes upfront.
const bool is_verbose_format = !(pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) || IsVerboseFormat(pScene);

pimpl->mProgressHandler->UpdateFileWrite(0, 4);

pimpl->mError = "";
for (size_t i = 0; i < pimpl->mExporters.size(); ++i) {
const Exporter::ExportFormatEntry& exp = pimpl->mExporters[i];
if (!strcmp(exp.mDescription.id,pFormatId)) {
try {
// Always create a full copy of the scene. We might optimize this one day,
// but for now it is the most pragmatic way.
aiScene* scenecopy_tmp = NULL;
aiScene* scenecopy_tmp = nullptr;
SceneCombiner::CopyScene(&scenecopy_tmp,pScene);

pimpl->mProgressHandler->UpdateFileWrite(1, 4);

std::unique_ptr<aiScene> scenecopy(scenecopy_tmp);
const ScenePrivateData* const priv = ScenePriv(pScene);

Expand Down Expand Up @@ -375,6 +411,8 @@ aiReturn Exporter::Export( const aiScene* pScene, const char* pFormatId, const c
}
}

pimpl->mProgressHandler->UpdateFileWrite(2, 4);

if (pp) {
// the three 'conversion' steps need to be executed first because all other steps rely on the standard data layout
{
Expand Down Expand Up @@ -418,18 +456,22 @@ aiReturn Exporter::Export( const aiScene* pScene, const char* pFormatId, const c
}
}
ScenePrivateData* const privOut = ScenePriv(scenecopy.get());
ai_assert(privOut);
ai_assert(nullptr != privOut);

privOut->mPPStepsApplied |= pp;
}

pimpl->mProgressHandler->UpdateFileWrite(3, 4);

if(must_join_again) {
JoinVerticesProcess proc;
proc.Execute(scenecopy.get());
}

ExportProperties emptyProperties; // Never pass NULL ExportProperties so Exporters don't have to worry.
exp.mExportFunction(pPath,pimpl->mIOSystem.get(),scenecopy.get(), pProperties ? pProperties : &emptyProperties);

pimpl->mProgressHandler->UpdateFileWrite(4, 4);
} catch (DeadlyExportError& err) {
pimpl->mError = err.what();
return AI_FAILURE;
Expand All @@ -452,7 +494,7 @@ const char* Exporter::GetErrorString() const {
// ------------------------------------------------------------------------------------------------
void Exporter::FreeBlob() {
delete pimpl->blob;
pimpl->blob = NULL;
pimpl->blob = nullptr;

pimpl->mError = "";
}
Expand All @@ -465,7 +507,7 @@ const aiExportDataBlob* Exporter::GetBlob() const {
// ------------------------------------------------------------------------------------------------
const aiExportDataBlob* Exporter::GetOrphanedBlob() const {
const aiExportDataBlob* tmp = pimpl->blob;
pimpl->blob = NULL;
pimpl->blob = nullptr;
return tmp;
}

Expand Down Expand Up @@ -545,75 +587,63 @@ bool ExportProperties::SetPropertyString(const char* szName, const std::string&

// ------------------------------------------------------------------------------------------------
// Set a configuration property
bool ExportProperties :: SetPropertyMatrix(const char* szName, const aiMatrix4x4& value)
{
bool ExportProperties::SetPropertyMatrix(const char* szName, const aiMatrix4x4& value) {
return SetGenericProperty<aiMatrix4x4>(mMatrixProperties, szName,value);
}

// ------------------------------------------------------------------------------------------------
// Get a configuration property
int ExportProperties :: GetPropertyInteger(const char* szName,
int iErrorReturn /*= 0xffffffff*/) const
{
int ExportProperties::GetPropertyInteger(const char* szName, int iErrorReturn /*= 0xffffffff*/) const {
return GetGenericProperty<int>(mIntProperties,szName,iErrorReturn);
}

// ------------------------------------------------------------------------------------------------
// Get a configuration property
ai_real ExportProperties :: GetPropertyFloat(const char* szName,
ai_real iErrorReturn /*= 10e10*/) const
{
ai_real ExportProperties::GetPropertyFloat(const char* szName, ai_real iErrorReturn /*= 10e10*/) const {
return GetGenericProperty<ai_real>(mFloatProperties,szName,iErrorReturn);
}

// ------------------------------------------------------------------------------------------------
// Get a configuration property
const std::string ExportProperties :: GetPropertyString(const char* szName,
const std::string& iErrorReturn /*= ""*/) const
{
const std::string ExportProperties::GetPropertyString(const char* szName,
const std::string& iErrorReturn /*= ""*/) const {
return GetGenericProperty<std::string>(mStringProperties,szName,iErrorReturn);
}

// ------------------------------------------------------------------------------------------------
// Has a configuration property
const aiMatrix4x4 ExportProperties :: GetPropertyMatrix(const char* szName,
const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const
{
const aiMatrix4x4 ExportProperties::GetPropertyMatrix(const char* szName,
const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const {
return GetGenericProperty<aiMatrix4x4>(mMatrixProperties,szName,iErrorReturn);
}

// ------------------------------------------------------------------------------------------------
// Has a configuration property
bool ExportProperties :: HasPropertyInteger(const char* szName) const
{
bool ExportProperties::HasPropertyInteger(const char* szName) const {
return HasGenericProperty<int>(mIntProperties, szName);
}

// ------------------------------------------------------------------------------------------------
// Has a configuration property
bool ExportProperties :: HasPropertyBool(const char* szName) const
{
bool ExportProperties::HasPropertyBool(const char* szName) const {
return HasGenericProperty<int>(mIntProperties, szName);
}

// ------------------------------------------------------------------------------------------------
// Has a configuration property
bool ExportProperties :: HasPropertyFloat(const char* szName) const
{
bool ExportProperties::HasPropertyFloat(const char* szName) const {
return HasGenericProperty<ai_real>(mFloatProperties, szName);
}

// ------------------------------------------------------------------------------------------------
// Has a configuration property
bool ExportProperties :: HasPropertyString(const char* szName) const
{
bool ExportProperties::HasPropertyString(const char* szName) const {
return HasGenericProperty<std::string>(mStringProperties, szName);
}

// ------------------------------------------------------------------------------------------------
// Has a configuration property
bool ExportProperties :: HasPropertyMatrix(const char* szName) const
{
bool ExportProperties::HasPropertyMatrix(const char* szName) const {
return HasGenericProperty<aiMatrix4x4>(mMatrixProperties, szName);
}

Expand Down
15 changes: 5 additions & 10 deletions code/Importer.cpp
Expand Up @@ -315,22 +315,19 @@ void Importer::SetIOHandler( IOSystem* pIOHandler)

// ------------------------------------------------------------------------------------------------
// Get the currently set IO handler
IOSystem* Importer::GetIOHandler() const
{
IOSystem* Importer::GetIOHandler() const {
return pimpl->mIOHandler;
}

// ------------------------------------------------------------------------------------------------
// Check whether a custom IO handler is currently set
bool Importer::IsDefaultIOHandler() const
{
bool Importer::IsDefaultIOHandler() const {
return pimpl->mIsDefaultHandler;
}

// ------------------------------------------------------------------------------------------------
// Supplies a custom progress handler to get regular callbacks during importing
void Importer::SetProgressHandler ( ProgressHandler* pHandler )
{
void Importer::SetProgressHandler ( ProgressHandler* pHandler ) {
ASSIMP_BEGIN_EXCEPTION_REGION();
// If the new handler is zero, allocate a default implementation.
if (!pHandler)
Expand All @@ -351,15 +348,13 @@ void Importer::SetProgressHandler ( ProgressHandler* pHandler )

// ------------------------------------------------------------------------------------------------
// Get the currently set progress handler
ProgressHandler* Importer::GetProgressHandler() const
{
ProgressHandler* Importer::GetProgressHandler() const {
return pimpl->mProgressHandler;
}

// ------------------------------------------------------------------------------------------------
// Check whether a custom progress handler is currently set
bool Importer::IsDefaultProgressHandler() const
{
bool Importer::IsDefaultProgressHandler() const {
return pimpl->mIsDefaultProgressHandler;
}

Expand Down
3 changes: 3 additions & 0 deletions code/PostStepRegistry.cpp
Expand Up @@ -203,6 +203,9 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out)
#if (!defined ASSIMP_BUILD_NO_SPLITLARGEMESHES_PROCESS)
out.push_back( new SplitLargeMeshesProcess_Triangle());
#endif
#if (!defined ASSIMP_BUILD_NO_GENFACENORMALS_PROCESS)
out.push_back( new DropFaceNormalsProcess());
#endif
#if (!defined ASSIMP_BUILD_NO_GENFACENORMALS_PROCESS)
out.push_back( new GenFaceNormalsProcess());
#endif
Expand Down
8 changes: 6 additions & 2 deletions code/ValidateDataStructure.cpp
Expand Up @@ -491,8 +491,12 @@ void ValidateDSProcess::Validate( const aiMesh* pMesh)
{
if (pMesh->mBones[i]->mName == pMesh->mBones[a]->mName)
{
ReportError("aiMesh::mBones[%i] has the same name as "
"aiMesh::mBones[%i]",i,a);
const char *name = "unknown";
if (nullptr != pMesh->mBones[ i ]->mName.C_Str()) {
name = pMesh->mBones[ i ]->mName.C_Str();
}
ReportError("aiMesh::mBones[%i], name = \"%s\" has the same name as "
"aiMesh::mBones[%i]", i, name, a );
}
}
}
Expand Down

0 comments on commit 4e5e6b5

Please sign in to comment.