MCPcopy Create free account
hub / github.com/TheRealMJP/DeferredTexturing / CreateWithAssimp

Method CreateWithAssimp

SampleFramework12/v1.00/Graphics/Model.cpp:404–559  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402// == Model =======================================================================================
403
404void Model::CreateWithAssimp(const ModelLoadSettings& settings)
405{
406 const wchar* filePath = settings.FilePath;
407 Assert_(filePath != nullptr);
408 if(FileExists(filePath) == false)
409 throw Exception(MakeString(L"Model file with path '%ls' does not exist", filePath));
410
411 WriteLog("Loading scene '%ls' with Assimp...", filePath);
412
413 std::string fileNameAnsi = WStringToAnsi(filePath);
414
415 Assimp::Importer importer;
416 const aiScene* scene = importer.ReadFile(fileNameAnsi, 0);
417
418 if(scene == nullptr)
419 throw Exception(L"Failed to load scene " + std::wstring(filePath) +
420 L": " + AnsiToWString(importer.GetErrorString()));
421
422 if(scene->mNumMeshes == 0)
423 throw Exception(L"Scene " + std::wstring(filePath) + L" has no meshes");
424
425 if(scene->mNumMaterials == 0)
426 throw Exception(L"Scene " + std::wstring(filePath) + L" has no materials");
427
428 fileDirectory = GetDirectoryFromFilePath(filePath);
429 forceSRGB = settings.ForceSRGB;
430
431 // Grab the lights before we process the scene
432 spotLights.Init(scene->mNumLights);
433 pointLights.Init(scene->mNumLights);
434
435 uint64 numSpotLights = 0;
436 uint64 numPointLights = 0;
437 for(uint64 i = 0; i < scene->mNumLights; ++i)
438 {
439 const aiLight& srcLight = *scene->mLights[i];
440 if(srcLight.mType == aiLightSource_SPOT)
441 {
442 // Assimp seems to mess up when importing spot light transforms for FBX
443 std::string translationName = MakeString("%s_$AssimpFbx$_Translation", srcLight.mName.C_Str());
444 const aiNode* translationNode = scene->mRootNode->FindNode(translationName.c_str());
445 if(translationNode == nullptr)
446 continue;
447
448 std::string rotationName = MakeString("%s_$AssimpFbx$_Rotation", srcLight.mName.C_Str());
449 const aiNode* rotationNode = translationNode->FindNode(rotationName.c_str());
450 if(rotationNode == nullptr)
451 continue;
452
453 ModelSpotLight& dstLight = spotLights[numSpotLights++];
454
455 Float4x4 translation = Float4x4::Transpose(ConvertMatrix(translationNode->mTransformation));
456 dstLight.Position = translation.Translation() * settings.SceneScale;
457 dstLight.Position.z *= -1.0f;
458 dstLight.Intensity = ConvertColor(srcLight.mColorDiffuse) * FP16Scale;
459 dstLight.AngularAttenuation.x = srcLight.mAngleInnerCone;
460 dstLight.AngularAttenuation.y = srcLight.mAngleOuterCone;
461

Callers 1

InitializeMethod · 0.80

Calls 15

FileExistsFunction · 0.85
ExceptionClass · 0.85
MakeStringFunction · 0.85
WriteLogFunction · 0.85
WStringToAnsiFunction · 0.85
AnsiToWStringFunction · 0.85
GetDirectoryFromFilePathFunction · 0.85
ConvertMatrixFunction · 0.85
ConvertColorFunction · 0.85
QuaternionClass · 0.85
ConvertVectorFunction · 0.85
GetFileNameFunction · 0.85

Tested by

no test coverage detected