-- Added BPy support for new Material modes. Recent additions of new mode

bits broke input-checking in the API, so added a bitmask #define in
   DNA_material_types.h which contains all valid mode bits.
This commit is contained in:
Ken Hughes
2005-12-15 21:54:00 +00:00
parent 641f3cd72d
commit 826591d778
3 changed files with 36 additions and 73 deletions

View File

@@ -324,6 +324,13 @@ static PyObject *Material_ModesDict( void )
PyConstant_Insert(c, "TRACEABLE", PyInt_FromLong(MA_TRACEBLE));
PyConstant_Insert(c, "SHADOW", PyInt_FromLong(MA_SHADOW));
PyConstant_Insert(c, "SHADOWBUF", PyInt_FromLong(MA_SHADBUF));
PyConstant_Insert(c, "TANGENTSTR", PyInt_FromLong(MA_TANGENT_STR));
PyConstant_Insert(c, "FULLOSA", PyInt_FromLong(MA_FULL_OSA));
PyConstant_Insert(c, "RAYBIAS", PyInt_FromLong(MA_RAYBIAS));
PyConstant_Insert(c, "TRANSPSHADOW", PyInt_FromLong(MA_SHADOW_TRA));
PyConstant_Insert(c, "RAMPCOL", PyInt_FromLong(MA_RAMP_COL));
PyConstant_Insert(c, "RAMPSPEC", PyInt_FromLong(MA_RAMP_SPEC));
PyConstant_Insert(c, "SHADELESS", PyInt_FromLong(MA_SHLESS));
PyConstant_Insert(c, "WIRE", PyInt_FromLong(MA_WIRE));
PyConstant_Insert(c, "VCOL_LIGHT", PyInt_FromLong(MA_VERTEXCOL));
@@ -1912,46 +1919,20 @@ static int Material_setName( BPy_Material * self, PyObject * value )
static int Material_setMode( BPy_Material * self, PyObject * value )
{
int param;
int bitmask = MA_TRACEBLE
| MA_SHADOW
| MA_SHLESS
| MA_WIRE
| MA_VERTEXCOL
| MA_VERTEXCOLP
| MA_HALO
| MA_ZTRA
| MA_ZINV
| MA_HALO_RINGS
| MA_HALO_LINES
| MA_ONLYSHADOW
| MA_HALO_XALPHA
| MA_STAR
| MA_FACETEXTURE
| MA_HALOTEX
| MA_HALOPUNO
| MA_NOMIST
| MA_HALO_SHADE
| MA_HALO_FLARE
| MA_RADIO
| MA_RAYMIRROR
| MA_ZTRA
| MA_RAYTRANSP
| MA_ONLYSHADOW
| MA_NOMIST
| MA_ENV;
if( !PyInt_CheckExact ( value ) ) {
char errstr[128];
sprintf ( errstr , "expected int bitmask of 0x%08x", bitmask );
sprintf ( errstr , "expected int bitmask of 0x%08x", MA_MODE_MASK );
return EXPP_ReturnIntError( PyExc_TypeError, errstr );
}
param = PyInt_AS_LONG ( value );
if ( ( param & bitmask ) != param )
if ( ( param & MA_MODE_MASK ) != param )
return EXPP_ReturnIntError( PyExc_ValueError,
"invalid bit(s) set in mask" );
self->material->mode = param;
self->material->mode &= ( MA_RAMP_COL | MA_RAMP_SPEC );
self->material->mode |= param & ~( MA_RAMP_COL | MA_RAMP_SPEC );
return 0;
}
@@ -2938,34 +2919,6 @@ static PyObject *Matr_oldsetMode( BPy_Material * self, PyObject * args )
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL
};
static int bitmask = MA_TRACEBLE
| MA_SHADOW
| MA_SHLESS
| MA_WIRE
| MA_VERTEXCOL
| MA_VERTEXCOLP
| MA_HALO
| MA_ZTRA
| MA_ZINV
| MA_HALO_RINGS
| MA_HALO_LINES
| MA_ONLYSHADOW
| MA_HALO_XALPHA
| MA_STAR
| MA_FACETEXTURE
| MA_HALOTEX
| MA_HALOPUNO
| MA_NOMIST
| MA_HALO_SHADE
| MA_HALO_FLARE
| MA_RADIO
| MA_RAYMIRROR
| MA_ZTRA
| MA_RAYTRANSP
| MA_ONLYSHADOW
| MA_NOMIST
| MA_ENV;
/*
* check for a single integer argument; do a quick check for now
@@ -2975,7 +2928,7 @@ static PyObject *Matr_oldsetMode( BPy_Material * self, PyObject * args )
if ( (PySequence_Size( args ) == 1)
&& PyInt_Check ( PyTuple_GET_ITEM ( args , 0 ) )
&& PyArg_ParseTuple( args, "i", &flag )
&& (flag & bitmask) == flag ) {
&& (flag & MA_MODE_MASK ) == flag ) {
ok = 1;
/*

View File

@@ -25,8 +25,18 @@ Example::
@type Modes: readonly dictionary
@var Modes: The available Material Modes.
B{Note}: Some Modes are only available when the 'Halo' mode is I{off} and
others only when it is I{on}. But these two subsets of modes share the same
numerical values in their Blender C #defines. So, for example, if 'Halo' is
on, then 'NoMist' is actually interpreted as 'HaloShaded'. We marked all
such possibilities in the Modes dict below: each halo-related mode that
uses an already taken value is preceded by "+" and appear below the normal
mode which also uses that value.
- TRACEABLE - Make Material visible for shadow lamps.
- SHADOW - Enable Material for shadows.
- SHADOWBUF - Enable Material to cast shadows with shadow buffers.
- SHADELESS - Make Material insensitive to light or shadow.
- WIRE - Render only the edges of faces.
- VCOL_LIGHT - Add vertex colors as extra light.
@@ -34,28 +44,26 @@ Example::
- HALO - Render as a halo.
- ZTRANSP - Z-buffer transparent faces.
- ZINVERT - Render with inverted Z-buffer.
- - HALORINGS - Render rings over the basic halo.
- + HALORINGS - Render rings over the basic halo.
- ENV - Do not render Material.
- - HALOLINES - Render star shaped lines over the basic halo.
- + HALOLINES - Render star shaped lines over the basic halo.
- ONLYSHADOW - Let alpha be determined on the degree of shadow.
- - HALOXALPHA - Use extreme alpha.
- TEXFACE - UV-Editor assigned texture gives color and texture info
for faces.
- - HALOSTAR - Render halo as a star.
- + HALOXALPHA - Use extreme alpha.
- TEXFACE - UV-Editor assigned texture gives color and texture info for faces.
- + HALOSTAR - Render halo as a star.
- NOMIST - Set the Material insensitive to mist.
- - HALOSHADED - Let halo receive light.
- + HALOSHADED - Let halo receive light.
- HALOTEX - Give halo a texture.
- HALOPUNO - Use the vertex normal to specify the dimension of the halo.
- HALOFLARE - Render halo as a lens flare.
- RAYMIRROR - Enables raytracing for mirror reflection rendering.
- RAYTRANSP - Enables raytracing for transparency rendering.
@warn: Some Modes are only available when the 'Halo' mode is I{off} and
others only when it is I{on}. But these two subsets of modes share the same
numerical values in their Blender C #defines. So, for example, if 'Halo' is
on, then 'NoMist' is actually interpreted as 'HaloShaded'. We marked all
such possibilities in the Modes dict below: each halo-related mode that
uses an already taken value is preceded by "-" and appear below the normal
mode which also uses that value.
- RAYBIAS - Prevent ray traced shadow errors with Phong interpolated normals.
- RAMPCOL - Status of colorband ramp for Material's diffuse color. This is a read-only bit.
- RAMPSPEC - Status of colorband ramp for Material's specular color. This is a read-only bit.
- TANGENTSTR - Uses direction of strands as normal for tangent-shading.
- TRANSPSHADOW - Lets Material receive transparent shadows based on material color and alpha.
- FULLOSA - Force rendering of all OSA samples.
@type Shaders: readonly dictionary
@var Shaders: The available Material Shaders.