diff --git a/03-UnrealEngine/Gameplay/Gameplay/RuntimeLoadStaticMesh.md b/03-UnrealEngine/Gameplay/Gameplay/RuntimeLoadStaticMesh.md index ea01d15..c1e771d 100644 --- a/03-UnrealEngine/Gameplay/Gameplay/RuntimeLoadStaticMesh.md +++ b/03-UnrealEngine/Gameplay/Gameplay/RuntimeLoadStaticMesh.md @@ -7,8 +7,39 @@ rating: ⭐ --- # 前言 - StaticMesh:https://zhuanlan.zhihu.com/p/702589732 +- 其他代码 + - [RuntimeStaticMeshImporter](https://github.com/RianeDev/RuntimeStaticMeshImporter) + - [RuntimeMeshLoader](https://github.com/Chrizey91/RuntimeMeshLoader) ## 相关函数 ```text +bool FSceneImporter::ProcessMeshData(FAssetData& MeshData) UStaticMesh::BuildFromMeshDescription +``` + +```c++ +FDatasmithMeshElementPayload MeshPayload; +{ + if (!Translator->LoadStaticMesh(MeshElement, MeshPayload)) + { // If mesh cannot be loaded, add scene's resource path if valid and retry + bool bSecondTrySucceeded = false; + + if (FPaths::DirectoryExists(SceneElement->GetResourcePath()) && FPaths::IsRelative(MeshElement->GetFile())) + { MeshElement->SetFile( *FPaths::Combine(SceneElement->GetResourcePath(), MeshElement->GetFile()) ); + bSecondTrySucceeded = Translator->LoadStaticMesh(MeshElement, MeshPayload); + } + if (!bSecondTrySucceeded) + { // #ueent_datasmithruntime: TODO : Update FAssetFactory + ActionCounter.Add(MeshData.Referencers.Num()); + FAssetRegistry::UnregisteredAssetsData(StaticMesh, SceneKey, [](FAssetData& AssetData) -> void + { + AssetData.AddState(EAssetState::Completed); + AssetData.Object.Reset(); + }); + UE_LOG(LogDatasmithRuntime, Warning, TEXT("CreateStaticMesh: Loading file %s failed. Mesh element %s has not been imported"), MeshElement->GetFile(), MeshElement->GetLabel()); + + return true; + } }} + +TArray< FMeshDescription >& MeshDescriptions = MeshPayload.LodMeshes; ``` \ No newline at end of file