Part of Bpy Cleanup: change attribute access to use tp_getset.

for these modules.  Adds some new convenience funcs to gen_utils.

This is internal change only and presents little change to the
BPy  API except for cleanup of some inconsistencies.

A big contribution from Ken Hughes.  Thanks!
This commit is contained in:
Stephen Swaney
2005-09-21 19:48:40 +00:00
parent e1fe7c88ec
commit 5bac916e83
10 changed files with 3965 additions and 2951 deletions

View File

@@ -1,5 +1,6 @@
/* /*
* $Id$ * $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@@ -393,11 +394,11 @@ static PyGetSetDef BPy_Lamp_getseters[] = {
NULL}, NULL},
{"quad1", {"quad1",
(getter)Lamp_getQuad1, (setter)Lamp_setQuad1, (getter)Lamp_getQuad1, (setter)Lamp_setQuad1,
"Quad lamp linear distance attenuatation", "Quad lamp linear distance attenuation",
NULL}, NULL},
{"quad2", {"quad2",
(getter)Lamp_getQuad2, (setter)Lamp_setQuad2, (getter)Lamp_getQuad2, (setter)Lamp_setQuad2,
"Quad lamp quadratic distance attenuatation", "Quad lamp quadratic distance attenuation",
NULL}, NULL},
{"samples", {"samples",
(getter)Lamp_getSamples, (setter)Lamp_setSamples, (getter)Lamp_getSamples, (setter)Lamp_setSamples,
@@ -1055,8 +1056,8 @@ static int Lamp_setName( BPy_Lamp * self, PyObject * value )
static int Lamp_setType( BPy_Lamp * self, PyObject * value ) static int Lamp_setType( BPy_Lamp * self, PyObject * value )
{ {
return EXPP_setShortRange ( value, &self->lamp->type, return EXPP_setIValueRange ( value, &self->lamp->type,
0, EXPP_LAMP_TYPE_MAX ); 0, EXPP_LAMP_TYPE_MAX, 'h' );
} }
static int Lamp_setMode( BPy_Lamp * self, PyObject * value ) static int Lamp_setMode( BPy_Lamp * self, PyObject * value )
@@ -1091,23 +1092,23 @@ static int Lamp_setMode( BPy_Lamp * self, PyObject * value )
static int Lamp_setSamples( BPy_Lamp * self, PyObject * value ) static int Lamp_setSamples( BPy_Lamp * self, PyObject * value )
{ {
return EXPP_setShortClamped ( value, &self->lamp->samp, return EXPP_setIValueClamped ( value, &self->lamp->samp,
EXPP_LAMP_SAMPLES_MIN, EXPP_LAMP_SAMPLES_MIN,
EXPP_LAMP_SAMPLES_MAX ); EXPP_LAMP_SAMPLES_MAX, 'h' );
} }
static int Lamp_setBufferSize( BPy_Lamp * self, PyObject * value ) static int Lamp_setBufferSize( BPy_Lamp * self, PyObject * value )
{ {
return EXPP_setShortClamped ( value, &self->lamp->bufsize, return EXPP_setIValueClamped ( value, &self->lamp->bufsize,
EXPP_LAMP_BUFFERSIZE_MIN, EXPP_LAMP_BUFFERSIZE_MIN,
EXPP_LAMP_BUFFERSIZE_MAX ); EXPP_LAMP_BUFFERSIZE_MAX, 'h' );
} }
static int Lamp_setHaloStep( BPy_Lamp * self, PyObject * value ) static int Lamp_setHaloStep( BPy_Lamp * self, PyObject * value )
{ {
return EXPP_setShortClamped ( value, &self->lamp->shadhalostep, return EXPP_setIValueClamped ( value, &self->lamp->shadhalostep,
EXPP_LAMP_HALOSTEP_MIN, EXPP_LAMP_HALOSTEP_MIN,
EXPP_LAMP_HALOSTEP_MAX ); EXPP_LAMP_HALOSTEP_MAX, 'h' );
} }
static int Lamp_setEnergy( BPy_Lamp * self, PyObject * value ) static int Lamp_setEnergy( BPy_Lamp * self, PyObject * value )
@@ -1217,11 +1218,11 @@ static int Lamp_setComponent( BPy_Lamp * self, PyObject * value,
{ {
float color; float color;
if( !PyFloat_CheckExact ( value ) ) if( !PyNumber_Check ( value ) )
return EXPP_ReturnIntError( PyExc_TypeError, return EXPP_ReturnIntError( PyExc_TypeError,
"expected float argument in [0.0,1.0]" ); "expected float argument in [0.0,1.0]" );
color = PyFloat_AS_DOUBLE( value ); color = PyFloat_AsDouble( value );
color = EXPP_ClampFloat( color, EXPP_LAMP_COL_MIN, EXPP_LAMP_COL_MAX ); color = EXPP_ClampFloat( color, EXPP_LAMP_COL_MIN, EXPP_LAMP_COL_MAX );
switch ( (int)closure ) { switch ( (int)closure ) {
@@ -1241,14 +1242,7 @@ static int Lamp_setComponent( BPy_Lamp * self, PyObject * value,
static int Lamp_setCol( BPy_Lamp * self, PyObject * args ) static int Lamp_setCol( BPy_Lamp * self, PyObject * args )
{ {
PyObject *error; return rgbTuple_setCol( self->color, args );
error = rgbTuple_setCol( self->color, args );
if ( error ) {
Py_DECREF ( error );
return 0;
}
return -1;
} }
/* lamp.addScriptLink */ /* lamp.addScriptLink */
@@ -1476,108 +1470,89 @@ static PyObject *Lamp_getUsers( BPy_Lamp * self )
/* #####DEPRECATED###### */ /* #####DEPRECATED###### */
/*
* Procedure to handle older setStuff() methods. Assumes that argument
* is a tuple with one object, and so grabs the object and passes it to
* the specified tp_getset setter for the corresponding attribute.
*/
static PyObject *Lamp_setterWrapper ( BPy_Lamp * self, PyObject * args,
int (*func)( BPy_Lamp * self, PyObject * args ))
{
int error;
if ( !PyTuple_Check( args ) || PyTuple_Size( args ) != 1 )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"expected tuple of one item" );
error = func ( self, PySequence_Fast_GET_ITEM( args, 0 ) );
if ( !error ) {
Py_INCREF( Py_None );
return Py_None;
} else
return NULL;
}
static PyObject *Lamp_oldsetName( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetName( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setName ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setName );
} }
static PyObject *Lamp_oldsetSamples( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetSamples( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setSamples ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSamples );
} }
static PyObject *Lamp_oldsetBufferSize( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetBufferSize( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setBufferSize ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setBufferSize );
} }
static PyObject *Lamp_oldsetHaloStep( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetHaloStep( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setHaloStep ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setHaloStep );
} }
static PyObject *Lamp_oldsetEnergy( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetEnergy( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setEnergy ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setEnergy );
} }
static PyObject *Lamp_oldsetDist( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetDist( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setDist ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setDist );
} }
static PyObject *Lamp_oldsetSpotSize( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetSpotSize( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setSpotSize ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSpotSize );
} }
static PyObject *Lamp_oldsetSpotBlend( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetSpotBlend( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setSpotBlend ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSpotBlend );
} }
static PyObject *Lamp_oldsetClipStart( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetClipStart( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setClipStart ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setClipStart );
} }
static PyObject *Lamp_oldsetClipEnd( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetClipEnd( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setClipEnd ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setClipEnd );
} }
static PyObject *Lamp_oldsetBias( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetBias( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setBias ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setBias );
} }
static PyObject *Lamp_oldsetSoftness( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetSoftness( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setSoftness ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSoftness );
} }
static PyObject *Lamp_oldsetHaloInt( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetHaloInt( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setHaloInt ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setHaloInt );
} }
static PyObject *Lamp_oldsetQuad1( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetQuad1( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setQuad1 ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setQuad1 );
} }
static PyObject *Lamp_oldsetQuad2( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetQuad2( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setQuad2 ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setQuad2 );
} }
static PyObject *Lamp_oldsetIpo( BPy_Lamp * self, PyObject * args ) static PyObject *Lamp_oldsetIpo( BPy_Lamp * self, PyObject * args )
{ {
return Lamp_setterWrapper ( self, args, Lamp_setIpo ); return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setIpo );
}
static PyObject *Lamp_oldsetCol( BPy_Lamp * self, PyObject * args )
{
return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setCol );
} }
/* /*
@@ -1595,7 +1570,7 @@ static PyObject *Lamp_clearIpo( BPy_Lamp * self )
if( self->lamp->ipo ) { if( self->lamp->ipo ) {
PyObject *value = Py_BuildValue( "(O)", Py_None ); PyObject *value = Py_BuildValue( "(O)", Py_None );
Lamp_setterWrapper ( self, value, Lamp_setIpo ); EXPP_setterWrapper ( (void *)self, value, (setter)Lamp_setIpo );
Py_DECREF ( value ); Py_DECREF ( value );
return EXPP_incr_ret_True(); return EXPP_incr_ret_True();
} }
@@ -1638,7 +1613,7 @@ static PyObject *Lamp_oldsetType( BPy_Lamp * self, PyObject * args )
/* build tuple, call wrapper */ /* build tuple, call wrapper */
value = Py_BuildValue( "(i)", type ); value = Py_BuildValue( "(i)", type );
error = Lamp_setterWrapper ( self, value, Lamp_setType ); error = EXPP_setterWrapper ( (void *)self, value, (setter)Lamp_setType );
Py_DECREF ( value ); Py_DECREF ( value );
return error; return error;
} }
@@ -1695,19 +1670,8 @@ static PyObject *Lamp_oldsetMode( BPy_Lamp * self, PyObject * args )
/* build tuple, call wrapper */ /* build tuple, call wrapper */
value = Py_BuildValue( "(i)", flag ); value = Py_BuildValue( "(i)", flag );
error = Lamp_setterWrapper ( self, value, Lamp_setMode ); error = EXPP_setterWrapper ( (void *)self, value, (setter)Lamp_setMode );
Py_DECREF ( value ); Py_DECREF ( value );
return error; return error;
} }
/*
* This one isn't changed at all since rgbTuple_setCol() hasn't changed
* either, and the new attribute setter expects a tuple with a single
* argument. It's valid to do "lamp.setCol(r,g,b)", which passes three-
* argument tuple.
*/
static PyObject *Lamp_oldsetCol( BPy_Lamp * self, PyObject * args )
{
return rgbTuple_setCol( self->color, args );
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -17,6 +17,25 @@ Example::
l.setMode('square', 'shadow') # set these two lamp mode flags l.setMode('square', 'shadow') # set these two lamp mode flags
ob = Object.New('Lamp') # create new lamp object ob = Object.New('Lamp') # create new lamp object
ob.link(l) # link lamp obj with lamp data ob.link(l) # link lamp obj with lamp data
@type Types: read-only dictionary
@var Types: The lamp types.
- 'Lamp': 0
- 'Sun' : 1
- 'Spot': 2
- 'Hemi': 3
- 'Area': 4
- 'Photon': 5
@type Modes: read-only dictionary
@var Modes: The lamp modes. Modes may be ORed together.
- 'Shadows'
- 'Halo'
- 'Layer'
- 'Quad'
- 'Negative'
- 'OnlyShadow'
- 'Sphere'
- 'Square'
""" """
def New (type = 'Lamp', name = 'LampData'): def New (type = 'Lamp', name = 'LampData'):
@@ -46,44 +65,73 @@ class Lamp:
The Lamp Data object The Lamp Data object
==================== ====================
This object gives access to Lamp-specific data in Blender. This object gives access to Lamp-specific data in Blender.
@ivar name: The Lamp Data name.
@ivar type: The Lamp type (see the Types dict). @ivar B: Lamp color blue component.
@cvar Types: The Types dictionary. Value is clamped to the range [0.0,1.0].
- 'Lamp': 0 @type B: float
- 'Sun' : 1 @ivar G: Lamp color green component.
- 'Spot': 2 Value is clamped to the range [0.0,1.0].
- 'Hemi': 3 @type G: float
- 'Area': 4 @ivar R: Lamp color red component.
- 'Photon': 5 Value is clamped to the range [0.0,1.0].
@ivar mode: The mode flags: B{or'ed value} of the flags in the Modes dict. @type R: float
@cvar Modes: The Modes dictionary. @ivar bias: Lamp shadow map sampling bias.
- 'Shadows' Value is clamped to the range [0.01,5.0].
- 'Halo' @type bias: float
- 'Layer' @ivar bufferSize: Lamp shadow buffer size.
- 'Quad' Value is clamped to the range [512,5120].
- 'Negative' @type bufferSize: int
- 'OnlyShadow' @ivar clipEnd: Lamp shadow map clip end.
- 'Sphere' Value is clamped to the range [1.0,5000.0].
- 'Square' @type clipEnd: float
@ivar samples: The number of shadow map samples in [1, 16]. @ivar clipStart: Lamp shadow map clip start.
@ivar bufferSize: The size of the shadow buffer in [512, 5120]. Value is clamped to the range [0.1,1000.0].
@ivar haloStep: Volumetric halo sampling frequency in [0, 12]. @type clipStart: float
@ivar energy: The intensity of the light in [0.0, 10.0]. @ivar col: Lamp RGB color triplet.
@ivar dist: The distance value in [0.1, 5000.0]. Components are clamped to the range [0.0,1.0].
@ivar spotSize: The angle of the spot beam in degrees in [1.0, 180.0]. @type col: RGB tuple
@ivar spotBlend: The softness of the spot edge in [0.0, 1.0]. @ivar dist: Lamp clipping distance.
@ivar clipStart: The shadow map clip start in [0.1, 1000.0]. Value is clamped to the range [0.1,5000.0].
@ivar clipEnd: The shadow map clip end in [1.0, 5000.0]. @type dist: float
@ivar bias: The shadow map sampling bias in [0.01, 5.00]. @ivar energy: Lamp light intensity.
@ivar softness: The size of the shadow sample area in [1.0, 100.0]. Value is clamped to the range [0.0,10.0].
@ivar haloInt: The intensity of the spot halo in [0.0, 5.0]. @type energy: float
@ivar quad1: Light intensity value 1 for a Quad lamp in [0.0, 1.0]. @ivar haloInt: Lamp spotlight halo intensity.
@ivar quad2: Light intensity value 2 for a Quad lamp in [0.0, 1.0]. Value is clamped to the range [0.0,5.0].
@ivar col: The color of the light, with each rgb component in [0.0, 1.0]. @type haloInt: float
This is an rgb tuple whose values can be accessed in many ways: @ivar haloStep: Lamp volumetric halo sampling frequency.
- as a tuple: lamp.col, lamp.col[0], same for 1 and 2. Value is clamped to the range [0,12].
- as a dictionary: lamp.col['R'], same for 'G' and 'B'. @type haloStep: int
- as an object: lamp.col.R, same for G and B. @ivar ipo: Lamp Ipo.
Contains the Ipo if one is assigned to the object, B{None} otherwise. Setting to B{None} clears the current Ipo..
@type ipo: Blender Ipo
@ivar mode: Lamp mode bitfield. See L{Modes} for values.
@type mode: int
@ivar name: Lamp data name.
@type name: str
@ivar quad1: Quad lamp linear distance attenuation.
Value is clamped to the range [0.0,1.0].
@type quad1: float
@ivar quad2: Quad lamp quadratic distance attenuation.
Value is clamped to the range [0.0,1.0].
@type quad2: float
@ivar samples: Lamp shadow map samples.
Value is clamped to the range [1,16].
@type samples: int
@ivar softness: Lamp shadow sample area size.
Value is clamped to the range [1.0,100.0].
@type softness: float
@ivar spotBlend: Lamp spotlight edge softness.
Value is clamped to the range [0.0,1.0].
@type spotBlend: float
@ivar spotSize: Lamp spotlight beam angle (in degrees).
Value is clamped to the range [1.0,180.0].
@type spotSize: float
@ivar type: Lamp type. See L{Types} for values.
@type type: int
@ivar users: Number of lamp users.
@type users: int
@warning: Most member variables assume values in some [Min, Max] interval. @warning: Most member variables assume values in some [Min, Max] interval.
When trying to set them, the given parameter will be clamped to lie in When trying to set them, the given parameter will be clamped to lie in
that range: if val < Min, then val = Min, if val > Max, then val = Max. that range: if val < Min, then val = Min, if val > Max, then val = Max.

View File

@@ -57,7 +57,6 @@ Example::
uses an already taken value is preceded by "-" and appear below the normal uses an already taken value is preceded by "-" and appear below the normal
mode which also uses that value. mode which also uses that value.
@type Shaders: readonly dictionary @type Shaders: readonly dictionary
@var Shaders: The available Material Shaders. @var Shaders: The available Material Shaders.
- DIFFUSE_LAMBERT - Make Material use the lambert diffuse shader. - DIFFUSE_LAMBERT - Make Material use the lambert diffuse shader.
@@ -96,59 +95,173 @@ class Material:
The Material object The Material object
=================== ===================
This object gives access to Materials in Blender. This object gives access to Materials in Blender.
@ivar name: Material's name. @ivar B: Diffuse color (L{rgbCol}) blue component.
@type mode: int Value is clamped to the range [0.0,1.0].
@ivar mode: Mode flags as an or'ed int value. See the Modes dictionary keys @type B: float
and descriptions in L{Modes}. @ivar G: Diffuse color (L{rgbCol}) green component.
@ivar rgbCol: Material's RGB color triplet sequence. Value is clamped to the range [0.0,1.0].
@ivar specCol: Specular color rgb triplet sequence. @type G: float
@ivar mirCol: Mirror color rgb triplet sequence. @ivar IOR: Angular index of refraction for raytrace.
@ivar R: Red component of L{rgbCol} - [0.0, 1.0]. Value is clamped to the range [1.0,3.0].
@ivar G: Green component of L{rgbCol} - [0.0, 1.0]. @type IOR: float
@ivar B: Blue component of L{rgbCol} - [0.0, 1.0]. @ivar R: Diffuse color (L{rgbCol}) red component.
@ivar alpha: Alpha (translucency) component of the Material - [0.0, 1.0]. Value is clamped to the range [0.0,1.0].
@ivar amb: Ambient factor - [0.0, 1.0]. @type R: float
@ivar emit: Emitting light intensity - [0.0, 1.0]. @ivar add: Strength of the add effect.
@ivar ref: Reflectivity - [0.0, 1.0]. Value is clamped to the range [0.0,1.0].
@ivar spec: Specularity - [0.0, 2.0]. @type add: float
@ivar specTransp: Specular transparency - [0.0, 1.0]. @ivar alpha: Alpha (translucency) component of the material.
@ivar add: Glow factor - [0.0, 1.0]. Value is clamped to the range [0.0,1.0].
@ivar zOffset: Artificial Z offset for faces - [0.0, 10.0]. @type alpha: float
@ivar haloSize: Dimension of the halo - [0.0, 100.0]. @ivar amb: Amount of global ambient color material receives.
@ivar flareSize: Factor the flare is larger than the halo - [0.1, 25.0]. Value is clamped to the range [0.0,1.0].
@ivar flareBoost: Flare's extra strength - [0.1, 10.0]. @type amb: float
@ivar haloSeed: To use random values for ring dimension and line location - @ivar diffuseDarkness: Material's diffuse darkness ("Minnaert" diffuse shader only).
[0, 255]. Value is clamped to the range [0.0,2.0].
@ivar flareSeed: Offset in the seed table - [0, 255]. @type diffuseDarkness: float
@ivar subSize: Dimension of subflares, dots and circles - [0.1, 25.0]. @ivar diffuseShader: Diffuse shader type (see L{Shaders}).
@ivar hard: Hardness of the specularity - [1, 255]. Value must be in the range [0,3].
@ivar nFlares: Number of halo subflares - [1, 32]. @type diffuseShader: int
@ivar nStars: Number of points on the halo stars - [3, 50]. @ivar diffuseSize: Material's diffuse area size ("Toon" diffuse shader only).
@ivar nLines: Number of star shaped lines on each halo - [0, 250]. Value is clamped to the range [0.0,3.14].
@ivar nRings: Number of halo rings - [0, 24]. @type diffuseSize: float
@type ipo: Blender Ipo @ivar diffuseSmooth: Material's diffuse area smoothing ("Toon" diffuse shader only).
@ivar ipo: This Material's ipo. Value is clamped to the range [0.0,1.0].
@ivar rayMirr: Amount mirror reflection for raytrace. @type diffuseSmooth: float
@ivar rayMirrDepth: Amount of inter-reflections calculated maximal. @ivar emit: Amount of light the material emits.
@ivar fresnelDepth: Power of Fresnel for mirror reflection. Value is clamped to the range [0.0,1.0].
@ivar fresnelDepthFac: Blending factor for Fresnel. @type emit: float
@ivar IOR: Sets the angular index of refraction for raytrace. @ivar filter: Amount of filtering when transparent raytrace is enabled.
@ivar transDepth: Amount of refractions calculated maximal. Value is clamped to the range [0.0,1.0].
@ivar fresnelTrans: Power of Fresnel for transparency. @type filter: float
@ivar fresnelTransFac: Blending factor for Fresnel. @ivar flareBoost: Flare's extra strength.
@ivar specTrans: Makes specular areas opaque on transparent materials. Value is clamped to the range [0.1,1.0].
@cvar specShader: Specular shader from one of the shaders in Material.Shaders dict - [0, 4]. @type flareBoost: float
@cvar diffuseShader: Diffuse shader from one of the shaders in Material.Shaders dict - [0, 3]. @ivar flareSeed: Offset in the flare seed table.
@cvar roughness: Material's Roughness (applies to the \"Oren Nayar\" Diffuse Shader only) - [0.0, 3.14]. Value is clamped to the range [1,255].
@cvar specSize: Material's size of speculara area (applies to the \"Toon\" Specular Shader only) - [0.0, 1.53]. @type flareSeed: int
@cvar diffuseSize: Material's size of diffuse area (applies to the \"Toon\" Diffuse Shader only) - [0.0, 3.14]. @ivar flareSize: Ratio of flare size to halo size.
@cvar specSmooth: Material's smoothing of specular area (applies to the \"Toon\" Specular Shader only) - [0.0, 1.0]. Value is clamped to the range [0.1,25.0].
@cvar diffuseSmooth: Material's smoothing of diffuse area (applies to the \"Toon\" Diffuse Shader only) - [0.0, 1.0]. @type flareSize: float
@cvar diffuseDarkness: Material's diffuse darkness (applies to the \"Minnaert\" Diffuse Shader only) - [0.0, 2.0]. @ivar fresnelDepth: Power of Fresnel for mirror reflection.
@cvar refracIndex: Material's Index of Refraction (applies to the \"Blinn\" Specular Shader only) - [1.0, 10.0]. Value is clamped to the range [0.0,5.0].
@cvar rms: Material's standard deviation of surface slope (applies to the \"WardIso\" Specular Shader only) - [0.0, 0.4]. @type fresnelDepth: float
@cvar filter: Amount of filtering when transparent raytrace is enabled - [0.0, 1.0]. @ivar fresnelDepthFac: Blending factor for Fresnel mirror.
@cvar translucency: Amount of diffuse shading of the back side - [0.0, 1.0]. Value is clamped to the range [1.0,5.0].
@type fresnelDepthFac: float
@ivar fresnelTrans: Power of Fresnel for transparency.
Value is clamped to the range [0.0,5.0].
@type fresnelTrans: float
@ivar fresnelTransFac: Blending factor for Fresnel transparency.
Value is clamped to the range [1.0,5.0].
@type fresnelTransFac: float
@ivar haloSeed: Randomizes halo ring dimension and line location.
Value is clamped to the range [1,255].
@type haloSeed: int
@ivar haloSize: Dimension of the halo.
Value is clamped to the range [0.0,100.0].
@type haloSize: float
@ivar hard: Hardness of the specularity.
Value is clamped to the range [1,255].
@type hard: int
@ivar ipo: Material Ipo data.
Contains the Ipo if one is assigned to the object, None otherwise. Setting to None clears the current Ipo.
@type ipo: Blender Ipo
@ivar mirB: Mirror color (L{mirCol}) blue component.
Value is clamped to the range [0.0,1.0].
@type mirB: float
@ivar mirCol: Mirror RGB color triplet.
Components are clamped to the range [0.0,1.0].
@type mirCol: list of 3 floats
@ivar mirG: Mirror color (L{mirCol}) green component.
Value is clamped to the range [0.0,1.0].
@type mirG: float
@ivar mirR: Mirror color (L{mirCol}) red component.
Value is clamped to the range [0.0,1.0].
@type mirR: float
@ivar mode: Mode mode bitfield. See L{the Modes dictionary<Modes>} keys and descriptions.
@type mode: int
@ivar nFlares: Number of subflares with halo.
Value is clamped to the range [1,32].
@type nFlares: int
@ivar nLines: Number of star-shaped lines with halo.
Value is clamped to the range [0,250].
@type nLines: int
@ivar nRings: Number of rings with halo.
Value is clamped to the range [0,24].
@type nRings: int
@ivar nStars: Number of star points with halo.
Value is clamped to the range [3,50].
@type nStars: int
@ivar name: Material data name.
@type name: str
@ivar oopsLoc: Material OOPs location. Returns None if materal not found in list.
@type oopsLoc: list of 2 floats
@ivar oopsSel: Material OOPs selection flag.
Value must be in the range [0,1].
@type oopsSel: int
@ivar rayMirr: Mirror reflection amount for raytrace.
Value is clamped to the range [0.0,1.0].
@type rayMirr: float
@ivar rayMirrDepth: Amount of raytrace inter-reflections.
Value is clamped to the range [0,10].
@type rayMirrDepth: int
@ivar ref: Amount of reflections (for shader).
Value is clamped to the range [0.0,1.0].
@type ref: float
@ivar refracIndex: Material's Index of Refraction (applies to the "Blinn" Specular Shader only.
Value is clamped to the range [1.0,10.0].
@type refracIndex: float
@ivar rgbCol: Diffuse RGB color triplet.
Components are clamped to the range [0.0,1.0].
@type rgbCol: list of 3 floats
@ivar rms: Material's surface slope standard deviation ("WardIso" specular shader only).
Value is clamped to the range [0.0,0.4].
@type rms: float
@ivar roughness: Material's roughness ("Oren Nayar" diffuse shader only).
Value is clamped to the range [0.0,3.14].
@type roughness: float
@ivar spec: Degree of specularity.
Value is clamped to the range [0.0,2.0].
@type spec: float
@ivar specB: Specular color (L{specCol}) blue component.
Value is clamped to the range [0.0,1.0].
@type specB: float
@ivar specCol: Specular RGB color triplet.
Components are clamped to the range [0.0,1.0].
@type specCol: list of 3 floats
@ivar specG: Specular color (L{specCol}) green component.
Value is clamped to the range [0.0,1.0].
@type specG: float
@ivar specR: Specular color (L{specCol}) red component.
Value is clamped to the range [0.0,1.0].
@type specR: float
@ivar specShader: Specular shader type. See L{Shaders}.
Value must be in the range [0,4].
@type specShader: int
@ivar specSize: Material's specular area size ("Toon" specular shader only).
Value is clamped to the range [0.0,1.53].
@type specSize: float
@ivar specSmooth: Sets the smoothness of specular toon area.
Value is clamped to the range [0.0,1.0].
@type specSmooth: float
@ivar specTransp: Makes specular areas opaque on transparent materials.
Value is clamped to the range [0.0,1.0].
@type specTransp: float
@ivar subSize: Dimension of subflares, dots and circles.
Value is clamped to the range [0.1,25.0].
@type subSize: float
@ivar transDepth: calculated maximal. Amount of refractions for raytrace.
Value is clamped to the range [0,10].
@type transDepth: int
@ivar translucency: Amount of diffuse shading of the back side.
Value is clamped to the range [0.0,1.0].
@type translucency: float
@ivar users: Number of material users.
@type users: int
@ivar zOffset: Artificial offset in the Z buffer (for Ztransp option).
Value is clamped to the range [0.0,10.0].
@type zOffset: float
@warning: Most member variables assume values in some [Min, Max] interval. @warning: Most member variables assume values in some [Min, Max] interval.
When trying to set them, the given parameter will be clamped to lie in When trying to set them, the given parameter will be clamped to lie in
that range: if val < Min, then val = Min, if val > Max, then val = Max. that range: if val < Min, then val = Min, if val > Max, then val = Max.

View File

@@ -4,7 +4,6 @@
# Written by Alex Mole # Written by Alex Mole
# #
""" """
The Blender.Texture submodule. The Blender.Texture submodule.
@@ -46,11 +45,16 @@ Example::
- IMAGE - Image texture - IMAGE - Image texture
- PLUGIN - Plugin texture - PLUGIN - Plugin texture
- ENVMAP - EnvMap texture - ENVMAP - EnvMap texture
- MUSGRAVE - Musgrave procedural texture
- VORONOI - Voronoi procedural texture
- DISTNOISE - Distorted noise texture
@type Flags: readonly dictionary @type Flags: readonly dictionary
@var Flags: The available Texture flags: @var Flags: The available Texture flags:
- FLIPBLEND - Flips the blend texture's X and Y directions - FLIPBLEND - Flips the blend texture's X and Y directions
- NEGALPHA - Reverse the alpha value - NEGALPHA - Reverse the alpha value
- CHECKER_ODD - Fill the "odd" checkerboard tiles
- CHECKER_EVEN - Fill the "even" checkerboard tiles
@type ImageFlags: readonly dictionary @type ImageFlags: readonly dictionary
@var ImageFlags: The available image flags for Texture.imageFlags: @var ImageFlags: The available image flags for Texture.imageFlags:
@@ -67,11 +71,31 @@ Example::
- NORMALMAP - Use image RGB values for normal mapping - NORMALMAP - Use image RGB values for normal mapping
@type ExtendModes: readonly dictionary @type ExtendModes: readonly dictionary
@var ExtendModes: Extend, clamp or repeat modes for images @var ExtendModes: Extend, clip, repeat or checker modes for image textures
- EXTEND - Extends the colour of the edge - EXTEND - Extends the colour of the edge
- CLIP - Return alpha 0.0 outside image - CLIP - Return alpha 0.0 outside image
- CLIPCUBE - Return alpha 0.0 around cube-shaped area around image - CLIPCUBE - Return alpha 0.0 around cube-shaped area around image
- REPEAT - Repeat image vertically and horizontally - REPEAT - Repeat image vertically and horizontally
- CHECKER - Repeat image in checkerboard pattern
@type Noise: readonly dictionary
@var Noise: Noise types and bases. SINE, SAW and TRI are only used for
marble and wood textures, while the remainder are used for all textures
which has a noise basis function (for these textures, the constant should
be used with the second noise basis setting).
- SINE - Produce bands using sine wave (marble, wood textures)
- SAW - Produce bands using saw wave (marble, wood textures)
- TRI - Produce bands using triangle wave (marble, wood textures)
- BLENDER - Original Blender algorithm
- PERLIN - Ken Perlin's original (1985) algorithm
- IMPROVEPERLIN - Ken Perlin's newer (2002) algorithm
- VORONOIF1 - none
- VORONOIF2 - none
- VORONOIF3 - none
- VORONOIF4 - none
- VORONOIF2F1 - none
- VORONOICRACKLE - none
- CELLNOISE - Steven Worley's cellular basis algorithm (1996)
@type STypes: readonly dictionary @type STypes: readonly dictionary
@var STypes: Texture-type specific data. Depending on the value of @var STypes: Texture-type specific data. Depending on the value of
@@ -113,6 +137,28 @@ Example::
- ENV_STATIC - Calculate map only once - ENV_STATIC - Calculate map only once
- ENV_ANIM - Calculate map each rendering - ENV_ANIM - Calculate map each rendering
- ENV_LOAD - Load map from disk - ENV_LOAD - Load map from disk
11. Musgrave type
- MUS_MFRACTAL - Hetero Multifractal
- MUS_RIDGEDMF - Ridged Multifractal
- MUS_HYBRIDMF - Hybrid Multifractal
- MUS_FBM - Fractal Brownian Motion
- MUS_HTERRAIN - Hetero Terrain
12. Voronoi type
- VN_INT - Only calculate intensity
- VN_COL1 - Color cells by position
- VN_COL2 - Same as Col1 plus outline based on F2-F1
- VN_COL3 - Same as Col2 multiplied by intensity
13. Distorted noise type
- DN_BLENDER - Original Blender algorithm
- DN_PERLIN - Ken Perlin's original (1985) algorithm
- DN_IMPROVEPERLIN - Ken Perlin's newer (2002) algorithm
- DN_VORONOIF1 - none
- DN_VORONOIF2 - none
- DN_VORONOIF3 - none
- DN_VORONOIF4 - none
- DN_VORONOIF2F1 - none
- DN_VORONOICRACKLE - none
- DN_CELLNOISE - Steven Worley's cellular basis algorithm (1996)
@var TexCo: Flags for MTex.texco. @var TexCo: Flags for MTex.texco.
- ORCO - Use the original coordinates of the mesh - ORCO - Use the original coordinates of the mesh
@@ -166,41 +212,146 @@ class Texture:
================== ==================
This object gives access to Texture-specific data in Blender. This object gives access to Texture-specific data in Blender.
Note that many of the attributes of this object are only relevant if Note that many of the attributes of this object are only relevant for
specific modes are enabled. specific texture types.
@ivar name: The Texture name. @ivar animFrames: Number of frames of a movie to use.
@ivar type: The Texture type. See L{Types} Value is clamped to the range [0,30000].
@ivar flags: The texture flags (OR'd together). See L{Flags} @type animFrames: int
@ivar imageFlags: The texture image flags (OR'd tegether). @ivar animLength: Number of frames of a movie to use (0 for all).
See L{ImageFlags} Value is clamped to the range [0,9000].
@ivar stype: Texture-type specific data. See L{STypes} @type animLength: int
@ivar image: The image associated with this texture, or None. @ivar animMontage: Montage mode, start frames and durations. Example: C{( (fra1,dur1), (fra2,dur2), (fra3,dur3), (fra4,dur4) )}.
@type image: Blender Image @type animMontage: tuple of 4 (int,int)
@ivar rgbCol: The texture's RGB color triplet. @ivar animOffset: Offsets the number of the first movie frame to use.
@ivar brightness: The brightness in range [0,2]. Value is clamped to the range [-9000,9000].
@ivar contrast: The contrast in range [0,2]. @type animOffset: int
@ivar filterSize: The filter size for the image. @ivar animStart: Starting frame of the movie to use.
@ivar extend: Texture extend/repeat mode. See L{ExtendModes} Value is clamped to the range [1,9000].
@ivar crop: Tuple of image crop values as floats, @type animStart: int
like C{(xmin, ymin, xmax, ymax)} @ivar anti: Image anti-aliasing enabled. Also see L{ImageFlags}.
@ivar repeat: Tuple of image repeat values as ints, like @type anti: int
C{(xrepeat, yrepeat)} @ivar brightness: Changes the brightness of a texture's color.
@ivar noiseSize: The noise size. Value is clamped to the range [0.0,2.0].
@ivar noiseDepth: The noise depth. @type brightness: float
@ivar noiseType: The noise type: 'soft' or 'hard'. @ivar calcAlpha: Calculation of image's alpha channel enabled. Also see L{ImageFlags}.
@ivar animLength: Length of the animation. @type calcAlpha: int
@ivar animFrames: Frames of the animation. @ivar contrast: Changes the contrast of a texture's color.
@ivar animOffset: The number of the first picture of the animation. Value is clamped to the range [0.01,5.0].
@ivar animStart: Start frame of the animation. @type contrast: float
@ivar fieldsPerImage: The number of fields per rendered frame. @ivar crop: Sets the cropping extents (for image textures).
@ivar animMontage: Montage mode data as a tuple of tuples, like @type crop: tuple of 4 ints
C{( (fra1,dur1), (fra2,dur2), (fra3,dur3), (fra4,dur4) )} @ivar cyclic: Looping of animated frames enabled. Also see L{ImageFlags}.
@type cyclic: int
@ivar distAmnt: Amount of distortion (for distorted noise textures).
Value is clamped to the range [0.0,10.0].
@type distAmnt: float
@ivar distMetric: The distance metric (for Voronoi textures).
@type distMetric: int
@ivar exp: Minkovsky exponent (for Minkovsky Voronoi textures).
Value is clamped to the range [0.01,10.0].
@type exp: float
@ivar extend: Texture's 'Extend' mode (for image textures). See L{ExtendModes}.
@type extend: int
@ivar fields: Use of image's fields enabled. Also see L{ImageFlags}.
@type fields: int
@ivar fieldsPerImage: Number of fields per rendered frame.
Value is clamped to the range [1,200].
@type fieldsPerImage: int
@ivar filterSize: The filter size (for image and envmap textures).
Value is clamped to the range [0.1,25.0].
@type filterSize: float
@ivar flags: Texture's 'Flag' bitfield. See L{Flags}.
bitmask.
@type flags: int
@ivar hFracDim: Highest fractional dimension (for Musgrave textures).
Value is clamped to the range [0.0001,2.0].
@type hFracDim: float
@ivar iScale: Intensity output scale (for Musgrave and Voronoi textures).
Value is clamped to the range [0.0,10.0].
@type iScale: float
@ivar image: Texture's image object.
@type image: Blender Image (or None)
@ivar imageFlags: Texture's 'ImageFlags' bits.
@type imageFlags: int
@ivar interpol: Interpolate image's pixels to fit texture mapping enabled. Also see L{ImageFlags}.
@type interpol: int
@ivar ipo: Texture Ipo data.
Contains the Ipo if one is assigned to the object, B{None} otherwise. Setting to B{None} clears the current Ipo..
@type ipo: Blender Ipo
@ivar lacunarity: Gap between succesive frequencies (for Musgrave textures).
Value is clamped to the range [0.0,6.0].
@type lacunarity: float
@ivar mipmap: Mipmaps enabled. Also see L{ImageFlags}.
@type mipmap: int
@ivar movie: Movie frames as images enabled. Also see L{ImageFlags}.
@type movie: int
@ivar name: Texture data name.
@type name: string
@ivar noiseBasis: Noise basis type (wood, stucci, marble, clouds,
Musgrave, distorted). See L{Noise} dictionary.
@type noiseBasis: int
@ivar noiseBasis2: Additional noise basis type (wood, marble, distorted
noise). See L{Noise} dictionary.
@type noiseBasis2: int
@ivar noiseDepth: Noise depth (magic, marble, clouds).
Value is clamped to the range [0,6].
@type noiseDepth: int
@ivar noiseSize: Noise size (wood, stucci, marble, clouds, Musgrave,
distorted noise).
Value is clamped to the range [0.0001,2.0].
@type noiseSize: float
@ivar noiseType: Noise type (for wood, stucci, marble, clouds textures). Valid values are 'hard' or 'soft'.
@type noiseType: string
@ivar normalMap: Use of image RGB values for normal mapping enabled.
Also see L{ImageFlags}.
@type normalMap: int
@ivar octs: Number of frequencies (for Musgrave textures).
Value is clamped to the range [0.0,8.0].
@type octs: float
@ivar repeat: Repetition multiplier (for image textures).
@type repeat: tuple of 2 ints
@ivar rgbCol: RGB color tuple.
@type rgbCol: tuple of 3 floats
@ivar rot90: X/Y flip for rendering enabled. Also see L{ImageFlags}.
@type rot90: int
@ivar saw: Produce bands using saw wave (marble, wood textures). Also see L{Noise}.
@type saw: int
@ivar sine: Produce bands using sine wave (marble, wood textures). Also see L{Noise}.
@type sine: int
@ivar stField: Standard field deinterlacing enabled. Also see L{ImageFlags}.
@type stField: int
@ivar stype: Texture's 'SType' mode. See L{STypes}.
@type stype: int
@ivar tri: Produce bands using triangle wave (marble, wood textures). Also see L{Noise}.
@type tri: int
@ivar turbulence: Turbulence (for magic, wood, stucci, marble textures).
Value is clamped to the range [0.0,200.0].
@type turbulence: float
@ivar type: Texture's 'Type' mode. See L{Types}.
Value must be in the range [0,13].
@type type: int
@ivar useAlpha: Use of image's alpha channel enabled. Also see L{ImageFlags}.
@type useAlpha: int
@ivar users: Number of texture users. Read-only.
@type users: int
@ivar weight1: Weight 1 (for Voronoi textures).
Value is clamped to the range [-2.0,2.0].
@type weight1: float
@ivar weight2: Weight 2 (for Voronoi textures).
Value is clamped to the range [-2.0,2.0].
@type weight2: float
@ivar weight3: Weight 3 (for Voronoi textures).
Value is clamped to the range [-2.0,2.0].
@type weight3: float
@ivar weight4: Weight 4 (for Voronoi textures).
Value is clamped to the range [-2.0,2.0].
@type weight4: float
""" """
def getExtend(): def getExtend():
""" """
Get the extend mode of the texture. See L{setExtend} Get the extend mode of the texture. See L{setExtend}.
@rtype: string. @rtype: string.
""" """
@@ -218,9 +369,8 @@ class Texture:
def getType(): def getType():
""" """
Get this Texture's type. Get this Texture's type. See L{setType}.
@rtype: string @rtype: string
@return: The Texture's type. See L{setType}
""" """
def setExtend(extendmode): def setExtend(extendmode):
@@ -231,12 +381,12 @@ class Texture:
@type extendmode: string @type extendmode: string
""" """
def setFlags(f=None, f2=None, f3=None): def setFlags(f1=None, f2=None, f3=None, f4=None):
""" """
Set this object's flags. Set this object's flags.
@param f: Flags to be set (omitted flags are cleared). Can be any of @param f1,f2,f3,f4: Flags to be set (omitted flags are cleared). Can be any of
'ColorBand', 'FlipBlendXY', and 'NegAlpha' 'FlipBlendXY', 'NegAlpha', 'CheckerOdd', and 'CheckerEven'
@type f: string @type f1,f2,f3,f4: string
""" """
def setImage(image): def setImage(image):
@@ -247,14 +397,14 @@ class Texture:
@warning: This sets the texture's type to 'Image' if it is not already. @warning: This sets the texture's type to 'Image' if it is not already.
""" """
def setImageFlags(f=None, f2=None, f3=None, and_so_on=None): def setImageFlags(f1=None, f2=None, f3=None, etc=None):
""" """
Set the Image flags (only makes sense for IMAGE textures). Omitted Set the Image flags (only makes sense for IMAGE textures). Omitted
flags are cleared. flags are cleared.
@param f: Flag to set. See L{ImageFlags} for their meanings. Can be @param f1, f2, f3, etc: Flag to set. See L{ImageFlags} for their meanings. Can be
any of: 'InterPol', 'UseAlpha', 'MipMap', 'Fields', 'Rot90', any of: 'InterPol', 'UseAlpha', 'MipMap', 'Fields', 'Rot90',
'CalcAlpha', 'StField', 'Movie' and 'Cyclic' 'CalcAlpha', 'Cyclic', 'Movie', 'StField', 'Anti' and 'NormalMap'
@type f: string @type f1, f2, f3, etc: string
""" """
def setName(name): def setName(name):
@@ -267,16 +417,13 @@ class Texture:
def setSType(stype): def setSType(stype):
""" """
Set the SType. Set the SType.
@param stype: The new stype. This can be one of the following values @param stype: The new stype. This can be any of the values listed in
or 'Default' which sets the stype to the default value. See L{STypes} or 'Default' which sets the stype to the default value.
L{STypes} for their meanings.
'CloudDefault', 'CloudColor', 'WoodBands', 'WoodRings',
'WoodBandNoise', 'WoodRingNoise', 'MarbleSoft', 'MarbleSharp',
'MarbleSharper', 'BlendLin', 'BlendQuad', 'BlendEase',
'BlendDiag', 'BlendSphere', 'BlendHalo', 'StucciPlastic',
'StucciWallIn', 'StucciWallOut', 'EnvmapStatic', 'EnvmapAnim',
'EnvmapLoad'
@type stype: string @type stype: string
@note: the set of valid parameters is dependent on the current
texture type. Be sure to always set the texture type B{before}
setting the texture's stype; otherwise an exception might occur.
""" """
def setType(type): def setType(type):
@@ -284,7 +431,8 @@ class Texture:
Set this Texture's type. Set this Texture's type.
@param type: The new type. Possible options are: @param type: The new type. Possible options are:
'None', 'Clouds', 'Wood', 'Marble', 'Magic', 'Blend', 'Stucci', 'None', 'Clouds', 'Wood', 'Marble', 'Magic', 'Blend', 'Stucci',
'Noise', 'Image', 'Plugin' and 'EnvMap' 'Noise', 'Image', 'Plugin', 'EnvMap', 'Musgrave', 'Voronoi'
and 'DistNoise'
@type type: string @type type: string
""" """

View File

@@ -39,6 +39,8 @@
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_main.h" #include "BKE_main.h"
#include "constant.h"
//---------------------- EXPP_GetModuleConstant ------------------------- //---------------------- EXPP_GetModuleConstant -------------------------
//Helper function for returning a module constant //Helper function for returning a module constant
PyObject *EXPP_GetModuleConstant(char *module, char *constant) PyObject *EXPP_GetModuleConstant(char *module, char *constant)
@@ -597,69 +599,59 @@ PyObject *EXPP_addScriptLink(ScriptLink *slink, PyObject *args, int is_scene)
* value: PyObject containing the new value * value: PyObject containing the new value
* param: pointer to destination variable * param: pointer to destination variable
* max, min: range of values for clamping * max, min: range of values for clamping
* type: kind of pointer and data (uses the same characters as
* PyArgs_ParseTuple() and Py_BuildValue()
* *
* Return 0 on success, -1 on error. * Return 0 on success, -1 on error.
*/ */
int EXPP_setCharClamped ( PyObject *value, char *param, int EXPP_setFloatClamped( PyObject *value, float *param,
short min, short max )
{
/* if value not of correct type, raise Type exception */
if( !PyInt_CheckExact( value ) ) {
char errstr[128];
sprintf ( errstr, "expected char argument in [%d,%d]", min, max );
return EXPP_ReturnIntError( PyExc_TypeError, errstr );
}
/* clamp and store value */
*param = EXPP_ClampInt( PyInt_AS_LONG ( value ), min, max );
return 0;
}
int EXPP_setShortClamped ( PyObject *value, short *param,
short min, short max )
{
if( !PyInt_CheckExact ( value ) ) {
char errstr[128];
sprintf ( errstr, "expected int argument in [%d,%d]", min, max );
return EXPP_ReturnIntError( PyExc_TypeError, errstr );
}
*param = EXPP_ClampInt( PyInt_AS_LONG ( value ), min, max );
return 0;
}
int EXPP_setIntClamped ( PyObject *value, int *param,
int min, int max )
{
if( !PyInt_CheckExact ( value ) ) {
char errstr[128];
sprintf ( errstr, "expected int argument in [%d,%d]", min, max );
return EXPP_ReturnIntError( PyExc_TypeError, errstr );
}
*param = EXPP_ClampInt( PyInt_AS_LONG ( value ), min, max );
return 0;
}
int EXPP_setFloatClamped ( PyObject *value, float *param,
float min, float max ) float min, float max )
{ {
if( !PyFloat_CheckExact ( value ) ) { if( !PyNumber_Check ( value ) ) {
char errstr[128]; char errstr[128];
sprintf ( errstr, "expected float argument in [%f,%f]", min, max ); sprintf ( errstr, "expected float argument in [%f,%f]", min, max );
return EXPP_ReturnIntError( PyExc_TypeError, errstr ); return EXPP_ReturnIntError( PyExc_TypeError, errstr );
} }
*param = EXPP_ClampFloat( PyFloat_AS_DOUBLE( value ), min, max ); *param = EXPP_ClampFloat( PyFloat_AsDouble( value ), min, max );
return 0; return 0;
} }
int EXPP_setIValueClamped( PyObject *value, void *param,
int min, int max, char type )
{
char errstr[128];
int number;
sprintf ( errstr, "expected int argument in [%d,%d]", min, max );
if( !PyInt_CheckExact ( value ) )
return EXPP_ReturnIntError( PyExc_TypeError, errstr );
number = PyInt_AS_LONG( value );
switch ( type ) {
case 'b':
*(char *)param = EXPP_ClampInt( number, min, max );
return 0;
case 'h':
*(short *)param = EXPP_ClampInt( number, min, max );
return 0;
case 'H':
*(unsigned short *)param = EXPP_ClampInt( number, min, max );
return 0;
case 'i':
*(int *)param = EXPP_ClampInt( number, min, max );
return 0;
default:
return EXPP_ReturnIntError( PyExc_RuntimeError,
"EXPP_setIValueClamped(): invalid type code" );
}
}
/* /*
* Utility routines to range-check and store various datatypes. The object * Utility routines to range-check and store various datatypes. The object
* type is checked and a exception is raised if it's not the correct type. * type is checked and a exception is raised if it's not the correct type.
@@ -670,49 +662,24 @@ int EXPP_setFloatClamped ( PyObject *value, float *param,
* value: PyObject containing the new value * value: PyObject containing the new value
* param: pointer to destination variable * param: pointer to destination variable
* max, min: valid range for value * max, min: valid range for value
* type: kind of pointer and data (uses the same characters as
* PyArgs_ParseTuple() and Py_BuildValue()
* *
* Return 0 on success, -1 on error. * Return 0 on success, -1 on error.
*/ */
int EXPP_setCharRange ( PyObject *value, char *param, int EXPP_setFloatRange( PyObject *value, float *param,
short min, short max ) float min, float max )
{ {
char errstr[128]; char errstr[128];
short number; short number;
/* build exception error string */ sprintf ( errstr, "expected int argument in [%f,%f]", min, max );
sprintf ( errstr, "expected int argument in [%d,%d]", min, max ); if( !PyNumber_Check ( value ) )
/* if value not of correct type, raise Type exception */
if( !PyInt_CheckExact ( value ) )
return EXPP_ReturnIntError( PyExc_TypeError, errstr ); return EXPP_ReturnIntError( PyExc_TypeError, errstr );
/* if value out of range, raise Value exception */ number = PyFloat_AsDouble( value );
number = PyInt_AS_LONG ( value );
if ( number < min || number > max )
return EXPP_ReturnIntError( PyExc_ValueError, errstr );
/* store value */
*param = number;
return 0;
}
int EXPP_setShortRange ( PyObject *value, short *param,
short min, short max )
{
char errstr[128];
short number;
sprintf ( errstr, "expected int argument in [%d,%d]", min, max );
if( !PyInt_CheckExact ( value ) )
return EXPP_ReturnIntError( PyExc_TypeError, errstr );
number = PyInt_AS_LONG ( value );
if ( number < min || number > max ) if ( number < min || number > max )
return EXPP_ReturnIntError( PyExc_ValueError, errstr ); return EXPP_ReturnIntError( PyExc_ValueError, errstr );
@@ -720,8 +687,8 @@ int EXPP_setShortRange ( PyObject *value, short *param,
return 0; return 0;
} }
int EXPP_setIntRange ( PyObject *value, int *param, int EXPP_setIValueRange( PyObject *value, void *param,
int min, int max ) int min, int max, char type )
{ {
char errstr[128]; char errstr[128];
int number; int number;
@@ -731,29 +698,179 @@ int EXPP_setIntRange ( PyObject *value, int *param,
if( !PyInt_CheckExact ( value ) ) if( !PyInt_CheckExact ( value ) )
return EXPP_ReturnIntError( PyExc_TypeError, errstr ); return EXPP_ReturnIntError( PyExc_TypeError, errstr );
number = PyInt_AS_LONG ( value ); number = PyInt_AS_LONG( value );
if ( number < min || number > max ) if( number < min || number > max )
return EXPP_ReturnIntError( PyExc_ValueError, errstr ); return EXPP_ReturnIntError( PyExc_ValueError, errstr );
*param = number; switch ( type ) {
return 0; case 'b':
*(char *)param = number;
return 0;
case 'h':
*(short *)param = number;
return 0;
case 'H':
*(unsigned short *)param = number;
return 0;
case 'i':
*(int *)param = number;
return 0;
default:
return EXPP_ReturnIntError( PyExc_RuntimeError,
"EXPP_setIValueRange(): invalid type code" );
}
} }
int EXPP_setFloatRange ( PyObject *value, float *param, /*
float min, float max ) * Utility routines to handle all attribute setters which use module
* constants. Generic pointer to destination variable is used, and typecast
* to the appropriate type based on the "type" specifier.
*
* Inputs:
* constant: constant_Type value
* param: pointer to destination variable
* type: kind of pointer and data
*
* Return 0 on success, -1 on error.
*/
int EXPP_setModuleConstant ( BPy_constant *constant, void *param, char type )
{ {
char errstr[128]; PyObject *item;
short number;
sprintf ( errstr, "expected int argument in [%f,%f]", min, max ); if( constant->ob_type != &constant_Type )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected module constant" );
if( !PyFloat_CheckExact ( value ) ) item = PyDict_GetItemString( constant->dict, "value" );
if( !item )
return EXPP_ReturnIntError( PyExc_RuntimeError,
"module constant has no \"value\" key" );
switch ( type ) {
case 'h':
*(short *)param = PyInt_AS_LONG( item );
return 0;
case 'i':
*(int *)param = PyInt_AS_LONG( item );
return 0;
case 'f':
*(float *)param = PyFloat_AS_DOUBLE( item );
return 0;
default:
return EXPP_ReturnIntError( PyExc_RuntimeError,
"EXPP_setModuleConstant(): invalid type code" );
}
}
/*
* Utility routines to get/set bits in bitfields. Adapted from code in
* sceneRender.c (thanks, ascotan!).
*
* Inputs:
* param: pointer to source/destination variable
* setting: the bit to get/set
* type: pointer type ('h' == short, 'i' == integer)
*/
PyObject *EXPP_getBitfield( void *param, int setting, char type )
{
switch ( type ) {
case 'b':
return (*(char *)param & setting)
? EXPP_incr_ret_True() : EXPP_incr_ret_False();
case 'h':
return (*(short *)param & setting)
? EXPP_incr_ret_True() : EXPP_incr_ret_False();
case 'i':
return (*(int *)param & setting)
? EXPP_incr_ret_True() : EXPP_incr_ret_False();
default:
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"EXPP_getBit(): invalid type code" );
}
}
int EXPP_setBitfield( PyObject * value, void *param, int setting, char type )
{
int flag;
char errstr[] = "expected TRUE or FALSE (1 or 0)";
if( !PyInt_CheckExact ( value ) )
return EXPP_ReturnIntError( PyExc_TypeError, errstr ); return EXPP_ReturnIntError( PyExc_TypeError, errstr );
number = PyFloat_AS_DOUBLE( value ); flag = PyInt_AS_LONG ( value );
if ( number < min || number > max ) if( flag != 0 && flag != 1 )
return EXPP_ReturnIntError( PyExc_ValueError, errstr ); return EXPP_ReturnIntError( PyExc_ValueError, errstr );
*param = number; switch ( type ) {
return 0; case 'b':
if ( flag )
*(char *)param |= setting;
else
*(char *)param &= ~setting;
return 0;
case 'h':
if ( flag )
*(short *)param |= setting;
else
*(short *)param &= ~setting;
return 0;
case 'i':
if ( flag )
*(int *)param |= setting;
else
*(int *)param &= ~setting;
return 0;
default:
return EXPP_ReturnIntError( PyExc_RuntimeError,
"EXPP_setBit(): invalid type code" );
}
} }
/*
* Procedure to handle older setStuff() methods. Assumes that argument
* is a tuple with one object, and so grabs the object and passes it to
* the specified tp_getset setter for the corresponding attribute.
*/
PyObject *EXPP_setterWrapper ( PyObject * self, PyObject * args,
setter func)
{
int error;
if ( !PyTuple_Check( args ) || PyTuple_Size( args ) != 1 )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"expected tuple of one item" );
error = func ( self, PySequence_Fast_GET_ITEM( args, 0 ), NULL );
if ( !error ) {
Py_INCREF( Py_None );
return Py_None;
} else
return NULL;
}
/*
* Procedure to handle older setStuff() methods. Assumes that argument
* is a tuple, so just passes it to the specified tp_getset setter for
* the corresponding attribute.
*/
PyObject *EXPP_setterWrapperTuple ( PyObject * self, PyObject * args,
setter func)
{
int error;
if ( !PyTuple_Check( args ) )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"expected tuple" );
error = func ( self, args, NULL );
if ( !error ) {
Py_INCREF( Py_None );
return Py_None;
} else
return NULL;
}

View File

@@ -38,6 +38,8 @@
#include "DNA_scriptlink_types.h" #include "DNA_scriptlink_types.h"
#include "DNA_listBase.h" #include "DNA_listBase.h"
#include "constant.h"
#define Py_PI 3.14159265358979323846 #define Py_PI 3.14159265358979323846
#define Py_WRAP 1024 #define Py_WRAP 1024
#define Py_NEW 2048 #define Py_NEW 2048
@@ -99,24 +101,36 @@ int EXPP_map_getStrVal( const EXPP_map_pair * map,
/* clamping and range-checking utilities */ /* clamping and range-checking utilities */
int EXPP_setCharClamped ( PyObject *value, char *param, int EXPP_setIValueClamped( PyObject *value, void *param,
short min, short max); int min, int max, char type );
int EXPP_setShortClamped ( PyObject *value, short *param,
short min, short max);
int EXPP_setIntClamped ( PyObject *value, int *param,
int min, int max);
int EXPP_setFloatClamped ( PyObject *value, float *param, int EXPP_setFloatClamped ( PyObject *value, float *param,
float min, float max); float min, float max);
int EXPP_setIValueRange( PyObject *value, void *param,
int EXPP_setChrRange ( PyObject *value, char *param, int min, int max, char type );
short min, short max);
int EXPP_setShortRange ( PyObject *value, short *param,
short min, short max);
int EXPP_setIntRange ( PyObject *value, int *param,
int min, int max);
int EXPP_setFloatRange ( PyObject *value, float *param, int EXPP_setFloatRange ( PyObject *value, float *param,
float min, float max); float min, float max);
/* utility routine for PyType attributes setters with module constant */
int EXPP_setModuleConstant ( BPy_constant *constant, void *param,
char type );
/* utilities to get/set bits in bitfields */
PyObject *EXPP_getBitfield( void *param, int setting, char type );
int EXPP_setBitfield( PyObject * value, void *param, int setting, char type );
/*
* Procedures to handle older setStuff() methods, which now access
* a PyType's setter attributes using the tp_getset mechanism.
*/
PyObject *EXPP_setterWrapper ( PyObject * self, PyObject * args,
setter func);
PyObject *EXPP_setterWrapperTuple ( PyObject * self, PyObject * args,
setter func);
/* scriplinks-related: */ /* scriplinks-related: */
PyObject *EXPP_getScriptLinks(ScriptLink *slink, PyObject *args, int is_scene); PyObject *EXPP_getScriptLinks(ScriptLink *slink, PyObject *args, int is_scene);
PyObject *EXPP_addScriptLink(ScriptLink *slink, PyObject *args, int is_scene); PyObject *EXPP_addScriptLink(ScriptLink *slink, PyObject *args, int is_scene);

View File

@@ -45,7 +45,7 @@ static PyObject *rgbTuple_getAttr( BPy_rgbTuple * self, char *name );
static int rgbTuple_setAttr( BPy_rgbTuple * self, char *name, PyObject * v ); static int rgbTuple_setAttr( BPy_rgbTuple * self, char *name, PyObject * v );
static PyObject *rgbTuple_repr( BPy_rgbTuple * self ); static PyObject *rgbTuple_repr( BPy_rgbTuple * self );
static int rgbTupleLength( BPy_rgbTuple * self ); static int rgbTupleLength( void );
static PyObject *rgbTupleSubscript( BPy_rgbTuple * self, PyObject * key ); static PyObject *rgbTupleSubscript( BPy_rgbTuple * self, PyObject * key );
static int rgbTupleAssSubscript( BPy_rgbTuple * self, PyObject * who, static int rgbTupleAssSubscript( BPy_rgbTuple * self, PyObject * who,
@@ -138,39 +138,47 @@ PyObject *rgbTuple_New( float *rgb[3] )
/*****************************************************************************/ /*****************************************************************************/
PyObject *rgbTuple_getCol( BPy_rgbTuple * self ) PyObject *rgbTuple_getCol( BPy_rgbTuple * self )
{ {
PyObject *list = PyList_New( 3 ); PyObject *attr = Py_BuildValue( "[fff]", *(self->rgb[0]),
*(self->rgb[1]), *(self->rgb[2]));
if( !list ) if( !attr )
return EXPP_ReturnPyObjError( PyExc_MemoryError, return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create PyList" ); "Py_BuildValue() failed" );
return attr;
PyList_SET_ITEM( list, 0, Py_BuildValue( "f", *( self->rgb[0] ) ) );
PyList_SET_ITEM( list, 1, Py_BuildValue( "f", *( self->rgb[1] ) ) );
PyList_SET_ITEM( list, 2, Py_BuildValue( "f", *( self->rgb[2] ) ) );
return list;
} }
PyObject *rgbTuple_setCol( BPy_rgbTuple * self, PyObject * args ) int rgbTuple_setCol( BPy_rgbTuple * self, PyObject * args )
{ {
int ok; int ok = 0;
float r = 0, g = 0, b = 0; float r = 0, g = 0, b = 0;
if( PyObject_Length( args ) == 3 ) /*
ok = PyArg_ParseTuple( args, "fff", &r, &g, &b ); * since rgbTuple_getCol() returns a list, be sure we accept a list
* as valid input
*/
else if( PyObject_Length( args ) == 3 ) {
if ( PyList_Check ( args ) &&
PyNumber_Check( PySequence_Fast_GET_ITEM( args, 0 ) ) &&
PyNumber_Check( PySequence_Fast_GET_ITEM( args, 1 ) ) &&
PyNumber_Check( PySequence_Fast_GET_ITEM( args, 2 ) ) ) {
r = PyFloat_AsDouble( PySequence_Fast_GET_ITEM( args, 0 ) );
g = PyFloat_AsDouble( PySequence_Fast_GET_ITEM( args, 1 ) );
b = PyFloat_AsDouble( PySequence_Fast_GET_ITEM( args, 2 ) );
ok = 1;
} else
ok = PyArg_ParseTuple( args, "fff", &r, &g, &b );
} else
ok = PyArg_ParseTuple( args, "|(fff)", &r, &g, &b ); ok = PyArg_ParseTuple( args, "|(fff)", &r, &g, &b );
if( !ok ) if( !ok )
return EXPP_ReturnPyObjError( PyExc_TypeError, return EXPP_ReturnIntError( PyExc_TypeError,
"expected [f,f,f] or f,f,f as arguments (or nothing)" ); "expected [f,f,f], (f,f,f) or f,f,f as arguments (or nothing)" );
*( self->rgb[0] ) = EXPP_ClampFloat( r, 0.0, 1.0 ); *( self->rgb[0] ) = EXPP_ClampFloat( r, 0.0, 1.0 );
*( self->rgb[1] ) = EXPP_ClampFloat( g, 0.0, 1.0 ); *( self->rgb[1] ) = EXPP_ClampFloat( g, 0.0, 1.0 );
*( self->rgb[2] ) = EXPP_ClampFloat( b, 0.0, 1.0 ); *( self->rgb[2] ) = EXPP_ClampFloat( b, 0.0, 1.0 );
return EXPP_incr_ret( Py_None ); return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -245,7 +253,7 @@ static int rgbTuple_setAttr( BPy_rgbTuple * self, char *name, PyObject * v )
/* These functions provide code to access rgbTuple objects as */ /* These functions provide code to access rgbTuple objects as */
/* mappings. */ /* mappings. */
/*****************************************************************************/ /*****************************************************************************/
static int rgbTupleLength( BPy_rgbTuple * self ) static int rgbTupleLength( void )
{ {
return 3; return 3;
} }

View File

@@ -51,6 +51,6 @@ typedef struct {
/*****************************************************************************/ /*****************************************************************************/
PyObject *rgbTuple_New( float *rgb[3] ); PyObject *rgbTuple_New( float *rgb[3] );
PyObject *rgbTuple_getCol( BPy_rgbTuple * self ); PyObject *rgbTuple_getCol( BPy_rgbTuple * self );
PyObject *rgbTuple_setCol( BPy_rgbTuple * self, PyObject * args ); int rgbTuple_setCol( BPy_rgbTuple * self, PyObject * args );
#endif /* EXPP_rgbTuple_H */ #endif /* EXPP_rgbTuple_H */