AssxmlExporter.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2019, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file AssxmlExporter.cpp
  34. * ASSXML exporter main code
  35. */
  36. #ifndef ASSIMP_BUILD_NO_EXPORT
  37. #ifndef ASSIMP_BUILD_NO_ASSXML_EXPORTER
  38. #include "PostProcessing/ProcessHelper.h"
  39. #include <assimp/version.h>
  40. #include <assimp/IOStream.hpp>
  41. #include <assimp/IOSystem.hpp>
  42. #include <assimp/Exporter.hpp>
  43. #include <stdarg.h>
  44. #ifdef ASSIMP_BUILD_NO_OWN_ZLIB
  45. # include <zlib.h>
  46. #else
  47. # include <contrib/zlib/zlib.h>
  48. #endif
  49. #include <time.h>
  50. #include <stdio.h>
  51. using namespace Assimp;
  52. namespace Assimp {
  53. namespace AssxmlExport {
  54. // -----------------------------------------------------------------------------------
  55. static int ioprintf( IOStream * io, const char *format, ... ) {
  56. using namespace std;
  57. if ( nullptr == io ) {
  58. return -1;
  59. }
  60. static const int Size = 4096;
  61. char sz[ Size ];
  62. ::memset( sz, '\0', Size );
  63. va_list va;
  64. va_start( va, format );
  65. const unsigned int nSize = vsnprintf( sz, Size-1, format, va );
  66. ai_assert( nSize < Size );
  67. va_end( va );
  68. io->Write( sz, sizeof(char), nSize );
  69. return nSize;
  70. }
  71. // -----------------------------------------------------------------------------------
  72. // Convert a name to standard XML format
  73. static void ConvertName(aiString& out, const aiString& in) {
  74. out.length = 0;
  75. for (unsigned int i = 0; i < in.length; ++i) {
  76. switch (in.data[i]) {
  77. case '<':
  78. out.Append("&lt;");break;
  79. case '>':
  80. out.Append("&gt;");break;
  81. case '&':
  82. out.Append("&amp;");break;
  83. case '\"':
  84. out.Append("&quot;");break;
  85. case '\'':
  86. out.Append("&apos;");break;
  87. default:
  88. out.data[out.length++] = in.data[i];
  89. }
  90. }
  91. out.data[out.length] = 0;
  92. }
  93. // -----------------------------------------------------------------------------------
  94. // Write a single node as text dump
  95. static void WriteNode(const aiNode* node, IOStream * io, unsigned int depth) {
  96. char prefix[512];
  97. for (unsigned int i = 0; i < depth;++i)
  98. prefix[i] = '\t';
  99. prefix[depth] = '\0';
  100. const aiMatrix4x4& m = node->mTransformation;
  101. aiString name;
  102. ConvertName(name,node->mName);
  103. ioprintf(io,"%s<Node name=\"%s\"> \n"
  104. "%s\t<Matrix4> \n"
  105. "%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
  106. "%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
  107. "%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
  108. "%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
  109. "%s\t</Matrix4> \n",
  110. prefix,name.data,prefix,
  111. prefix,m.a1,m.a2,m.a3,m.a4,
  112. prefix,m.b1,m.b2,m.b3,m.b4,
  113. prefix,m.c1,m.c2,m.c3,m.c4,
  114. prefix,m.d1,m.d2,m.d3,m.d4,prefix);
  115. if (node->mNumMeshes) {
  116. ioprintf(io, "%s\t<MeshRefs num=\"%i\">\n%s\t",
  117. prefix,node->mNumMeshes,prefix);
  118. for (unsigned int i = 0; i < node->mNumMeshes;++i) {
  119. ioprintf(io,"%i ",node->mMeshes[i]);
  120. }
  121. ioprintf(io,"\n%s\t</MeshRefs>\n",prefix);
  122. }
  123. if (node->mNumChildren) {
  124. ioprintf(io,"%s\t<NodeList num=\"%i\">\n",
  125. prefix,node->mNumChildren);
  126. for (unsigned int i = 0; i < node->mNumChildren;++i) {
  127. WriteNode(node->mChildren[i],io,depth+2);
  128. }
  129. ioprintf(io,"%s\t</NodeList>\n",prefix);
  130. }
  131. ioprintf(io,"%s</Node>\n",prefix);
  132. }
  133. // -----------------------------------------------------------------------------------
  134. // Some chuncks of text will need to be encoded for XML
  135. // http://stackoverflow.com/questions/5665231/most-efficient-way-to-escape-xml-html-in-c-string#5665377
  136. static std::string encodeXML(const std::string& data) {
  137. std::string buffer;
  138. buffer.reserve(data.size());
  139. for(size_t pos = 0; pos != data.size(); ++pos) {
  140. switch(data[pos]) {
  141. case '&': buffer.append("&amp;"); break;
  142. case '\"': buffer.append("&quot;"); break;
  143. case '\'': buffer.append("&apos;"); break;
  144. case '<': buffer.append("&lt;"); break;
  145. case '>': buffer.append("&gt;"); break;
  146. default: buffer.append(&data[pos], 1); break;
  147. }
  148. }
  149. return buffer;
  150. }
  151. // -----------------------------------------------------------------------------------
  152. // Write a text model dump
  153. static
  154. void WriteDump(const aiScene* scene, IOStream* io, bool shortened) {
  155. time_t tt = ::time( NULL );
  156. #if _WIN32
  157. tm* p = gmtime(&tt);
  158. #else
  159. struct tm now;
  160. tm* p = gmtime_r(&tt, &now);
  161. #endif
  162. ai_assert(nullptr != p);
  163. // write header
  164. std::string header(
  165. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  166. "<ASSIMP format_id=\"1\">\n\n"
  167. "<!-- XML Model dump produced by assimp dump\n"
  168. " Library version: %i.%i.%i\n"
  169. " %s\n"
  170. "-->"
  171. " \n\n"
  172. "<Scene flags=\"%d\" postprocessing=\"%i\">\n"
  173. );
  174. const unsigned int majorVersion( aiGetVersionMajor() );
  175. const unsigned int minorVersion( aiGetVersionMinor() );
  176. const unsigned int rev( aiGetVersionRevision() );
  177. const char *curtime( asctime( p ) );
  178. ioprintf( io, header.c_str(), majorVersion, minorVersion, rev, curtime, scene->mFlags, 0 );
  179. // write the node graph
  180. WriteNode(scene->mRootNode, io, 0);
  181. #if 0
  182. // write cameras
  183. for (unsigned int i = 0; i < scene->mNumCameras;++i) {
  184. aiCamera* cam = scene->mCameras[i];
  185. ConvertName(name,cam->mName);
  186. // camera header
  187. ioprintf(io,"\t<Camera parent=\"%s\">\n"
  188. "\t\t<Vector3 name=\"up\" > %0 8f %0 8f %0 8f </Vector3>\n"
  189. "\t\t<Vector3 name=\"lookat\" > %0 8f %0 8f %0 8f </Vector3>\n"
  190. "\t\t<Vector3 name=\"pos\" > %0 8f %0 8f %0 8f </Vector3>\n"
  191. "\t\t<Float name=\"fov\" > %f </Float>\n"
  192. "\t\t<Float name=\"aspect\" > %f </Float>\n"
  193. "\t\t<Float name=\"near_clip\" > %f </Float>\n"
  194. "\t\t<Float name=\"far_clip\" > %f </Float>\n"
  195. "\t</Camera>\n",
  196. name.data,
  197. cam->mUp.x,cam->mUp.y,cam->mUp.z,
  198. cam->mLookAt.x,cam->mLookAt.y,cam->mLookAt.z,
  199. cam->mPosition.x,cam->mPosition.y,cam->mPosition.z,
  200. cam->mHorizontalFOV,cam->mAspect,cam->mClipPlaneNear,cam->mClipPlaneFar,i);
  201. }
  202. // write lights
  203. for (unsigned int i = 0; i < scene->mNumLights;++i) {
  204. aiLight* l = scene->mLights[i];
  205. ConvertName(name,l->mName);
  206. // light header
  207. ioprintf(io,"\t<Light parent=\"%s\"> type=\"%s\"\n"
  208. "\t\t<Vector3 name=\"diffuse\" > %0 8f %0 8f %0 8f </Vector3>\n"
  209. "\t\t<Vector3 name=\"specular\" > %0 8f %0 8f %0 8f </Vector3>\n"
  210. "\t\t<Vector3 name=\"ambient\" > %0 8f %0 8f %0 8f </Vector3>\n",
  211. name.data,
  212. (l->mType == aiLightSource_DIRECTIONAL ? "directional" :
  213. (l->mType == aiLightSource_POINT ? "point" : "spot" )),
  214. l->mColorDiffuse.r, l->mColorDiffuse.g, l->mColorDiffuse.b,
  215. l->mColorSpecular.r,l->mColorSpecular.g,l->mColorSpecular.b,
  216. l->mColorAmbient.r, l->mColorAmbient.g, l->mColorAmbient.b);
  217. if (l->mType != aiLightSource_DIRECTIONAL) {
  218. ioprintf(io,
  219. "\t\t<Vector3 name=\"pos\" > %0 8f %0 8f %0 8f </Vector3>\n"
  220. "\t\t<Float name=\"atten_cst\" > %f </Float>\n"
  221. "\t\t<Float name=\"atten_lin\" > %f </Float>\n"
  222. "\t\t<Float name=\"atten_sqr\" > %f </Float>\n",
  223. l->mPosition.x,l->mPosition.y,l->mPosition.z,
  224. l->mAttenuationConstant,l->mAttenuationLinear,l->mAttenuationQuadratic);
  225. }
  226. if (l->mType != aiLightSource_POINT) {
  227. ioprintf(io,
  228. "\t\t<Vector3 name=\"lookat\" > %0 8f %0 8f %0 8f </Vector3>\n",
  229. l->mDirection.x,l->mDirection.y,l->mDirection.z);
  230. }
  231. if (l->mType == aiLightSource_SPOT) {
  232. ioprintf(io,
  233. "\t\t<Float name=\"cone_out\" > %f </Float>\n"
  234. "\t\t<Float name=\"cone_inn\" > %f </Float>\n",
  235. l->mAngleOuterCone,l->mAngleInnerCone);
  236. }
  237. ioprintf(io,"\t</Light>\n");
  238. }
  239. #endif
  240. aiString name;
  241. // write textures
  242. if (scene->mNumTextures) {
  243. ioprintf(io,"<TextureList num=\"%i\">\n",scene->mNumTextures);
  244. for (unsigned int i = 0; i < scene->mNumTextures;++i) {
  245. aiTexture* tex = scene->mTextures[i];
  246. bool compressed = (tex->mHeight == 0);
  247. // mesh header
  248. ioprintf(io,"\t<Texture width=\"%i\" height=\"%i\" compressed=\"%s\"> \n",
  249. (compressed ? -1 : tex->mWidth),(compressed ? -1 : tex->mHeight),
  250. (compressed ? "true" : "false"));
  251. if (compressed) {
  252. ioprintf(io,"\t\t<Data length=\"%i\"> \n",tex->mWidth);
  253. if (!shortened) {
  254. for (unsigned int n = 0; n < tex->mWidth;++n) {
  255. ioprintf(io,"\t\t\t%2x",reinterpret_cast<uint8_t*>(tex->pcData)[n]);
  256. if (n && !(n % 50)) {
  257. ioprintf(io,"\n");
  258. }
  259. }
  260. }
  261. }
  262. else if (!shortened){
  263. ioprintf(io,"\t\t<Data length=\"%i\"> \n",tex->mWidth*tex->mHeight*4);
  264. // const unsigned int width = (unsigned int)std::log10((double)std::max(tex->mHeight,tex->mWidth))+1;
  265. for (unsigned int y = 0; y < tex->mHeight;++y) {
  266. for (unsigned int x = 0; x < tex->mWidth;++x) {
  267. aiTexel* tx = tex->pcData + y*tex->mWidth+x;
  268. unsigned int r = tx->r,g=tx->g,b=tx->b,a=tx->a;
  269. ioprintf(io,"\t\t\t%2x %2x %2x %2x",r,g,b,a);
  270. // group by four for readability
  271. if ( 0 == ( x + y*tex->mWidth ) % 4 ) {
  272. ioprintf( io, "\n" );
  273. }
  274. }
  275. }
  276. }
  277. ioprintf(io,"\t\t</Data>\n\t</Texture>\n");
  278. }
  279. ioprintf(io,"</TextureList>\n");
  280. }
  281. // write materials
  282. if (scene->mNumMaterials) {
  283. ioprintf(io,"<MaterialList num=\"%i\">\n",scene->mNumMaterials);
  284. for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
  285. const aiMaterial* mat = scene->mMaterials[i];
  286. ioprintf(io,"\t<Material>\n");
  287. ioprintf(io,"\t\t<MatPropertyList num=\"%i\">\n",mat->mNumProperties);
  288. for (unsigned int n = 0; n < mat->mNumProperties;++n) {
  289. const aiMaterialProperty* prop = mat->mProperties[n];
  290. const char* sz = "";
  291. if (prop->mType == aiPTI_Float) {
  292. sz = "float";
  293. }
  294. else if (prop->mType == aiPTI_Integer) {
  295. sz = "integer";
  296. }
  297. else if (prop->mType == aiPTI_String) {
  298. sz = "string";
  299. }
  300. else if (prop->mType == aiPTI_Buffer) {
  301. sz = "binary_buffer";
  302. }
  303. ioprintf(io,"\t\t\t<MatProperty key=\"%s\" \n\t\t\ttype=\"%s\" tex_usage=\"%s\" tex_index=\"%i\"",
  304. prop->mKey.data, sz,
  305. ::TextureTypeToString((aiTextureType)prop->mSemantic),prop->mIndex);
  306. if (prop->mType == aiPTI_Float) {
  307. ioprintf(io," size=\"%i\">\n\t\t\t\t",
  308. static_cast<int>(prop->mDataLength/sizeof(float)));
  309. for (unsigned int p = 0; p < prop->mDataLength/sizeof(float);++p) {
  310. ioprintf(io,"%f ",*((float*)(prop->mData+p*sizeof(float))));
  311. }
  312. }
  313. else if (prop->mType == aiPTI_Integer) {
  314. ioprintf(io," size=\"%i\">\n\t\t\t\t",
  315. static_cast<int>(prop->mDataLength/sizeof(int)));
  316. for (unsigned int p = 0; p < prop->mDataLength/sizeof(int);++p) {
  317. ioprintf(io,"%i ",*((int*)(prop->mData+p*sizeof(int))));
  318. }
  319. }
  320. else if (prop->mType == aiPTI_Buffer) {
  321. ioprintf(io," size=\"%i\">\n\t\t\t\t",
  322. static_cast<int>(prop->mDataLength));
  323. for (unsigned int p = 0; p < prop->mDataLength;++p) {
  324. ioprintf(io,"%2x ",prop->mData[p]);
  325. if (p && 0 == p%30) {
  326. ioprintf(io,"\n\t\t\t\t");
  327. }
  328. }
  329. }
  330. else if (prop->mType == aiPTI_String) {
  331. ioprintf(io,">\n\t\t\t\t\"%s\"",encodeXML(prop->mData+4).c_str() /* skip length */);
  332. }
  333. ioprintf(io,"\n\t\t\t</MatProperty>\n");
  334. }
  335. ioprintf(io,"\t\t</MatPropertyList>\n");
  336. ioprintf(io,"\t</Material>\n");
  337. }
  338. ioprintf(io,"</MaterialList>\n");
  339. }
  340. // write animations
  341. if (scene->mNumAnimations) {
  342. ioprintf(io,"<AnimationList num=\"%i\">\n",scene->mNumAnimations);
  343. for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
  344. aiAnimation* anim = scene->mAnimations[i];
  345. // anim header
  346. ConvertName(name,anim->mName);
  347. ioprintf(io,"\t<Animation name=\"%s\" duration=\"%e\" tick_cnt=\"%e\">\n",
  348. name.data, anim->mDuration, anim->mTicksPerSecond);
  349. // write bone animation channels
  350. if (anim->mNumChannels) {
  351. ioprintf(io,"\t\t<NodeAnimList num=\"%i\">\n",anim->mNumChannels);
  352. for (unsigned int n = 0; n < anim->mNumChannels;++n) {
  353. aiNodeAnim* nd = anim->mChannels[n];
  354. // node anim header
  355. ConvertName(name,nd->mNodeName);
  356. ioprintf(io,"\t\t\t<NodeAnim node=\"%s\">\n",name.data);
  357. if (!shortened) {
  358. // write position keys
  359. if (nd->mNumPositionKeys) {
  360. ioprintf(io,"\t\t\t\t<PositionKeyList num=\"%i\">\n",nd->mNumPositionKeys);
  361. for (unsigned int a = 0; a < nd->mNumPositionKeys;++a) {
  362. aiVectorKey* vc = nd->mPositionKeys+a;
  363. ioprintf(io,"\t\t\t\t\t<PositionKey time=\"%e\">\n"
  364. "\t\t\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t\t\t</PositionKey>\n",
  365. vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z);
  366. }
  367. ioprintf(io,"\t\t\t\t</PositionKeyList>\n");
  368. }
  369. // write scaling keys
  370. if (nd->mNumScalingKeys) {
  371. ioprintf(io,"\t\t\t\t<ScalingKeyList num=\"%i\">\n",nd->mNumScalingKeys);
  372. for (unsigned int a = 0; a < nd->mNumScalingKeys;++a) {
  373. aiVectorKey* vc = nd->mScalingKeys+a;
  374. ioprintf(io,"\t\t\t\t\t<ScalingKey time=\"%e\">\n"
  375. "\t\t\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t\t\t</ScalingKey>\n",
  376. vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z);
  377. }
  378. ioprintf(io,"\t\t\t\t</ScalingKeyList>\n");
  379. }
  380. // write rotation keys
  381. if (nd->mNumRotationKeys) {
  382. ioprintf(io,"\t\t\t\t<RotationKeyList num=\"%i\">\n",nd->mNumRotationKeys);
  383. for (unsigned int a = 0; a < nd->mNumRotationKeys;++a) {
  384. aiQuatKey* vc = nd->mRotationKeys+a;
  385. ioprintf(io,"\t\t\t\t\t<RotationKey time=\"%e\">\n"
  386. "\t\t\t\t\t\t%0 8f %0 8f %0 8f %0 8f\n\t\t\t\t\t</RotationKey>\n",
  387. vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z,vc->mValue.w);
  388. }
  389. ioprintf(io,"\t\t\t\t</RotationKeyList>\n");
  390. }
  391. }
  392. ioprintf(io,"\t\t\t</NodeAnim>\n");
  393. }
  394. ioprintf(io,"\t\t</NodeAnimList>\n");
  395. }
  396. ioprintf(io,"\t</Animation>\n");
  397. }
  398. ioprintf(io,"</AnimationList>\n");
  399. }
  400. // write meshes
  401. if (scene->mNumMeshes) {
  402. ioprintf(io,"<MeshList num=\"%i\">\n",scene->mNumMeshes);
  403. for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
  404. aiMesh* mesh = scene->mMeshes[i];
  405. // const unsigned int width = (unsigned int)std::log10((double)mesh->mNumVertices)+1;
  406. // mesh header
  407. ioprintf(io,"\t<Mesh types=\"%s %s %s %s\" material_index=\"%i\">\n",
  408. (mesh->mPrimitiveTypes & aiPrimitiveType_POINT ? "points" : ""),
  409. (mesh->mPrimitiveTypes & aiPrimitiveType_LINE ? "lines" : ""),
  410. (mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE ? "triangles" : ""),
  411. (mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON ? "polygons" : ""),
  412. mesh->mMaterialIndex);
  413. // bones
  414. if (mesh->mNumBones) {
  415. ioprintf(io,"\t\t<BoneList num=\"%i\">\n",mesh->mNumBones);
  416. for (unsigned int n = 0; n < mesh->mNumBones;++n) {
  417. aiBone* bone = mesh->mBones[n];
  418. ConvertName(name,bone->mName);
  419. // bone header
  420. ioprintf(io,"\t\t\t<Bone name=\"%s\">\n"
  421. "\t\t\t\t<Matrix4> \n"
  422. "\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
  423. "\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
  424. "\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
  425. "\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
  426. "\t\t\t\t</Matrix4> \n",
  427. name.data,
  428. bone->mOffsetMatrix.a1,bone->mOffsetMatrix.a2,bone->mOffsetMatrix.a3,bone->mOffsetMatrix.a4,
  429. bone->mOffsetMatrix.b1,bone->mOffsetMatrix.b2,bone->mOffsetMatrix.b3,bone->mOffsetMatrix.b4,
  430. bone->mOffsetMatrix.c1,bone->mOffsetMatrix.c2,bone->mOffsetMatrix.c3,bone->mOffsetMatrix.c4,
  431. bone->mOffsetMatrix.d1,bone->mOffsetMatrix.d2,bone->mOffsetMatrix.d3,bone->mOffsetMatrix.d4);
  432. if (!shortened && bone->mNumWeights) {
  433. ioprintf(io,"\t\t\t\t<WeightList num=\"%i\">\n",bone->mNumWeights);
  434. // bone weights
  435. for (unsigned int a = 0; a < bone->mNumWeights;++a) {
  436. aiVertexWeight* wght = bone->mWeights+a;
  437. ioprintf(io,"\t\t\t\t\t<Weight index=\"%i\">\n\t\t\t\t\t\t%f\n\t\t\t\t\t</Weight>\n",
  438. wght->mVertexId,wght->mWeight);
  439. }
  440. ioprintf(io,"\t\t\t\t</WeightList>\n");
  441. }
  442. ioprintf(io,"\t\t\t</Bone>\n");
  443. }
  444. ioprintf(io,"\t\t</BoneList>\n");
  445. }
  446. // faces
  447. if (!shortened && mesh->mNumFaces) {
  448. ioprintf(io,"\t\t<FaceList num=\"%i\">\n",mesh->mNumFaces);
  449. for (unsigned int n = 0; n < mesh->mNumFaces; ++n) {
  450. aiFace& f = mesh->mFaces[n];
  451. ioprintf(io,"\t\t\t<Face num=\"%i\">\n"
  452. "\t\t\t\t",f.mNumIndices);
  453. for (unsigned int j = 0; j < f.mNumIndices;++j)
  454. ioprintf(io,"%i ",f.mIndices[j]);
  455. ioprintf(io,"\n\t\t\t</Face>\n");
  456. }
  457. ioprintf(io,"\t\t</FaceList>\n");
  458. }
  459. // vertex positions
  460. if (mesh->HasPositions()) {
  461. ioprintf(io,"\t\t<Positions num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
  462. if (!shortened) {
  463. for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
  464. ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
  465. mesh->mVertices[n].x,
  466. mesh->mVertices[n].y,
  467. mesh->mVertices[n].z);
  468. }
  469. }
  470. ioprintf(io,"\t\t</Positions>\n");
  471. }
  472. // vertex normals
  473. if (mesh->HasNormals()) {
  474. ioprintf(io,"\t\t<Normals num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
  475. if (!shortened) {
  476. for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
  477. ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
  478. mesh->mNormals[n].x,
  479. mesh->mNormals[n].y,
  480. mesh->mNormals[n].z);
  481. }
  482. }
  483. ioprintf(io,"\t\t</Normals>\n");
  484. }
  485. // vertex tangents and bitangents
  486. if (mesh->HasTangentsAndBitangents()) {
  487. ioprintf(io,"\t\t<Tangents num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
  488. if (!shortened) {
  489. for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
  490. ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
  491. mesh->mTangents[n].x,
  492. mesh->mTangents[n].y,
  493. mesh->mTangents[n].z);
  494. }
  495. }
  496. ioprintf(io,"\t\t</Tangents>\n");
  497. ioprintf(io,"\t\t<Bitangents num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
  498. if (!shortened) {
  499. for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
  500. ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
  501. mesh->mBitangents[n].x,
  502. mesh->mBitangents[n].y,
  503. mesh->mBitangents[n].z);
  504. }
  505. }
  506. ioprintf(io,"\t\t</Bitangents>\n");
  507. }
  508. // texture coordinates
  509. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
  510. if (!mesh->mTextureCoords[a])
  511. break;
  512. ioprintf(io,"\t\t<TextureCoords num=\"%i\" set=\"%i\" num_components=\"%i\"> \n",mesh->mNumVertices,
  513. a,mesh->mNumUVComponents[a]);
  514. if (!shortened) {
  515. if (mesh->mNumUVComponents[a] == 3) {
  516. for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
  517. ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
  518. mesh->mTextureCoords[a][n].x,
  519. mesh->mTextureCoords[a][n].y,
  520. mesh->mTextureCoords[a][n].z);
  521. }
  522. }
  523. else {
  524. for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
  525. ioprintf(io,"\t\t%0 8f %0 8f\n",
  526. mesh->mTextureCoords[a][n].x,
  527. mesh->mTextureCoords[a][n].y);
  528. }
  529. }
  530. }
  531. ioprintf(io,"\t\t</TextureCoords>\n");
  532. }
  533. // vertex colors
  534. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
  535. if (!mesh->mColors[a])
  536. break;
  537. ioprintf(io,"\t\t<Colors num=\"%i\" set=\"%i\" num_components=\"4\"> \n",mesh->mNumVertices,a);
  538. if (!shortened) {
  539. for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
  540. ioprintf(io,"\t\t%0 8f %0 8f %0 8f %0 8f\n",
  541. mesh->mColors[a][n].r,
  542. mesh->mColors[a][n].g,
  543. mesh->mColors[a][n].b,
  544. mesh->mColors[a][n].a);
  545. }
  546. }
  547. ioprintf(io,"\t\t</Colors>\n");
  548. }
  549. ioprintf(io,"\t</Mesh>\n");
  550. }
  551. ioprintf(io,"</MeshList>\n");
  552. }
  553. ioprintf(io,"</Scene>\n</ASSIMP>");
  554. }
  555. } // end of namespace AssxmlExport
  556. void ExportSceneAssxml(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/)
  557. {
  558. IOStream * out = pIOSystem->Open( pFile, "wt" );
  559. if (!out) return;
  560. bool shortened = false;
  561. AssxmlExport::WriteDump( pScene, out, shortened );
  562. pIOSystem->Close( out );
  563. }
  564. } // end of namespace Assimp
  565. #endif // ASSIMP_BUILD_NO_ASSXML_EXPORTER
  566. #endif // ASSIMP_BUILD_NO_EXPORT