OpenAssetImporter.cpp 41 KB

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