AssxmlExporter.cpp 20 KB

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