|
| 1 | +```python |
| 2 | +import unreal_engine as ue |
| 3 | +from unreal_engine.classes import MaterialFactoryNew |
| 4 | +from unreal_engine.classes import MaterialExpressionStaticSwitch, MaterialExpressionStaticSwitchParameter, MaterialExpressionVectorParameter |
| 5 | +from unreal_engine.structs import ColorMaterialInput, ExpressionInput |
| 6 | +import time |
| 7 | + |
| 8 | +material_factory = MaterialFactoryNew() |
| 9 | +material = material_factory.factory_create_new('/Game/Materials/Test' + str(int(time.time()))) |
| 10 | + |
| 11 | +material.modify() |
| 12 | + |
| 13 | +static_switch_node = MaterialExpressionStaticSwitch('', material) |
| 14 | +static_switch_node.MaterialExpressionEditorX = -200 |
| 15 | +static_switch_node.MaterialExpressionEditorY = 50 |
| 16 | + |
| 17 | +static_switch_parameter_node_true = MaterialExpressionStaticSwitchParameter('', material) |
| 18 | +static_switch_parameter_node_true.MaterialExpressionEditorX = -400 |
| 19 | +static_switch_parameter_node_true.MaterialExpressionEditorY = 0 |
| 20 | +static_switch_parameter_node_true.ParameterName = 'True' |
| 21 | + |
| 22 | +static_switch_parameter_node_false = MaterialExpressionStaticSwitchParameter('', material) |
| 23 | +static_switch_parameter_node_false.MaterialExpressionEditorX = -400 |
| 24 | +static_switch_parameter_node_false.MaterialExpressionEditorY = 200 |
| 25 | +static_switch_parameter_node_false.ParameterName = 'False' |
| 26 | + |
| 27 | +static_switch_node.A = ExpressionInput(Expression=static_switch_parameter_node_true) |
| 28 | +static_switch_node.B = ExpressionInput(Expression=static_switch_parameter_node_false) |
| 29 | + |
| 30 | +vector_parameter_one = MaterialExpressionVectorParameter('', material) |
| 31 | +vector_parameter_one.MaterialExpressionEditorX = -600 |
| 32 | +vector_parameter_one.MaterialExpressionEditorY = -150 |
| 33 | +vector_parameter_one.ParameterName = 'One' |
| 34 | + |
| 35 | +vector_parameter_two = MaterialExpressionVectorParameter('', material) |
| 36 | +vector_parameter_two.MaterialExpressionEditorX = -800 |
| 37 | +vector_parameter_two.MaterialExpressionEditorY = -50 |
| 38 | +vector_parameter_two.ParameterName = 'Two' |
| 39 | + |
| 40 | +vector_parameter_three = MaterialExpressionVectorParameter('', material) |
| 41 | +vector_parameter_three.MaterialExpressionEditorX = -600 |
| 42 | +vector_parameter_three.MaterialExpressionEditorY = 150 |
| 43 | +vector_parameter_three.ParameterName = 'Three' |
| 44 | + |
| 45 | +vector_parameter_four = MaterialExpressionVectorParameter('', material) |
| 46 | +vector_parameter_four.MaterialExpressionEditorX = -800 |
| 47 | +vector_parameter_four.MaterialExpressionEditorY = 250 |
| 48 | +vector_parameter_four.ParameterName = 'Four' |
| 49 | + |
| 50 | + |
| 51 | +static_switch_parameter_node_true.A = ExpressionInput(Expression=vector_parameter_one) |
| 52 | +static_switch_parameter_node_true.B = ExpressionInput(Expression=vector_parameter_two) |
| 53 | + |
| 54 | +static_switch_parameter_node_false.A = ExpressionInput(Expression=vector_parameter_three) |
| 55 | +static_switch_parameter_node_false.B = ExpressionInput(Expression=vector_parameter_four) |
| 56 | + |
| 57 | +material.BaseColor = ColorMaterialInput(Expression=static_switch_node) |
| 58 | + |
| 59 | +material.Expressions = [ |
| 60 | + static_switch_node, |
| 61 | + static_switch_parameter_node_true, |
| 62 | + static_switch_parameter_node_false, |
| 63 | + vector_parameter_one, |
| 64 | + vector_parameter_two, |
| 65 | + vector_parameter_three, |
| 66 | + vector_parameter_four |
| 67 | + ] |
| 68 | + |
| 69 | +material.post_edit_change() |
| 70 | + |
| 71 | +ue.open_editor_for_asset(material) |
| 72 | +``` |
0 commit comments