| 302 | } |
| 303 | |
| 304 | bool AssimpShapeLoader::fillGuiTreeView(const char* sourceShapePath, GuiTreeViewCtrl* tree) |
| 305 | { |
| 306 | Assimp::Importer importer; |
| 307 | Torque::Path path(sourceShapePath); |
| 308 | String cleanFile = AppMaterial::cleanString(path.getFileName()); |
| 309 | |
| 310 | // Attempt to import with Assimp. |
| 311 | const aiScene* shapeScene = importer.ReadFile(path.getFullPath().c_str(), (aiProcessPreset_TargetRealtime_Quality | aiProcess_CalcTangentSpace) |
| 312 | & ~aiProcess_RemoveRedundantMaterials & ~aiProcess_GenSmoothNormals); |
| 313 | |
| 314 | if (!shapeScene) |
| 315 | { |
| 316 | Con::printf("AssimpShapeLoader::fillGuiTreeView - Assimp Error: %s", importer.GetErrorString()); |
| 317 | return false; |
| 318 | } |
| 319 | mScene = shapeScene; |
| 320 | |
| 321 | // Initialize tree |
| 322 | tree->removeItem(0); |
| 323 | S32 meshItem = tree->insertItem(0, "Meshes", String::ToString("%i", shapeScene->mNumMeshes)); |
| 324 | S32 matItem = tree->insertItem(0, "Materials", String::ToString("%i", shapeScene->mNumMaterials)); |
| 325 | S32 animItem = tree->insertItem(0, "Animations", String::ToString("%i", shapeScene->mNumAnimations)); |
| 326 | //S32 lightsItem = tree->insertItem(0, "Lights", String::ToString("%i", shapeScene->mNumLights)); |
| 327 | //S32 texturesItem = tree->insertItem(0, "Textures", String::ToString("%i", shapeScene->mNumTextures)); |
| 328 | |
| 329 | //Details! |
| 330 | U32 numPolys = 0; |
| 331 | U32 numVerts = 0; |
| 332 | for (U32 i = 0; i < shapeScene->mNumMeshes; i++) |
| 333 | { |
| 334 | tree->insertItem(meshItem, String::ToString("%s", shapeScene->mMeshes[i]->mName.C_Str())); |
| 335 | numPolys += shapeScene->mMeshes[i]->mNumFaces; |
| 336 | numVerts += shapeScene->mMeshes[i]->mNumVertices; |
| 337 | } |
| 338 | |
| 339 | U32 defaultMatNumber = 0; |
| 340 | for (U32 i = 0; i < shapeScene->mNumMaterials; i++) |
| 341 | { |
| 342 | aiMaterial* aiMat = shapeScene->mMaterials[i]; |
| 343 | |
| 344 | aiString matName; |
| 345 | aiMat->Get(AI_MATKEY_NAME, matName); |
| 346 | String name = matName.C_Str(); |
| 347 | if (name.isEmpty()) |
| 348 | { |
| 349 | name = AppMaterial::cleanString(path.getFileName()); |
| 350 | name += "_defMat"; |
| 351 | name += String::ToString("%d", defaultMatNumber); |
| 352 | defaultMatNumber++; |
| 353 | } |
| 354 | |
| 355 | aiString texPath; |
| 356 | aiMat->GetTexture(aiTextureType::aiTextureType_DIFFUSE, 0, &texPath); |
| 357 | String texName = texPath.C_Str(); |
| 358 | if (texName.isEmpty()) |
| 359 | { |
| 360 | aiColor3D read_color(1.f, 1.f, 1.f); |
| 361 | if (AI_SUCCESS == aiMat->Get(AI_MATKEY_COLOR_DIFFUSE, read_color)) |
no test coverage detected