2
0

AssxmlExporter.cpp 20 KB

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