2011-01-21 15:37:34 +00:00
|
|
|
/*
|
2012-02-03 03:38:30 +00:00
|
|
|
Open Asset Import Library (assimp)
|
2011-01-21 15:37:34 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
Copyright (c) 2006-2012, assimp team
|
2011-01-21 15:37:34 +00:00
|
|
|
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.
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
* Neither the name of the assimp team, nor the names of its
|
2011-01-21 15:37:34 +00:00
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
2012-02-03 03:38:30 +00:00
|
|
|
written permission of the assimp team.
|
2011-01-21 15:37:34 +00:00
|
|
|
|
|
|
|
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 ColladaExporter.h
|
|
|
|
* Declares the exporter class to write a scene to a Collada file
|
|
|
|
*/
|
|
|
|
#ifndef AI_COLLADAEXPORTER_H_INC
|
|
|
|
#define AI_COLLADAEXPORTER_H_INC
|
|
|
|
|
2012-04-22 23:14:39 +00:00
|
|
|
#include "../include/assimp/ai_assert.h"
|
2015-04-15 19:22:26 +00:00
|
|
|
#include "../include/assimp/material.h"
|
|
|
|
#include "../include/assimp/mesh.h"
|
|
|
|
#include "../include/assimp/Exporter.hpp"
|
2011-01-21 15:37:34 +00:00
|
|
|
#include <sstream>
|
2015-04-15 19:22:26 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <boost/lexical_cast.hpp>
|
2011-01-21 15:37:34 +00:00
|
|
|
|
|
|
|
struct aiScene;
|
|
|
|
struct aiNode;
|
|
|
|
|
|
|
|
namespace Assimp
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Helper class to export a given scene to a Collada file. Just for my personal
|
|
|
|
/// comfort when implementing it.
|
2011-08-22 20:22:51 +00:00
|
|
|
class ColladaExporter
|
2011-01-21 15:37:34 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Constructor for a specific scene to export
|
2013-12-10 16:21:15 +00:00
|
|
|
ColladaExporter( const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file);
|
2011-01-21 15:37:34 +00:00
|
|
|
|
2013-10-14 07:59:07 +00:00
|
|
|
/// Destructor
|
|
|
|
virtual ~ColladaExporter();
|
|
|
|
|
2011-01-21 15:37:34 +00:00
|
|
|
protected:
|
|
|
|
/// Starts writing the contents
|
|
|
|
void WriteFile();
|
|
|
|
|
|
|
|
/// Writes the asset header
|
|
|
|
void WriteHeader();
|
|
|
|
|
2013-12-05 16:54:12 +00:00
|
|
|
/// Writes the embedded textures
|
|
|
|
void WriteTextures();
|
|
|
|
|
|
|
|
/// Writes the material setup
|
|
|
|
void WriteMaterials();
|
2012-02-14 17:42:25 +00:00
|
|
|
|
2011-01-21 15:37:34 +00:00
|
|
|
/// Writes the geometry library
|
|
|
|
void WriteGeometryLibrary();
|
|
|
|
|
|
|
|
/// Writes the given mesh
|
|
|
|
void WriteGeometry( size_t pIndex);
|
|
|
|
|
|
|
|
enum FloatDataType { FloatType_Vector, FloatType_TexCoord2, FloatType_TexCoord3, FloatType_Color };
|
|
|
|
|
|
|
|
/// Writes a float array of the given type
|
|
|
|
void WriteFloatArray( const std::string& pIdString, FloatDataType pType, const float* pData, size_t pElementCount);
|
|
|
|
|
|
|
|
/// Writes the scene library
|
|
|
|
void WriteSceneLibrary();
|
|
|
|
|
|
|
|
/// Recursively writes the given node
|
2014-06-09 13:17:45 +00:00
|
|
|
void WriteNode( aiNode* pNode);
|
2011-01-21 15:37:34 +00:00
|
|
|
|
|
|
|
/// Enters a new xml element, which increases the indentation
|
|
|
|
void PushTag() { startstr.append( " "); }
|
|
|
|
/// Leaves an element, decreasing the indentation
|
|
|
|
void PopTag() { ai_assert( startstr.length() > 1); startstr.erase( startstr.length() - 2); }
|
|
|
|
|
|
|
|
/// Creates a mesh ID for the given mesh
|
|
|
|
std::string GetMeshId( size_t pIndex) const { return std::string( "meshId" ) + boost::lexical_cast<std::string> (pIndex); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Stringstream to write all output into
|
|
|
|
std::stringstream mOutput;
|
|
|
|
|
|
|
|
protected:
|
2013-12-05 16:54:12 +00:00
|
|
|
/// The IOSystem for output
|
|
|
|
IOSystem* mIOSystem;
|
|
|
|
|
|
|
|
/// Path of the directory where the scene will be exported
|
2013-12-10 16:21:15 +00:00
|
|
|
const std::string mPath;
|
|
|
|
|
|
|
|
/// Name of the file (without extension) where the scene will be exported
|
|
|
|
const std::string mFile;
|
2013-12-05 16:54:12 +00:00
|
|
|
|
2011-01-21 15:37:34 +00:00
|
|
|
/// The scene to be written
|
|
|
|
const aiScene* mScene;
|
2013-10-14 07:59:07 +00:00
|
|
|
bool mSceneOwned;
|
2011-01-21 15:37:34 +00:00
|
|
|
|
|
|
|
/// current line start string, contains the current indentation for simple stream insertion
|
|
|
|
std::string startstr;
|
|
|
|
/// current line end string for simple stream insertion
|
|
|
|
std::string endstr;
|
2012-02-14 17:42:25 +00:00
|
|
|
|
|
|
|
// pair of color and texture - texture precedences color
|
|
|
|
struct Surface
|
|
|
|
{
|
2013-10-07 13:56:21 +00:00
|
|
|
bool exist;
|
2012-02-14 17:42:25 +00:00
|
|
|
aiColor4D color;
|
|
|
|
std::string texture;
|
|
|
|
size_t channel;
|
2013-10-07 13:56:21 +00:00
|
|
|
Surface() { exist = false; channel = 0; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Property
|
|
|
|
{
|
|
|
|
bool exist;
|
2015-05-16 19:13:22 +00:00
|
|
|
float value;
|
|
|
|
Property()
|
|
|
|
: exist(false)
|
|
|
|
, value(0.0f)
|
|
|
|
{}
|
2012-02-14 17:42:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// summarize a material in an convinient way.
|
|
|
|
struct Material
|
|
|
|
{
|
|
|
|
std::string name;
|
2013-10-07 13:56:21 +00:00
|
|
|
std::string shading_model;
|
|
|
|
Surface ambient, diffuse, specular, emissive, reflective, transparent, normal;
|
|
|
|
Property shininess, transparency, index_refraction;
|
2012-02-14 17:42:25 +00:00
|
|
|
|
2013-10-07 13:56:21 +00:00
|
|
|
Material() {}
|
2012-02-14 17:42:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<Material> materials;
|
|
|
|
|
2013-12-05 16:54:12 +00:00
|
|
|
std::map<unsigned int, std::string> textures;
|
|
|
|
|
2012-02-14 17:42:25 +00:00
|
|
|
protected:
|
|
|
|
/// Dammit C++ - y u no compile two-pass? No I have to add all methods below the struct definitions
|
|
|
|
/// Reads a single surface entry from the given material keys
|
|
|
|
void ReadMaterialSurface( Surface& poSurface, const aiMaterial* pSrcMat, aiTextureType pTexture, const char* pKey, size_t pType, size_t pIndex);
|
|
|
|
/// Writes an image entry for the given surface
|
|
|
|
void WriteImageEntry( const Surface& pSurface, const std::string& pNameAdd);
|
2012-02-18 15:20:28 +00:00
|
|
|
/// Writes the two parameters necessary for referencing a texture in an effect entry
|
|
|
|
void WriteTextureParamEntry( const Surface& pSurface, const std::string& pTypeName, const std::string& pMatName);
|
2012-02-14 17:42:25 +00:00
|
|
|
/// Writes a color-or-texture entry into an effect definition
|
|
|
|
void WriteTextureColorEntry( const Surface& pSurface, const std::string& pTypeName, const std::string& pImageName);
|
2013-10-07 13:56:21 +00:00
|
|
|
/// Writes a scalar property
|
2013-10-14 07:59:07 +00:00
|
|
|
void WriteFloatEntry( const Property& pProperty, const std::string& pTypeName);
|
2011-01-21 15:37:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !! AI_COLLADAEXPORTER_H_INC
|