本文整理汇总了C++中UMaterial::PostEditChange方法的典型用法代码示例。如果您正苦于以下问题:C++ UMaterial::PostEditChange方法的具体用法?C++ UMaterial::PostEditChange怎么用?C++ UMaterial::PostEditChange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UMaterial
的用法示例。
在下文中一共展示了UMaterial::PostEditChange方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PostEditChangeProperty
void UMaterialParameterCollection::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
// If the array counts have changed, an element has been added or removed, and we need to update the uniform buffer layout,
// Which also requires recompiling any referencing materials
if (ScalarParameters.Num() != PreviousScalarParameters.Num()
|| VectorParameters.Num() != PreviousVectorParameters.Num())
{
// Limit the count of parameters to fit within uniform buffer limits
const uint32 MaxScalarParameters = 1024;
if (ScalarParameters.Num() > MaxScalarParameters)
{
ScalarParameters.RemoveAt(MaxScalarParameters, ScalarParameters.Num() - MaxScalarParameters);
}
const uint32 MaxVectorParameters = 1024;
if (VectorParameters.Num() > MaxVectorParameters)
{
VectorParameters.RemoveAt(MaxVectorParameters, VectorParameters.Num() - MaxVectorParameters);
}
// Generate a new Id so that unloaded materials that reference this collection will update correctly on load
StateId = FGuid::NewGuid();
// Update the uniform buffer layout
CreateBufferStruct();
// Recreate each instance of this collection
for (TObjectIterator<UWorld> It; It; ++It)
{
UWorld* CurrentWorld = *It;
CurrentWorld->AddParameterCollectionInstance(this, false);
}
// Build set of changed parameter names
TSet<FName> ParameterNames;
for (const FCollectionVectorParameter& Param : PreviousVectorParameters)
{
ParameterNames.Add(Param.ParameterName);
}
for (const FCollectionScalarParameter& Param : PreviousScalarParameters)
{
ParameterNames.Add(Param.ParameterName);
}
for (const FCollectionVectorParameter& Param : VectorParameters)
{
ParameterNames.Remove(Param.ParameterName);
}
for (const FCollectionScalarParameter& Param : ScalarParameters)
{
ParameterNames.Remove(Param.ParameterName);
}
// Create a material update context so we can safely update materials using this parameter collection.
{
FMaterialUpdateContext UpdateContext;
// Go through all materials in memory and recompile them if they use this material parameter collection
for (TObjectIterator<UMaterial> It; It; ++It)
{
UMaterial* CurrentMaterial = *It;
bool bRecompile = false;
// Preview materials often use expressions for rendering that are not in their Expressions array,
// And therefore their MaterialParameterCollectionInfos are not up to date.
if (CurrentMaterial->bIsPreviewMaterial)
{
bRecompile = true;
}
else
{
for (int32 FunctionIndex = 0; FunctionIndex < CurrentMaterial->MaterialParameterCollectionInfos.Num() && !bRecompile; FunctionIndex++)
{
if (CurrentMaterial->MaterialParameterCollectionInfos[FunctionIndex].ParameterCollection == this)
{
TArray<UMaterialExpressionCollectionParameter*> CollectionParameters;
CurrentMaterial->GetAllExpressionsInMaterialAndFunctionsOfType(CollectionParameters);
for (UMaterialExpressionCollectionParameter* CollectionParameter : CollectionParameters)
{
if (ParameterNames.Contains(CollectionParameter->ParameterName))
{
bRecompile = true;
break;
}
}
}
}
}
if (bRecompile)
{
UpdateContext.AddMaterial(CurrentMaterial);
// Propagate the change to this material
CurrentMaterial->PreEditChange(NULL);
//.........这里部分代码省略.........
示例2: TEXT
void UnFbx::FFbxImporter::CreateUnrealMaterial(FbxSurfaceMaterial* FbxMaterial, TArray<UMaterialInterface*>& OutMaterials, TArray<FString>& UVSets)
{
FString MaterialFullName = ANSI_TO_TCHAR(MakeName(FbxMaterial->GetName()));
// check for a 'skinXX' suffix in the material name
int32 MaterialNameLen = FCString::Strlen(*MaterialFullName) + 1;
char* MaterialNameANSI = new char[MaterialNameLen];
FCStringAnsi::Strcpy(MaterialNameANSI, MaterialNameLen, TCHAR_TO_ANSI(*MaterialFullName));
if (FCStringAnsi::Strlen(MaterialNameANSI) > 6)
{
const char* SkinXX = MaterialNameANSI + FCStringAnsi::Strlen(MaterialNameANSI) - 6;
if (FCharAnsi::ToUpper(*SkinXX) == 'S' && FCharAnsi::ToUpper(*(SkinXX+1)) == 'K' &&
FCharAnsi::ToUpper(*(SkinXX+2)) == 'I' && FCharAnsi::ToUpper(*(SkinXX+3)) == 'N')
{
if (FCharAnsi::IsDigit(*(SkinXX+4)) && FCharAnsi::IsDigit(*(SkinXX+5)))
{
// remove the 'skinXX' suffix from the material name
MaterialFullName = MaterialFullName.Left(MaterialNameLen - 7);
}
}
}
MaterialFullName = ObjectTools::SanitizeObjectName(MaterialFullName);
// Make sure we have a parent
if ( !ensure(Parent) )
{
return;
}
// set where to place the materials
FString NewPackageName = FPackageName::GetLongPackagePath(Parent->GetOutermost()->GetName()) + TEXT("/") + MaterialFullName;
NewPackageName = PackageTools::SanitizePackageName(NewPackageName);
UPackage* Package = CreatePackage(NULL, *NewPackageName);
UMaterialInterface* UnrealMaterialInterface = FindObject<UMaterialInterface>(Package,*MaterialFullName);
// does not override existing materials
if (UnrealMaterialInterface != NULL)
{
OutMaterials.Add(UnrealMaterialInterface);
return;
}
// create an unreal material asset
UMaterialFactoryNew* MaterialFactory = new UMaterialFactoryNew(FPostConstructInitializeProperties());
UMaterial* UnrealMaterial = (UMaterial*)MaterialFactory->FactoryCreateNew(
UMaterial::StaticClass(), Package, *MaterialFullName, RF_Standalone|RF_Public, NULL, GWarn );
// TODO : need this ? UnrealMaterial->bUsedWithStaticLighting = true;
if ( UnrealMaterial != NULL )
{
// Notify the asset registry
FAssetRegistryModule::AssetCreated(UnrealMaterial);
// Set the dirty flag so this package will get saved later
Package->SetDirtyFlag(true);
}
// textures and properties
CreateAndLinkExpressionForMaterialProperty( *FbxMaterial, UnrealMaterial, FbxSurfaceMaterial::sDiffuse, UnrealMaterial->DiffuseColor, false, UVSets);
CreateAndLinkExpressionForMaterialProperty( *FbxMaterial, UnrealMaterial, FbxSurfaceMaterial::sEmissive, UnrealMaterial->EmissiveColor, false, UVSets);
CreateAndLinkExpressionForMaterialProperty( *FbxMaterial, UnrealMaterial, FbxSurfaceMaterial::sSpecular, UnrealMaterial->SpecularColor, false, UVSets);
CreateAndLinkExpressionForMaterialProperty( *FbxMaterial, UnrealMaterial, FbxSurfaceMaterial::sSpecularFactor, UnrealMaterial->SpecularColor, false, UVSets); // SpecularFactor modulates the SpecularColor value if there's one
//CreateAndLinkExpressionForMaterialProperty( *FbxMaterial, UnrealMaterial, FbxSurfaceMaterial::sShininess, UnrealMaterial->SpecularPower, false, UVSets);
if (!CreateAndLinkExpressionForMaterialProperty( *FbxMaterial, UnrealMaterial, FbxSurfaceMaterial::sNormalMap, UnrealMaterial->Normal, true, UVSets))
{
CreateAndLinkExpressionForMaterialProperty( *FbxMaterial, UnrealMaterial, FbxSurfaceMaterial::sBump, UnrealMaterial->Normal, true, UVSets); // no bump in unreal, use as normal map
}
//CreateAndLinkExpressionForMaterialProperty( *FbxMaterial, UnrealMaterial, KFbxSurfaceMaterial::sTransparentColor, UnrealMaterial->Opacity, false, UVSets);
//CreateAndLinkExpressionForMaterialProperty( *FbxMaterial, UnrealMaterial, KFbxSurfaceMaterial::sTransparencyFactor, UnrealMaterial->OpacityMask, false, UVSets);
FixupMaterial( *FbxMaterial, UnrealMaterial); // add random diffuse if none exists
// compile shaders for PC (from UPrecompileShadersCommandlet::ProcessMaterial
// and FMaterialEditor::UpdateOriginalMaterial)
// make sure that any static meshes, etc using this material will stop using the FMaterialResource of the original
// material, and will use the new FMaterialResource created when we make a new UMaterial in place
FGlobalComponentReregisterContext RecreateComponents;
// let the material update itself if necessary
UnrealMaterial->PreEditChange(NULL);
UnrealMaterial->PostEditChange();
OutMaterials.Add(UnrealMaterial);
}
示例3: CreateMaterial
//! @brief Create an Unreal Material for the given graph-instance
UMaterial* CreateMaterial(graph_inst_t* GraphInstance,
const FString & MaterialName,
UObject* Outer)
{
// create an unreal material asset
UMaterialFactoryNew* MaterialFactory = NewObject<UMaterialFactoryNew>();
UMaterial* UnrealMaterial =
(UMaterial*)MaterialFactory->FactoryCreateNew(
UMaterial::StaticClass(),
Substance::Helpers::CreateObjectPackage(Outer, MaterialName),
*MaterialName,
RF_Standalone|RF_Public, NULL, GWarn );
// textures and properties
for (auto ItOut = GraphInstance->Outputs.itfront(); ItOut; ++ItOut)
{
output_inst_t* OutputInst = &(*ItOut);
output_desc_t* OutputDesc = OutputInst->GetOutputDesc();
CreateMaterialExpression(
OutputInst,
UnrealMaterial);
}
// special case: emissive only materials
TArray<FName> ParamNames;
TArray<FGuid> ParamIds;
UnrealMaterial->GetAllTextureParameterNames(ParamNames, ParamIds);
if (ParamNames.Num() == 1)
{
if (ParamNames[0].ToString() == TEXT("emissive"))
{
UnrealMaterial->SetShadingModel(MSM_Unlit);
}
}
// special case: no roughness but glossiness
if (!UnrealMaterial->Roughness.IsConnected())
{
for (auto ItOut = GraphInstance->Outputs.itfront(); ItOut; ++ItOut)
{
output_inst_t* OutputInst = &(*ItOut);
output_desc_t* OutputDesc = OutputInst->GetOutputDesc();
UTexture* Texture = *OutputInst->Texture;
if (OutputDesc->Channel == CHAN_Glossiness && Texture)
{
// and link it to the material
UMaterialExpressionOneMinus* OneMinus = NewObject<UMaterialExpressionOneMinus>(UnrealMaterial);
UMaterialExpressionTextureSampleParameter2D* UnrealTextureExpression =
CreateSampler(UnrealMaterial, Texture, OutputDesc);
UnrealTextureExpression->MaterialExpressionEditorX -= 200;
OneMinus->MaterialExpressionEditorX = -200;
OneMinus->MaterialExpressionEditorY = UnrealTextureExpression->MaterialExpressionEditorY;
UnrealTextureExpression->ConnectExpression(OneMinus->GetInput(0), 0);
UnrealMaterial->Roughness.Expression = OneMinus;
UnrealMaterial->Expressions.Add(UnrealTextureExpression);
UnrealMaterial->Expressions.Add(OneMinus);
}
}
}
// let the material update itself if necessary
UnrealMaterial->PreEditChange(NULL);
UnrealMaterial->PostEditChange();
return UnrealMaterial;
}