Files
UnrealEngineUWP/Engine/Plugins/Runtime/MeshModelingToolset/Source/ModelingComponents/Public/AssetUtils/StaticMeshMaterialUtil.h
ryan schmidt db4634dfb9 GeometryScripting: improve support for handling StaticMesh/DynamicMesh LOD and Material aspects
UE::AssetUtils::GetStaticMeshLODMaterialListBySection() now returns the slot name for each Material
BP function GetSectionMaterialListFromStaticMesh() now returns slot names. Fixed issue in this function where LODIndex was clamped to Render LODs, not SourceModel LODs. This function now also works for RenderData LODs. In CopyMeshToStaticMesh, for RenderData LODs, the MaterialID is set to the MaterialIndex referenced by each mesh section. So in this case in GetSectionMaterialListFromStaticMesh, the Asset Material List is returned directly. This is not really a "per Section Material List' as the function name implies, however it allows this function to provide comparable behavior between SourceModel and RenderData LODs.

Add new BP function RemapToNewMaterialIDsByMaterial() which figures out MaterialID remapping based on original and new Material lists (assuming MaterialID indexes into original Material list)
Add BP functions GetNumStaticMeshLODsOfType() and CheckStaticMeshHasAvailableLOD(), these utilities are useful for dealing w/ multi-LOD assets

#rb jimmy.andrews

[CL 29052212 by ryan schmidt in ue5-main branch]
2023-10-24 15:57:31 -04:00

80 lines
2.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
class UMaterialInterface;
class UStaticMesh;
struct FStaticMaterial;
namespace UE
{
namespace AssetUtils
{
/**
* Information about a mesh material slot (eg a FStaticMaterial)
*/
struct MODELINGCOMPONENTS_API FStaticMeshMaterialSlot
{
UMaterialInterface* Material;
FName SlotName;
};
/**
* Information about the materials assigned to a StaticMesh LOD.
* The StaticMesh stores a Material List and per-mesh-Section assignments into that Material List.
* This relationship is not necessarily 1-1, multiple Sections can use the same material, and there
* can be arbitrary remappings, and the storage of this information is somewhat scattered across StaticMesh.
* This data structure encapsulates the critical information needed to (eg) assign materials
* to a new mesh/component such that they match the rendered materials on an existing StaticMesh.
*
* The GetStaticMeshAssetMaterials() function can be used to build this data structure for a given StaticMesh LOD.
*/
struct MODELINGCOMPONENTS_API FStaticMeshLODMaterialSetInfo
{
/** MaterialSlots array is a copy of the UStaticMesh::StaticMaterials array/data */
TArray<FStaticMeshMaterialSlot> MaterialSlots;
/** LOD Index the data below refers to */
int32 LODIndex = 0;
/** Number of Sections on the mesh LOD */
int32 NumSections = 0;
/** The index into MaterialSlots array of the Material assigned to each Section, in linear order */
TArray<int32> SectionSlotIndexes;
/** The Material assigned to each Section, in linear order */
TArray<UMaterialInterface*> SectionMaterials;
};
/**
* Extract information about the material set for a given LODIndex of a StaticMeshAsset
*/
MODELINGCOMPONENTS_API bool GetStaticMeshLODAssetMaterials(
UStaticMesh* StaticMeshAsset,
int32 LODIndex,
FStaticMeshLODMaterialSetInfo& MaterialInfoOut);
/**
* Construct the linear per-section material list for a given LODIndex of a StaticMeshAsset
* @param MaterialListOut the list of linear per-section indices into the Asset Material List
* @param MaterialIndexOut the corresponding list of linear per-section indices into the Asset Material List
* @param MaterialSlotNameOut the corresponding list of material slot names
*/
MODELINGCOMPONENTS_API bool GetStaticMeshLODMaterialListBySection(
UStaticMesh* StaticMeshAsset,
int32 LODIndex,
TArray<UMaterialInterface*>& MaterialListOut,
TArray<int32>& MaterialIndexOut,
TArray<FName>& MaterialSlotNameOut);
/**
* Generate a new unique material slot name for the given SlotMaterial and NewSlotIndex,
* ensuring that the name is not already used in the set of ExistingMaterials
*/
MODELINGCOMPONENTS_API FName GenerateNewMaterialSlotName(
const TArray<FStaticMaterial>& ExistingMaterials,
UMaterialInterface* SlotMaterial,
int32 NewSlotIndex);
}
}