diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-05-28 18:01:10 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-05-28 18:01:10 +0400 |
commit | 0edb6e89be23c20f1b1e3521ea854e44829b4969 (patch) | |
tree | 41f51413bc2e8de1237d0911160c3dfb870a83fc | |
parent | 8c4620f3d3d5cb533f3d1bf5c526c6ffc0355aaa (diff) |
[#18803] 'ShadeModes' dictionary and 'shadeMode' instance variable exported to Python API
Ton was ok with adding Vladislav Turbanov (vladius)'s patch during the freeze.
-rw-r--r-- | source/blender/python/api2_2x/Material.c | 49 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Material.py | 7 |
2 files changed, 54 insertions, 2 deletions
diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c index cb2c81aba6e..ad4296d19d8 100644 --- a/source/blender/python/api2_2x/Material.c +++ b/source/blender/python/api2_2x/Material.c @@ -335,6 +335,20 @@ static PyObject *M_Material_Get( PyObject * self, PyObject * args ) } } +static PyObject *Material_ShadeModesDict( void ) +{ + PyObject *ShadeModes = PyConstant_New( ); + + if( ShadeModes ) { + BPy_constant *c = ( BPy_constant * ) ShadeModes; + + PyConstant_Insert(c, "CUBIC", PyInt_FromLong(MA_CUBIC)); + PyConstant_Insert(c, "OBCOLOR", PyInt_FromLong(MA_OBCOLOR)); + } + + return ShadeModes; +} + static PyObject *Material_ModesDict( void ) { PyObject *Modes = PyConstant_New( ); @@ -454,12 +468,13 @@ static PyObject *Material_ColorRampInputDict( void ) /*****************************************************************************/ PyObject *Material_Init( void ) { - PyObject *submodule, *Modes, *Shaders, *ColorbandInput, *ColorbandMethod; + PyObject *submodule, *Modes, *ShadeModes, *Shaders, *ColorbandInput, *ColorbandMethod; if( PyType_Ready( &Material_Type ) < 0) return NULL; Modes = Material_ModesDict( ); + ShadeModes = Material_ShadeModesDict( ); Shaders = Material_ShadersDict( ); ColorbandMethod = Material_ColorRampMethodsDict( ); ColorbandInput = Material_ColorRampInputDict( ); @@ -469,6 +484,8 @@ PyObject *Material_Init( void ) if( Modes ) PyModule_AddObject( submodule, "Modes", Modes ); + if( ShadeModes ) + PyModule_AddObject( submodule, "ShadeModes", ShadeModes ); if( Shaders ) PyModule_AddObject( submodule, "Shaders", Shaders ); if( ColorbandMethod ) @@ -541,6 +558,7 @@ static PyObject *Matr_oldsetTranslucency( BPy_Material * self, PyObject * args ) static int Material_setIpo( BPy_Material * self, PyObject * value ); static int Material_setMode( BPy_Material * self, PyObject * value ); +static int Material_setShadeMode( BPy_Material * self, PyObject * value ); static int Material_setRGBCol( BPy_Material * self, PyObject * value ); static int Material_setSpecCol( BPy_Material * self, PyObject * value ); static int Material_setMirCol( BPy_Material * self, PyObject * value ); @@ -620,6 +638,7 @@ static PyObject *Material_getColorComponent( BPy_Material * self, /*****************************************************************************/ static PyObject *Material_getIpo( BPy_Material * self ); static PyObject *Material_getMode( BPy_Material * self ); +static PyObject *Material_getShadeMode( BPy_Material * self ); static PyObject *Material_getRGBCol( BPy_Material * self ); /*static PyObject *Material_getAmbCol(BPy_Material *self);*/ static PyObject *Material_getSpecCol( BPy_Material * self ); @@ -1098,6 +1117,10 @@ static PyGetSetDef BPy_Material_getseters[] = { (getter)Material_getMode, (setter)Material_setMode, "Material mode bitmask", NULL}, + {"shadeMode", + (getter)Material_getShadeMode, (setter)Material_setShadeMode, + "Material shade mode bitmask", + NULL}, {"nFlares", (getter)Material_getNFlares, (setter)Material_setNFlares, "Number of subflares with halo", @@ -1495,6 +1518,11 @@ static PyObject *Material_getMode( BPy_Material * self ) return PyInt_FromLong( ( long ) self->material->mode ); } +static PyObject *Material_getShadeMode( BPy_Material * self ) +{ + return PyInt_FromLong( ( long ) self->material->shade_flag ); +} + static PyObject *Material_getRGBCol( BPy_Material * self ) { return rgbTuple_getCol( self->col ); @@ -1970,6 +1998,24 @@ static int Material_setMode( BPy_Material * self, PyObject * value ) return 0; } +static int Material_setShadeMode( BPy_Material * self, PyObject * value ) +{ + int param; + + if( !PyInt_Check( value ) ) { + char errstr[128]; + sprintf ( errstr , "expected int bitmask of 0x%08x", (MA_CUBIC | MA_OBCOLOR) ); + return EXPP_ReturnIntError( PyExc_TypeError, errstr ); + } + param = PyInt_AS_LONG ( value ); + if ( ( param & (MA_CUBIC | MA_OBCOLOR) ) != param ) + return EXPP_ReturnIntError( PyExc_ValueError, + "invalid bit(s) set in mask" ); + self->material->shade_flag |= param; + + return 0; +} + static int Material_setRGBCol( BPy_Material * self, PyObject * value ) { return rgbTuple_setCol( self->col, value ); @@ -3476,4 +3522,3 @@ static int Material_setColorbandSpecularInput ( BPy_Material * self, PyObject * return EXPP_setIValueClamped(value, &self->material->rampin_spec, MA_RAMP_IN_SHADER, MA_RAMP_IN_RESULT, 'b'); } - diff --git a/source/blender/python/api2_2x/doc/Material.py b/source/blender/python/api2_2x/doc/Material.py index b37fd660810..3b8148b3f11 100644 --- a/source/blender/python/api2_2x/doc/Material.py +++ b/source/blender/python/api2_2x/doc/Material.py @@ -69,6 +69,11 @@ Example:: - NMAP_TS - Tangent space normal mapping. - GROUP_EXCLUSIVE - Light from this group even if the lights are on a hidden Layer. +@type ShadeModes: readonly dictionary +@var ShadeModes: The available Material Shade Modes. + - CUBIC - Use cubic interpolation of diffuse values, for smoother transitions. + - OBCOLOR - Modulate result with a per object color. + @type Shaders: readonly dictionary @var Shaders: The available Material Shaders. - DIFFUSE_LAMBERT - Make Material use the lambert diffuse shader. @@ -246,6 +251,8 @@ class Material: @ivar mode: Mode mode bitfield. See L{the Modes dictionary<Modes>} keys and descriptions. @type mode: int + @ivar shadeMode: Shade mode bitfield. See L{the ShadeModes dictionary<ShadeModes>} keys and descriptions. + @type shadeMode: int @ivar nFlares: Number of subflares with halo. Value is clamped to the range [1,32]. @type nFlares: int |