+ experimental STL exporter.

- improve process handling during exporting. This is still WIP.
+ BaseProcess::RequireVerboseFormat.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1062 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/2/head
aramis_acg 2011-08-04 11:27:13 +00:00
parent 36b3695a31
commit 45b0ccfc92
9 changed files with 385 additions and 110 deletions

View File

@ -96,3 +96,10 @@ void BaseProcess::SetupProperties(const Importer* /*pImp*/)
{ {
// the default implementation does nothing // the default implementation does nothing
} }
// ------------------------------------------------------------------------------------------------
bool BaseProcess::RequireVerboseFormat() const
{
return true;
}

View File

@ -234,6 +234,11 @@ public:
*/ */
virtual bool IsActive( unsigned int pFlags) const = 0; virtual bool IsActive( unsigned int pFlags) const = 0;
// -------------------------------------------------------------------
/** Check whether this step expects its input vertex data to be
* in verbose format. */
virtual bool RequireVerboseFormat() const;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Executes the post processing step on the given imported data. /** Executes the post processing step on the given imported data.
* The function deletes the scene if the postprocess step fails ( * The function deletes the scene if the postprocess step fails (

View File

@ -435,6 +435,8 @@ SET( PostProcessing_SRCS
ProcessHelper.h ProcessHelper.h
ProcessHelper.cpp ProcessHelper.cpp
PolyTools.h PolyTools.h
MakeVerboseFormat.cpp
MakeVerboseFormat.h
) )
SOURCE_GROUP( PostProcessing FILES ${PostProcessing_SRCS}) SOURCE_GROUP( PostProcessing FILES ${PostProcessing_SRCS})
@ -470,6 +472,8 @@ SOURCE_GROUP( SMD FILES ${SMD_SRCS})
SET( STL_SRCS SET( STL_SRCS
STLLoader.cpp STLLoader.cpp
STLLoader.h STLLoader.h
STLExporter.h
STLExporter.cpp
) )
SOURCE_GROUP( STL FILES ${STL_SRCS}) SOURCE_GROUP( STL FILES ${STL_SRCS})
@ -496,8 +500,6 @@ SET( Exporter_SRCS
SOURCE_GROUP( Exporter FILES ${Exporter_SRCS}) SOURCE_GROUP( Exporter FILES ${Exporter_SRCS})
SET( Extra_SRCS SET( Extra_SRCS
MakeVerboseFormat.cpp
MakeVerboseFormat.h
MD4FileData.h MD4FileData.h
) )
SOURCE_GROUP( Extra FILES ${Extra_SRCS}) SOURCE_GROUP( Extra FILES ${Extra_SRCS})

View File

@ -60,6 +60,9 @@ Here we implement only the C++ interface (Assimp::Exporter).
#include "BaseProcess.h" #include "BaseProcess.h"
#include "Importer.h" // need this for GetPostProcessingStepInstanceList() #include "Importer.h" // need this for GetPostProcessingStepInstanceList()
#include "MakeVerboseFormat.h"
#include "ConvertToLHProcess.h"
namespace Assimp { namespace Assimp {
// PostStepRegistry.cpp // PostStepRegistry.cpp
@ -69,6 +72,7 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out);
// Exporter worker function prototypes. Should not be necessary to #ifndef them, it's just a prototype // Exporter worker function prototypes. Should not be necessary to #ifndef them, it's just a prototype
void ExportSceneCollada(const char*,IOSystem*, const aiScene*); void ExportSceneCollada(const char*,IOSystem*, const aiScene*);
void ExportSceneObj(const char*,IOSystem*, const aiScene*); void ExportSceneObj(const char*,IOSystem*, const aiScene*);
void ExportSceneSTL(const char*,IOSystem*, const aiScene*);
void ExportScene3DS(const char*, IOSystem*, const aiScene*) {} void ExportScene3DS(const char*, IOSystem*, const aiScene*) {}
/// Function pointer type of a Export worker function /// Function pointer type of a Export worker function
@ -110,9 +114,15 @@ ExportFormatEntry gExporters[] =
ExportFormatEntry( "obj", "Wavefront OBJ format", "obj", &ExportSceneObj), ExportFormatEntry( "obj", "Wavefront OBJ format", "obj", &ExportSceneObj),
#endif #endif
#ifndef ASSIMP_BUILD_NO_3DS_EXPORTER #ifndef ASSIMP_BUILD_NO_STL_EXPORTER
ExportFormatEntry( "3ds", "Autodesk 3DS (legacy format)", "3ds" , &ExportScene3DS), ExportFormatEntry( "stl", "Stereolithography", "stl" , &ExportSceneSTL,
aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_PreTransformVertices
),
#endif #endif
//#ifndef ASSIMP_BUILD_NO_3DS_EXPORTER
// ExportFormatEntry( "3ds", "Autodesk 3DS (legacy format)", "3ds" , &ExportScene3DS),
//#endif
}; };
@ -258,11 +268,60 @@ aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const
pp |= (nonIdempotentSteps & priv->mPPStepsApplied); pp |= (nonIdempotentSteps & priv->mPPStepsApplied);
} }
if (pp) { // If the input scene is not in verbose format, but there is at least postprocessing step that relies on it,
// we need to run the MakeVerboseFormat step first.
if (scenecopy->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) {
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];
if (p->IsActive(pp)) { if (p->IsActive(pp) && p->RequireVerboseFormat()) {
verbosify = true;
break;
}
}
if (verbosify || (gExporters[i].mEnforcePP & aiProcess_JoinIdenticalVertices)) {
DefaultLogger::get()->debug("export: Scene data not in verbose format, applying MakeVerboseFormat step first");
MakeVerboseFormatProcess proc;
proc.Execute(scenecopy.get());
}
}
if (pp) {
// the three 'conversion' steps need to be executed first because all other steps rely on the standard data layout
{
FlipWindingOrderProcess step;
if (step.IsActive(pp)) {
step.Execute(scenecopy.get());
}
}
{
FlipUVsProcess step;
if (step.IsActive(pp)) {
step.Execute(scenecopy.get());
}
}
{
MakeLeftHandedProcess step;
if (step.IsActive(pp)) {
step.Execute(scenecopy.get());
}
}
// dispatch other processes
for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) {
BaseProcess* const p = pimpl->mPostProcessingSteps[a];
if (p->IsActive(pp)
&& !dynamic_cast<FlipUVsProcess*>(p)
&& !dynamic_cast<FlipWindingOrderProcess*>(p)
&& !dynamic_cast<MakeLeftHandedProcess*>(p)) {
p->Execute(scenecopy.get()); p->Execute(scenecopy.get());
} }
} }

View File

@ -63,9 +63,7 @@ namespace Assimp {
* useful, too. */ * useful, too. */
class ASSIMP_API MakeVerboseFormatProcess : public BaseProcess class ASSIMP_API MakeVerboseFormatProcess : public BaseProcess
{ {
friend class Importer; public:
protected:
/** Constructor to be privately used by Importer, or by applications /** Constructor to be privately used by Importer, or by applications
which know what they are doing if they modify the aiScene object */ which know what they are doing if they modify the aiScene object */

View File

@ -119,4 +119,4 @@ private:
} }
#endif #endif

View File

@ -0,0 +1,112 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2010, ASSIMP Development 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 Development 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 "AssimpPCH.h"
#if !defined(ASSIMP_BUILD_NO_EXPORT) && !defined(ASSIMP_BUILD_NO_STL_EXPORTER)
#include "STLExporter.h"
#include "../include/aiVersion.h"
using namespace Assimp;
namespace Assimp {
// ------------------------------------------------------------------------------------------------
// Worker function for exporting a scene to Stereolithograpy. Prototyped and registered in Exporter.cpp
void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
{
// invoke the exporter
STLExporter exporter(pFile, pScene);
// we're still here - export successfully completed. Write the file.
boost::scoped_ptr<IOStream> outfile (pIOSystem->Open(pFile,"wt"));
outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1);
}
} // end of namespace Assimp
// ------------------------------------------------------------------------------------------------
STLExporter :: STLExporter(const char* _filename, const aiScene* pScene)
: filename(_filename)
, pScene(pScene)
, endl("\n")
{
// make sure that all formatting happens using the standard, C locale and not the user's current locale
const std::locale& l = std::locale("C");
mOutput.imbue(l);
const std::string& name = "AssimpScene";
mOutput << "solid " << name << endl;
for(unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
WriteMesh(pScene->mMeshes[i]);
}
mOutput << "endsolid " << name << endl;
}
// ------------------------------------------------------------------------------------------------
void STLExporter :: WriteMesh(const aiMesh* m)
{
for (unsigned int i = 0; i < m->mNumFaces; ++i) {
const aiFace& f = m->mFaces[i];
// we need per-face normals. We specified aiProcess_GenNormals as pre-requisite for this exporter,
// but nonetheless we have to expect per-vertex normals.
aiVector3D nor;
if (m->mNormals) {
for(unsigned int a = 0; a < f.mNumIndices; ++a) {
nor += m->mNormals[f.mIndices[a]];
}
nor.Normalize();
}
mOutput << " facet normal " << nor.x << " " << nor.y << " " << nor.z << endl;
mOutput << " outer loop" << endl;
for(unsigned int a = 0; a < f.mNumIndices; ++a) {
const aiVector3D& v = m->mVertices[f.mIndices[a]];
mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl;
}
mOutput << " endloop" << endl;
mOutput << " endfacet" << endl << endl;
}
}
#endif

84
code/STLExporter.h 100644
View File

@ -0,0 +1,84 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2010, ASSIMP Development 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 Development 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.
----------------------------------------------------------------------
*/
/** @file STLExporter.h
* Declares the exporter class to write a scene to a Stereolithography (STL) file
*/
#ifndef AI_STLEXPORTER_H_INC
#define AI_STLEXPORTER_H_INC
#include <sstream>
struct aiScene;
struct aiNode;
namespace Assimp
{
// ------------------------------------------------------------------------------------------------
/** Helper class to export a given scene to a STL file. */
// ------------------------------------------------------------------------------------------------
class ASSIMP_API STLExporter
{
public:
/// Constructor for a specific scene to export
STLExporter(const char* filename, const aiScene* pScene);
public:
/// public stringstreams to write all output into
std::ostringstream mOutput;
private:
void WriteMesh(const aiMesh* m);
private:
const std::string filename;
const aiScene* const pScene;
// this endl() doesn't flush() the stream
const std::string endl;
};
}
#endif

View File

@ -2124,6 +2124,102 @@
RelativePath="..\..\code\LimitBoneWeightsProcess.h" RelativePath="..\..\code\LimitBoneWeightsProcess.h"
> >
</File> </File>
<File
RelativePath="..\..\code\MakeVerboseFormat.cpp"
>
<FileConfiguration
Name="debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release-dll|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="debug-dll|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release-noboost-st|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="debug-noboost-st|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="debug-st|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release-st|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release-noboost-st|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release-st|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\code\MakeVerboseFormat.h"
>
</File>
<File <File
RelativePath="..\..\code\OptimizeGraph.cpp" RelativePath="..\..\code\OptimizeGraph.cpp"
> >
@ -2488,102 +2584,6 @@
RelativePath="..\..\code\LineSplitter.h" RelativePath="..\..\code\LineSplitter.h"
> >
</File> </File>
<File
RelativePath="..\..\code\MakeVerboseFormat.cpp"
>
<FileConfiguration
Name="debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release-dll|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="debug-dll|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release-noboost-st|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="debug-noboost-st|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="debug-st|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release-st|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release-noboost-st|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release-st|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\code\MakeVerboseFormat.h"
>
</File>
<File <File
RelativePath="..\..\code\ParsingUtils.h" RelativePath="..\..\code\ParsingUtils.h"
> >
@ -4188,10 +4188,6 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="3ds"
>
</Filter>
<Filter <Filter
Name="obj" Name="obj"
> >
@ -4204,6 +4200,18 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="stl"
>
<File
RelativePath="..\..\code\STLExporter.cpp"
>
</File>
<File
RelativePath="..\..\code\STLExporter.h"
>
</File>
</Filter>
</Filter> </Filter>
</Filter> </Filter>
<Filter <Filter