Skip to content

Commit 967e2db

Browse files
author
Roberto De Ioris
committed
added static_mesh_set_collision_for_lod and static_mesh_set_shadow_for_lod
1 parent 18062da commit 967e2db

File tree

3 files changed

+150
-81
lines changed

3 files changed

+150
-81
lines changed

Source/UnrealEnginePython/Private/UEPyMaterial.cpp

Lines changed: 144 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,125 +2,189 @@
22

33
#include "UnrealEnginePythonPrivatePCH.h"
44

5-
PyObject *py_ue_set_scalar_parameter( ue_PyUObject *self , PyObject * args ) {
5+
PyObject *py_ue_set_scalar_parameter(ue_PyUObject *self, PyObject * args) {
66

7-
ue_py_check( self );
7+
ue_py_check(self);
88

9-
if ( !self->ue_object->IsA<UMaterialInstanceConstant>() ) {
10-
return PyErr_Format( PyExc_Exception, "uobject is not a UMaterialInstanceConstant" );
11-
}
9+
if (!self->ue_object->IsA<UMaterialInstanceConstant>()) {
10+
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInstanceConstant");
11+
}
1212

13-
char *scalarName = nullptr;
14-
float scalarValue = 0;
15-
if ( !PyArg_ParseTuple( args, "sf:set_scalar_parameter", &scalarName, &scalarValue ) ) {
16-
return NULL;
17-
}
13+
char *scalarName = nullptr;
14+
float scalarValue = 0;
15+
if (!PyArg_ParseTuple(args, "sf:set_scalar_parameter", &scalarName, &scalarValue)) {
16+
return NULL;
17+
}
1818

19-
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
19+
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
2020

21-
FName parameterName(UTF8_TO_TCHAR( scalarName ));
22-
material_instance->SetScalarParameterValueEditorOnly( parameterName, scalarValue );
21+
FName parameterName(UTF8_TO_TCHAR(scalarName));
22+
material_instance->SetScalarParameterValueEditorOnly(parameterName, scalarValue);
2323

24-
Py_INCREF( Py_None );
25-
return Py_None;
24+
Py_INCREF(Py_None);
25+
return Py_None;
2626

2727
}
2828

29-
PyObject *py_ue_set_vector_parameter( ue_PyUObject *self, PyObject * args ) {
30-
ue_py_check( self );
29+
PyObject *py_ue_set_vector_parameter(ue_PyUObject *self, PyObject * args) {
30+
ue_py_check(self);
3131

32-
if ( !self->ue_object->IsA<UMaterialInstanceConstant>() ) {
33-
return PyErr_Format( PyExc_Exception, "uobject is not a UMaterialInstanceConstant" );
34-
}
32+
if (!self->ue_object->IsA<UMaterialInstanceConstant>()) {
33+
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInstanceConstant");
34+
}
3535

36-
char *vectorName;
37-
PyObject *vectorValue = nullptr;
38-
if ( !PyArg_ParseTuple( args, "sO:set_vector_parameter", &vectorName, &vectorValue ) ) {
39-
return NULL;
40-
}
36+
char *vectorName;
37+
PyObject *vectorValue = nullptr;
38+
if (!PyArg_ParseTuple(args, "sO:set_vector_parameter", &vectorName, &vectorValue)) {
39+
return NULL;
40+
}
4141

42-
FVector vectorParameter( 0, 0, 0 );
42+
FVector vectorParameter(0, 0, 0);
4343

44-
if ( vectorValue ) {
45-
ue_PyFVector *py_vector = py_ue_is_fvector( vectorValue );
46-
if ( !py_vector )
47-
return PyErr_Format( PyExc_Exception, "argument must be an FVector" );
48-
vectorParameter = py_vector->vec;
49-
}
44+
if (vectorValue) {
45+
ue_PyFVector *py_vector = py_ue_is_fvector(vectorValue);
46+
if (!py_vector)
47+
return PyErr_Format(PyExc_Exception, "argument must be an FVector");
48+
vectorParameter = py_vector->vec;
49+
}
5050

51-
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
51+
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
5252

53-
FName parameterName( UTF8_TO_TCHAR( vectorName ) );
54-
material_instance->SetVectorParameterValueEditorOnly( parameterName, FLinearColor( vectorParameter) );
53+
FName parameterName(UTF8_TO_TCHAR(vectorName));
54+
material_instance->SetVectorParameterValueEditorOnly(parameterName, FLinearColor(vectorParameter));
5555

56-
Py_INCREF( Py_None );
57-
return Py_None;
56+
Py_INCREF(Py_None);
57+
return Py_None;
5858

5959

6060
}
61-
PyObject *py_ue_set_texture_parameter( ue_PyUObject *self, PyObject * args ) {
62-
ue_py_check( self );
61+
PyObject *py_ue_set_texture_parameter(ue_PyUObject *self, PyObject * args) {
62+
ue_py_check(self);
6363

64-
if ( !self->ue_object->IsA<UMaterialInstanceConstant>() ) {
65-
return PyErr_Format( PyExc_Exception, "uobject is not a UMaterialInstanceConstant" );
66-
}
64+
if (!self->ue_object->IsA<UMaterialInstanceConstant>()) {
65+
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInstanceConstant");
66+
}
6767

68-
char *textureName;
69-
PyObject *textureObject = nullptr;
70-
if ( !PyArg_ParseTuple( args, "sO:set_texture_parameter", &textureName, &textureObject ) ) {
71-
return NULL;
72-
}
68+
char *textureName;
69+
PyObject *textureObject = nullptr;
70+
if (!PyArg_ParseTuple(args, "sO:set_texture_parameter", &textureName, &textureObject)) {
71+
return NULL;
72+
}
7373

74-
if ( !ue_is_pyuobject( textureObject ) ) {
75-
return PyErr_Format( PyExc_Exception, "argument is not a UObject" );
76-
}
74+
if (!ue_is_pyuobject(textureObject)) {
75+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
76+
}
7777

78-
ue_PyUObject *py_obj = (ue_PyUObject *)textureObject;
79-
if ( !py_obj->ue_object->IsA<UTexture>() )
80-
return PyErr_Format( PyExc_Exception, "uobject is not a UTexture" );
78+
ue_PyUObject *py_obj = (ue_PyUObject *)textureObject;
79+
if (!py_obj->ue_object->IsA<UTexture>())
80+
return PyErr_Format(PyExc_Exception, "uobject is not a UTexture");
8181

82-
UTexture *ue_texture = (UTexture *)py_obj->ue_object;
82+
UTexture *ue_texture = (UTexture *)py_obj->ue_object;
8383

84-
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
84+
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
8585

86-
FName parameterName( UTF8_TO_TCHAR( textureName ) );
87-
material_instance->SetTextureParameterValueEditorOnly( parameterName, ue_texture );
86+
FName parameterName(UTF8_TO_TCHAR(textureName));
87+
material_instance->SetTextureParameterValueEditorOnly(parameterName, ue_texture);
8888

89-
Py_INCREF( Py_None );
90-
return Py_None;
89+
Py_INCREF(Py_None);
90+
return Py_None;
9191
}
9292

93-
PyObject *py_ue_set_parent( ue_PyUObject *self, PyObject * args ) {
93+
PyObject *py_ue_set_parent(ue_PyUObject *self, PyObject * args) {
9494

95-
ue_py_check( self );
95+
ue_py_check(self);
9696

97-
if ( !self->ue_object->IsA<UMaterialInstanceConstant>() ) {
98-
return PyErr_Format( PyExc_Exception, "uobject is not a UMaterialInstanceConstant" );
99-
}
97+
if (!self->ue_object->IsA<UMaterialInstanceConstant>()) {
98+
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInstanceConstant");
99+
}
100100

101-
PyObject *py_material = nullptr;
101+
PyObject *py_material = nullptr;
102102

103-
if ( !PyArg_ParseTuple( args, "O:set_parent", &py_material ) ) {
104-
return NULL;
105-
}
103+
if (!PyArg_ParseTuple(args, "O:set_parent", &py_material)) {
104+
return NULL;
105+
}
106106

107-
if ( !ue_is_pyuobject( py_material ) ) {
108-
return PyErr_Format( PyExc_Exception, "argument is not a UObject" );
109-
}
107+
if (!ue_is_pyuobject(py_material)) {
108+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
109+
}
110110

111-
ue_PyUObject *py_obj = (ue_PyUObject *)py_material;
112-
if ( !py_obj->ue_object->IsA<UMaterialInterface>() )
113-
return PyErr_Format( PyExc_Exception, "uobject is not a UMaterialInterface" );
111+
ue_PyUObject *py_obj = (ue_PyUObject *)py_material;
112+
if (!py_obj->ue_object->IsA<UMaterialInterface>())
113+
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInterface");
114114

115115

116-
UMaterialInterface *materialInterface = (UMaterialInterface *)py_obj->ue_object;
117-
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
118-
material_instance->SetParentEditorOnly( materialInterface );
119-
material_instance->PostEditChange();
116+
UMaterialInterface *materialInterface = (UMaterialInterface *)py_obj->ue_object;
117+
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
118+
material_instance->SetParentEditorOnly(materialInterface);
119+
material_instance->PostEditChange();
120120

121-
Py_INCREF( Py_None );
122-
return Py_None;
121+
Py_INCREF(Py_None);
122+
return Py_None;
123123

124124
}
125125

126+
PyObject *py_ue_static_mesh_set_collision_for_lod(ue_PyUObject *self, PyObject * args) {
127+
ue_py_check(self);
128+
129+
int lod_index;
130+
int material_index;
131+
PyObject *py_bool;
132+
if (!PyArg_ParseTuple(args, "iiO:static_mesh_set_collision_for_lod", &lod_index, &material_index, &py_bool)) {
133+
return NULL;
134+
}
135+
136+
137+
if (!self->ue_object->IsA<UStaticMesh>()) {
138+
return PyErr_Format(PyExc_Exception, "uobject is not a StaticMesh");
139+
}
140+
141+
UStaticMesh *mesh = (UStaticMesh *)self->ue_object;
142+
143+
bool enabled = false;
144+
if (PyObject_IsTrue(py_bool)) {
145+
enabled = true;
146+
}
147+
148+
FMeshSectionInfo info = mesh->SectionInfoMap.Get(lod_index, material_index);
149+
info.bEnableCollision = enabled;
150+
mesh->SectionInfoMap.Set(lod_index, material_index, info);
151+
152+
mesh->MarkPackageDirty();
153+
154+
Py_INCREF(Py_None);
155+
return Py_None;
156+
}
157+
158+
PyObject *py_ue_static_mesh_set_shadow_for_lod(ue_PyUObject *self, PyObject * args) {
159+
ue_py_check(self);
160+
161+
int lod_index;
162+
int material_index;
163+
PyObject *py_bool;
164+
if (!PyArg_ParseTuple(args, "iiO:static_mesh_set_shadow_for_lod", &lod_index, &material_index, &py_bool)) {
165+
return NULL;
166+
}
167+
168+
169+
if (!self->ue_object->IsA<UStaticMesh>()) {
170+
return PyErr_Format(PyExc_Exception, "uobject is not a StaticMesh");
171+
}
172+
173+
UStaticMesh *mesh = (UStaticMesh *)self->ue_object;
174+
175+
bool enabled = false;
176+
if (PyObject_IsTrue(py_bool)) {
177+
enabled = true;
178+
}
179+
180+
FMeshSectionInfo info = mesh->SectionInfoMap.Get(lod_index, material_index);
181+
info.bCastShadow = enabled;
182+
mesh->SectionInfoMap.Set(lod_index, material_index, info);
183+
184+
mesh->MarkPackageDirty();
185+
186+
Py_INCREF(Py_None);
187+
return Py_None;
188+
}
189+
126190
#endif

Source/UnrealEnginePython/Private/UEPyMaterial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ PyObject *py_ue_set_texture_parameter( ue_PyUObject *, PyObject * );
1010

1111
PyObject *py_ue_set_parent( ue_PyUObject *, PyObject * );
1212

13+
PyObject *py_ue_static_mesh_set_collision_for_lod(ue_PyUObject *, PyObject *);
14+
PyObject *py_ue_static_mesh_set_shadow_for_lod(ue_PyUObject *, PyObject *);
15+
1316
#endif

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,9 @@ static PyMethodDef ue_PyUObject_methods[] = {
473473
{ "set_scalar_parameter", (PyCFunction)py_ue_set_scalar_parameter, METH_VARARGS, "" },
474474
{ "set_vector_parameter", (PyCFunction)py_ue_set_vector_parameter, METH_VARARGS, "" },
475475
{ "set_texture_parameter", (PyCFunction)py_ue_set_texture_parameter, METH_VARARGS, "" },
476-
{ "set_parent", (PyCFunction)py_ue_set_parent, METH_VARARGS, "" },
476+
{ "set_parent", (PyCFunction)py_ue_set_parent, METH_VARARGS, "" },
477+
{ "static_mesh_set_collision_for_lod", (PyCFunction)py_ue_static_mesh_set_collision_for_lod, METH_VARARGS, "" },
478+
{ "static_mesh_set_shadow_for_lod", (PyCFunction)py_ue_static_mesh_set_shadow_for_lod, METH_VARARGS, "" },
477479
#endif
478480

479481

0 commit comments

Comments
 (0)