1 /* 2 Open Asset Import Library (assimp) 3 ---------------------------------------------------------------------- 4 5 Copyright (c) 2006-2021, assimp team 6 7 8 All rights reserved. 9 10 Redistribution and use of this software in source and binary forms, 11 with or without modification, are permitted provided that the 12 following conditions are met: 13 14 * Redistributions of source code must retain the above 15 copyright notice, this list of conditions and the 16 following disclaimer. 17 18 * Redistributions in binary form must reproduce the above 19 copyright notice, this list of conditions and the 20 following disclaimer in the documentation and/or other 21 materials provided with the distribution. 22 23 * Neither the name of the assimp team, nor the names of its 24 contributors may be used to endorse or promote products 25 derived from this software without specific prior 26 written permission of the assimp team. 27 28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 40 @author: Richard Steffen, 2014 41 42 ---------------------------------------------------------------------- 43 */ 44 45 /** @file XFileExporter.h 46 * Declares the exporter class to write a scene to a Collada file 47 */ 48 #ifndef AI_XFILEEXPORTER_H_INC 49 #define AI_XFILEEXPORTER_H_INC 50 51 #include <assimp/ai_assert.h> 52 #include <assimp/matrix4x4.h> 53 #include <assimp/Exporter.hpp> 54 #include <sstream> 55 56 struct aiScene; 57 struct aiNode; 58 struct aiMesh; 59 struct aiString; 60 61 namespace Assimp { 62 63 class IOSystem; 64 65 66 /// Helper class to export a given scene to a X-file. 67 /// Note: an xFile uses a left hand system. Assimp used a right hand system (OpenGL), therefore we have to transform everything 68 class XFileExporter 69 { 70 public: 71 /// Constructor for a specific scene to export 72 XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file, const ExportProperties* pProperties); 73 74 /// Destructor 75 virtual ~XFileExporter(); 76 77 protected: 78 /// Starts writing the contents 79 void WriteFile(); 80 81 /// Writes the asset header 82 void WriteHeader(); 83 84 /// write a frame transform 85 void WriteFrameTransform(aiMatrix4x4& m); 86 87 /// Recursively writes the given node 88 void WriteNode( aiNode* pNode ); 89 90 /// write a mesh entry of the scene 91 void WriteMesh( aiMesh* mesh); 92 93 /// Enters a new xml element, which increases the indentation PushTag()94 void PushTag() { startstr.append( " "); } 95 96 /// Leaves an element, decreasing the indentation PopTag()97 void PopTag() { 98 ai_assert( startstr.length() > 1); 99 startstr.erase( startstr.length() - 2); 100 } 101 102 public: 103 /// Stringstream to write all output into 104 std::stringstream mOutput; 105 106 protected: 107 108 /// normalize the name to be accepted by xfile readers 109 std::string toXFileString(aiString &name); 110 111 /// hold the properties pointer 112 const ExportProperties* mProperties; 113 114 /// write a path 115 void writePath(const aiString &path); 116 117 /// The IOSystem for output 118 IOSystem* mIOSystem; 119 120 /// Path of the directory where the scene will be exported 121 const std::string mPath; 122 123 /// Name of the file (without extension) where the scene will be exported 124 const std::string mFile; 125 126 /// The scene to be written 127 const aiScene* mScene; 128 bool mSceneOwned; 129 130 /// current line start string, contains the current indentation for simple stream insertion 131 std::string startstr; 132 133 /// current line end string for simple stream insertion 134 std::string endstr; 135 136 }; 137 138 } 139 140 #endif // !! AI_XFILEEXPORTER_H_INC 141