2008-08-01 02:25:21 +00:00
|
|
|
#include "BPy_FrsMaterial.h"
|
2008-07-31 11:59:06 +00:00
|
|
|
|
|
|
|
|
#include "BPy_Convert.h"
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
|
|
2008-07-31 11:59:06 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//-------------------MODULE INITIALIZATION--------------------------------
|
2009-09-27 00:32:20 +00:00
|
|
|
int FrsMaterial_Init( PyObject *module )
|
2008-07-31 11:59:06 +00:00
|
|
|
{
|
|
|
|
|
if( module == NULL )
|
2009-09-27 00:32:20 +00:00
|
|
|
return -1;
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2008-08-01 02:25:21 +00:00
|
|
|
if( PyType_Ready( &FrsMaterial_Type ) < 0 )
|
2009-09-27 00:32:20 +00:00
|
|
|
return -1;
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2008-08-01 02:25:21 +00:00
|
|
|
Py_INCREF( &FrsMaterial_Type );
|
2010-05-09 18:05:33 +00:00
|
|
|
PyModule_AddObject(module, "Material", (PyObject *)&FrsMaterial_Type);
|
2013-02-03 17:01:21 +00:00
|
|
|
|
|
|
|
|
FrsMaterial_mathutils_register_callback();
|
2009-09-27 00:32:20 +00:00
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------INSTANCE METHODS ----------------------------------
|
|
|
|
|
|
2010-04-17 23:47:47 +00:00
|
|
|
static char FrsMaterial___doc__[] =
|
|
|
|
|
"Class defining a material.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
".. method:: __init__()\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" Default constructor.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
".. method:: __init__(m)\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" Copy constructor.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" :arg m: A Material object.\n"
|
2010-05-09 18:05:33 +00:00
|
|
|
" :type m: :class:`Material`\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
"\n"
|
|
|
|
|
".. method:: __init__(iDiffuse, iAmbiant, iSpecular, iEmission, iShininess)\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" Builds a Material from its diffuse, ambiant, specular, emissive\n"
|
|
|
|
|
" colors and a shininess coefficient.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" :arg iDiffuse: The diffuse color.\n"
|
2013-01-09 00:20:48 +00:00
|
|
|
" :type iDiffuse: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
" :arg iAmbiant: The ambiant color.\n"
|
2013-01-09 00:20:48 +00:00
|
|
|
" :type iAmbiant: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
" :arg iSpecular: The specular color.\n"
|
2013-01-09 00:20:48 +00:00
|
|
|
" :type iSpecular: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
" :arg iEmission: The emissive color.\n"
|
2013-01-09 00:20:48 +00:00
|
|
|
" :type iEmission: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
" :arg iShininess: The shininess coefficient.\n"
|
2013-01-09 00:20:48 +00:00
|
|
|
" :type iShininess: :class:float\n";
|
2010-04-17 23:47:47 +00:00
|
|
|
|
2009-08-02 17:38:51 +00:00
|
|
|
static int Vec4(PyObject *obj, float *v)
|
|
|
|
|
{
|
|
|
|
|
if (VectorObject_Check(obj) && ((VectorObject *)obj)->size == 4) {
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
v[i] = ((VectorObject *)obj)->vec[i];
|
|
|
|
|
} else if( PyList_Check(obj) && PyList_Size(obj) == 4 ) {
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
v[i] = PyFloat_AsDouble(PyList_GetItem(obj, i));
|
|
|
|
|
} else if( PyTuple_Check(obj) && PyTuple_Size(obj) == 4 ) {
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
v[i] = PyFloat_AsDouble(PyTuple_GetItem(obj, i));
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-17 23:47:47 +00:00
|
|
|
static int FrsMaterial___init__(BPy_FrsMaterial *self, PyObject *args, PyObject *kwds)
|
2008-07-31 11:59:06 +00:00
|
|
|
{
|
2009-08-02 17:38:51 +00:00
|
|
|
PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0;
|
|
|
|
|
float f1[4], f2[4], f3[4], f4[4], f5 = 0.;
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2009-08-02 17:38:51 +00:00
|
|
|
if (! PyArg_ParseTuple(args, "|OOOOf", &obj1, &obj2, &obj3, &obj4, &f5) )
|
2008-07-31 11:59:06 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if( !obj1 ){
|
2008-08-07 15:04:25 +00:00
|
|
|
self->m = new FrsMaterial();
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2009-08-02 17:38:51 +00:00
|
|
|
} else if( BPy_FrsMaterial_Check(obj1) && !obj2 ) {
|
|
|
|
|
FrsMaterial *m = ((BPy_FrsMaterial *) obj1)->m;
|
|
|
|
|
if( !m ) {
|
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "invalid FrsMaterial object");
|
2008-07-31 11:59:06 +00:00
|
|
|
return -1;
|
2009-08-02 17:38:51 +00:00
|
|
|
}
|
|
|
|
|
self->m = new FrsMaterial( *m );
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2009-08-02 17:38:51 +00:00
|
|
|
} else if( Vec4(obj1, f1) && obj2 && Vec4(obj2, f2) && obj3 && Vec4(obj3, f3) && obj4 && Vec4(obj4, f4) ) {
|
|
|
|
|
self->m = new FrsMaterial(f1, f2, f3, f4, f5);
|
2008-07-31 11:59:06 +00:00
|
|
|
|
|
|
|
|
} else {
|
2009-08-02 17:38:51 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
|
2008-07-31 11:59:06 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
SWIG/directors dependency removal (cont'd)
* Added to python/BPy_Convert.{cpp,h} 4 utility converters below for
better introspection-based automatic type conversion.
PyObject * Any_BPy_Interface0D_from_Interface0D( Interface0D& if0D );
PyObject * Any_BPy_Interface1D_from_Interface1D( Interface1D& if1D );
PyObject * Any_BPy_FEdge_from_FEdge( FEdge& fe );
PyObject * Any_BPy_ViewVertex_from_ViewVertex( ViewVertex& vv );
There are 4 corresponding converters without the "Any_" prefix. All
calls of them in the code base were replaced with these new converters
so that the introspection-based automatic conversion would take place
universally.
* python/BPy_Convert.{cpp,h}: Those C++ to Python converters having
had a "_ptr" suffix were renamed to a name without the suffix, and
their arguments were changed so as to take a reference (e.g.,
ViewVertex&) instead of a pointer (e.g., ViewVertex *). The changed
converters and their new function prototypes are listed below. These
converters now return a Python wrapper object that retains the passed
reference, instead of retaining a newly created C++ object by the
converters.
// Interface0D converters
PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D );
PyObject * BPy_CurvePoint_from_CurvePoint( CurvePoint& cp );
PyObject * BPy_StrokeVertex_from_StrokeVertex( StrokeVertex& sv );
PyObject * BPy_SVertex_from_SVertex( SVertex& sv );
PyObject * BPy_ViewVertex_from_ViewVertex( ViewVertex& vv );
PyObject * BPy_TVertex_from_TVertex( TVertex& tv );
PyObject * BPy_NonTVertex_from_NonTVertex( NonTVertex& ntv );
// Interface1D converters
PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D );
PyObject * BPy_Chain_from_Chain( Chain& c );
PyObject * BPy_FEdge_from_FEdge( FEdge& fe );
PyObject * BPy_FEdgeSharp_from_FEdgeSharp( FEdgeSharp& fes );
PyObject * BPy_FEdgeSmooth_from_FEdgeSmooth( FEdgeSmooth& fes );
PyObject * BPy_Stroke_from_Stroke( Stroke& s );
PyObject * BPy_ViewEdge_from_ViewEdge( ViewEdge& ve );
PyObject * BPy_directedViewEdge_from_directedViewEdge( ViewVertex::directedViewEdge& dve );
// some other converters
PyObject * BPy_ViewShape_from_ViewShape( ViewShape& vs );
PyObject * BPy_SShape_from_SShape( SShape& ss );
PyObject * BPy_FrsMaterial_from_FrsMaterial( FrsMaterial& m );
PyObject * BPy_StrokeAttribute_from_StrokeAttribute( StrokeAttribute& sa );
* Added a "borrowed" flag to the definitions of Python types being
used to wrap C++ components of Freestyle's internal data structures.
The flag indicates whether or not a Python wrapper object has a
reference to a C++ object that comprises the internal data structures.
The deallocation routines of the Python types check this flag and
release a wrapped C++ object only when it is not part of the internal
data structures. The following files were modified:
python/BPy_FrsMaterial.{cpp,h}
python/BPy_Interface0D.{cpp,h}
python/BPy_Interface1D.{cpp,h}
python/BPy_SShape.{cpp,h}
python/BPy_StrokeAttribute.{cpp,h}
python/BPy_ViewShape.{cpp,h}
python/Interface0D/BPy_CurvePoint.cpp
python/Interface0D/BPy_SVertex.cpp
python/Interface0D/BPy_ViewVertex.cpp
python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
python/Interface0D/ViewVertex/BPy_NonTVertex.cpp
python/Interface0D/ViewVertex/BPy_TVertex.cpp
python/Interface1D/BPy_FEdge.cpp
python/Interface1D/BPy_FrsCurve.cpp
python/Interface1D/BPy_Stroke.cpp
python/Interface1D/BPy_ViewEdge.cpp
python/Interface1D/Curve/BPy_Chain.cpp
python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
* view_map/Interface[01]D.h, python/BPy_Interface[01]D.cpp: Removed
from the Interface0D and Interface1D C++ classes a back pointer to a
Python wrapper object and all "director" calls. These classes (and
their subclasses) are used to build Freestyle's main data structures
(such as a view map and strokes) and their class hierarchy is static.
Python wrappers of these C++ classes are only used to access the data
structures from the Python layer, and not intended to extend the data
structures by subclassing the Python wrappers. Without the necessity
of subclassing in the Python layer, the back pointer to a wrapping
Python object and "director" calls would be useless (actually they
were not used at all), so they were all removed.
* python/Director.{cpp,h}: Removed the definitions of directors that
were no longer used.
* stroke/Stroke.{cpp,h}: Removed an (unused) back pointer to a Python
wrapper object.
* python/BPy_ViewMap.cpp: Fixed a possible null pointer reference.
* python/Interface1D/BPy_FEdge.cpp: Fixed parameter checking in
FEdge___init__().
2009-08-02 16:23:18 +00:00
|
|
|
self->borrowed = 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-17 23:47:47 +00:00
|
|
|
static void FrsMaterial___dealloc__( BPy_FrsMaterial* self)
|
2008-07-31 11:59:06 +00:00
|
|
|
{
|
SWIG/directors dependency removal (cont'd)
* Added to python/BPy_Convert.{cpp,h} 4 utility converters below for
better introspection-based automatic type conversion.
PyObject * Any_BPy_Interface0D_from_Interface0D( Interface0D& if0D );
PyObject * Any_BPy_Interface1D_from_Interface1D( Interface1D& if1D );
PyObject * Any_BPy_FEdge_from_FEdge( FEdge& fe );
PyObject * Any_BPy_ViewVertex_from_ViewVertex( ViewVertex& vv );
There are 4 corresponding converters without the "Any_" prefix. All
calls of them in the code base were replaced with these new converters
so that the introspection-based automatic conversion would take place
universally.
* python/BPy_Convert.{cpp,h}: Those C++ to Python converters having
had a "_ptr" suffix were renamed to a name without the suffix, and
their arguments were changed so as to take a reference (e.g.,
ViewVertex&) instead of a pointer (e.g., ViewVertex *). The changed
converters and their new function prototypes are listed below. These
converters now return a Python wrapper object that retains the passed
reference, instead of retaining a newly created C++ object by the
converters.
// Interface0D converters
PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D );
PyObject * BPy_CurvePoint_from_CurvePoint( CurvePoint& cp );
PyObject * BPy_StrokeVertex_from_StrokeVertex( StrokeVertex& sv );
PyObject * BPy_SVertex_from_SVertex( SVertex& sv );
PyObject * BPy_ViewVertex_from_ViewVertex( ViewVertex& vv );
PyObject * BPy_TVertex_from_TVertex( TVertex& tv );
PyObject * BPy_NonTVertex_from_NonTVertex( NonTVertex& ntv );
// Interface1D converters
PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D );
PyObject * BPy_Chain_from_Chain( Chain& c );
PyObject * BPy_FEdge_from_FEdge( FEdge& fe );
PyObject * BPy_FEdgeSharp_from_FEdgeSharp( FEdgeSharp& fes );
PyObject * BPy_FEdgeSmooth_from_FEdgeSmooth( FEdgeSmooth& fes );
PyObject * BPy_Stroke_from_Stroke( Stroke& s );
PyObject * BPy_ViewEdge_from_ViewEdge( ViewEdge& ve );
PyObject * BPy_directedViewEdge_from_directedViewEdge( ViewVertex::directedViewEdge& dve );
// some other converters
PyObject * BPy_ViewShape_from_ViewShape( ViewShape& vs );
PyObject * BPy_SShape_from_SShape( SShape& ss );
PyObject * BPy_FrsMaterial_from_FrsMaterial( FrsMaterial& m );
PyObject * BPy_StrokeAttribute_from_StrokeAttribute( StrokeAttribute& sa );
* Added a "borrowed" flag to the definitions of Python types being
used to wrap C++ components of Freestyle's internal data structures.
The flag indicates whether or not a Python wrapper object has a
reference to a C++ object that comprises the internal data structures.
The deallocation routines of the Python types check this flag and
release a wrapped C++ object only when it is not part of the internal
data structures. The following files were modified:
python/BPy_FrsMaterial.{cpp,h}
python/BPy_Interface0D.{cpp,h}
python/BPy_Interface1D.{cpp,h}
python/BPy_SShape.{cpp,h}
python/BPy_StrokeAttribute.{cpp,h}
python/BPy_ViewShape.{cpp,h}
python/Interface0D/BPy_CurvePoint.cpp
python/Interface0D/BPy_SVertex.cpp
python/Interface0D/BPy_ViewVertex.cpp
python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
python/Interface0D/ViewVertex/BPy_NonTVertex.cpp
python/Interface0D/ViewVertex/BPy_TVertex.cpp
python/Interface1D/BPy_FEdge.cpp
python/Interface1D/BPy_FrsCurve.cpp
python/Interface1D/BPy_Stroke.cpp
python/Interface1D/BPy_ViewEdge.cpp
python/Interface1D/Curve/BPy_Chain.cpp
python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
* view_map/Interface[01]D.h, python/BPy_Interface[01]D.cpp: Removed
from the Interface0D and Interface1D C++ classes a back pointer to a
Python wrapper object and all "director" calls. These classes (and
their subclasses) are used to build Freestyle's main data structures
(such as a view map and strokes) and their class hierarchy is static.
Python wrappers of these C++ classes are only used to access the data
structures from the Python layer, and not intended to extend the data
structures by subclassing the Python wrappers. Without the necessity
of subclassing in the Python layer, the back pointer to a wrapping
Python object and "director" calls would be useless (actually they
were not used at all), so they were all removed.
* python/Director.{cpp,h}: Removed the definitions of directors that
were no longer used.
* stroke/Stroke.{cpp,h}: Removed an (unused) back pointer to a Python
wrapper object.
* python/BPy_ViewMap.cpp: Fixed a possible null pointer reference.
* python/Interface1D/BPy_FEdge.cpp: Fixed parameter checking in
FEdge___init__().
2009-08-02 16:23:18 +00:00
|
|
|
if( self->m && !self->borrowed )
|
|
|
|
|
delete self->m;
|
2009-09-27 00:32:20 +00:00
|
|
|
Py_TYPE(self)->tp_free((PyObject*)self);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-04-17 23:47:47 +00:00
|
|
|
static PyObject * FrsMaterial___repr__( BPy_FrsMaterial* self)
|
2008-07-31 11:59:06 +00:00
|
|
|
{
|
2010-05-09 18:05:33 +00:00
|
|
|
return PyUnicode_FromFormat("Material - address: %p", self->m );
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
/*----------------------FrsMaterial instance definitions ----------------------------*/
|
|
|
|
|
static PyMethodDef BPy_FrsMaterial_methods[] = {
|
|
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
|
};
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
/*----------------------mathutils callbacks ----------------------------*/
|
2010-04-17 23:47:47 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
/* subtype */
|
|
|
|
|
#define MATHUTILS_SUBTYPE_DIFFUSE 1
|
|
|
|
|
#define MATHUTILS_SUBTYPE_SPECULAR 2
|
|
|
|
|
#define MATHUTILS_SUBTYPE_AMBIENT 3
|
|
|
|
|
#define MATHUTILS_SUBTYPE_EMISSION 4
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_mathutils_check(BaseMathObject *bmo)
|
|
|
|
|
{
|
|
|
|
|
if (!BPy_FrsMaterial_Check(bmo->cb_user))
|
|
|
|
|
return -1;
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_mathutils_get(BaseMathObject *bmo, int subtype)
|
|
|
|
|
{
|
|
|
|
|
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
|
|
|
|
|
switch (subtype) {
|
|
|
|
|
case MATHUTILS_SUBTYPE_DIFFUSE:
|
|
|
|
|
bmo->data[0] = self->m->diffuseR();
|
|
|
|
|
bmo->data[1] = self->m->diffuseG();
|
|
|
|
|
bmo->data[2] = self->m->diffuseB();
|
|
|
|
|
bmo->data[3] = self->m->diffuseA();
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_SPECULAR:
|
|
|
|
|
bmo->data[0] = self->m->specularR();
|
|
|
|
|
bmo->data[1] = self->m->specularG();
|
|
|
|
|
bmo->data[2] = self->m->specularB();
|
|
|
|
|
bmo->data[3] = self->m->specularA();
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_AMBIENT:
|
|
|
|
|
bmo->data[0] = self->m->ambientR();
|
|
|
|
|
bmo->data[1] = self->m->ambientG();
|
|
|
|
|
bmo->data[2] = self->m->ambientB();
|
|
|
|
|
bmo->data[3] = self->m->ambientA();
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_EMISSION:
|
|
|
|
|
bmo->data[0] = self->m->emissionR();
|
|
|
|
|
bmo->data[1] = self->m->emissionG();
|
|
|
|
|
bmo->data[2] = self->m->emissionB();
|
|
|
|
|
bmo->data[3] = self->m->emissionA();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_mathutils_set(BaseMathObject *bmo, int subtype)
|
|
|
|
|
{
|
|
|
|
|
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
|
|
|
|
|
switch (subtype) {
|
|
|
|
|
case MATHUTILS_SUBTYPE_DIFFUSE:
|
|
|
|
|
self->m->setDiffuse(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]);
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_SPECULAR:
|
|
|
|
|
self->m->setSpecular(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]);
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_AMBIENT:
|
|
|
|
|
self->m->setAmbient(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]);
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_EMISSION:
|
|
|
|
|
self->m->setEmission(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_mathutils_get_index(BaseMathObject *bmo, int subtype, int index)
|
|
|
|
|
{
|
|
|
|
|
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
|
|
|
|
|
switch (subtype) {
|
|
|
|
|
case MATHUTILS_SUBTYPE_DIFFUSE:
|
|
|
|
|
{
|
|
|
|
|
const float *color = self->m->diffuse();
|
|
|
|
|
bmo->data[index] = color[index];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_SPECULAR:
|
|
|
|
|
{
|
|
|
|
|
const float *color = self->m->specular();
|
|
|
|
|
bmo->data[index] = color[index];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_AMBIENT:
|
|
|
|
|
{
|
|
|
|
|
const float *color = self->m->ambient();
|
|
|
|
|
bmo->data[index] = color[index];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_EMISSION:
|
|
|
|
|
{
|
|
|
|
|
const float *color = self->m->emission();
|
|
|
|
|
bmo->data[index] = color[index];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_mathutils_set_index(BaseMathObject *bmo, int subtype, int index)
|
|
|
|
|
{
|
|
|
|
|
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
|
|
|
|
|
float color[4];
|
|
|
|
|
switch (subtype) {
|
|
|
|
|
case MATHUTILS_SUBTYPE_DIFFUSE:
|
|
|
|
|
copy_v4_v4(color, self->m->diffuse());
|
|
|
|
|
color[index] = bmo->data[index];
|
|
|
|
|
self->m->setDiffuse(color[0], color[1], color[2], color[3]);
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_SPECULAR:
|
|
|
|
|
copy_v4_v4(color, self->m->specular());
|
|
|
|
|
color[index] = bmo->data[index];
|
|
|
|
|
self->m->setSpecular(color[0], color[1], color[2], color[3]);
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_AMBIENT:
|
|
|
|
|
copy_v4_v4(color, self->m->ambient());
|
|
|
|
|
color[index] = bmo->data[index];
|
|
|
|
|
self->m->setAmbient(color[0], color[1], color[2], color[3]);
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_EMISSION:
|
|
|
|
|
copy_v4_v4(color, self->m->emission());
|
|
|
|
|
color[index] = bmo->data[index];
|
|
|
|
|
self->m->setEmission(color[0], color[1], color[2], color[3]);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static Mathutils_Callback FrsMaterial_mathutils_cb = {
|
|
|
|
|
FrsMaterial_mathutils_check,
|
|
|
|
|
FrsMaterial_mathutils_get,
|
|
|
|
|
FrsMaterial_mathutils_set,
|
|
|
|
|
FrsMaterial_mathutils_get_index,
|
|
|
|
|
FrsMaterial_mathutils_set_index
|
|
|
|
|
};
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static unsigned char FrsMaterial_mathutils_cb_index = -1;
|
2010-04-17 23:47:47 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
void FrsMaterial_mathutils_register_callback()
|
|
|
|
|
{
|
|
|
|
|
FrsMaterial_mathutils_cb_index = Mathutils_RegisterCallback(&FrsMaterial_mathutils_cb);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
/*----------------------FrsMaterial get/setters ----------------------------*/
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
PyDoc_STRVAR(FrsMaterial_diffuse_doc,
|
|
|
|
|
"RGBA components of the diffuse color of the material.\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
"\n"
|
2013-02-03 17:01:21 +00:00
|
|
|
":type: mathutils.Vector"
|
|
|
|
|
);
|
2010-04-17 23:47:47 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static PyObject *FrsMaterial_diffuse_get(BPy_FrsMaterial *self, void *UNUSED(closure))
|
|
|
|
|
{
|
|
|
|
|
return Vector_CreatePyObject_cb((PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_DIFFUSE);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_diffuse_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
|
|
|
|
|
{
|
|
|
|
|
float color[4];
|
|
|
|
|
if (!Vec4((PyObject *)value, color)) {
|
|
|
|
|
PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->m->setDiffuse(color[0], color[1], color[2], color[3]);
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
PyDoc_STRVAR(FrsMaterial_specular_doc,
|
|
|
|
|
"RGBA components of the specular color of the material.\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
"\n"
|
2013-02-03 17:01:21 +00:00
|
|
|
":type: mathutils.Vector"
|
|
|
|
|
);
|
2010-04-17 23:47:47 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static PyObject *FrsMaterial_specular_get(BPy_FrsMaterial *self, void *UNUSED(closure))
|
|
|
|
|
{
|
|
|
|
|
return Vector_CreatePyObject_cb((PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_SPECULAR);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_specular_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
|
|
|
|
|
{
|
|
|
|
|
float color[4];
|
|
|
|
|
if (!Vec4((PyObject *)value, color)) {
|
|
|
|
|
PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->m->setSpecular(color[0], color[1], color[2], color[3]);
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
PyDoc_STRVAR(FrsMaterial_ambient_doc,
|
|
|
|
|
"RGBA components of the ambient color of the material.\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
"\n"
|
2013-02-03 17:01:21 +00:00
|
|
|
":type: mathutils.Color"
|
|
|
|
|
);
|
2010-04-17 23:47:47 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static PyObject *FrsMaterial_ambient_get(BPy_FrsMaterial *self, void *UNUSED(closure))
|
|
|
|
|
{
|
|
|
|
|
return Vector_CreatePyObject_cb((PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_AMBIENT);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_ambient_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
|
|
|
|
|
{
|
|
|
|
|
float color[4];
|
|
|
|
|
if (!Vec4((PyObject *)value, color)) {
|
|
|
|
|
PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->m->setAmbient(color[0], color[1], color[2], color[3]);
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
PyDoc_STRVAR(FrsMaterial_emission_doc,
|
|
|
|
|
"RGBA components of the emissive color of the material.\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
"\n"
|
2013-02-03 17:01:21 +00:00
|
|
|
":type: mathutils.Color"
|
|
|
|
|
);
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static PyObject *FrsMaterial_emission_get(BPy_FrsMaterial *self, void *UNUSED(closure))
|
|
|
|
|
{
|
|
|
|
|
return Vector_CreatePyObject_cb((PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_EMISSION);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_emission_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
|
|
|
|
|
{
|
|
|
|
|
float color[4];
|
|
|
|
|
if (!Vec4((PyObject *)value, color)) {
|
|
|
|
|
PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->m->setEmission(color[0], color[1], color[2], color[3]);
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
PyDoc_STRVAR(FrsMaterial_shininess_doc,
|
|
|
|
|
"Shininess coefficient of the material.\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
"\n"
|
2013-02-03 17:01:21 +00:00
|
|
|
":type: float"
|
|
|
|
|
);
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static PyObject *FrsMaterial_shininess_get(BPy_FrsMaterial *self, void *UNUSED(closure))
|
|
|
|
|
{
|
|
|
|
|
return PyFloat_FromDouble(self->m->shininess());
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_shininess_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
|
|
|
|
|
{
|
|
|
|
|
float scalar;
|
|
|
|
|
if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "value must be a number");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->m->setShininess(scalar);
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static PyGetSetDef BPy_FrsMaterial_getseters[] = {
|
|
|
|
|
{(char *)"diffuse", (getter)FrsMaterial_diffuse_get, (setter)FrsMaterial_diffuse_set, (char *)FrsMaterial_diffuse_doc, NULL},
|
|
|
|
|
{(char *)"specular", (getter)FrsMaterial_specular_get, (setter)FrsMaterial_specular_set, (char *)FrsMaterial_specular_doc, NULL},
|
|
|
|
|
{(char *)"ambient", (getter)FrsMaterial_ambient_get, (setter)FrsMaterial_ambient_set, (char *)FrsMaterial_ambient_doc, NULL},
|
|
|
|
|
{(char *)"emission", (getter)FrsMaterial_emission_get, (setter)FrsMaterial_emission_set, (char *)FrsMaterial_emission_doc, NULL},
|
|
|
|
|
{(char *)"shininess", (getter)FrsMaterial_shininess_get, (setter)FrsMaterial_shininess_set, (char *)FrsMaterial_shininess_doc, NULL},
|
|
|
|
|
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
|
2010-04-17 23:47:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*-----------------------BPy_FrsMaterial type definition ------------------------------*/
|
|
|
|
|
|
|
|
|
|
PyTypeObject FrsMaterial_Type = {
|
|
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2010-05-09 18:05:33 +00:00
|
|
|
"Material", /* tp_name */
|
2010-04-17 23:47:47 +00:00
|
|
|
sizeof(BPy_FrsMaterial), /* tp_basicsize */
|
|
|
|
|
0, /* tp_itemsize */
|
|
|
|
|
(destructor)FrsMaterial___dealloc__, /* tp_dealloc */
|
|
|
|
|
0, /* tp_print */
|
|
|
|
|
0, /* tp_getattr */
|
|
|
|
|
0, /* tp_setattr */
|
|
|
|
|
0, /* tp_reserved */
|
|
|
|
|
(reprfunc)FrsMaterial___repr__, /* tp_repr */
|
|
|
|
|
0, /* tp_as_number */
|
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
|
0, /* tp_hash */
|
|
|
|
|
0, /* tp_call */
|
|
|
|
|
0, /* tp_str */
|
|
|
|
|
0, /* tp_getattro */
|
|
|
|
|
0, /* tp_setattro */
|
|
|
|
|
0, /* tp_as_buffer */
|
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
|
|
|
|
FrsMaterial___doc__, /* tp_doc */
|
|
|
|
|
0, /* tp_traverse */
|
|
|
|
|
0, /* tp_clear */
|
|
|
|
|
0, /* tp_richcompare */
|
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
|
0, /* tp_iter */
|
|
|
|
|
0, /* tp_iternext */
|
|
|
|
|
BPy_FrsMaterial_methods, /* tp_methods */
|
|
|
|
|
0, /* tp_members */
|
2013-02-03 17:01:21 +00:00
|
|
|
BPy_FrsMaterial_getseters, /* tp_getset */
|
2010-04-17 23:47:47 +00:00
|
|
|
0, /* tp_base */
|
|
|
|
|
0, /* tp_dict */
|
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
|
(initproc)FrsMaterial___init__, /* tp_init */
|
|
|
|
|
0, /* tp_alloc */
|
|
|
|
|
PyType_GenericNew, /* tp_new */
|
|
|
|
|
};
|
|
|
|
|
|
2008-07-31 11:59:06 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|