AssxmlExporter.cpp 26 KB

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