assimpShapeLoader.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  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
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell 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
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. /*
  23. Resource stream -> Buffer
  24. Buffer -> Collada DOM
  25. Collada DOM -> TSShapeLoader
  26. TSShapeLoader installed into TSShape
  27. */
  28. //-----------------------------------------------------------------------------
  29. #include "platform/platform.h"
  30. #include "ts/assimp/assimpShapeLoader.h"
  31. #include "ts/assimp/assimpAppNode.h"
  32. #include "ts/assimp/assimpAppMesh.h"
  33. #include "ts/assimp/assimpAppMaterial.h"
  34. #include "ts/assimp/assimpAppSequence.h"
  35. #include "core/util/tVector.h"
  36. #include "core/strings/findMatch.h"
  37. #include "core/strings/stringUnit.h"
  38. #include "core/stream/fileStream.h"
  39. #include "core/fileObject.h"
  40. #include "ts/tsShape.h"
  41. #include "ts/tsShapeInstance.h"
  42. #include "materials/materialManager.h"
  43. #include "console/persistenceManager.h"
  44. #include "ts/tsShapeConstruct.h"
  45. #include "core/util/zip/zipVolume.h"
  46. #include "gfx/bitmap/gBitmap.h"
  47. #include "gui/controls/guiTreeViewCtrl.h"
  48. #if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
  49. #ifdef new
  50. #undef new
  51. #endif
  52. #endif
  53. // assimp include files.
  54. #include <assimp/cimport.h>
  55. #include <assimp/scene.h>
  56. #include <assimp/postprocess.h>
  57. #include <assimp/types.h>
  58. #include <assimp/config.h>
  59. #include <exception>
  60. #if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
  61. # define _new new(__FILE__, __LINE__)
  62. # define new _new
  63. #endif
  64. MODULE_BEGIN( AssimpShapeLoader )
  65. MODULE_INIT_AFTER( ShapeLoader )
  66. MODULE_INIT
  67. {
  68. TSShapeLoader::addFormat("DirectX X", "x");
  69. TSShapeLoader::addFormat("Autodesk FBX", "fbx");
  70. TSShapeLoader::addFormat("Blender 3D", "blend" );
  71. TSShapeLoader::addFormat("3ds Max 3DS", "3ds");
  72. TSShapeLoader::addFormat("3ds Max ASE", "ase");
  73. TSShapeLoader::addFormat("Wavefront Object", "obj");
  74. TSShapeLoader::addFormat("Industry Foundation Classes (IFC/Step)", "ifc");
  75. TSShapeLoader::addFormat("Stanford Polygon Library", "ply");
  76. TSShapeLoader::addFormat("AutoCAD DXF", "dxf");
  77. TSShapeLoader::addFormat("LightWave", "lwo");
  78. TSShapeLoader::addFormat("LightWave Scene", "lws");
  79. TSShapeLoader::addFormat("Modo", "lxo");
  80. TSShapeLoader::addFormat("Stereolithography", "stl");
  81. TSShapeLoader::addFormat("AC3D", "ac");
  82. TSShapeLoader::addFormat("Milkshape 3D", "ms3d");
  83. TSShapeLoader::addFormat("TrueSpace COB", "cob");
  84. TSShapeLoader::addFormat("TrueSpace SCN", "scn");
  85. TSShapeLoader::addFormat("Ogre XML", "xml");
  86. TSShapeLoader::addFormat("Irrlicht Mesh", "irrmesh");
  87. TSShapeLoader::addFormat("Irrlicht Scene", "irr");
  88. TSShapeLoader::addFormat("Quake I", "mdl" );
  89. TSShapeLoader::addFormat("Quake II", "md2" );
  90. TSShapeLoader::addFormat("Quake III Mesh", "md3");
  91. TSShapeLoader::addFormat("Quake III Map/BSP", "pk3");
  92. TSShapeLoader::addFormat("Return to Castle Wolfenstein", "mdc");
  93. TSShapeLoader::addFormat("Doom 3", "md5" );
  94. TSShapeLoader::addFormat("Valve SMD", "smd");
  95. TSShapeLoader::addFormat("Valve VTA", "vta");
  96. TSShapeLoader::addFormat("Starcraft II M3", "m3");
  97. TSShapeLoader::addFormat("Unreal", "3d");
  98. TSShapeLoader::addFormat("BlitzBasic 3D", "b3d" );
  99. TSShapeLoader::addFormat("Quick3D Q3D", "q3d");
  100. TSShapeLoader::addFormat("Quick3D Q3S", "q3s");
  101. TSShapeLoader::addFormat("Neutral File Format", "nff");
  102. TSShapeLoader::addFormat("Object File Format", "off");
  103. TSShapeLoader::addFormat("PovRAY Raw", "raw");
  104. TSShapeLoader::addFormat("Terragen Terrain", "ter");
  105. TSShapeLoader::addFormat("3D GameStudio (3DGS)", "mdl");
  106. TSShapeLoader::addFormat("3D GameStudio (3DGS) Terrain", "hmp");
  107. TSShapeLoader::addFormat("Izware Nendo", "ndo");
  108. TSShapeLoader::addFormat("gltf", "gltf");
  109. TSShapeLoader::addFormat("gltf binary", "glb");
  110. }
  111. MODULE_END;
  112. //-----------------------------------------------------------------------------
  113. AssimpShapeLoader::AssimpShapeLoader()
  114. {
  115. mScene = NULL;
  116. }
  117. AssimpShapeLoader::~AssimpShapeLoader()
  118. {
  119. }
  120. void AssimpShapeLoader::releaseImport()
  121. {
  122. }
  123. void applyTransformation(aiNode* node, const aiMatrix4x4& transform) {
  124. node->mTransformation = transform * node->mTransformation; // Apply transformation to the node
  125. }
  126. void scaleScene(const aiScene* scene, F32 scaleFactor) {
  127. aiMatrix4x4 scaleMatrix;
  128. scaleMatrix = aiMatrix4x4::Scaling(aiVector3D(scaleFactor, scaleFactor, scaleFactor), scaleMatrix);
  129. applyTransformation(scene->mRootNode, scaleMatrix);
  130. }
  131. void debugSceneMetaData(const aiScene* scene) {
  132. if (!scene->mMetaData) {
  133. Con::printf("[ASSIMP] No metadata available.");
  134. return;
  135. }
  136. for (U32 i = 0; i < scene->mMetaData->mNumProperties; ++i) {
  137. const char* key = scene->mMetaData->mKeys[i].C_Str();
  138. aiMetadataType type = scene->mMetaData->mValues[i].mType;
  139. Con::printf("[ASSIMP] Metadata key: %s", key);
  140. switch (type) {
  141. case AI_BOOL:
  142. Con::printf(" Value: %d (bool)", *(bool*)scene->mMetaData->mValues[i].mData);
  143. break;
  144. case AI_INT32:
  145. Con::printf(" Value: %d (int)", *(S32*)scene->mMetaData->mValues[i].mData);
  146. break;
  147. case AI_UINT64:
  148. Con::printf(" Value: %llu (uint64)", *(U64*)scene->mMetaData->mValues[i].mData);
  149. break;
  150. case AI_FLOAT:
  151. Con::printf(" Value: %f (float)", *(F32*)scene->mMetaData->mValues[i].mData);
  152. break;
  153. case AI_DOUBLE:
  154. Con::printf(" Value: %f (double)", *(F64*)scene->mMetaData->mValues[i].mData);
  155. break;
  156. case AI_AISTRING:
  157. Con::printf(" Value: %s (string)", ((aiString*)scene->mMetaData->mValues[i].mData)->C_Str());
  158. break;
  159. case AI_AIVECTOR3D:
  160. {
  161. aiVector3D* vec = (aiVector3D*)scene->mMetaData->mValues[i].mData;
  162. Con::printf(" Value: (%f, %f, %f) (vector3d)", vec->x, vec->y, vec->z);
  163. }
  164. break;
  165. default:
  166. Con::printf(" Unknown metadata type.");
  167. }
  168. }
  169. }
  170. void AssimpShapeLoader::enumerateScene()
  171. {
  172. TSShapeLoader::updateProgress(TSShapeLoader::Load_ReadFile, "Reading File");
  173. Con::printf("[ASSIMP] Attempting to load file: %s", shapePath.getFullPath().c_str());
  174. const ColladaUtils::ImportOptions& opts = ColladaUtils::getOptions();
  175. // Define post-processing steps
  176. unsigned flags =
  177. aiProcess_Triangulate |
  178. aiProcess_JoinIdenticalVertices |
  179. aiProcess_ValidateDataStructure |
  180. aiProcess_ConvertToLeftHanded & ~aiProcess_MakeLeftHanded;
  181. if (opts.convertLeftHanded) flags |= aiProcess_MakeLeftHanded;
  182. if (opts.reverseWindingOrder) flags |= aiProcess_FlipWindingOrder;
  183. if (opts.genUVCoords) flags |= aiProcess_GenUVCoords;
  184. if (opts.transformUVCoords) flags |= aiProcess_TransformUVCoords;
  185. if (opts.limitBoneWeights) flags |= aiProcess_LimitBoneWeights;
  186. if (opts.calcTangentSpace) flags |= aiProcess_CalcTangentSpace;
  187. if (opts.findInstances) flags |= aiProcess_FindInstances;
  188. if (opts.removeRedundantMats) flags |= aiProcess_RemoveRedundantMaterials;
  189. if (opts.joinIdenticalVerts) flags |= aiProcess_JoinIdenticalVertices;
  190. if (opts.invertNormals) flags |= aiProcess_FixInfacingNormals;
  191. if (opts.flipUVCoords) flags |= aiProcess_FlipUVs;
  192. if (Con::getBoolVariable("$Assimp::OptimizeMeshes", false)) {
  193. flags |= aiProcess_OptimizeMeshes | aiProcess_OptimizeGraph;
  194. }
  195. if (Con::getBoolVariable("$Assimp::SplitLargeMeshes", false)) {
  196. flags |= aiProcess_SplitLargeMeshes;
  197. }
  198. struct aiLogStream shapeLog = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT, NULL);
  199. shapeLog.callback = assimpLogCallback;
  200. shapeLog.user = 0;
  201. aiAttachLogStream(&shapeLog);
  202. #ifdef TORQUE_DEBUG
  203. aiEnableVerboseLogging(true);
  204. #endif
  205. // Read the file
  206. mScene = mImporter.ReadFile(shapePath.getFullPath().c_str(), flags);
  207. if (!mScene || !mScene->mRootNode) {
  208. Con::errorf("[ASSIMP] ERROR: Could not load file: %s", shapePath.getFullPath().c_str());
  209. Con::errorf("[ASSIMP] Importer error: %s", mImporter.GetErrorString());
  210. TSShapeLoader::updateProgress(TSShapeLoader::Load_Complete, "Import failed");
  211. return;
  212. }
  213. Con::printf("[ASSIMP] Mesh Count: %d", mScene->mNumMeshes);
  214. Con::printf("[ASSIMP] Material Count: %d", mScene->mNumMaterials);
  215. #ifdef TORQUE_DEBUG
  216. debugSceneMetaData(mScene);
  217. #endif
  218. // Handle scaling
  219. configureImportUnits();
  220. if (mScene->mMetaData) {
  221. aiString fmt;
  222. if (mScene->mMetaData->Get("SourceAsset_Format", fmt)) {
  223. if (dStrstr(fmt.C_Str(), "FBX") != NULL) {
  224. // FBX is always centimeters. Convert to meters.
  225. ColladaUtils::getOptions().formatScaleFactor = 0.0100f;
  226. Con::printf("[ASSIMP] FBX detected: applying 0.01 scale (cm -> m).");
  227. }
  228. }
  229. }
  230. ColladaUtils::getOptions().upAxis = UPAXISTYPE_Z_UP;
  231. // Compute & apply axis conversion matrix
  232. getRootAxisTransform();
  233. for (U32 i = 0; i < mScene->mNumTextures; ++i) {
  234. extractTexture(i, mScene->mTextures[i]);
  235. }
  236. // Load all materials
  237. AssimpAppMaterial::sDefaultMatNumber = 0;
  238. for (U32 i = 0; i < mScene->mNumMaterials; ++i) {
  239. AppMesh::appMaterials.push_back(new AssimpAppMaterial(mScene->mMaterials[i]));
  240. }
  241. // Setup LOD checks
  242. detectDetails();
  243. aiNode* root = mScene->mRootNode;
  244. for (S32 iNode = 0; iNode < root->mNumChildren; iNode++)
  245. {
  246. aiNode* child = root->mChildren[iNode];
  247. AssimpAppNode* node = new AssimpAppNode(mScene, child);
  248. if (!processNode(node)) {
  249. delete node;
  250. }
  251. }
  252. // Add a bounds node if none exists
  253. if (!boundsNode) {
  254. aiNode* reqNode = new aiNode("bounds");
  255. reqNode->mTransformation = aiMatrix4x4();// *sceneRoot;
  256. AssimpAppNode* appBoundsNode = new AssimpAppNode(mScene, reqNode);
  257. if (!processNode(appBoundsNode)) {
  258. delete appBoundsNode;
  259. }
  260. }
  261. // Process animations if available
  262. processAnimations();
  263. // Clean up log stream
  264. aiDetachLogStream(&shapeLog);
  265. }
  266. void AssimpShapeLoader::configureImportUnits() {
  267. auto& opts = ColladaUtils::getOptions();
  268. // Configure unit scaling
  269. if (opts.unit > 0.0f)
  270. return;
  271. // Try metadata for some formats
  272. if (mScene->mMetaData)
  273. {
  274. F64 unitScaleFactor = 1.0;
  275. if (!getMetaDouble("UnitScaleFactor", unitScaleFactor)) {
  276. F32 floatVal;
  277. S32 intVal;
  278. if (getMetaFloat("UnitScaleFactor", floatVal)) {
  279. unitScaleFactor = static_cast<F64>(floatVal);
  280. }
  281. else if (getMetaInt("UnitScaleFactor", intVal)) {
  282. unitScaleFactor = static_cast<F64>(intVal);
  283. }
  284. }
  285. opts.formatScaleFactor = unitScaleFactor;
  286. unitScaleFactor = 1.0;
  287. if (!getMetaDouble("OriginalUnitScaleFactor", unitScaleFactor)) {
  288. F32 floatVal;
  289. S32 intVal;
  290. if (getMetaFloat("OriginalUnitScaleFactor", floatVal)) {
  291. unitScaleFactor = static_cast<F64>(floatVal);
  292. }
  293. else if (getMetaInt("OriginalUnitScaleFactor", intVal)) {
  294. unitScaleFactor = static_cast<F64>(intVal);
  295. }
  296. }
  297. opts.unit = unitScaleFactor;
  298. // FBX may use another property name
  299. U32 unit = 0;
  300. if (mScene->mMetaData->Get("Unit", unit))
  301. {
  302. opts.unit = (F32)unit;
  303. }
  304. F32 fps;
  305. getMetaFloat("CustomFrameRate", fps);
  306. opts.animFPS = fps;
  307. }
  308. }
  309. void AssimpShapeLoader::getRootAxisTransform()
  310. {
  311. aiMetadata* meta = mScene->mMetaData;
  312. if (!meta)
  313. {
  314. // assume y up
  315. ColladaUtils::getOptions().upAxis = UPAXISTYPE_Y_UP;
  316. return;
  317. }
  318. // Fetch metadata values
  319. int upAxis = 1, upSign = 1;
  320. int frontAxis = 2, frontSign = -1;
  321. int coordAxis = 0, coordSign = 1;
  322. meta->Get("UpAxis", upAxis);
  323. meta->Get("UpAxisSign", upSign);
  324. meta->Get("FrontAxis", frontAxis);
  325. meta->Get("FrontAxisSign", frontSign);
  326. meta->Get("CoordAxis", coordAxis);
  327. meta->Get("CoordAxisSign", coordSign);
  328. switch (upAxis)
  329. {
  330. case 0: ColladaUtils::getOptions().upAxis = UPAXISTYPE_X_UP; break;
  331. case 1: ColladaUtils::getOptions().upAxis = UPAXISTYPE_Y_UP; break;
  332. case 2: ColladaUtils::getOptions().upAxis = UPAXISTYPE_Z_UP; break;
  333. default: ColladaUtils::getOptions().upAxis = UPAXISTYPE_Y_UP; break;
  334. }
  335. MatrixF rot(true);
  336. // ===== Y-UP SOURCE =====
  337. if (upAxis == 1)
  338. {
  339. if (frontAxis == 2)
  340. {
  341. // Y-up, Z-forward → Z-up, Y-forward
  342. // Rotate 180° Y, then 90° X
  343. rot(0, 0) = -1.0f;
  344. rot(1, 1) = 0.0f; rot(2, 1) = 1.0f;
  345. rot(1, 2) = 1.0f; rot(2, 2) = 0.0f;
  346. }
  347. else if (frontAxis == 0)
  348. {
  349. // Y-up, X-forward → Z-up, Y-forward
  350. // Rotate -90° around Z then 90° around X
  351. rot(0, 0) = 0.0f; rot(0, 1) = -1.0f;
  352. rot(1, 0) = 1.0f; rot(1, 1) = 0.0f;
  353. rot(2, 2) = 1.0f;
  354. }
  355. }
  356. // ===== Z-UP SOURCE =====
  357. if (upAxis == 2)
  358. {
  359. if (frontAxis == 1)
  360. {
  361. // Already Z-up, Y-forward → no change
  362. }
  363. else if (frontAxis == 0)
  364. {
  365. // Z-up, X-forward → rotate -90° around Z
  366. rot(0, 0) = 0.0f; rot(0, 1) = -1.0f;
  367. rot(1, 0) = 1.0f; rot(1, 1) = 0.0f;
  368. }
  369. }
  370. // ===== X-UP SOURCE =====
  371. if (upAxis == 0)
  372. {
  373. if (frontAxis == 2)
  374. {
  375. // X-up, Z-forward → Z-up, Y-forward
  376. // Rotate -90° around Y then -90° around Z
  377. rot(0, 0) = 0.0f; rot(0, 1) = 0.0f; rot(0, 2) = -1.0f;
  378. rot(1, 0) = 1.0f; rot(1, 1) = 0.0f; rot(1, 2) = 0.0f;
  379. rot(2, 0) = 0.0f; rot(2, 1) = -1.0f; rot(2, 2) = 0.0f;
  380. }
  381. }
  382. ColladaUtils::getOptions().axisCorrectionMat = rot;
  383. }
  384. void AssimpShapeLoader::processAnimations()
  385. {
  386. // add all animations into 1 ambient animation.
  387. aiAnimation* ambientSeq = new aiAnimation();
  388. ambientSeq->mName = "ambient";
  389. Vector<aiNodeAnim*> ambientChannels;
  390. F32 duration = 0.0f;
  391. F32 maxKeyTime = 0.0f;
  392. if (mScene->mNumAnimations > 0)
  393. {
  394. for (U32 i = 0; i < mScene->mNumAnimations; ++i)
  395. {
  396. aiAnimation* anim = mScene->mAnimations[i];
  397. duration = 0.0f;
  398. for (U32 j = 0; j < anim->mNumChannels; j++)
  399. {
  400. aiNodeAnim* nodeAnim = anim->mChannels[j];
  401. // Determine the maximum keyframe time for this animation
  402. for (U32 k = 0; k < nodeAnim->mNumPositionKeys; k++) {
  403. maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mPositionKeys[k].mTime);
  404. }
  405. for (U32 k = 0; k < nodeAnim->mNumRotationKeys; k++) {
  406. maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mRotationKeys[k].mTime);
  407. }
  408. for (U32 k = 0; k < nodeAnim->mNumScalingKeys; k++) {
  409. maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mScalingKeys[k].mTime);
  410. }
  411. ambientChannels.push_back(nodeAnim);
  412. duration = getMax(duration, maxKeyTime);
  413. }
  414. }
  415. ambientSeq->mNumChannels = ambientChannels.size();
  416. ambientSeq->mChannels = ambientChannels.address();
  417. ambientSeq->mDuration = duration;
  418. ambientSeq->mTicksPerSecond = ColladaUtils::getOptions().animFPS;
  419. AssimpAppSequence* defaultAssimpSeq = new AssimpAppSequence(ambientSeq);
  420. appSequences.push_back(defaultAssimpSeq);
  421. }
  422. }
  423. void AssimpShapeLoader::computeBounds(Box3F& bounds)
  424. {
  425. TSShapeLoader::computeBounds(bounds);
  426. // Check if the model origin needs adjusting
  427. bool adjustCenter = ColladaUtils::getOptions().adjustCenter;
  428. bool adjustFloor = ColladaUtils::getOptions().adjustFloor;
  429. if (bounds.isValidBox() && (adjustCenter || adjustFloor))
  430. {
  431. // Compute shape offset
  432. Point3F shapeOffset = Point3F::Zero;
  433. if (adjustCenter)
  434. {
  435. bounds.getCenter(&shapeOffset);
  436. shapeOffset = -shapeOffset;
  437. }
  438. if (adjustFloor)
  439. shapeOffset.z = -bounds.minExtents.z;
  440. // Adjust bounds
  441. bounds.minExtents += shapeOffset;
  442. bounds.maxExtents += shapeOffset;
  443. // Now adjust all positions for root level nodes (nodes with no parent)
  444. for (S32 iNode = 0; iNode < shape->nodes.size(); iNode++)
  445. {
  446. if (!appNodes[iNode]->isParentRoot())
  447. continue;
  448. // Adjust default translation
  449. shape->defaultTranslations[iNode] += shapeOffset;
  450. // Adjust animated translations
  451. for (S32 iSeq = 0; iSeq < shape->sequences.size(); iSeq++)
  452. {
  453. const TSShape::Sequence& seq = shape->sequences[iSeq];
  454. if (seq.translationMatters.test(iNode))
  455. {
  456. for (S32 iFrame = 0; iFrame < seq.numKeyframes; iFrame++)
  457. {
  458. S32 index = seq.baseTranslation + seq.translationMatters.count(iNode)*seq.numKeyframes + iFrame;
  459. shape->nodeTranslations[index] += shapeOffset;
  460. }
  461. }
  462. }
  463. }
  464. }
  465. }
  466. bool AssimpShapeLoader::fillGuiTreeView(const char* sourceShapePath, GuiTreeViewCtrl* tree)
  467. {
  468. Assimp::Importer importer;
  469. Torque::Path path(sourceShapePath);
  470. String cleanFile = AppMaterial::cleanString(path.getFileName());
  471. // Attempt to import with Assimp.
  472. const aiScene* shapeScene = importer.ReadFile(path.getFullPath().c_str(), (aiProcessPreset_TargetRealtime_Quality | aiProcess_CalcTangentSpace)
  473. & ~aiProcess_RemoveRedundantMaterials & ~aiProcess_GenSmoothNormals);
  474. if (!shapeScene)
  475. {
  476. Con::printf("AssimpShapeLoader::fillGuiTreeView - Assimp Error: %s", importer.GetErrorString());
  477. return false;
  478. }
  479. mScene = shapeScene;
  480. // Initialize tree
  481. tree->removeItem(0);
  482. S32 meshItem = tree->insertItem(0, "Meshes", String::ToString("%i", shapeScene->mNumMeshes));
  483. S32 matItem = tree->insertItem(0, "Materials", String::ToString("%i", shapeScene->mNumMaterials));
  484. S32 animItem = tree->insertItem(0, "Animations", String::ToString("%i", shapeScene->mNumAnimations));
  485. //S32 lightsItem = tree->insertItem(0, "Lights", String::ToString("%i", shapeScene->mNumLights));
  486. //S32 texturesItem = tree->insertItem(0, "Textures", String::ToString("%i", shapeScene->mNumTextures));
  487. //Details!
  488. U32 numPolys = 0;
  489. U32 numVerts = 0;
  490. for (U32 i = 0; i < shapeScene->mNumMeshes; i++)
  491. {
  492. tree->insertItem(meshItem, String::ToString("%s", shapeScene->mMeshes[i]->mName.C_Str()));
  493. numPolys += shapeScene->mMeshes[i]->mNumFaces;
  494. numVerts += shapeScene->mMeshes[i]->mNumVertices;
  495. }
  496. U32 defaultMatNumber = 0;
  497. for (U32 i = 0; i < shapeScene->mNumMaterials; i++)
  498. {
  499. aiMaterial* aiMat = shapeScene->mMaterials[i];
  500. aiString matName;
  501. aiMat->Get(AI_MATKEY_NAME, matName);
  502. String name = matName.C_Str();
  503. if (name.isEmpty())
  504. {
  505. name = AppMaterial::cleanString(path.getFileName());
  506. name += "_defMat";
  507. name += String::ToString("%d", defaultMatNumber);
  508. defaultMatNumber++;
  509. }
  510. aiString texPath;
  511. aiMat->GetTexture(aiTextureType::aiTextureType_DIFFUSE, 0, &texPath);
  512. String texName = texPath.C_Str();
  513. if (texName.isEmpty())
  514. {
  515. aiColor3D read_color(1.f, 1.f, 1.f);
  516. if (AI_SUCCESS == aiMat->Get(AI_MATKEY_COLOR_DIFFUSE, read_color))
  517. texName = String::ToString("Color: %0.3f %0.3f %0.3f", (F32)read_color.r, (F32)read_color.g, (F32)read_color.b); //formatted as words for easy parsing
  518. else
  519. texName = "No Texture";
  520. }
  521. else
  522. texName = AssimpAppMaterial::cleanTextureName(texName, cleanFile, sourceShapePath, true);
  523. tree->insertItem(matItem, String::ToString("%s", name.c_str()), String::ToString("%s", texName.c_str()));
  524. }
  525. if (shapeScene->mNumAnimations == 0)
  526. {
  527. tree->insertItem(animItem, "ambient", "animation", "", 0, 0);
  528. }
  529. else
  530. {
  531. for (U32 i = 0; i < shapeScene->mNumAnimations; i++)
  532. {
  533. tree->insertItem(animItem, shapeScene->mAnimations[i]->mName.C_Str(), "animation", "", 0, 0);
  534. }
  535. }
  536. U32 numNodes = 0;
  537. if (shapeScene->mRootNode)
  538. {
  539. S32 nodesItem = tree->insertItem(0, "Nodes", "");
  540. addNodeToTree(nodesItem, shapeScene->mRootNode, tree, numNodes);
  541. tree->setItemValue(nodesItem, String::ToString("%i", numNodes));
  542. }
  543. U32 numMetaTags = shapeScene->mMetaData ? shapeScene->mMetaData->mNumProperties : 0;
  544. if (numMetaTags)
  545. addMetaDataToTree(shapeScene->mMetaData, tree);
  546. F64 unit;
  547. if (!getMetaDouble("UnitScaleFactor", unit))
  548. unit = 1.0f;
  549. S32 upAxis;
  550. if (!getMetaInt("UpAxis", upAxis))
  551. upAxis = UPAXISTYPE_Z_UP;
  552. /*for (U32 i = 0; i < shapeScene->mNumLights; i++)
  553. {
  554. treeObj->insertItem(lightsItem, String::ToString("%s", shapeScene->mLights[i]->mType));
  555. }*/
  556. // Store shape information in the tree control
  557. tree->setDataField(StringTable->insert("_nodeCount"), 0, avar("%d", numNodes));
  558. tree->setDataField(StringTable->insert("_meshCount"), 0, avar("%d", shapeScene->mNumMeshes));
  559. tree->setDataField(StringTable->insert("_polygonCount"), 0, avar("%d", numPolys));
  560. tree->setDataField(StringTable->insert("_materialCount"), 0, avar("%d", shapeScene->mNumMaterials));
  561. tree->setDataField(StringTable->insert("_lightCount"), 0, avar("%d", shapeScene->mNumLights));
  562. tree->setDataField(StringTable->insert("_animCount"), 0, avar("%d", shapeScene->mNumAnimations));
  563. tree->setDataField(StringTable->insert("_textureCount"), 0, avar("%d", shapeScene->mNumTextures));
  564. tree->setDataField(StringTable->insert("_vertCount"), 0, avar("%d", numVerts));
  565. tree->setDataField(StringTable->insert("_metaTagCount"), 0, avar("%d", numMetaTags));
  566. tree->setDataField(StringTable->insert("_unit"), 0, avar("%g", (F32)unit));
  567. if (upAxis == UPAXISTYPE_X_UP)
  568. tree->setDataField(StringTable->insert("_upAxis"), 0, "X_AXIS");
  569. else if (upAxis == UPAXISTYPE_Y_UP)
  570. tree->setDataField(StringTable->insert("_upAxis"), 0, "Y_AXIS");
  571. else
  572. tree->setDataField(StringTable->insert("_upAxis"), 0, "Z_AXIS");
  573. return true;
  574. }
  575. /// Check if an up-to-date cached DTS is available for this DAE file
  576. bool AssimpShapeLoader::canLoadCachedDTS(const Torque::Path& path)
  577. {
  578. // Generate the cached filename
  579. Torque::Path cachedPath(path);
  580. if (String::compare(path.getExtension(), "dsq") != 0)
  581. cachedPath.setExtension("cached.dts");
  582. // Check if a cached DTS newer than this file is available
  583. FileTime cachedModifyTime;
  584. if (Platform::getFileTimes(cachedPath.getFullPath(), NULL, &cachedModifyTime))
  585. {
  586. bool forceLoad = Con::getBoolVariable("$assimp::forceLoad", false);
  587. FileTime daeModifyTime;
  588. if (!Platform::getFileTimes(path.getFullPath(), NULL, &daeModifyTime) ||
  589. (!forceLoad && (Platform::compareFileTimes(cachedModifyTime, daeModifyTime) >= 0) ))
  590. {
  591. // Original file not found, or cached DTS is newer
  592. return true;
  593. }
  594. }
  595. return false;
  596. }
  597. void AssimpShapeLoader::assimpLogCallback(const char* message, char* user)
  598. {
  599. Con::printf("[Assimp log message] %s", StringUnit::getUnit(message, 0, "\n"));
  600. }
  601. bool AssimpShapeLoader::ignoreNode(const String& name)
  602. {
  603. // Do not add AssimpFbx dummy nodes to the TSShape. See: Assimp::FBX::ImportSettings::preservePivots
  604. // https://github.com/assimp/assimp/blob/master/code/FBXImportSettings.h#L116-L135
  605. if (name.find("_$AssimpFbx$_") != String::NPos)
  606. return true;
  607. if (FindMatch::isMatchMultipleExprs(ColladaUtils::getOptions().alwaysImport, name, false))
  608. return false;
  609. return FindMatch::isMatchMultipleExprs(ColladaUtils::getOptions().neverImport, name, false);
  610. }
  611. bool AssimpShapeLoader::ignoreMesh(const String& name)
  612. {
  613. if (FindMatch::isMatchMultipleExprs(ColladaUtils::getOptions().alwaysImportMesh, name, false))
  614. return false;
  615. else
  616. return FindMatch::isMatchMultipleExprs(ColladaUtils::getOptions().neverImportMesh, name, false);
  617. }
  618. void AssimpShapeLoader::detectDetails()
  619. {
  620. // Set LOD option
  621. bool singleDetail = true;
  622. switch (ColladaUtils::getOptions().lodType)
  623. {
  624. case ColladaUtils::ImportOptions::DetectDTS:
  625. // Check for a baseXX->startXX hierarchy at the top-level, if we find
  626. // one, use trailing numbers for LOD, otherwise use a single size
  627. for (S32 iNode = 0; singleDetail && (iNode < mScene->mRootNode->mNumChildren); iNode++) {
  628. aiNode* node = mScene->mRootNode->mChildren[iNode];
  629. if (node && dStrStartsWith(node->mName.C_Str(), "base")) {
  630. for (S32 iChild = 0; iChild < node->mNumChildren; iChild++) {
  631. aiNode* child = node->mChildren[iChild];
  632. if (child && dStrStartsWith(child->mName.C_Str(), "start")) {
  633. singleDetail = false;
  634. break;
  635. }
  636. }
  637. }
  638. }
  639. break;
  640. case ColladaUtils::ImportOptions::SingleSize:
  641. singleDetail = true;
  642. break;
  643. case ColladaUtils::ImportOptions::TrailingNumber:
  644. singleDetail = false;
  645. break;
  646. default:
  647. break;
  648. }
  649. AssimpAppMesh::fixDetailSize(singleDetail, ColladaUtils::getOptions().singleDetailSize);
  650. }
  651. void AssimpShapeLoader::extractTexture(U32 index, aiTexture* pTex)
  652. { // Cache an embedded texture to disk
  653. updateProgress(Load_EnumerateScene, "Extracting Textures...", mScene->mNumTextures, index);
  654. Con::printf("[Assimp] Extracting Texture %s, W: %d, H: %d, %d of %d, format hint: (%s)", pTex->mFilename.C_Str(),
  655. pTex->mWidth, pTex->mHeight, index, mScene->mNumTextures, pTex->achFormatHint);
  656. // Create the texture filename
  657. String cleanFile = AppMaterial::cleanString(TSShapeLoader::getShapePath().getFileName());
  658. String texName = String::ToString("%s_cachedTex%d", cleanFile.c_str(), index);
  659. Torque::Path texPath = shapePath;
  660. texPath.setFileName(texName);
  661. if (pTex->mHeight == 0)
  662. { // Compressed format, write the data directly to disc
  663. texPath.setExtension(pTex->achFormatHint);
  664. FileStream *outputStream;
  665. if ((outputStream = FileStream::createAndOpen(texPath.getFullPath(), Torque::FS::File::Write)) != NULL)
  666. {
  667. outputStream->setPosition(0);
  668. outputStream->write(pTex->mWidth, pTex->pcData);
  669. outputStream->close();
  670. delete outputStream;
  671. }
  672. }
  673. else
  674. { // Embedded pixel data, fill a bitmap and save it.
  675. GFXTexHandle shapeTex;
  676. shapeTex.set(pTex->mWidth, pTex->mHeight, GFXFormatR8G8B8A8_SRGB, &GFXDynamicTextureSRGBProfile,
  677. String::ToString("AssimpShapeLoader (%s:%i)", __FILE__, __LINE__), 1, 0);
  678. GFXLockedRect *rect = shapeTex.lock();
  679. for (U32 y = 0; y < pTex->mHeight; ++y)
  680. {
  681. for (U32 x = 0; x < pTex->mWidth; ++x)
  682. {
  683. U32 targetIndex = (y * rect->pitch) + (x * 4);
  684. U32 sourceIndex = ((y * pTex->mWidth) + x) * 4;
  685. rect->bits[targetIndex] = pTex->pcData[sourceIndex].r;
  686. rect->bits[targetIndex + 1] = pTex->pcData[sourceIndex].g;
  687. rect->bits[targetIndex + 2] = pTex->pcData[sourceIndex].b;
  688. rect->bits[targetIndex + 3] = pTex->pcData[sourceIndex].a;
  689. }
  690. }
  691. shapeTex.unlock();
  692. texPath.setExtension("png");
  693. shapeTex->dumpToDisk("PNG", texPath.getFullPath());
  694. }
  695. }
  696. void AssimpShapeLoader::addNodeToTree(S32 parentItem, aiNode* node, GuiTreeViewCtrl* tree, U32& nodeCount)
  697. {
  698. // Add this node
  699. S32 nodeItem = parentItem;
  700. String nodeName = node->mName.C_Str();
  701. if (!ignoreNode(nodeName))
  702. {
  703. if (nodeName.isEmpty())
  704. nodeName = "null";
  705. nodeItem = tree->insertItem(parentItem, nodeName.c_str(), String::ToString("%i", node->mNumChildren));
  706. nodeCount++;
  707. }
  708. // Add any child nodes
  709. for (U32 n = 0; n < node->mNumChildren; ++n)
  710. addNodeToTree(nodeItem, node->mChildren[n], tree, nodeCount);
  711. }
  712. void AssimpShapeLoader::addMetaDataToTree(const aiMetadata* metaData, GuiTreeViewCtrl* tree)
  713. {
  714. S32 metaItem = tree->insertItem(0, "MetaData", String::ToString("%i", metaData->mNumProperties));
  715. aiString valString;
  716. aiVector3D valVec;
  717. for (U32 n = 0; n < metaData->mNumProperties; ++n)
  718. {
  719. String keyStr = metaData->mKeys[n].C_Str();
  720. keyStr += ": ";
  721. switch (metaData->mValues[n].mType)
  722. {
  723. case AI_BOOL:
  724. keyStr += ((bool)metaData->mValues[n].mData) ? "true" : "false";
  725. break;
  726. case AI_INT32:
  727. keyStr += String::ToString(*((S32*)(metaData->mValues[n].mData)));
  728. break;
  729. case AI_UINT64:
  730. keyStr += String::ToString("%I64u", *((U64*)metaData->mValues[n].mData));
  731. break;
  732. case AI_FLOAT:
  733. keyStr += String::ToString(*((F32*)metaData->mValues[n].mData));
  734. break;
  735. case AI_DOUBLE:
  736. keyStr += String::ToString(*((F64*)metaData->mValues[n].mData));
  737. break;
  738. case AI_AISTRING:
  739. metaData->Get<aiString>(metaData->mKeys[n], valString);
  740. keyStr += valString.C_Str();
  741. break;
  742. case AI_AIVECTOR3D:
  743. metaData->Get<aiVector3D>(metaData->mKeys[n], valVec);
  744. keyStr += String::ToString("%f, %f, %f", valVec.x, valVec.y, valVec.z);
  745. break;
  746. default:
  747. break;
  748. }
  749. tree->insertItem(metaItem, keyStr.c_str(), String::ToString("%i", n));
  750. }
  751. }
  752. bool AssimpShapeLoader::getMetabool(const char* key, bool& boolVal)
  753. {
  754. if (!mScene || !mScene->mMetaData)
  755. return false;
  756. String keyStr = key;
  757. for (U32 n = 0; n < mScene->mMetaData->mNumProperties; ++n)
  758. {
  759. if (keyStr.equal(mScene->mMetaData->mKeys[n].C_Str(), String::NoCase))
  760. {
  761. if (mScene->mMetaData->mValues[n].mType == AI_BOOL)
  762. {
  763. boolVal = (bool)mScene->mMetaData->mValues[n].mData;
  764. return true;
  765. }
  766. }
  767. }
  768. return false;
  769. }
  770. bool AssimpShapeLoader::getMetaInt(const char* key, S32& intVal)
  771. {
  772. if (!mScene || !mScene->mMetaData)
  773. return false;
  774. String keyStr = key;
  775. for (U32 n = 0; n < mScene->mMetaData->mNumProperties; ++n)
  776. {
  777. if (keyStr.equal(mScene->mMetaData->mKeys[n].C_Str(), String::NoCase))
  778. {
  779. if (mScene->mMetaData->mValues[n].mType == AI_INT32)
  780. {
  781. intVal = *((S32*)(mScene->mMetaData->mValues[n].mData));
  782. return true;
  783. }
  784. }
  785. }
  786. return false;
  787. }
  788. bool AssimpShapeLoader::getMetaFloat(const char* key, F32& floatVal)
  789. {
  790. if (!mScene || !mScene->mMetaData)
  791. return false;
  792. String keyStr = key;
  793. for (U32 n = 0; n < mScene->mMetaData->mNumProperties; ++n)
  794. {
  795. if (keyStr.equal(mScene->mMetaData->mKeys[n].C_Str(), String::NoCase))
  796. {
  797. if (mScene->mMetaData->mValues[n].mType == AI_FLOAT)
  798. {
  799. floatVal = *((F32*)mScene->mMetaData->mValues[n].mData);
  800. return true;
  801. }
  802. }
  803. }
  804. return false;
  805. }
  806. bool AssimpShapeLoader::getMetaDouble(const char* key, F64& doubleVal)
  807. {
  808. if (!mScene || !mScene->mMetaData)
  809. return false;
  810. String keyStr = key;
  811. for (U32 n = 0; n < mScene->mMetaData->mNumProperties; ++n)
  812. {
  813. if (keyStr.equal(mScene->mMetaData->mKeys[n].C_Str(), String::NoCase))
  814. {
  815. if (mScene->mMetaData->mValues[n].mType == AI_DOUBLE)
  816. {
  817. doubleVal = *((F64*)mScene->mMetaData->mValues[n].mData);
  818. return true;
  819. }
  820. }
  821. }
  822. return false;
  823. }
  824. bool AssimpShapeLoader::getMetaString(const char* key, String& stringVal)
  825. {
  826. if (!mScene || !mScene->mMetaData)
  827. return false;
  828. String keyStr = key;
  829. for (U32 n = 0; n < mScene->mMetaData->mNumProperties; ++n)
  830. {
  831. if (keyStr.equal(mScene->mMetaData->mKeys[n].C_Str(), String::NoCase))
  832. {
  833. if (mScene->mMetaData->mValues[n].mType == AI_AISTRING)
  834. {
  835. aiString valString;
  836. mScene->mMetaData->Get<aiString>(mScene->mMetaData->mKeys[n], valString);
  837. stringVal = valString.C_Str();
  838. return true;
  839. }
  840. }
  841. }
  842. return false;
  843. }
  844. //-----------------------------------------------------------------------------
  845. /// This function is invoked by the resource manager based on file extension.
  846. TSShape* assimpLoadShape(const Torque::Path &path)
  847. {
  848. // TODO: add .cached.dts generation.
  849. // Generate the cached filename
  850. Torque::Path cachedPath(path);
  851. if ( String::compare(path.getExtension(),"dsq") != 0)
  852. cachedPath.setExtension("cached.dts");
  853. // Check if an up-to-date cached DTS version of this file exists, and
  854. // if so, use that instead.
  855. if (AssimpShapeLoader::canLoadCachedDTS(path))
  856. {
  857. FileStream cachedStream;
  858. cachedStream.open(cachedPath.getFullPath(), Torque::FS::File::Read);
  859. if (cachedStream.getStatus() == Stream::Ok)
  860. {
  861. TSShape *shape = new TSShape;
  862. if (String::compare(path.getExtension(), "dsq") == 0)
  863. {
  864. if (!shape->importSequences(&cachedStream, cachedPath.getFullPath()))
  865. {
  866. Con::errorf("assimpLoadShape: Load sequence file '%s' failed", cachedPath.getFullPath().c_str());
  867. delete shape;
  868. shape = NULL;
  869. }
  870. cachedStream.close();
  871. return shape;
  872. }
  873. bool readSuccess = shape->read(&cachedStream);
  874. cachedStream.close();
  875. if (readSuccess)
  876. {
  877. #ifdef TORQUE_DEBUG
  878. Con::printf("Loaded cached shape from %s", cachedPath.getFullPath().c_str());
  879. #endif
  880. return shape;
  881. }
  882. else
  883. delete shape;
  884. }
  885. Con::warnf("Failed to load cached shape from %s", cachedPath.getFullPath().c_str());
  886. }
  887. if (!Torque::FS::IsFile(path))
  888. {
  889. // File does not exist, bail.
  890. return NULL;
  891. }
  892. // Allow TSShapeConstructor object to override properties
  893. ColladaUtils::getOptions().reset();
  894. TSShapeConstructor* tscon = TSShapeConstructor::findShapeConstructorByFilename(path.getFullPath());
  895. if (tscon)
  896. {
  897. ColladaUtils::getOptions() = tscon->mOptions;
  898. }
  899. AssimpShapeLoader loader;
  900. TSShape* tss = loader.generateShape(path);
  901. if (tss)
  902. {
  903. TSShapeLoader::updateProgress(TSShapeLoader::Load_Complete, "Import complete");
  904. Con::printf("[ASSIMP] Shape created successfully.");
  905. bool realMesh = false;
  906. for (U32 i = 0; i < tss->meshes.size(); ++i)
  907. {
  908. if (tss->meshes[i] && tss->meshes[i]->getMeshType() != TSMesh::NullMeshType)
  909. realMesh = true;
  910. }
  911. if (!realMesh)
  912. {
  913. Torque::Path dsqPath(cachedPath);
  914. dsqPath.setExtension("dsq");
  915. FileStream animOutStream;
  916. for (S32 i = 0; i < tss->sequences.size(); i++)
  917. {
  918. const String& seqName = tss->getName(tss->sequences[i].nameIndex);
  919. Con::printf("Writing DSQ Animation File for sequence '%s'", seqName.c_str());
  920. dsqPath.setFileName(cachedPath.getFileName() + "_" + seqName);
  921. if (animOutStream.open(dsqPath.getFullPath(), Torque::FS::File::Write))
  922. {
  923. tss->exportSequence(&animOutStream, tss->sequences[i], false);
  924. animOutStream.close();
  925. }
  926. }
  927. }
  928. else
  929. {
  930. // Cache the model to a DTS file for faster loading next time.
  931. FileStream dtsStream;
  932. if (dtsStream.open(cachedPath.getFullPath(), Torque::FS::File::Write))
  933. {
  934. Con::printf("Writing cached shape to %s", cachedPath.getFullPath().c_str());
  935. tss->write(&dtsStream);
  936. }
  937. }
  938. }
  939. loader.releaseImport();
  940. return tss;
  941. }
  942. DefineEngineFunction(GetShapeInfo, bool, (const char* shapePath, const char* ctrl, bool loadCachedDts), ("", "", true),
  943. "(string shapePath, GuiTreeViewCtrl ctrl) Collect scene information from "
  944. "a shape file and store it in a GuiTreeView control. This function is "
  945. "used by the assimp import gui to show a preview of the scene contents "
  946. "prior to import, and is probably not much use for anything else.\n"
  947. "@param shapePath shape filename\n"
  948. "@param ctrl GuiTreeView control to add elements to\n"
  949. "@return true if successful, false otherwise\n"
  950. "@ingroup Editors\n"
  951. "@internal")
  952. {
  953. GuiTreeViewCtrl* tree;
  954. if (!Sim::findObject(ctrl, tree))
  955. {
  956. Con::errorf("enumColladaScene::Could not find GuiTreeViewCtrl '%s'", ctrl);
  957. return false;
  958. }
  959. // Check if a cached DTS is available => no need to import the source file
  960. // if we can load the DTS instead
  961. Torque::Path path(shapePath);
  962. if (loadCachedDts && AssimpShapeLoader::canLoadCachedDTS(path))
  963. return false;
  964. AssimpShapeLoader loader;
  965. return loader.fillGuiTreeView(shapePath, tree);
  966. }