vrshoot

diff libs/assimp/ColladaExporter.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/assimp/ColladaExporter.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,147 @@
     1.4 +/*
     1.5 +Open Asset Import Library (assimp)
     1.6 +----------------------------------------------------------------------
     1.7 +
     1.8 +Copyright (c) 2006-2012, assimp team
     1.9 +All rights reserved.
    1.10 +
    1.11 +Redistribution and use of this software in source and binary forms, 
    1.12 +with or without modification, are permitted provided that the 
    1.13 +following conditions are met:
    1.14 +
    1.15 +* Redistributions of source code must retain the above
    1.16 +  copyright notice, this list of conditions and the
    1.17 +  following disclaimer.
    1.18 +
    1.19 +* Redistributions in binary form must reproduce the above
    1.20 +  copyright notice, this list of conditions and the
    1.21 +  following disclaimer in the documentation and/or other
    1.22 +  materials provided with the distribution.
    1.23 +
    1.24 +* Neither the name of the assimp team, nor the names of its
    1.25 +  contributors may be used to endorse or promote products
    1.26 +  derived from this software without specific prior
    1.27 +  written permission of the assimp team.
    1.28 +
    1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
    1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.40 +
    1.41 +----------------------------------------------------------------------
    1.42 +*/
    1.43 +
    1.44 +/** @file ColladaExporter.h
    1.45 + * Declares the exporter class to write a scene to a Collada file
    1.46 + */
    1.47 +#ifndef AI_COLLADAEXPORTER_H_INC
    1.48 +#define AI_COLLADAEXPORTER_H_INC
    1.49 +
    1.50 +#include "assimp/ai_assert.h"
    1.51 +#include <sstream>
    1.52 +
    1.53 +struct aiScene;
    1.54 +struct aiNode;
    1.55 +
    1.56 +namespace Assimp	
    1.57 +{
    1.58 +
    1.59 +/// Helper class to export a given scene to a Collada file. Just for my personal
    1.60 +/// comfort when implementing it.
    1.61 +class ColladaExporter
    1.62 +{
    1.63 +public:
    1.64 +	/// Constructor for a specific scene to export
    1.65 +	ColladaExporter( const aiScene* pScene);
    1.66 +
    1.67 +protected:
    1.68 +	/// Starts writing the contents
    1.69 +	void WriteFile();
    1.70 +
    1.71 +	/// Writes the asset header
    1.72 +	void WriteHeader();
    1.73 +
    1.74 +  /// Writes the material setup
    1.75 +  void WriteMaterials();
    1.76 +
    1.77 +	/// Writes the geometry library
    1.78 +	void WriteGeometryLibrary();
    1.79 +
    1.80 +	/// Writes the given mesh
    1.81 +	void WriteGeometry( size_t pIndex);
    1.82 +
    1.83 +	enum FloatDataType { FloatType_Vector, FloatType_TexCoord2, FloatType_TexCoord3, FloatType_Color };
    1.84 +
    1.85 +	/// Writes a float array of the given type
    1.86 +	void WriteFloatArray( const std::string& pIdString, FloatDataType pType, const float* pData, size_t pElementCount);
    1.87 +
    1.88 +	/// Writes the scene library
    1.89 +	void WriteSceneLibrary();
    1.90 +
    1.91 +	/// Recursively writes the given node
    1.92 +	void WriteNode( const aiNode* pNode);
    1.93 +
    1.94 +	/// Enters a new xml element, which increases the indentation
    1.95 +	void PushTag() { startstr.append( "  "); }
    1.96 +	/// Leaves an element, decreasing the indentation
    1.97 +	void PopTag() { ai_assert( startstr.length() > 1); startstr.erase( startstr.length() - 2); }
    1.98 +
    1.99 +	/// Creates a mesh ID for the given mesh
   1.100 +	std::string GetMeshId( size_t pIndex) const { return std::string( "meshId" ) + boost::lexical_cast<std::string> (pIndex); }
   1.101 +
   1.102 +public:
   1.103 +	/// Stringstream to write all output into
   1.104 +	std::stringstream mOutput;
   1.105 +
   1.106 +protected:
   1.107 +	/// The scene to be written
   1.108 +	const aiScene* mScene;
   1.109 +
   1.110 +	/// current line start string, contains the current indentation for simple stream insertion
   1.111 +	std::string startstr;
   1.112 +	/// current line end string for simple stream insertion
   1.113 +	std::string endstr;
   1.114 +
   1.115 +  // pair of color and texture - texture precedences color
   1.116 +  struct Surface 
   1.117 +  { 
   1.118 +    aiColor4D color; 
   1.119 +    std::string texture; 
   1.120 +    size_t channel; 
   1.121 +    Surface() { channel = 0; }
   1.122 +  };
   1.123 +
   1.124 +  // summarize a material in an convinient way. 
   1.125 +  struct Material
   1.126 +  {
   1.127 +    std::string name;
   1.128 +    Surface ambient, diffuse, specular, emissive, reflective, normal;
   1.129 +    float shininess; /// specular exponent
   1.130 +
   1.131 +    Material() { shininess = 16.0f; }
   1.132 +  };
   1.133 +
   1.134 +  std::vector<Material> materials;
   1.135 +
   1.136 +protected:
   1.137 +  /// Dammit C++ - y u no compile two-pass? No I have to add all methods below the struct definitions
   1.138 +  /// Reads a single surface entry from the given material keys
   1.139 +  void ReadMaterialSurface( Surface& poSurface, const aiMaterial* pSrcMat, aiTextureType pTexture, const char* pKey, size_t pType, size_t pIndex);
   1.140 +  /// Writes an image entry for the given surface
   1.141 +  void WriteImageEntry( const Surface& pSurface, const std::string& pNameAdd);
   1.142 +  /// Writes the two parameters necessary for referencing a texture in an effect entry
   1.143 +  void WriteTextureParamEntry( const Surface& pSurface, const std::string& pTypeName, const std::string& pMatName);
   1.144 +  /// Writes a color-or-texture entry into an effect definition
   1.145 +  void WriteTextureColorEntry( const Surface& pSurface, const std::string& pTypeName, const std::string& pImageName);
   1.146 +};
   1.147 +
   1.148 +}
   1.149 +
   1.150 +#endif // !! AI_COLLADAEXPORTER_H_INC