ColladaExporter.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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. #include "AssimpPCH.h"
  34. #ifndef ASSIMP_BUILD_NO_EXPORT
  35. #ifndef ASSIMP_BUILD_NO_COLLADA_EXPORTER
  36. #include "ColladaExporter.h"
  37. using namespace Assimp;
  38. namespace Assimp
  39. {
  40. // ------------------------------------------------------------------------------------------------
  41. // Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp
  42. void ExportSceneCollada(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
  43. {
  44. // invoke the exporter
  45. ColladaExporter iDoTheExportThing( pScene);
  46. // we're still here - export successfully completed. Write result to the given IOSYstem
  47. boost::scoped_ptr<IOStream> outfile (pIOSystem->Open(pFile,"wt"));
  48. // XXX maybe use a small wrapper around IOStream that behaves like std::stringstream in order to avoid the extra copy.
  49. outfile->Write( iDoTheExportThing.mOutput.str().c_str(), static_cast<size_t>(iDoTheExportThing.mOutput.tellp()),1);
  50. }
  51. } // end of namespace Assimp
  52. // ------------------------------------------------------------------------------------------------
  53. // Constructor for a specific scene to export
  54. ColladaExporter::ColladaExporter( const aiScene* pScene)
  55. {
  56. // make sure that all formatting happens using the standard, C locale and not the user's current locale
  57. mOutput.imbue( std::locale("C") );
  58. mScene = pScene;
  59. // set up strings
  60. endstr = "\n";
  61. // start writing
  62. WriteFile();
  63. }
  64. // ------------------------------------------------------------------------------------------------
  65. // Starts writing the contents
  66. void ColladaExporter::WriteFile()
  67. {
  68. // write the DTD
  69. mOutput << "<?xml version=\"1.0\"?>" << endstr;
  70. // COLLADA element start
  71. mOutput << "<COLLADA xmlns=\"http://www.collada.org/2005/11/COLLADASchema\" version=\"1.4.1\">" << endstr;
  72. PushTag();
  73. WriteHeader();
  74. WriteMaterials();
  75. WriteGeometryLibrary();
  76. WriteSceneLibrary();
  77. // useless Collada bullshit at the end, just in case we haven't had enough indirections, yet.
  78. mOutput << startstr << "<scene>" << endstr;
  79. PushTag();
  80. mOutput << startstr << "<instance_visual_scene url=\"#myScene\" />" << endstr;
  81. PopTag();
  82. mOutput << startstr << "</scene>" << endstr;
  83. PopTag();
  84. mOutput << "</COLLADA>" << endstr;
  85. }
  86. // ------------------------------------------------------------------------------------------------
  87. // Writes the asset header
  88. void ColladaExporter::WriteHeader()
  89. {
  90. // Dummy stuff. Nobody actually cares for it anyways
  91. mOutput << startstr << "<asset>" << endstr;
  92. PushTag();
  93. mOutput << startstr << "<contributor>" << endstr;
  94. PushTag();
  95. mOutput << startstr << "<author>Someone</author>" << endstr;
  96. mOutput << startstr << "<authoring_tool>Assimp Collada Exporter</authoring_tool>" << endstr;
  97. PopTag();
  98. mOutput << startstr << "</contributor>" << endstr;
  99. mOutput << startstr << "<unit meter=\"1.0\" name=\"meter\" />" << endstr;
  100. mOutput << startstr << "<up_axis>Y_UP</up_axis>" << endstr;
  101. PopTag();
  102. mOutput << startstr << "</asset>" << endstr;
  103. }
  104. // ------------------------------------------------------------------------------------------------
  105. // Reads a single surface entry from the given material keys
  106. void ColladaExporter::ReadMaterialSurface( Surface& poSurface, const aiMaterial* pSrcMat, aiTextureType pTexture, const char* pKey, size_t pType, size_t pIndex)
  107. {
  108. if( pSrcMat->GetTextureCount( pTexture) > 0 )
  109. {
  110. aiString texfile;
  111. unsigned int uvChannel = 0;
  112. pSrcMat->GetTexture( pTexture, 0, &texfile, NULL, &uvChannel);
  113. poSurface.texture = texfile.C_Str();
  114. poSurface.channel = uvChannel;
  115. } else
  116. {
  117. if( pKey )
  118. pSrcMat->Get( pKey, pType, pIndex, poSurface.color);
  119. }
  120. }
  121. // ------------------------------------------------------------------------------------------------
  122. // Writes an image entry for the given surface
  123. void ColladaExporter::WriteImageEntry( const Surface& pSurface, const std::string& pNameAdd)
  124. {
  125. if( !pSurface.texture.empty() )
  126. {
  127. mOutput << startstr << "<image id=\"" << pNameAdd << "\" name=\"" << pNameAdd << "\">" << endstr;
  128. PushTag();
  129. mOutput << startstr << "<init_from>" << pSurface.texture << "</init_from>" << endstr;
  130. PopTag();
  131. mOutput << startstr << "</image>" << endstr;
  132. }
  133. }
  134. // ------------------------------------------------------------------------------------------------
  135. // Writes a color-or-texture entry into an effect definition
  136. void ColladaExporter::WriteTextureColorEntry( const Surface& pSurface, const std::string& pTypeName, const std::string& pImageName)
  137. {
  138. mOutput << startstr << "<" << pTypeName << ">" << endstr;
  139. PushTag();
  140. if( pSurface.texture.empty() )
  141. {
  142. mOutput << startstr << "<color sid=\"" << pTypeName << "\">" << pSurface.color.r << " " << pSurface.color.g << " " << pSurface.color.b << " " << pSurface.color.a << "</color>" << endstr;
  143. } else
  144. {
  145. mOutput << startstr << "<texture texture=\"" << pImageName << "\" texcoord=\"CHANNEL" << pSurface.channel << "\" />" << endstr;
  146. }
  147. PopTag();
  148. mOutput << startstr << "</" << pTypeName << ">" << endstr;
  149. }
  150. // ------------------------------------------------------------------------------------------------
  151. // Writes the material setup
  152. void ColladaExporter::WriteMaterials()
  153. {
  154. materials.resize( mScene->mNumMaterials);
  155. /// collect all materials from the scene
  156. for( size_t a = 0; a < mScene->mNumMaterials; ++a )
  157. {
  158. const aiMaterial* mat = mScene->mMaterials[a];
  159. aiString name;
  160. if( mat->Get( AI_MATKEY_NAME, name) != aiReturn_SUCCESS )
  161. name = "mat";
  162. materials[a].name = boost::lexical_cast<std::string> (a) + name.C_Str();
  163. ReadMaterialSurface( materials[a].ambient, mat, aiTextureType_AMBIENT, AI_MATKEY_COLOR_AMBIENT);
  164. ReadMaterialSurface( materials[a].diffuse, mat, aiTextureType_DIFFUSE, AI_MATKEY_COLOR_DIFFUSE);
  165. ReadMaterialSurface( materials[a].specular, mat, aiTextureType_SPECULAR, AI_MATKEY_COLOR_SPECULAR);
  166. ReadMaterialSurface( materials[a].emissive, mat, aiTextureType_EMISSIVE, AI_MATKEY_COLOR_EMISSIVE);
  167. ReadMaterialSurface( materials[a].reflective, mat, aiTextureType_REFLECTION, AI_MATKEY_COLOR_REFLECTIVE);
  168. ReadMaterialSurface( materials[a].normal, mat, aiTextureType_NORMALS, NULL, 0, 0);
  169. mat->Get( AI_MATKEY_SHININESS, materials[a].shininess);
  170. }
  171. // output textures if present
  172. mOutput << startstr << "<library_images>" << endstr;
  173. PushTag();
  174. for( std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it )
  175. {
  176. const Material& mat = *it;
  177. WriteImageEntry( mat.ambient, mat.name + "_ambient_image");
  178. WriteImageEntry( mat.diffuse, mat.name + "_diffuse_image");
  179. WriteImageEntry( mat.specular, mat.name + "_specular_image");
  180. WriteImageEntry( mat.emissive, mat.name + "_emissive_image");
  181. WriteImageEntry( mat.reflective, mat.name + "_reflective_image");
  182. WriteImageEntry( mat.normal, mat.name + "_normal_image");
  183. }
  184. PopTag();
  185. mOutput << startstr << "</library_images>" << endstr;
  186. // output effects - those are the actual carriers of information
  187. mOutput << startstr << "<library_effects>" << endstr;
  188. PushTag();
  189. for( std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it )
  190. {
  191. const Material& mat = *it;
  192. // this is so ridiculous it must be right
  193. mOutput << startstr << "<effect id=\"" << mat.name << "-fx\" name=\"" << mat.name << "\">" << endstr;
  194. PushTag();
  195. mOutput << startstr << "<profile_COMMON>" << endstr;
  196. PushTag();
  197. mOutput << startstr << "<technique sid=\"standard\">" << endstr;
  198. PushTag();
  199. mOutput << startstr << "<phong>" << endstr;
  200. PushTag();
  201. WriteTextureColorEntry( mat.ambient, "ambient", mat.name + "_ambient_image");
  202. WriteTextureColorEntry( mat.diffuse, "diffuse", mat.name + "_diffuse_image");
  203. WriteTextureColorEntry( mat.specular, "specular", mat.name + "_specular_image");
  204. WriteTextureColorEntry( mat.emissive, "emission", mat.name + "_emissive_image");
  205. WriteTextureColorEntry( mat.reflective, "reflective", mat.name + "_reflective_image");
  206. if( !mat.normal.texture.empty() )
  207. WriteTextureColorEntry( mat.normal, "bump", mat.name + "_normal_image");
  208. mOutput << startstr << "<shininess>" << endstr;
  209. PushTag();
  210. mOutput << startstr << "<float sid=\"shininess\">" << mat.shininess << "</float>" << endstr;
  211. PopTag();
  212. mOutput << startstr << "</shininess>" << endstr;
  213. PopTag();
  214. mOutput << startstr << "</phong>" << endstr;
  215. PopTag();
  216. mOutput << startstr << "</technique>" << endstr;
  217. PopTag();
  218. mOutput << startstr << "</profile_COMMON>" << endstr;
  219. PopTag();
  220. mOutput << startstr << "</effect>" << endstr;
  221. }
  222. PopTag();
  223. mOutput << startstr << "</library_effects>" << endstr;
  224. // write materials - they're just effect references
  225. mOutput << startstr << "<library_materials>" << endstr;
  226. PushTag();
  227. for( std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it )
  228. {
  229. const Material& mat = *it;
  230. mOutput << startstr << "<material id=\"" << mat.name << "\" name=\"" << mat.name << "\">" << endstr;
  231. PushTag();
  232. mOutput << startstr << "<instance_effect url=\"#" << mat.name << "-fx\"/>" << endstr;
  233. PopTag();
  234. mOutput << startstr << "</material>" << endstr;
  235. }
  236. PopTag();
  237. mOutput << startstr << "</library_materials>" << endstr;
  238. }
  239. // ------------------------------------------------------------------------------------------------
  240. // Writes the geometry library
  241. void ColladaExporter::WriteGeometryLibrary()
  242. {
  243. mOutput << startstr << "<library_geometries>" << endstr;
  244. PushTag();
  245. for( size_t a = 0; a < mScene->mNumMeshes; ++a)
  246. WriteGeometry( a);
  247. PopTag();
  248. mOutput << startstr << "</library_geometries>" << endstr;
  249. }
  250. // ------------------------------------------------------------------------------------------------
  251. // Writes the given mesh
  252. void ColladaExporter::WriteGeometry( size_t pIndex)
  253. {
  254. const aiMesh* mesh = mScene->mMeshes[pIndex];
  255. std::string idstr = GetMeshId( pIndex);
  256. if( mesh->mNumFaces == 0 || mesh->mNumVertices == 0 )
  257. return;
  258. // opening tag
  259. mOutput << startstr << "<geometry id=\"" << idstr << "\" name=\"" << idstr << "_name\" >" << endstr;
  260. PushTag();
  261. mOutput << startstr << "<mesh>" << endstr;
  262. PushTag();
  263. // Positions
  264. WriteFloatArray( idstr + "-positions", FloatType_Vector, (float*) mesh->mVertices, mesh->mNumVertices);
  265. // Normals, if any
  266. if( mesh->HasNormals() )
  267. WriteFloatArray( idstr + "-normals", FloatType_Vector, (float*) mesh->mNormals, mesh->mNumVertices);
  268. // texture coords
  269. for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a)
  270. {
  271. if( mesh->HasTextureCoords( a) )
  272. {
  273. WriteFloatArray( idstr + "-tex" + boost::lexical_cast<std::string> (a), mesh->mNumUVComponents[a] == 3 ? FloatType_TexCoord3 : FloatType_TexCoord2,
  274. (float*) mesh->mTextureCoords[a], mesh->mNumVertices);
  275. }
  276. }
  277. // vertex colors
  278. for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a)
  279. {
  280. if( mesh->HasVertexColors( a) )
  281. WriteFloatArray( idstr + "-color" + boost::lexical_cast<std::string> (a), FloatType_Color, (float*) mesh->mColors[a], mesh->mNumVertices);
  282. }
  283. // assemble vertex structure
  284. mOutput << startstr << "<vertices id=\"" << idstr << "-vertices" << "\">" << endstr;
  285. PushTag();
  286. mOutput << startstr << "<input semantic=\"POSITION\" source=\"#" << idstr << "-positions\" />" << endstr;
  287. if( mesh->HasNormals() )
  288. mOutput << startstr << "<input semantic=\"NORMAL\" source=\"#" << idstr << "-normals\" />" << endstr;
  289. for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a )
  290. {
  291. if( mesh->HasTextureCoords( a) )
  292. mOutput << startstr << "<input semantic=\"TEXCOORD\" source=\"#" << idstr << "-tex" << a << "\" set=\"" << a << "\" />" << endstr;
  293. }
  294. for( size_t a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a )
  295. {
  296. if( mesh->HasVertexColors( a) )
  297. mOutput << startstr << "<input semantic=\"COLOR\" source=\"#" << idstr << "-color" << a << "\" set=\"" << a << "\" />" << endstr;
  298. }
  299. PopTag();
  300. mOutput << startstr << "</vertices>" << endstr;
  301. // write face setup
  302. mOutput << startstr << "<polylist count=\"" << mesh->mNumFaces << "\" material=\"theresonlyone\">" << endstr;
  303. PushTag();
  304. mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << idstr << "-vertices\" />" << endstr;
  305. mOutput << startstr << "<vcount>";
  306. for( size_t a = 0; a < mesh->mNumFaces; ++a )
  307. mOutput << mesh->mFaces[a].mNumIndices << " ";
  308. mOutput << "</vcount>" << endstr;
  309. mOutput << startstr << "<p>";
  310. for( size_t a = 0; a < mesh->mNumFaces; ++a )
  311. {
  312. const aiFace& face = mesh->mFaces[a];
  313. for( size_t b = 0; b < face.mNumIndices; ++b )
  314. mOutput << face.mIndices[b] << " ";
  315. }
  316. mOutput << "</p>" << endstr;
  317. PopTag();
  318. mOutput << startstr << "</polylist>" << endstr;
  319. // closing tags
  320. PopTag();
  321. mOutput << startstr << "</mesh>" << endstr;
  322. PopTag();
  323. mOutput << startstr << "</geometry>" << endstr;
  324. }
  325. // ------------------------------------------------------------------------------------------------
  326. // Writes a float array of the given type
  327. void ColladaExporter::WriteFloatArray( const std::string& pIdString, FloatDataType pType, const float* pData, size_t pElementCount)
  328. {
  329. size_t floatsPerElement = 0;
  330. switch( pType )
  331. {
  332. case FloatType_Vector: floatsPerElement = 3; break;
  333. case FloatType_TexCoord2: floatsPerElement = 2; break;
  334. case FloatType_TexCoord3: floatsPerElement = 3; break;
  335. case FloatType_Color: floatsPerElement = 3; break;
  336. default:
  337. return;
  338. }
  339. std::string arrayId = pIdString + "-array";
  340. mOutput << startstr << "<source id=\"" << pIdString << "\" name=\"" << pIdString << "\">" << endstr;
  341. PushTag();
  342. // source array
  343. mOutput << startstr << "<float_array id=\"" << arrayId << "\" count=\"" << pElementCount * floatsPerElement << "\"> ";
  344. PushTag();
  345. if( pType == FloatType_TexCoord2 )
  346. {
  347. for( size_t a = 0; a < pElementCount; ++a )
  348. {
  349. mOutput << pData[a*3+0] << " ";
  350. mOutput << pData[a*3+1] << " ";
  351. }
  352. }
  353. else if( pType == FloatType_Color )
  354. {
  355. for( size_t a = 0; a < pElementCount; ++a )
  356. {
  357. mOutput << pData[a*4+0] << " ";
  358. mOutput << pData[a*4+1] << " ";
  359. mOutput << pData[a*4+2] << " ";
  360. }
  361. }
  362. else
  363. {
  364. for( size_t a = 0; a < pElementCount * floatsPerElement; ++a )
  365. mOutput << pData[a] << " ";
  366. }
  367. mOutput << "</float_array>" << endstr;
  368. PopTag();
  369. // the usual Collada bullshit. Let's bloat it even more!
  370. mOutput << startstr << "<technique_common>" << endstr;
  371. PushTag();
  372. mOutput << startstr << "<accessor count=\"" << pElementCount << "\" offset=\"0\" source=\"#" << arrayId << "\" stride=\"" << floatsPerElement << "\">" << endstr;
  373. PushTag();
  374. switch( pType )
  375. {
  376. case FloatType_Vector:
  377. mOutput << startstr << "<param name=\"X\" type=\"float\" />" << endstr;
  378. mOutput << startstr << "<param name=\"Y\" type=\"float\" />" << endstr;
  379. mOutput << startstr << "<param name=\"Z\" type=\"float\" />" << endstr;
  380. break;
  381. case FloatType_TexCoord2:
  382. mOutput << startstr << "<param name=\"S\" type=\"float\" />" << endstr;
  383. mOutput << startstr << "<param name=\"T\" type=\"float\" />" << endstr;
  384. break;
  385. case FloatType_TexCoord3:
  386. mOutput << startstr << "<param name=\"S\" type=\"float\" />" << endstr;
  387. mOutput << startstr << "<param name=\"T\" type=\"float\" />" << endstr;
  388. mOutput << startstr << "<param name=\"P\" type=\"float\" />" << endstr;
  389. break;
  390. case FloatType_Color:
  391. mOutput << startstr << "<param name=\"R\" type=\"float\" />" << endstr;
  392. mOutput << startstr << "<param name=\"G\" type=\"float\" />" << endstr;
  393. mOutput << startstr << "<param name=\"B\" type=\"float\" />" << endstr;
  394. break;
  395. }
  396. PopTag();
  397. mOutput << startstr << "</accessor>" << endstr;
  398. PopTag();
  399. mOutput << startstr << "</technique_common>" << endstr;
  400. PopTag();
  401. mOutput << startstr << "</source>" << endstr;
  402. }
  403. // ------------------------------------------------------------------------------------------------
  404. // Writes the scene library
  405. void ColladaExporter::WriteSceneLibrary()
  406. {
  407. mOutput << startstr << "<library_visual_scenes>" << endstr;
  408. PushTag();
  409. mOutput << startstr << "<visual_scene id=\"myScene\" name=\"myScene\">" << endstr;
  410. PushTag();
  411. // start recursive write at the root node
  412. WriteNode( mScene->mRootNode);
  413. PopTag();
  414. mOutput << startstr << "</visual_scene>" << endstr;
  415. PopTag();
  416. mOutput << startstr << "</library_visual_scenes>" << endstr;
  417. }
  418. // ------------------------------------------------------------------------------------------------
  419. // Recursively writes the given node
  420. void ColladaExporter::WriteNode( const aiNode* pNode)
  421. {
  422. mOutput << startstr << "<node id=\"" << pNode->mName.data << "\" name=\"" << pNode->mName.data << "\">" << endstr;
  423. PushTag();
  424. // write transformation - we can directly put the matrix there
  425. // TODO: (thom) decompose into scale - rot - quad to allow adressing it by animations afterwards
  426. const aiMatrix4x4& mat = pNode->mTransformation;
  427. mOutput << startstr << "<matrix>";
  428. mOutput << mat.a1 << " " << mat.a2 << " " << mat.a3 << " " << mat.a4 << " ";
  429. mOutput << mat.b1 << " " << mat.b2 << " " << mat.b3 << " " << mat.b4 << " ";
  430. mOutput << mat.c1 << " " << mat.c2 << " " << mat.c3 << " " << mat.c4 << " ";
  431. mOutput << mat.d1 << " " << mat.d2 << " " << mat.d3 << " " << mat.d4;
  432. mOutput << "</matrix>" << endstr;
  433. // instance every geometry
  434. for( size_t a = 0; a < pNode->mNumMeshes; ++a )
  435. {
  436. const aiMesh* mesh = mScene->mMeshes[pNode->mMeshes[a]];
  437. // do not instanciate mesh if empty. I wonder how this could happen
  438. if( mesh->mNumFaces == 0 || mesh->mNumVertices == 0 )
  439. continue;
  440. mOutput << startstr << "<instance_geometry url=\"#" << GetMeshId( pNode->mMeshes[a]) << "\">" << endstr;
  441. PushTag();
  442. mOutput << startstr << "<bind_material>" << endstr;
  443. PushTag();
  444. mOutput << startstr << "<technique_common>" << endstr;
  445. PushTag();
  446. mOutput << startstr << "<instance_material symbol=\"theresonlyone\" target=\"#" << materials[mesh->mMaterialIndex].name << "\" />" << endstr;
  447. PopTag();
  448. mOutput << startstr << "</technique_common>" << endstr;
  449. PopTag();
  450. mOutput << startstr << "</bind_material>" << endstr;
  451. PopTag();
  452. mOutput << startstr << "</instance_geometry>" << endstr;
  453. }
  454. // recurse into subnodes
  455. for( size_t a = 0; a < pNode->mNumChildren; ++a )
  456. WriteNode( pNode->mChildren[a]);
  457. PopTag();
  458. mOutput << startstr << "</node>" << endstr;
  459. }
  460. #endif
  461. #endif