Skip to content

Commit a601633

Browse files
author
Roberto De Ioris
committed
added FMaterialEditorUtilities
1 parent ff3d43b commit a601633

File tree

7 files changed

+115
-8
lines changed

7 files changed

+115
-8
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
#include "UnrealEnginePythonPrivatePCH.h"
3+
4+
#if WITH_EDITOR
5+
6+
#include "UEPyFMaterialEditorUtilities.h"
7+
8+
9+
10+
11+
static PyObject *py_ue_paste_nodes_here(PyObject *cls, PyObject * args)
12+
{
13+
PyObject *py_graph;
14+
float x;
15+
float y;
16+
17+
if (!PyArg_ParseTuple(args, "O(ff):paste_nodes_here", &py_graph, &x, &y))
18+
return nullptr;
19+
20+
UEdGraph *Graph = ue_py_check_type<UEdGraph>(py_graph);
21+
if (!Graph)
22+
{
23+
return PyErr_Format(PyExc_Exception, "argument is not a UEdGraph");
24+
}
25+
26+
FMaterialEditorUtilities::PasteNodesHere(Graph, FVector2D(x, y));
27+
Py_RETURN_NONE;
28+
}
29+
30+
31+
static PyMethodDef ue_PyFMaterialEditorUtilities_methods[] = {
32+
{ "paste_nodes_here", (PyCFunction)py_ue_paste_nodes_here, METH_VARARGS | METH_CLASS, "" },
33+
{ NULL } /* Sentinel */
34+
};
35+
36+
37+
static PyTypeObject ue_PyFMaterialEditorUtilitiesType = {
38+
PyVarObject_HEAD_INIT(NULL, 0)
39+
"unreal_engine.FMaterialEditorUtilities", /* tp_name */
40+
sizeof(ue_PyFMaterialEditorUtilities), /* tp_basicsize */
41+
0, /* tp_itemsize */
42+
0, /* tp_dealloc */
43+
0, /* tp_print */
44+
0, /* tp_getattr */
45+
0, /* tp_setattr */
46+
0, /* tp_reserved */
47+
0, /* tp_repr */
48+
0, /* tp_as_number */
49+
0, /* tp_as_sequence */
50+
0, /* tp_as_mapping */
51+
0, /* tp_hash */
52+
0, /* tp_call */
53+
0, /* tp_str */
54+
0, /* tp_getattro */
55+
0, /* tp_setattro */
56+
0, /* tp_as_buffer */
57+
Py_TPFLAGS_DEFAULT, /* tp_flags */
58+
"Unreal Engine MaterialEditorUtilities", /* tp_doc */
59+
0, /* tp_traverse */
60+
0, /* tp_clear */
61+
0, /* tp_richcompare */
62+
0, /* tp_weaklistoffset */
63+
0, /* tp_iter */
64+
0, /* tp_iternext */
65+
ue_PyFMaterialEditorUtilities_methods, /* tp_methods */
66+
0,
67+
0,
68+
};
69+
70+
static int py_ue_fmaterial_editor_utilities_init(ue_PyFMaterialEditorUtilities *self, PyObject * args)
71+
{
72+
PyErr_SetString(PyExc_Exception, "FMaterialEditorUtilities is a singleton");
73+
return -1;
74+
}
75+
76+
void ue_python_init_fmaterial_editor_utilities(PyObject *ue_module)
77+
{
78+
ue_PyFMaterialEditorUtilitiesType.tp_new = PyType_GenericNew;
79+
ue_PyFMaterialEditorUtilitiesType.tp_init = (initproc)py_ue_fmaterial_editor_utilities_init;
80+
81+
if (PyType_Ready(&ue_PyFMaterialEditorUtilitiesType) < 0)
82+
return;
83+
84+
Py_INCREF(&ue_PyFMaterialEditorUtilitiesType);
85+
PyModule_AddObject(ue_module, "FMaterialEditorUtilities", (PyObject *)&ue_PyFMaterialEditorUtilitiesType);
86+
}
87+
88+
#endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include "UnrealEnginePython.h"
4+
5+
#if WITH_EDITOR
6+
7+
#include "Editor/MaterialEditor/Public/MaterialEditorUtilities.h"
8+
9+
typedef struct
10+
{
11+
PyObject_HEAD
12+
/* Type-specific fields go here. */
13+
} ue_PyFMaterialEditorUtilities;
14+
15+
void ue_python_init_fmaterial_editor_utilities(PyObject *);
16+
#endif

Source/UnrealEnginePython/Private/Slate/UEPyFModifierKeysState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int ue_py_fmodifier_keys_state_init(ue_PyFModifierKeysState *self, PyObje
116116

117117
void ue_python_init_fmodifier_keys_state(PyObject *ue_module)
118118
{
119-
119+
ue_PyFModifierKeysStateType.tp_new = PyType_GenericNew;
120120
ue_PyFModifierKeysStateType.tp_init = (initproc)ue_py_fmodifier_keys_state_init;
121121

122122
if (PyType_Ready(&ue_PyFModifierKeysStateType) < 0)

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,7 @@ void unreal_engine_init_py_module()
19471947
ue_python_init_fslate_application(new_unreal_engine_module);
19481948

19491949
#if WITH_EDITOR
1950+
ue_python_init_fmaterial_editor_utilities(new_unreal_engine_module);
19501951
ue_python_init_icollection_manager(new_unreal_engine_module);
19511952
#endif
19521953

Source/UnrealEnginePython/Private/UObject/UEPyMaterial.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,16 +455,16 @@ PyObject *py_ue_get_material_graph(ue_PyUObject *self, PyObject * args)
455455

456456
ue_py_check(self);
457457

458-
if (!self->ue_object->IsA<UMaterial>())
459-
{
458+
UMaterial *material = ue_py_check_type<UMaterial>(self);
459+
if (!material)
460460
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInterface");
461-
}
462-
463-
UMaterial *material = (UMaterial *)self->ue_object;
464461

465462
UMaterialGraph *graph = material->MaterialGraph;
466463
if (!graph)
467-
material->MaterialGraph = (UMaterialGraph *)FBlueprintEditorUtils::CreateNewGraph(material, NAME_None, UMaterialGraph::StaticClass(), UMaterialGraphSchema::StaticClass());
464+
{
465+
graph = (UMaterialGraph *)FBlueprintEditorUtils::CreateNewGraph(material, NAME_None, UMaterialGraph::StaticClass(), UMaterialGraphSchema::StaticClass());
466+
material->MaterialGraph = graph;
467+
}
468468
if (!graph)
469469
return PyErr_Format(PyExc_Exception, "Unable to retrieve/allocate MaterialGraph");
470470

Source/UnrealEnginePython/Private/UnrealEnginePythonPrivatePCH.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include "Blueprint/UEPyEdGraphPin.h"
7373
#include "UEPyIPlugin.h"
7474
#include "CollectionManager/UEPyICollectionManager.h"
75+
#include "MaterialEditorUtilities/UEPyFMaterialEditorUtilities.h"
7576
#endif
7677

7778
#include "Slate/UEPySlate.h"

Source/UnrealEnginePython/UnrealEnginePython.Build.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ public UnrealEnginePython(TargetInfo Target)
166166
"FBX",
167167
"Persona",
168168
"PropertyEditor",
169-
"LandscapeEditor"
169+
"LandscapeEditor",
170+
"MaterialEditor"
170171
});
171172
}
172173

0 commit comments

Comments
 (0)