ue4.26 为staticmesh每级lod制定材质球
视频:
materialForEachLod - 知乎 (zhihu.com)
EditorStaticMeshLibarary.h
UFUNCTION(BlueprintCallable, Category = "MY") static void recreateSectionInfoMap(UStaticMesh* StaticMesh); UFUNCTION(BlueprintCallable, Category = "MY") static void createUVChannelDataForStaticMeshMaterial(UPARAM(ref)FStaticMaterial& staticMeshMaterial);
EditorStaticMeshLibarary.cpp
void UEditorStaticMeshLibrary::createUVChannelDataForStaticMeshMaterial(UPARAM(ref)FStaticMaterial&staticMeshMaterial) { staticMeshMaterial.UVChannelData= FMeshUVChannelInfo(1.f); } void UEditorStaticMeshLibrary::recreateSectionInfoMap_MY(UStaticMesh* StaticMesh) { const int32 lodCount = StaticMesh->GetNumLODs(); //重建SectionInfoMap { // StaticMesh->GetSectionInfoMap().Clear(); int32 materialIndex = 0; for (int32 LODIdx = 0; LODIdx < lodCount; LODIdx++) { int sectionNum=StaticMesh->GetSectionInfoMap().GetSectionNumber(LODIdx); for (int i = 0; i < sectionNum; i++) { FMeshSectionInfo info = StaticMesh->GetSectionInfoMap().Get(LODIdx,i);//FMeshSectionInfo(); info.MaterialIndex = materialIndex; StaticMesh->GetSectionInfoMap().Set(LODIdx, i, info); materialIndex++; } } } StaticMesh->PostEditChange(); StaticMesh->MarkPackageDirty(); }
注:staticMaterial结构体有三个成员变量MaterialInterface、MaterialSlotName、UVChannelData,但MakeStaticMaterial节点只有MaterialInterface和MaterialSlotName两个输入,我试着如果不初始化UVChannelData,在后续StaticMaterialList设给StaticMaterials时会触发断点,所以另加了一个createUVChannelDataForStaticMeshMaterial函数。