AssxmlExporter.cpp 20 KB

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