24
#include "PreCompiled.h"
27
#include "MaterialPy.h"
29
#include "MaterialPy.cpp"
31
#include <Base/PyWrapParseTupleAndKeywords.h>
35
Color MaterialPy::toColor(PyObject* value)
38
if (PyTuple_Check(value) && (PyTuple_Size(value) == 3 || PyTuple_Size(value) == 4)) {
40
item = PyTuple_GetItem(value, 0);
41
if (PyFloat_Check(item)) {
42
cCol.r = (float)PyFloat_AsDouble(item);
43
item = PyTuple_GetItem(value, 1);
44
if (PyFloat_Check(item)) {
45
cCol.g = (float)PyFloat_AsDouble(item);
48
throw Base::TypeError("Type in tuple must be consistent (float)");
50
item = PyTuple_GetItem(value, 2);
51
if (PyFloat_Check(item)) {
52
cCol.b = (float)PyFloat_AsDouble(item);
55
throw Base::TypeError("Type in tuple must be consistent (float)");
57
if (PyTuple_Size(value) == 4) {
58
item = PyTuple_GetItem(value, 3);
59
if (PyFloat_Check(item)) {
60
cCol.a = (float)PyFloat_AsDouble(item);
63
throw Base::TypeError("Type in tuple must be consistent (float)");
67
else if (PyLong_Check(item)) {
68
cCol.r = static_cast<float>(PyLong_AsLong(item)) / 255.0F;
69
item = PyTuple_GetItem(value, 1);
70
if (PyLong_Check(item)) {
71
cCol.g = static_cast<float>(PyLong_AsLong(item)) / 255.0F;
74
throw Base::TypeError("Type in tuple must be consistent (integer)");
76
item = PyTuple_GetItem(value, 2);
77
if (PyLong_Check(item)) {
78
cCol.b = static_cast<float>(PyLong_AsLong(item)) / 255.0F;
81
throw Base::TypeError("Type in tuple must be consistent (integer)");
83
if (PyTuple_Size(value) == 4) {
84
item = PyTuple_GetItem(value, 3);
85
if (PyLong_Check(item)) {
86
cCol.a = static_cast<float>(PyLong_AsLong(item)) / 255.0F;
89
throw Base::TypeError("Type in tuple must be consistent (integer)");
94
throw Base::TypeError("Type in tuple must be float or integer");
97
else if (PyLong_Check(value)) {
98
cCol.setPackedValue(PyLong_AsUnsignedLong(value));
102
std::string("type must be integer or tuple of float or tuple integer, not ");
103
error += value->ob_type->tp_name;
104
throw Base::TypeError(error);
110
PyObject* MaterialPy::PyMake(struct _typeobject*, PyObject*, PyObject*)
113
return new MaterialPy(new Material);
117
int MaterialPy::PyInit(PyObject* args, PyObject* kwds)
119
PyObject* diffuse = nullptr;
120
PyObject* ambient = nullptr;
121
PyObject* specular = nullptr;
122
PyObject* emissive = nullptr;
123
PyObject* shininess = nullptr;
124
PyObject* transparency = nullptr;
125
static const std::array<const char*, 7> kwds_colors {"DiffuseColor",
133
if (!Base::Wrapped_ParseTupleAndKeywords(args,
148
setDiffuseColor(Py::Object(diffuse));
152
setAmbientColor(Py::Object(ambient));
156
setSpecularColor(Py::Object(specular));
160
setEmissiveColor(Py::Object(emissive));
164
setShininess(Py::Float(shininess));
168
setTransparency(Py::Float(transparency));
173
catch (const Py::Exception&) {
179
std::string MaterialPy::representation() const
181
return {"<Material object>"};
184
PyObject* MaterialPy::set(PyObject* args)
187
if (!PyArg_ParseTuple(args, "s", &pstr)) {
191
getMaterialPtr()->set(pstr);
196
Py::Object MaterialPy::getAmbientColor() const
199
tuple.setItem(0, Py::Float(getMaterialPtr()->ambientColor.r));
200
tuple.setItem(1, Py::Float(getMaterialPtr()->ambientColor.g));
201
tuple.setItem(2, Py::Float(getMaterialPtr()->ambientColor.b));
202
tuple.setItem(3, Py::Float(getMaterialPtr()->ambientColor.a));
206
void MaterialPy::setAmbientColor(Py::Object arg)
209
getMaterialPtr()->ambientColor = toColor(*arg);
211
catch (const Base::Exception& e) {
213
throw Py::Exception();
217
Py::Object MaterialPy::getDiffuseColor() const
220
tuple.setItem(0, Py::Float(getMaterialPtr()->diffuseColor.r));
221
tuple.setItem(1, Py::Float(getMaterialPtr()->diffuseColor.g));
222
tuple.setItem(2, Py::Float(getMaterialPtr()->diffuseColor.b));
223
tuple.setItem(3, Py::Float(getMaterialPtr()->diffuseColor.a));
227
void MaterialPy::setDiffuseColor(Py::Object arg)
230
getMaterialPtr()->diffuseColor = toColor(*arg);
232
catch (const Base::Exception& e) {
234
throw Py::Exception();
238
Py::Object MaterialPy::getEmissiveColor() const
241
tuple.setItem(0, Py::Float(getMaterialPtr()->emissiveColor.r));
242
tuple.setItem(1, Py::Float(getMaterialPtr()->emissiveColor.g));
243
tuple.setItem(2, Py::Float(getMaterialPtr()->emissiveColor.b));
244
tuple.setItem(3, Py::Float(getMaterialPtr()->emissiveColor.a));
248
void MaterialPy::setEmissiveColor(Py::Object arg)
251
getMaterialPtr()->emissiveColor = toColor(*arg);
253
catch (const Base::Exception& e) {
255
throw Py::Exception();
259
Py::Object MaterialPy::getSpecularColor() const
262
tuple.setItem(0, Py::Float(getMaterialPtr()->specularColor.r));
263
tuple.setItem(1, Py::Float(getMaterialPtr()->specularColor.g));
264
tuple.setItem(2, Py::Float(getMaterialPtr()->specularColor.b));
265
tuple.setItem(3, Py::Float(getMaterialPtr()->specularColor.a));
269
void MaterialPy::setSpecularColor(Py::Object arg)
272
getMaterialPtr()->specularColor = toColor(*arg);
274
catch (const Base::Exception& e) {
276
throw Py::Exception();
280
Py::Float MaterialPy::getShininess() const
282
return Py::Float(getMaterialPtr()->shininess);
285
void MaterialPy::setShininess(Py::Float arg)
287
getMaterialPtr()->shininess = arg;
290
Py::Float MaterialPy::getTransparency() const
292
return Py::Float(getMaterialPtr()->transparency);
295
void MaterialPy::setTransparency(Py::Float arg)
297
getMaterialPtr()->transparency = arg;
300
PyObject* MaterialPy::getCustomAttributes(const char* ) const
305
int MaterialPy::setCustomAttributes(const char* , PyObject* )