Guest User

MaterialExressions.h

a guest
Dec 8th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.72 KB | None | 0 0
  1. // MaterialExpressions.h
  2.  
  3. //
  4. //  UMaterialExpressionStaticMultipleSwitch
  5. //
  6. UMaterialExpressionStaticMultipleSwitch::UMaterialExpressionStaticMultipleSwitch(const FObjectInitializer& ObjectInitializer)
  7.     : Super(ObjectInitializer)
  8. {
  9.     // Structure to hold one-time initialization
  10.     struct FConstructorStatics
  11.     {
  12.         FText NAME_Functions;
  13.         FConstructorStatics()
  14.             : NAME_Functions(LOCTEXT("Functions", "Functions"))
  15.         {
  16.         }
  17.     };
  18.     static FConstructorStatics ConstructorStatics;
  19.  
  20.     MenuCategories.Add(ConstructorStatics.NAME_Functions);
  21.    
  22.     Inputs.Add(FCustomInput());
  23.     Inputs.Add(FCustomInput());
  24.  
  25.     Inputs[0].InputName = TEXT("Input1");
  26.     Inputs[1].InputName = TEXT("Input2");
  27.  
  28.     bCollapsed = false;
  29. }
  30.  
  31. bool UMaterialExpressionStaticMultipleSwitch::IsResultMaterialAttributes(int32 OutputIndex)
  32. {
  33.     // If there is a loop anywhere in this expression's inputs then we can't risk checking them
  34.     check(OutputIndex == 0);
  35.     if ((!Value.Expression || Value.Expression->ContainsInputLoop()))
  36.     {
  37.         return Value.Expression->IsResultMaterialAttributes(Value.OutputIndex);
  38.     }
  39.     else
  40.     {
  41.         for (int32 i = 0; i < Inputs.Num(); i++)
  42.         {
  43.             if ((!Inputs[i].Input.Expression || Inputs[i].Input.Expression->ContainsInputLoop()))
  44.             {
  45.                 return Inputs[i].Input.Expression->IsResultMaterialAttributes(Inputs[i].Input.OutputIndex);
  46.             }          
  47.         }
  48.     }
  49.  
  50.     return false;
  51. }
  52.  
  53. int32 UMaterialExpressionStaticMultipleSwitch::Compile(class FMaterialCompiler* Compiler, int32 OutputIndex, int32 MultiplexIndex)
  54. {
  55.     int32 iValue = INDEX_NONE;
  56.  
  57.     if (Value.Expression)
  58.     {
  59.         bool bSucceeded;
  60.         iValue = Compiler->GetStaticIntValue(Value.Compile(Compiler), bSucceeded);
  61.  
  62.         if (!bSucceeded)
  63.         {
  64.             return INDEX_NONE;
  65.         }
  66.     }
  67.  
  68.     for (int32 i = 0; i < Inputs.Num(); i++)
  69.     {
  70.         if (iValue == i)
  71.         {
  72.             return Inputs[iValue].Input.Compile(Compiler, MultiplexIndex);
  73.         }
  74.     }
  75.  
  76.     return INDEX_NONE;
  77. }
  78.  
  79. void UMaterialExpressionStaticMultipleSwitch::GetCaption(TArray<FString>& OutCaptions) const
  80. {
  81.     OutCaptions.Add(FString(TEXT("Multiple Switch")));
  82. }
  83.  
  84.  
  85. const TArray<FExpressionInput*> UMaterialExpressionStaticMultipleSwitch::GetInputs()
  86. {
  87.     TArray<FExpressionInput*> OutInputs;
  88.  
  89.     OutInputs.Add(&Value);
  90.  
  91.     for (int32 i = 0; i < Inputs.Num(); i++)
  92.     {
  93.         OutInputs.Add(&Inputs[i].Input);
  94.     }
  95.  
  96.     return OutInputs;
  97. }
  98.  
  99. FExpressionInput* UMaterialExpressionStaticMultipleSwitch::GetInput(int32 InputIndex)
  100. {
  101.     if (InputIndex == 0)
  102.     {
  103.         return &Value;
  104.     }
  105.  
  106.     return &Inputs[InputIndex - 1].Input;
  107. }
  108.  
  109. FString UMaterialExpressionStaticMultipleSwitch::GetInputName(int32 InputIndex) const
  110. {
  111.     if (InputIndex == 0)
  112.     {
  113.         return TEXT("Value");
  114.     }
  115.  
  116.     if (InputIndex < Inputs.Num())
  117.     {
  118.         return Inputs[InputIndex - 1].InputName;
  119.     }
  120.     return TEXT("");
  121. }
  122.  
  123. #if WITH_EDITOR
  124. uint32 UMaterialExpressionStaticMultipleSwitch::GetInputType(int32 InputIndex)
  125. {
  126.     if (InputIndex == 0)
  127.     {
  128.         return MCT_Float;
  129.     }
  130.     else
  131.     {
  132.         return MCT_Unknown;
  133.     }
  134. }
  135. #endif
  136.  
  137. #if WITH_EDITOR
  138. void UMaterialExpressionStaticMultipleSwitch::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
  139. {
  140.     // strip any spaces from input name
  141.     UProperty* PropertyThatChanged = PropertyChangedEvent.Property;
  142.     if (PropertyThatChanged && PropertyThatChanged->GetFName() == FName(TEXT("InputName")))
  143.     {
  144.         for (int32 i = 0; i<Inputs.Num(); i++)
  145.         {
  146.             Inputs[i].InputName.ReplaceInline(TEXT(" "), TEXT(""));
  147.         }
  148.     }
  149.  
  150.     if (PropertyChangedEvent.MemberProperty)
  151.     {
  152.         const FName PropertyName = PropertyChangedEvent.MemberProperty->GetFName();
  153.         if (PropertyName == GET_MEMBER_NAME_CHECKED(UMaterialExpressionCustom, Inputs))
  154.         {
  155.             if (GraphNode)
  156.             {
  157.                 GraphNode->ReconstructNode();
  158.             }
  159.         }
  160.     }
  161.  
  162.     Super::PostEditChangeProperty(PropertyChangedEvent);
  163. }
  164. #endif // WITH_EDITOR
Advertisement
Add Comment
Please, Sign In to add comment