vrshoot
view libs/assimp/ColladaExporter.h @ 3:c179c72369be
rename candy->vr
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 03 Feb 2014 08:52:13 +0200 |
parents | |
children |
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 /** @file ColladaExporter.h
42 * Declares the exporter class to write a scene to a Collada file
43 */
44 #ifndef AI_COLLADAEXPORTER_H_INC
45 #define AI_COLLADAEXPORTER_H_INC
47 #include "assimp/ai_assert.h"
48 #include <sstream>
50 struct aiScene;
51 struct aiNode;
53 namespace Assimp
54 {
56 /// Helper class to export a given scene to a Collada file. Just for my personal
57 /// comfort when implementing it.
58 class ColladaExporter
59 {
60 public:
61 /// Constructor for a specific scene to export
62 ColladaExporter( const aiScene* pScene);
64 protected:
65 /// Starts writing the contents
66 void WriteFile();
68 /// Writes the asset header
69 void WriteHeader();
71 /// Writes the material setup
72 void WriteMaterials();
74 /// Writes the geometry library
75 void WriteGeometryLibrary();
77 /// Writes the given mesh
78 void WriteGeometry( size_t pIndex);
80 enum FloatDataType { FloatType_Vector, FloatType_TexCoord2, FloatType_TexCoord3, FloatType_Color };
82 /// Writes a float array of the given type
83 void WriteFloatArray( const std::string& pIdString, FloatDataType pType, const float* pData, size_t pElementCount);
85 /// Writes the scene library
86 void WriteSceneLibrary();
88 /// Recursively writes the given node
89 void WriteNode( const aiNode* pNode);
91 /// Enters a new xml element, which increases the indentation
92 void PushTag() { startstr.append( " "); }
93 /// Leaves an element, decreasing the indentation
94 void PopTag() { ai_assert( startstr.length() > 1); startstr.erase( startstr.length() - 2); }
96 /// Creates a mesh ID for the given mesh
97 std::string GetMeshId( size_t pIndex) const { return std::string( "meshId" ) + boost::lexical_cast<std::string> (pIndex); }
99 public:
100 /// Stringstream to write all output into
101 std::stringstream mOutput;
103 protected:
104 /// The scene to be written
105 const aiScene* mScene;
107 /// current line start string, contains the current indentation for simple stream insertion
108 std::string startstr;
109 /// current line end string for simple stream insertion
110 std::string endstr;
112 // pair of color and texture - texture precedences color
113 struct Surface
114 {
115 aiColor4D color;
116 std::string texture;
117 size_t channel;
118 Surface() { channel = 0; }
119 };
121 // summarize a material in an convinient way.
122 struct Material
123 {
124 std::string name;
125 Surface ambient, diffuse, specular, emissive, reflective, normal;
126 float shininess; /// specular exponent
128 Material() { shininess = 16.0f; }
129 };
131 std::vector<Material> materials;
133 protected:
134 /// Dammit C++ - y u no compile two-pass? No I have to add all methods below the struct definitions
135 /// Reads a single surface entry from the given material keys
136 void ReadMaterialSurface( Surface& poSurface, const aiMaterial* pSrcMat, aiTextureType pTexture, const char* pKey, size_t pType, size_t pIndex);
137 /// Writes an image entry for the given surface
138 void WriteImageEntry( const Surface& pSurface, const std::string& pNameAdd);
139 /// Writes the two parameters necessary for referencing a texture in an effect entry
140 void WriteTextureParamEntry( const Surface& pSurface, const std::string& pTypeName, const std::string& pMatName);
141 /// Writes a color-or-texture entry into an effect definition
142 void WriteTextureColorEntry( const Surface& pSurface, const std::string& pTypeName, const std::string& pImageName);
143 };
145 }
147 #endif // !! AI_COLLADAEXPORTER_H_INC