OpenAssetImporter.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  23. // Please see LICENSE.md in repository root for license information
  24. // https://github.com/AtomicGameEngine/AtomicGameEngine
  25. #include <Atomic/Core/ProcessUtils.h>
  26. #include <Atomic/Core/Context.h>
  27. #include <Atomic/IO/Log.h>
  28. #include <Atomic/IO/File.h>
  29. #include <Atomic/IO/FileSystem.h>
  30. #include <Atomic/Resource/XMLFile.h>
  31. #include <Atomic/Resource/ResourceCache.h>
  32. #include <Atomic/Atomic3D/AnimatedModel.h>
  33. #include <Atomic/Atomic3D/Animation.h>
  34. #include <Atomic/Graphics/Geometry.h>
  35. #include <Atomic/Graphics/IndexBuffer.h>
  36. #include <Atomic/Graphics/VertexBuffer.h>
  37. #include <Atomic/Graphics/Material.h>
  38. #include "OpenAssetImporter.h"
  39. namespace ToolCore
  40. {
  41. OpenAssetImporter::OpenAssetImporter(Context* context) : Object(context) ,
  42. scene_(0),
  43. rootNode_(0),
  44. useSubdirs_(true),
  45. localIDs_(false),
  46. saveBinary_(false),
  47. createZone_(true),
  48. noAnimations_(false),
  49. noHierarchy_(false),
  50. noMaterials_(false),
  51. noTextures_(false),
  52. noMaterialDiffuseColor_(false),
  53. noEmptyNodes_(false),
  54. saveMaterialList_(false),
  55. includeNonSkinningBones_(false),
  56. verboseLog_(false),
  57. emissiveAO_(false),
  58. noOverwriteMaterial_(true),
  59. noOverwriteTexture_(true),
  60. noOverwriteNewerTexture_(true),
  61. checkUniqueModel_(true),
  62. maxBones_(64),
  63. defaultTicksPerSecond_(4800.0f)
  64. {
  65. aiFlagsDefault_ =
  66. aiProcess_ConvertToLeftHanded |
  67. aiProcess_JoinIdenticalVertices |
  68. aiProcess_Triangulate |
  69. aiProcess_GenSmoothNormals |
  70. aiProcess_LimitBoneWeights |
  71. aiProcess_ImproveCacheLocality |
  72. aiProcess_RemoveRedundantMaterials |
  73. aiProcess_FixInfacingNormals |
  74. aiProcess_FindInvalidData |
  75. aiProcess_GenUVCoords |
  76. aiProcess_FindInstances |
  77. aiProcess_OptimizeMeshes;
  78. aiCurrentFlags_ = aiFlagsDefault_;
  79. }
  80. OpenAssetImporter::~OpenAssetImporter()
  81. {
  82. if (scene_)
  83. aiReleaseImport(scene_);
  84. }
  85. bool OpenAssetImporter::Load(const String &assetPath)
  86. {
  87. if (verboseLog_)
  88. Assimp::DefaultLogger::create("", Assimp::Logger::VERBOSE, aiDefaultLogStream_STDOUT);
  89. //PrintLine("Reading file " + assetPath);
  90. sourceAssetPath_ = GetPath(assetPath);
  91. scene_ = aiImportFile(GetNativePath(assetPath).CString(), aiCurrentFlags_);
  92. if (!scene_)
  93. ErrorExit("Could not open or parse input file " + assetPath + ": " + String(aiGetErrorString()));
  94. if (verboseLog_)
  95. Assimp::DefaultLogger::kill();
  96. rootNode_ = scene_->mRootNode;
  97. // DumpNodes(rootNode_, 0);
  98. return true;
  99. }
  100. void OpenAssetImporter::ExportModel(const String& outName, bool animationOnly)
  101. {
  102. if (outName.Empty())
  103. ErrorExit("No output file defined");
  104. OutModel model;
  105. model.rootNode_ = rootNode_;
  106. model.outName_ = outName + ".mdl";
  107. CollectMeshes(scene_, model, model.rootNode_);
  108. CollectBones(model, animationOnly);
  109. BuildBoneCollisionInfo(model);
  110. BuildAndSaveModel(model);
  111. if (!noAnimations_)
  112. {
  113. CollectAnimations(&model);
  114. BuildAndSaveAnimations(&model);
  115. // Save scene-global animations
  116. CollectAnimations();
  117. BuildAndSaveAnimations();
  118. }
  119. if (!noMaterials_)
  120. {
  121. HashSet<String> usedTextures;
  122. ExportMaterials(usedTextures);
  123. }
  124. ResourceCache* cache = GetSubsystem<ResourceCache>();
  125. Model* mdl = cache->GetResource<Model>( model.outName_);
  126. // Use a dummy model here? It kind of depends on how resource layout is
  127. // designed, importing, existing models, etc
  128. /*
  129. // Create a dummy model so that the reference can be stored
  130. String modelName = (useSubdirs_ ? "Models/" : "") + GetFileNameAndExtension(model.outName_);
  131. if (!cache->Exists(modelName))
  132. {
  133. Model* dummyModel = new Model(context_);
  134. dummyModel->SetName(modelName);
  135. dummyModel->SetNumGeometries(model.meshes_.Size());
  136. cache->AddManualResource(dummyModel);
  137. }
  138. */
  139. SharedPtr<Node> node(new Node(context_));
  140. node->SetName("Model");
  141. StaticModel* staticModel = node->CreateComponent<StaticModel>();
  142. staticModel->SetModel(mdl);
  143. if (!noMaterials_)
  144. {
  145. // Set materials if they are known
  146. for (unsigned j = 0; j < model.meshes_.Size(); ++j)
  147. {
  148. String matName = GetMeshMaterialName(model.meshes_[j]);
  149. String materialName = sourceAssetPath_ + matName;
  150. staticModel->SetMaterial(j, cache->GetResource<Material>(materialName));
  151. }
  152. }
  153. File outFile(context_);
  154. if (!outFile.Open(outName, FILE_WRITE))
  155. ErrorExit("Could not open output file " + outName);
  156. node->SaveXML(outFile);
  157. }
  158. void OpenAssetImporter::BuildAndSaveModel(OutModel& model)
  159. {
  160. if (!model.rootNode_)
  161. ErrorExit("Null root node for model");
  162. String rootNodeName = FromAIString(model.rootNode_->mName);
  163. if (!model.meshes_.Size())
  164. ErrorExit("No geometries found starting from node " + rootNodeName);
  165. //PrintLine("Writing model " + rootNodeName);
  166. SharedPtr<Model> outModel(new Model(context_));
  167. Vector<PODVector<unsigned> > allBoneMappings;
  168. BoundingBox box;
  169. unsigned numValidGeometries = 0;
  170. bool combineBuffers = true;
  171. // Check if buffers can be combined (same vertex element mask, under 65535 vertices)
  172. unsigned elementMask = GetElementMask(model.meshes_[0]);
  173. for (unsigned i = 0; i < model.meshes_.Size(); ++i)
  174. {
  175. if (GetNumValidFaces(model.meshes_[i]))
  176. {
  177. ++numValidGeometries;
  178. if (i > 0 && GetElementMask(model.meshes_[i]) != elementMask)
  179. combineBuffers = false;
  180. }
  181. }
  182. // Check if keeping separate buffers allows to avoid 32-bit indices
  183. if (combineBuffers && model.totalVertices_ > 65535)
  184. {
  185. bool allUnder65k = true;
  186. for (unsigned i = 0; i < model.meshes_.Size(); ++i)
  187. {
  188. if (GetNumValidFaces(model.meshes_[i]))
  189. {
  190. if (model.meshes_[i]->mNumVertices > 65535)
  191. allUnder65k = false;
  192. }
  193. }
  194. if (allUnder65k == true)
  195. combineBuffers = false;
  196. }
  197. SharedPtr<IndexBuffer> ib;
  198. SharedPtr<VertexBuffer> vb;
  199. Vector<SharedPtr<VertexBuffer> > vbVector;
  200. Vector<SharedPtr<IndexBuffer> > ibVector;
  201. unsigned startVertexOffset = 0;
  202. unsigned startIndexOffset = 0;
  203. unsigned destGeomIndex = 0;
  204. outModel->SetNumGeometries(numValidGeometries);
  205. for (unsigned i = 0; i < model.meshes_.Size(); ++i)
  206. {
  207. aiMesh* mesh = model.meshes_[i];
  208. unsigned elementMask = GetElementMask(mesh);
  209. unsigned validFaces = GetNumValidFaces(mesh);
  210. if (!validFaces)
  211. continue;
  212. bool largeIndices;
  213. if (combineBuffers)
  214. largeIndices = model.totalIndices_ > 65535;
  215. else
  216. largeIndices = mesh->mNumVertices > 65535;
  217. // Create new buffers if necessary
  218. if (!combineBuffers || vbVector.Empty())
  219. {
  220. vb = new VertexBuffer(context_);
  221. ib = new IndexBuffer(context_);
  222. vb->SetShadowed(true);
  223. ib->SetShadowed(true);
  224. if (combineBuffers)
  225. {
  226. ib->SetSize(model.totalIndices_, largeIndices);
  227. vb->SetSize(model.totalVertices_, elementMask);
  228. }
  229. else
  230. {
  231. ib->SetSize(validFaces * 3, largeIndices);
  232. vb->SetSize(mesh->mNumVertices, elementMask);
  233. }
  234. vbVector.Push(vb);
  235. ibVector.Push(ib);
  236. startVertexOffset = 0;
  237. startIndexOffset = 0;
  238. }
  239. // Get the world transform of the mesh for baking into the vertices
  240. Matrix3x4 vertexTransform;
  241. Matrix3 normalTransform;
  242. Vector3 pos, scale;
  243. Quaternion rot;
  244. GetPosRotScale(GetMeshBakingTransform(model.meshNodes_[i], model.rootNode_), pos, rot, scale);
  245. vertexTransform = Matrix3x4(pos, rot, scale);
  246. normalTransform = rot.RotationMatrix();
  247. SharedPtr<Geometry> geom(new Geometry(context_));
  248. //PrintLine("Writing geometry " + String(i) + " with " + String(mesh->mNumVertices) + " vertices " +
  249. // String(validFaces * 3) + " indices");
  250. unsigned char* vertexData = vb->GetShadowData();
  251. unsigned char* indexData = ib->GetShadowData();
  252. assert(vertexData);
  253. assert(indexData);
  254. // Build the index data
  255. if (!largeIndices)
  256. {
  257. unsigned short* dest = (unsigned short*)indexData + startIndexOffset;
  258. for (unsigned j = 0; j < mesh->mNumFaces; ++j)
  259. WriteShortIndices(dest, mesh, j, startVertexOffset);
  260. }
  261. else
  262. {
  263. unsigned* dest = (unsigned*)indexData + startIndexOffset;
  264. for (unsigned j = 0; j < mesh->mNumFaces; ++j)
  265. WriteLargeIndices(dest, mesh, j, startVertexOffset);
  266. }
  267. // Build the vertex data
  268. // If there are bones, get blend data
  269. Vector<PODVector<unsigned char> > blendIndices;
  270. Vector<PODVector<float> > blendWeights;
  271. PODVector<unsigned> boneMappings;
  272. if (model.bones_.Size())
  273. GetBlendData(model, mesh, boneMappings, blendIndices, blendWeights, maxBones_);
  274. float* dest = (float*)((unsigned char*)vertexData + startVertexOffset * vb->GetVertexSize());
  275. for (unsigned j = 0; j < mesh->mNumVertices; ++j)
  276. WriteVertex(dest, mesh, j, elementMask, box, vertexTransform, normalTransform, blendIndices, blendWeights);
  277. // Calculate the geometry center
  278. Vector3 center = Vector3::ZERO;
  279. if (validFaces)
  280. {
  281. for (unsigned j = 0; j < mesh->mNumFaces; ++j)
  282. {
  283. if (mesh->mFaces[j].mNumIndices == 3)
  284. {
  285. center += vertexTransform * ToVector3(mesh->mVertices[mesh->mFaces[j].mIndices[0]]);
  286. center += vertexTransform * ToVector3(mesh->mVertices[mesh->mFaces[j].mIndices[1]]);
  287. center += vertexTransform * ToVector3(mesh->mVertices[mesh->mFaces[j].mIndices[2]]);
  288. }
  289. }
  290. center /= (float)validFaces * 3;
  291. }
  292. // Define the geometry
  293. geom->SetIndexBuffer(ib);
  294. geom->SetVertexBuffer(0, vb);
  295. geom->SetDrawRange(TRIANGLE_LIST, startIndexOffset, validFaces * 3, true);
  296. outModel->SetNumGeometryLodLevels(destGeomIndex, 1);
  297. outModel->SetGeometry(destGeomIndex, 0, geom);
  298. outModel->SetGeometryCenter(destGeomIndex, center);
  299. if (model.bones_.Size() > maxBones_)
  300. allBoneMappings.Push(boneMappings);
  301. startVertexOffset += mesh->mNumVertices;
  302. startIndexOffset += validFaces * 3;
  303. ++destGeomIndex;
  304. }
  305. // Define the model buffers and bounding box
  306. PODVector<unsigned> emptyMorphRange;
  307. outModel->SetVertexBuffers(vbVector, emptyMorphRange, emptyMorphRange);
  308. outModel->SetIndexBuffers(ibVector);
  309. outModel->SetBoundingBox(box);
  310. // Build skeleton if necessary
  311. if (model.bones_.Size() && model.rootBone_)
  312. {
  313. //PrintLine("Writing skeleton with " + String(model.bones_.Size()) + " bones, rootbone " +
  314. // FromAIString(model.rootBone_->mName));
  315. Skeleton skeleton;
  316. Vector<Bone>& bones = skeleton.GetModifiableBones();
  317. for (unsigned i = 0; i < model.bones_.Size(); ++i)
  318. {
  319. aiNode* boneNode = model.bones_[i];
  320. String boneName(FromAIString(boneNode->mName));
  321. Bone newBone;
  322. newBone.name_ = boneName;
  323. aiMatrix4x4 transform = boneNode->mTransformation;
  324. // Make the root bone transform relative to the model's root node, if it is not already
  325. if (boneNode == model.rootBone_)
  326. transform = GetDerivedTransform(boneNode, model.rootNode_);
  327. GetPosRotScale(transform, newBone.initialPosition_, newBone.initialRotation_, newBone.initialScale_);
  328. // Get offset information if exists
  329. newBone.offsetMatrix_ = GetOffsetMatrix(model, boneName);
  330. newBone.radius_ = model.boneRadii_[i];
  331. newBone.boundingBox_ = model.boneHitboxes_[i];
  332. newBone.collisionMask_ = BONECOLLISION_SPHERE | BONECOLLISION_BOX;
  333. newBone.parentIndex_ = i;
  334. bones.Push(newBone);
  335. }
  336. // Set the bone hierarchy
  337. for (unsigned i = 1; i < model.bones_.Size(); ++i)
  338. {
  339. String parentName = FromAIString(model.bones_[i]->mParent->mName);
  340. for (unsigned j = 0; j < bones.Size(); ++j)
  341. {
  342. if (bones[j].name_ == parentName)
  343. {
  344. bones[i].parentIndex_ = j;
  345. break;
  346. }
  347. }
  348. }
  349. outModel->SetSkeleton(skeleton);
  350. if (model.bones_.Size() > maxBones_)
  351. outModel->SetGeometryBoneMappings(allBoneMappings);
  352. }
  353. File outFile(context_);
  354. if (!outFile.Open(model.outName_, FILE_WRITE))
  355. ErrorExit("Could not open output file " + model.outName_);
  356. outModel->Save(outFile);
  357. // If exporting materials, also save material list for use by the editor
  358. if (!noMaterials_ && saveMaterialList_)
  359. {
  360. String materialListName = ReplaceExtension(model.outName_, ".txt");
  361. File listFile(context_);
  362. if (listFile.Open(materialListName, FILE_WRITE))
  363. {
  364. for (unsigned i = 0; i < model.meshes_.Size(); ++i)
  365. listFile.WriteLine(GetMeshMaterialName(model.meshes_[i]));
  366. }
  367. else
  368. {
  369. PrintLine("Warning: could not write material list file " + materialListName);
  370. }
  371. }
  372. }
  373. String OpenAssetImporter::GetMeshMaterialName(aiMesh* mesh)
  374. {
  375. aiMaterial* material = scene_->mMaterials[mesh->mMaterialIndex];
  376. aiString matNameStr;
  377. material->Get(AI_MATKEY_NAME, matNameStr);
  378. String matName = SanitateAssetName(FromAIString(matNameStr));
  379. if (matName.Trimmed().Empty())
  380. matName = GenerateMaterialName(material);
  381. return (useSubdirs_ ? "Materials/" : "") + matName + ".material";
  382. }
  383. String OpenAssetImporter::GenerateMaterialName(aiMaterial* material)
  384. {
  385. for (unsigned i = 0; i < scene_->mNumMaterials; ++i)
  386. {
  387. if (scene_->mMaterials[i] == material)
  388. return inputName_ + "_Material" + String(i);
  389. }
  390. // Should not go here
  391. return String::EMPTY;
  392. }
  393. String OpenAssetImporter::GetMaterialTextureName(const String& nameIn)
  394. {
  395. // Detect assimp embedded texture
  396. if (nameIn.Length() && nameIn[0] == '*')
  397. return GenerateTextureName(ToInt(nameIn.Substring(1)));
  398. else
  399. return (useSubdirs_ ? "Textures/" : "") + nameIn;
  400. }
  401. String OpenAssetImporter::GenerateTextureName(unsigned texIndex)
  402. {
  403. if (texIndex < scene_->mNumTextures)
  404. {
  405. // If embedded texture contains encoded data, use the format hint for file extension. Else save RGBA8 data as PNG
  406. aiTexture* tex = scene_->mTextures[texIndex];
  407. if (!tex->mHeight)
  408. return (useSubdirs_ ? "Textures/" : "") + inputName_ + "_Texture" + String(texIndex) + "." + tex->achFormatHint;
  409. else
  410. return (useSubdirs_ ? "Textures/" : "") + inputName_ + "_Texture" + String(texIndex) + ".png";
  411. }
  412. // Should not go here
  413. return String::EMPTY;
  414. }
  415. void OpenAssetImporter::CollectSceneModels(OutScene& scene, aiNode* node)
  416. {
  417. Vector<Pair<aiNode*, aiMesh*> > meshes;
  418. GetMeshesUnderNode(scene_, meshes, node);
  419. if (meshes.Size())
  420. {
  421. OutModel model;
  422. model.rootNode_ = node;
  423. model.outName_ = resourcePath_ + (useSubdirs_ ? "Models/" : "") + SanitateAssetName(FromAIString(node->mName)) + ".mdl";
  424. for (unsigned i = 0; i < meshes.Size(); ++i)
  425. {
  426. aiMesh* mesh = meshes[i].second_;
  427. unsigned meshIndex = GetMeshIndex(scene_, mesh);
  428. model.meshIndices_.Insert(meshIndex);
  429. model.meshes_.Push(mesh);
  430. model.meshNodes_.Push(meshes[i].first_);
  431. model.totalVertices_ += mesh->mNumVertices;
  432. model.totalIndices_ += GetNumValidFaces(mesh) * 3;
  433. }
  434. // Check if a model with identical mesh indices already exists. If yes, do not export twice
  435. bool unique = true;
  436. if (checkUniqueModel_)
  437. {
  438. for (unsigned i = 0; i < scene.models_.Size(); ++i)
  439. {
  440. if (scene.models_[i].meshIndices_ == model.meshIndices_)
  441. {
  442. //PrintLine("Added node " + FromAIString(node->mName));
  443. scene.nodes_.Push(node);
  444. scene.nodeModelIndices_.Push(i);
  445. unique = false;
  446. break;
  447. }
  448. }
  449. }
  450. if (unique)
  451. {
  452. // PrintLine("Added model " + model.outName_);
  453. // PrintLine("Added node " + FromAIString(node->mName));
  454. CollectBones(model);
  455. BuildBoneCollisionInfo(model);
  456. if (!noAnimations_)
  457. {
  458. CollectAnimations(&model);
  459. BuildAndSaveAnimations(&model);
  460. }
  461. scene.models_.Push(model);
  462. scene.nodes_.Push(node);
  463. scene.nodeModelIndices_.Push(scene.models_.Size() - 1);
  464. }
  465. }
  466. for (unsigned i = 0; i < node->mNumChildren; ++i)
  467. CollectSceneModels(scene, node->mChildren[i]);
  468. }
  469. void OpenAssetImporter::CollectBones(OutModel& model, bool animationOnly)
  470. {
  471. HashSet<aiNode*> necessary;
  472. HashSet<aiNode*> rootNodes;
  473. for (unsigned i = 0; i < model.meshes_.Size(); ++i)
  474. {
  475. aiMesh* mesh = model.meshes_[i];
  476. aiNode* meshNode = model.meshNodes_[i];
  477. aiNode* meshParentNode = meshNode->mParent;
  478. aiNode* rootNode = 0;
  479. for (unsigned j = 0; j < mesh->mNumBones; ++j)
  480. {
  481. aiBone* bone = mesh->mBones[j];
  482. String boneName(FromAIString(bone->mName));
  483. aiNode* boneNode = GetNode(boneName, scene_->mRootNode, true);
  484. if (!boneNode)
  485. ErrorExit("Could not find scene node for bone " + boneName);
  486. necessary.Insert(boneNode);
  487. rootNode = boneNode;
  488. for (;;)
  489. {
  490. boneNode = boneNode->mParent;
  491. if (!boneNode || ((boneNode == meshNode || boneNode == meshParentNode) && !animationOnly))
  492. break;
  493. rootNode = boneNode;
  494. necessary.Insert(boneNode);
  495. }
  496. if (rootNodes.Find(rootNode) == rootNodes.End())
  497. rootNodes.Insert(rootNode);
  498. }
  499. }
  500. // If we find multiple root nodes, try to remedy by using their parent instead
  501. if (rootNodes.Size() > 1)
  502. {
  503. aiNode* commonParent = (*rootNodes.Begin())->mParent;
  504. for (HashSet<aiNode*>::Iterator i = rootNodes.Begin(); i != rootNodes.End(); ++i)
  505. {
  506. if (*i != commonParent)
  507. {
  508. if (!commonParent || (*i)->mParent != commonParent)
  509. ErrorExit("Skeleton with multiple root nodes found, not supported");
  510. }
  511. }
  512. rootNodes.Clear();
  513. rootNodes.Insert(commonParent);
  514. necessary.Insert(commonParent);
  515. }
  516. if (rootNodes.Empty())
  517. return;
  518. model.rootBone_ = *rootNodes.Begin();
  519. CollectBonesFinal(model.bones_, necessary, model.rootBone_);
  520. // Initialize the bone collision info
  521. model.boneRadii_.Resize(model.bones_.Size());
  522. model.boneHitboxes_.Resize(model.bones_.Size());
  523. for (unsigned i = 0; i < model.bones_.Size(); ++i)
  524. {
  525. model.boneRadii_[i] = 0.0f;
  526. model.boneHitboxes_[i] = BoundingBox(0.0f, 0.0f);
  527. }
  528. }
  529. void OpenAssetImporter::CollectBonesFinal(PODVector<aiNode*>& dest, const HashSet<aiNode*>& necessary, aiNode* node)
  530. {
  531. bool includeBone = necessary.Find(node) != necessary.End();
  532. String boneName = FromAIString(node->mName);
  533. // Check include/exclude filters for non-skinned bones
  534. if (!includeBone && includeNonSkinningBones_)
  535. {
  536. // If no includes specified, include by default but check for excludes
  537. if (nonSkinningBoneIncludes_.Empty())
  538. includeBone = true;
  539. // Check against includes/excludes
  540. for (unsigned i = 0; i < nonSkinningBoneIncludes_.Size(); ++i)
  541. {
  542. if (boneName.Contains(nonSkinningBoneIncludes_[i], false))
  543. {
  544. includeBone = true;
  545. break;
  546. }
  547. }
  548. for (unsigned i = 0; i < nonSkinningBoneExcludes_.Size(); ++i)
  549. {
  550. if (boneName.Contains(nonSkinningBoneExcludes_[i], false))
  551. {
  552. includeBone = false;
  553. break;
  554. }
  555. }
  556. if (includeBone)
  557. {
  558. //PrintLine("Including non-skinning bone " + boneName);
  559. }
  560. }
  561. if (includeBone)
  562. dest.Push(node);
  563. for (unsigned i = 0; i < node->mNumChildren; ++i)
  564. CollectBonesFinal(dest, necessary, node->mChildren[i]);
  565. }
  566. void OpenAssetImporter::CollectAnimations(OutModel* model)
  567. {
  568. const aiScene* scene = scene_;
  569. for (unsigned i = 0; i < scene->mNumAnimations; ++i)
  570. {
  571. aiAnimation* anim = scene->mAnimations[i];
  572. if (allAnimations_.Contains(anim))
  573. continue;
  574. if (model)
  575. {
  576. bool modelBoneFound = false;
  577. for (unsigned j = 0; j < anim->mNumChannels; ++j)
  578. {
  579. aiNodeAnim* channel = anim->mChannels[j];
  580. String channelName = FromAIString(channel->mNodeName);
  581. if (GetBoneIndex(*model, channelName) != M_MAX_UNSIGNED)
  582. {
  583. modelBoneFound = true;
  584. break;
  585. }
  586. }
  587. if (modelBoneFound)
  588. {
  589. model->animations_.Push(anim);
  590. allAnimations_.Insert(anim);
  591. }
  592. }
  593. else
  594. {
  595. sceneAnimations_.Push(anim);
  596. allAnimations_.Insert(anim);
  597. }
  598. }
  599. /// \todo Vertex morphs are ignored for now
  600. }
  601. void OpenAssetImporter::BuildBoneCollisionInfo(OutModel& model)
  602. {
  603. for (unsigned i = 0; i < model.meshes_.Size(); ++i)
  604. {
  605. aiMesh* mesh = model.meshes_[i];
  606. for (unsigned j = 0; j < mesh->mNumBones; ++j)
  607. {
  608. aiBone* bone = mesh->mBones[j];
  609. String boneName = FromAIString(bone->mName);
  610. unsigned boneIndex = GetBoneIndex(model, boneName);
  611. if (boneIndex == M_MAX_UNSIGNED)
  612. continue;
  613. for (unsigned k = 0; k < bone->mNumWeights; ++k)
  614. {
  615. float weight = bone->mWeights[k].mWeight;
  616. // Require skinning weight to be sufficiently large before vertex contributes to bone hitbox
  617. if (weight > 0.33f)
  618. {
  619. aiVector3D vertexBoneSpace = bone->mOffsetMatrix * mesh->mVertices[bone->mWeights[k].mVertexId];
  620. Vector3 vertex = ToVector3(vertexBoneSpace);
  621. float radius = vertex.Length();
  622. if (radius > model.boneRadii_[boneIndex])
  623. model.boneRadii_[boneIndex] = radius;
  624. model.boneHitboxes_[boneIndex].Merge(vertex);
  625. }
  626. }
  627. }
  628. }
  629. }
  630. void OpenAssetImporter::BuildAndSaveAnimations(OutModel* model)
  631. {
  632. const PODVector<aiAnimation*>& animations = model ? model->animations_ : sceneAnimations_;
  633. for (unsigned i = 0; i < animations.Size(); ++i)
  634. {
  635. aiAnimation* anim = animations[i];
  636. float duration = (float)anim->mDuration;
  637. String animName = FromAIString(anim->mName);
  638. String animOutName;
  639. if (animName.Empty())
  640. animName = "Anim" + String(i + 1);
  641. if (model)
  642. animOutName = GetPath(model->outName_) + GetFileName(model->outName_) + "_" + SanitateAssetName(animName) + ".ani";
  643. else
  644. animOutName = outPath_ + SanitateAssetName(animName) + ".ani";
  645. float ticksPerSecond = (float)anim->mTicksPerSecond;
  646. // If ticks per second not specified, it's probably a .X file. In this case use the default tick rate
  647. if (ticksPerSecond < M_EPSILON)
  648. ticksPerSecond = defaultTicksPerSecond_;
  649. float tickConversion = 1.0f / ticksPerSecond;
  650. // Find out the start time of animation from each channel's first keyframe for adjusting the keyframe times
  651. // to start from zero
  652. float startTime = duration;
  653. for (unsigned j = 0; j < anim->mNumChannels; ++j)
  654. {
  655. aiNodeAnim* channel = anim->mChannels[j];
  656. if (channel->mNumPositionKeys > 0)
  657. startTime = Min(startTime, (float)channel->mPositionKeys[0].mTime);
  658. if (channel->mNumRotationKeys > 0)
  659. startTime = Min(startTime, (float)channel->mRotationKeys[0].mTime);
  660. if (channel->mScalingKeys > 0)
  661. startTime = Min(startTime, (float)channel->mScalingKeys[0].mTime);
  662. }
  663. duration -= startTime;
  664. SharedPtr<Animation> outAnim(new Animation(context_));
  665. outAnim->SetAnimationName(animName);
  666. outAnim->SetLength(duration * tickConversion);
  667. //PrintLine("Writing animation " + animName + " length " + String(outAnim->GetLength()));
  668. Vector<AnimationTrack> tracks;
  669. for (unsigned j = 0; j < anim->mNumChannels; ++j)
  670. {
  671. aiNodeAnim* channel = anim->mChannels[j];
  672. String channelName = FromAIString(channel->mNodeName);
  673. aiNode* boneNode = 0;
  674. bool isRootBone = false;
  675. if (model)
  676. {
  677. unsigned boneIndex = GetBoneIndex(*model, channelName);
  678. if (boneIndex == M_MAX_UNSIGNED)
  679. {
  680. PrintLine("Warning: skipping animation track " + channelName + " not found in model skeleton");
  681. continue;
  682. }
  683. boneNode = model->bones_[boneIndex];
  684. isRootBone = boneIndex == 0;
  685. }
  686. else
  687. {
  688. boneNode = GetNode(channelName, scene_->mRootNode);
  689. if (!boneNode)
  690. {
  691. PrintLine("Warning: skipping animation track " + channelName + " whose scene node was not found");
  692. continue;
  693. }
  694. }
  695. // To export single frame animation, check if first key frame is identical to bone transformation
  696. aiVector3D bonePos, boneScale;
  697. aiQuaternion boneRot;
  698. boneNode->mTransformation.Decompose(boneScale, boneRot, bonePos);
  699. bool posEqual = true;
  700. bool scaleEqual = true;
  701. bool rotEqual = true;
  702. if (channel->mNumPositionKeys > 0 && !ToVector3(bonePos).Equals(ToVector3(channel->mPositionKeys[0].mValue)))
  703. posEqual = false;
  704. if (channel->mNumScalingKeys > 0 && !ToVector3(boneScale).Equals(ToVector3(channel->mScalingKeys[0].mValue)))
  705. scaleEqual = false;
  706. if (channel->mNumRotationKeys > 0 && !ToQuaternion(boneRot).Equals(ToQuaternion(channel->mRotationKeys[0].mValue)))
  707. rotEqual = false;
  708. AnimationTrack track;
  709. track.name_ = channelName;
  710. track.nameHash_ = channelName;
  711. // Check which channels are used
  712. track.channelMask_ = 0;
  713. if (channel->mNumPositionKeys > 1 || !posEqual)
  714. track.channelMask_ |= CHANNEL_POSITION;
  715. if (channel->mNumRotationKeys > 1 || !rotEqual)
  716. track.channelMask_ |= CHANNEL_ROTATION;
  717. if (channel->mNumScalingKeys > 1 || !scaleEqual)
  718. track.channelMask_ |= CHANNEL_SCALE;
  719. // Check for redundant identity scale in all keyframes and remove in that case
  720. if (track.channelMask_ & CHANNEL_SCALE)
  721. {
  722. bool redundantScale = true;
  723. for (unsigned k = 0; k < channel->mNumScalingKeys; ++k)
  724. {
  725. float SCALE_EPSILON = 0.000001f;
  726. Vector3 scaleVec = ToVector3(channel->mScalingKeys[k].mValue);
  727. if (fabsf(scaleVec.x_ - 1.0f) >= SCALE_EPSILON || fabsf(scaleVec.y_ - 1.0f) >= SCALE_EPSILON ||
  728. fabsf(scaleVec.z_ - 1.0f) >= SCALE_EPSILON)
  729. {
  730. redundantScale = false;
  731. break;
  732. }
  733. }
  734. if (redundantScale)
  735. track.channelMask_ &= ~CHANNEL_SCALE;
  736. }
  737. if (!track.channelMask_)
  738. PrintLine("Warning: skipping animation track " + channelName + " with no keyframes");
  739. // Currently only same amount of keyframes is supported
  740. // Note: should also check the times of individual keyframes for match
  741. if ((channel->mNumPositionKeys > 1 && channel->mNumRotationKeys > 1 && channel->mNumPositionKeys != channel->mNumRotationKeys) ||
  742. (channel->mNumPositionKeys > 1 && channel->mNumScalingKeys > 1 && channel->mNumPositionKeys != channel->mNumScalingKeys) ||
  743. (channel->mNumRotationKeys > 1 && channel->mNumScalingKeys > 1 && channel->mNumRotationKeys != channel->mNumScalingKeys))
  744. {
  745. PrintLine("Warning: differing amounts of channel keyframes, skipping animation track " + channelName);
  746. continue;
  747. }
  748. unsigned keyFrames = channel->mNumPositionKeys;
  749. if (channel->mNumRotationKeys > keyFrames)
  750. keyFrames = channel->mNumRotationKeys;
  751. if (channel->mNumScalingKeys > keyFrames)
  752. keyFrames = channel->mNumScalingKeys;
  753. for (unsigned k = 0; k < keyFrames; ++k)
  754. {
  755. AnimationKeyFrame kf;
  756. kf.time_ = 0.0f;
  757. kf.position_ = Vector3::ZERO;
  758. kf.rotation_ = Quaternion::IDENTITY;
  759. kf.scale_ = Vector3::ONE;
  760. // Get time for the keyframe. Adjust with animation's start time
  761. if (track.channelMask_ & CHANNEL_POSITION && k < channel->mNumPositionKeys)
  762. kf.time_ = ((float)channel->mPositionKeys[k].mTime - startTime) * tickConversion;
  763. else if (track.channelMask_ & CHANNEL_ROTATION && k < channel->mNumRotationKeys)
  764. kf.time_ = ((float)channel->mRotationKeys[k].mTime - startTime) * tickConversion;
  765. else if (track.channelMask_ & CHANNEL_SCALE && k < channel->mNumScalingKeys)
  766. kf.time_ = ((float)channel->mScalingKeys[k].mTime - startTime) * tickConversion;
  767. // Make sure time stays positive
  768. kf.time_ = Max(kf.time_, 0.0f);
  769. // Start with the bone's base transform
  770. aiMatrix4x4 boneTransform = boneNode->mTransformation;
  771. aiVector3D pos, scale;
  772. aiQuaternion rot;
  773. boneTransform.Decompose(scale, rot, pos);
  774. // Then apply the active channels
  775. if (track.channelMask_ & CHANNEL_POSITION && k < channel->mNumPositionKeys)
  776. pos = channel->mPositionKeys[k].mValue;
  777. if (track.channelMask_ & CHANNEL_ROTATION && k < channel->mNumRotationKeys)
  778. rot = channel->mRotationKeys[k].mValue;
  779. if (track.channelMask_ & CHANNEL_SCALE && k < channel->mNumScalingKeys)
  780. scale = channel->mScalingKeys[k].mValue;
  781. // If root bone, transform with the model root node transform
  782. if (model && isRootBone)
  783. {
  784. aiMatrix4x4 transMat, scaleMat, rotMat;
  785. aiMatrix4x4::Translation(pos, transMat);
  786. aiMatrix4x4::Scaling(scale, scaleMat);
  787. rotMat = aiMatrix4x4(rot.GetMatrix());
  788. aiMatrix4x4 tform = transMat * rotMat * scaleMat;
  789. tform = GetDerivedTransform(tform, boneNode, model->rootNode_);
  790. tform.Decompose(scale, rot, pos);
  791. }
  792. if (track.channelMask_ & CHANNEL_POSITION)
  793. kf.position_ = ToVector3(pos);
  794. if (track.channelMask_ & CHANNEL_ROTATION)
  795. kf.rotation_ = ToQuaternion(rot);
  796. if (track.channelMask_ & CHANNEL_SCALE)
  797. kf.scale_ = ToVector3(scale);
  798. track.keyFrames_.Push(kf);
  799. }
  800. tracks.Push(track);
  801. }
  802. outAnim->SetTracks(tracks);
  803. File outFile(context_);
  804. if (!outFile.Open(animOutName, FILE_WRITE))
  805. ErrorExit("Could not open output file " + animOutName);
  806. outAnim->Save(outFile);
  807. }
  808. }
  809. // Materials
  810. void OpenAssetImporter::ExportMaterials(HashSet<String>& usedTextures)
  811. {
  812. if (useSubdirs_)
  813. {
  814. context_->GetSubsystem<FileSystem>()->CreateDir(sourceAssetPath_ + "Materials");
  815. }
  816. for (unsigned i = 0; i < scene_->mNumMaterials; ++i)
  817. BuildAndSaveMaterial(scene_->mMaterials[i], usedTextures);
  818. }
  819. void OpenAssetImporter::BuildAndSaveMaterial(aiMaterial* material, HashSet<String>& usedTextures)
  820. {
  821. aiString matNameStr;
  822. material->Get(AI_MATKEY_NAME, matNameStr);
  823. String matName = SanitateAssetName(FromAIString(matNameStr));
  824. if (matName.Trimmed().Empty())
  825. matName = GenerateMaterialName(material);
  826. // Do not actually create a material instance, but instead craft an xml file manually
  827. XMLFile outMaterial(context_);
  828. XMLElement materialElem = outMaterial.CreateRoot("material");
  829. String diffuseTexName;
  830. String normalTexName;
  831. String specularTexName;
  832. String lightmapTexName;
  833. String emissiveTexName;
  834. Color diffuseColor = Color::WHITE;
  835. Color specularColor;
  836. Color emissiveColor = Color::BLACK;
  837. bool hasAlpha = false;
  838. bool twoSided = false;
  839. float specPower = 1.0f;
  840. aiString stringVal;
  841. float floatVal;
  842. int intVal;
  843. aiColor3D colorVal;
  844. if (material->Get(AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0), stringVal) == AI_SUCCESS)
  845. diffuseTexName = GetFileNameAndExtension(FromAIString(stringVal));
  846. if (material->Get(AI_MATKEY_TEXTURE(aiTextureType_NORMALS, 0), stringVal) == AI_SUCCESS)
  847. normalTexName = GetFileNameAndExtension(FromAIString(stringVal));
  848. if (material->Get(AI_MATKEY_TEXTURE(aiTextureType_SPECULAR, 0), stringVal) == AI_SUCCESS)
  849. specularTexName = GetFileNameAndExtension(FromAIString(stringVal));
  850. if (material->Get(AI_MATKEY_TEXTURE(aiTextureType_LIGHTMAP, 0), stringVal) == AI_SUCCESS)
  851. specularTexName = GetFileNameAndExtension(FromAIString(stringVal));
  852. if (material->Get(AI_MATKEY_TEXTURE(aiTextureType_EMISSIVE, 0), stringVal) == AI_SUCCESS)
  853. emissiveTexName = GetFileNameAndExtension(FromAIString(stringVal));
  854. diffuseTexName.Replace(".tif", ".png");
  855. if (!noMaterialDiffuseColor_)
  856. {
  857. if (material->Get(AI_MATKEY_COLOR_DIFFUSE, colorVal) == AI_SUCCESS)
  858. diffuseColor = Color(colorVal.r, colorVal.g, colorVal.b);
  859. }
  860. if (material->Get(AI_MATKEY_COLOR_SPECULAR, colorVal) == AI_SUCCESS)
  861. specularColor = Color(colorVal.r, colorVal.g, colorVal.b);
  862. if (!emissiveAO_)
  863. {
  864. // if (material->Get(AI_MATKEY_COLOR_EMISSIVE, colorVal) == AI_SUCCESS)
  865. // emissiveColor = Color(colorVal.r, colorVal.g, colorVal.b);
  866. }
  867. if (material->Get(AI_MATKEY_OPACITY, floatVal) == AI_SUCCESS)
  868. {
  869. if (floatVal < 1.0f)
  870. hasAlpha = true;
  871. diffuseColor.a_ = floatVal;
  872. }
  873. if (material->Get(AI_MATKEY_SHININESS, floatVal) == AI_SUCCESS)
  874. specPower = floatVal;
  875. if (material->Get(AI_MATKEY_TWOSIDED, intVal) == AI_SUCCESS)
  876. twoSided = (intVal != 0);
  877. String techniqueName = "Techniques/NoTexture";
  878. if (!diffuseTexName.Empty())
  879. {
  880. techniqueName = "Techniques/Diff";
  881. if (!normalTexName.Empty())
  882. techniqueName += "Normal";
  883. if (!specularTexName.Empty())
  884. techniqueName += "Spec";
  885. // For now lightmap does not coexist with normal & specular
  886. if (normalTexName.Empty() && specularTexName.Empty() && !lightmapTexName.Empty())
  887. techniqueName += "LightMap";
  888. if (lightmapTexName.Empty() && !emissiveTexName.Empty())
  889. techniqueName += emissiveAO_ ? "AO" : "Emissive";
  890. }
  891. if (hasAlpha)
  892. techniqueName += "Alpha";
  893. XMLElement techniqueElem = materialElem.CreateChild("technique");
  894. techniqueElem.SetString("name", techniqueName + ".xml");
  895. if (!diffuseTexName.Empty())
  896. {
  897. XMLElement diffuseElem = materialElem.CreateChild("texture");
  898. diffuseElem.SetString("unit", "diffuse");
  899. diffuseElem.SetString("name", GetMaterialTextureName(diffuseTexName));
  900. usedTextures.Insert(diffuseTexName);
  901. }
  902. if (!normalTexName.Empty())
  903. {
  904. XMLElement normalElem = materialElem.CreateChild("texture");
  905. normalElem.SetString("unit", "normal");
  906. normalElem.SetString("name", GetMaterialTextureName(normalTexName));
  907. usedTextures.Insert(normalTexName);
  908. }
  909. if (!specularTexName.Empty())
  910. {
  911. XMLElement specularElem = materialElem.CreateChild("texture");
  912. specularElem.SetString("unit", "specular");
  913. specularElem.SetString("name", GetMaterialTextureName(specularTexName));
  914. usedTextures.Insert(specularTexName);
  915. }
  916. if (!lightmapTexName.Empty())
  917. {
  918. XMLElement lightmapElem = materialElem.CreateChild("texture");
  919. lightmapElem.SetString("unit", "emissive");
  920. lightmapElem.SetString("name", GetMaterialTextureName(lightmapTexName));
  921. usedTextures.Insert(lightmapTexName);
  922. }
  923. if (!emissiveTexName.Empty())
  924. {
  925. XMLElement emissiveElem = materialElem.CreateChild("texture");
  926. emissiveElem.SetString("unit", "emissive");
  927. emissiveElem.SetString("name", GetMaterialTextureName(emissiveTexName));
  928. usedTextures.Insert(emissiveTexName);
  929. }
  930. XMLElement diffuseColorElem = materialElem.CreateChild("parameter");
  931. diffuseColorElem.SetString("name", "MatDiffColor");
  932. diffuseColorElem.SetColor("value", diffuseColor);
  933. XMLElement specularElem = materialElem.CreateChild("parameter");
  934. specularElem.SetString("name", "MatSpecColor");
  935. specularElem.SetVector4("value", Vector4(specularColor.r_, specularColor.g_, specularColor.b_, specPower));
  936. XMLElement emissiveColorElem = materialElem.CreateChild("parameter");
  937. emissiveColorElem.SetString("name", "MatEmissiveColor");
  938. emissiveColorElem.SetColor("value", emissiveColor);
  939. if (twoSided)
  940. {
  941. XMLElement cullElem = materialElem.CreateChild("cull");
  942. XMLElement shadowCullElem = materialElem.CreateChild("shadowcull");
  943. cullElem.SetString("value", "none");
  944. shadowCullElem.SetString("value", "none");
  945. }
  946. FileSystem* fileSystem = context_->GetSubsystem<FileSystem>();
  947. String outFileName = sourceAssetPath_ + (useSubdirs_ ? "Materials/" : "" ) + matName + ".material";
  948. if (noOverwriteMaterial_ && fileSystem->FileExists(outFileName))
  949. {
  950. PrintLine("Skipping save of existing material " + matName);
  951. return;
  952. }
  953. PrintLine("Writing material " + matName);
  954. File outFile(context_);
  955. if (!outFile.Open(outFileName, FILE_WRITE))
  956. ErrorExit("Could not open output file " + outFileName);
  957. outMaterial.Save(outFile);
  958. }
  959. void OpenAssetImporter::DumpNodes(aiNode* rootNode, unsigned level)
  960. {
  961. if (!rootNode)
  962. return;
  963. String indent(' ', level * 2);
  964. Vector3 pos, scale;
  965. Quaternion rot;
  966. aiMatrix4x4 transform = GetDerivedTransform(rootNode, rootNode_);
  967. GetPosRotScale(transform, pos, rot, scale);
  968. PrintLine(indent + "Node " + FromAIString(rootNode->mName) + " pos " + String(pos));
  969. if (rootNode->mNumMeshes == 1)
  970. PrintLine(indent + " " + String(rootNode->mNumMeshes) + " geometry");
  971. if (rootNode->mNumMeshes > 1)
  972. PrintLine(indent + " " + String(rootNode->mNumMeshes) + " geometries");
  973. for (unsigned i = 0; i < rootNode->mNumChildren; ++i)
  974. DumpNodes(rootNode->mChildren[i], level + 1);
  975. }
  976. }