[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16480] trunk/blender/source/blender/ python/api2_2x: Python API
Ken Hughes
khughes at pacific.edu
Fri Sep 12 04:23:52 CEST 2008
Revision: 16480
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16480
Author: khughes
Date: 2008-09-12 04:23:52 +0200 (Fri, 12 Sep 2008)
Log Message:
-----------
Python API
----------
Second and final part of MTex API changes. Added support for new attributes for MTex World objects, stricter checking of attribute types for materia/lamp/world MTex objects, setters for lamp.textures and world.textures attributes, and updated documentation.
Modified Paths:
--------------
trunk/blender/source/blender/python/api2_2x/Lamp.c
trunk/blender/source/blender/python/api2_2x/MTex.c
trunk/blender/source/blender/python/api2_2x/Material.c
trunk/blender/source/blender/python/api2_2x/Texture.c
trunk/blender/source/blender/python/api2_2x/World.c
trunk/blender/source/blender/python/api2_2x/doc/Texture.py
Modified: trunk/blender/source/blender/python/api2_2x/Lamp.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Lamp.c 2008-09-12 02:15:16 UTC (rev 16479)
+++ trunk/blender/source/blender/python/api2_2x/Lamp.c 2008-09-12 02:23:52 UTC (rev 16480)
@@ -34,6 +34,7 @@
#include "BKE_global.h"
#include "BKE_object.h"
#include "BKE_library.h"
+#include "BKE_texture.h"
#include "BLI_blenlib.h"
#include "BIF_space.h"
#include "BSE_editipo.h"
@@ -44,6 +45,7 @@
#include "gen_utils.h"
#include "gen_library.h"
#include "BKE_utildefines.h"
+#include "MEM_guardedalloc.h"
/*****************************************************************************/
/* Python BPy_Lamp defaults: */
@@ -255,6 +257,7 @@
static int Lamp_setQuad1( BPy_Lamp * self, PyObject * args );
static int Lamp_setQuad2( BPy_Lamp * self, PyObject * args );
static int Lamp_setCol( BPy_Lamp * self, PyObject * args );
+static int Lamp_setTextures( BPy_Lamp * self, PyObject * value );
static PyObject *Lamp_getScriptLinks( BPy_Lamp * self, PyObject * value );
static PyObject *Lamp_addScriptLink( BPy_Lamp * self, PyObject * args );
static PyObject *Lamp_clearScriptLinks( BPy_Lamp * self, PyObject * args );
@@ -503,7 +506,7 @@
"Lamp color blue component",
(void *)EXPP_LAMP_COMP_B},
{"textures",
- (getter)Lamp_getTextures, (setter)NULL,
+ (getter)Lamp_getTextures, (setter)Lamp_setTextures,
"The Lamp's texture list as a tuple",
NULL},
{"Modes",
@@ -1423,6 +1426,76 @@
return tuple;
}
+static int Lamp_setTextures( BPy_Lamp * self, PyObject * value )
+{
+ int i;
+
+ if( !PyList_Check( value ) && !PyTuple_Check( value ) )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected tuple or list of integers" );
+
+ /* don't allow more than MAX_MTEX items */
+ if( PySequence_Size(value) > MAX_MTEX )
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "size of sequence greater than number of allowed textures" );
+
+ /* get a fast sequence; in Python 2.5, this just return the original
+ * list or tuple and INCREFs it, so we must DECREF */
+ value = PySequence_Fast( value, "" );
+
+ /* check the list for valid entries */
+ for( i= 0; i < PySequence_Size(value) ; ++i ) {
+ PyObject *item = PySequence_Fast_GET_ITEM( value, i );
+ if( item == Py_None || ( BPy_MTex_Check( item ) &&
+ ((BPy_MTex *)item)->type == ID_LA ) ) {
+ continue;
+ } else {
+ Py_DECREF(value);
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected tuple or list containing lamp MTex objects and NONE" );
+ }
+ }
+
+ /* for each MTex object, copy to this structure */
+ for( i= 0; i < PySequence_Size(value) ; ++i ) {
+ PyObject *item = PySequence_Fast_GET_ITEM( value, i );
+ struct MTex *mtex = self->lamp->mtex[i];
+ if( item != Py_None ) {
+ BPy_MTex *obj = (BPy_MTex *)item;
+
+ /* if MTex is already at this location, just skip it */
+ if( obj->mtex == mtex ) continue;
+
+ /* create a new entry if needed, otherwise update reference count
+ * for texture that is being replaced */
+ if( !mtex )
+ mtex = self->lamp->mtex[i] = add_mtex( );
+ else
+ mtex->tex->id.us--;
+
+ /* copy the data */
+ mtex->tex = obj->mtex->tex;
+ id_us_plus( &mtex->tex->id );
+ mtex->texco = obj->mtex->texco;
+ mtex->mapto = obj->mtex->mapto;
+ }
+ }
+
+ /* now go back and free any entries now marked as None */
+ for( i= 0; i < PySequence_Size(value) ; ++i ) {
+ PyObject *item = PySequence_Fast_GET_ITEM( value, i );
+ struct MTex *mtex = self->lamp->mtex[i];
+ if( item == Py_None && mtex ) {
+ mtex->tex->id.us--;
+ MEM_freeN( mtex );
+ self->lamp->mtex[i] = NULL;
+ }
+ }
+
+ Py_DECREF(value);
+ return 0;
+}
+
/* #####DEPRECATED###### */
static PyObject *Lamp_oldsetSamples( BPy_Lamp * self, PyObject * args )
Modified: trunk/blender/source/blender/python/api2_2x/MTex.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/MTex.c 2008-09-12 02:15:16 UTC (rev 16479)
+++ trunk/blender/source/blender/python/api2_2x/MTex.c 2008-09-12 02:23:52 UTC (rev 16480)
@@ -22,7 +22,7 @@
*
* This is a new part of Blender.
*
- * Contributor(s): Alex Mole, Yehoshua Sapir
+ * Contributor(s): Alex Mole, Yehoshua Sapir, Ken Hughes
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -36,7 +36,8 @@
#include "gen_utils.h"
#include "gen_library.h"
-#include <DNA_material_types.h>
+#include "DNA_material_types.h"
+#include "DNA_world_types.h"
/*****************************************************************************/
/* Python BPy_MTex methods declarations: */
@@ -95,6 +96,7 @@
MTEXGETSET(ProjY)
MTEXGETSET(ProjZ)
MTEXGETSET(MapToFlag)
+MTEXGETSET(WorldMapToFlag)
/*****************************************************************************/
/* Python get/set methods table */
@@ -155,8 +157,14 @@
"Projection of Y axis to Texture space", NULL },
{ "zproj", (getter) MTex_getProjZ, (setter) MTex_setProjZ,
"Projection of Z axis to Texture space", NULL },
+
+ /* MapTo for Material and Lamp MTex */
+
{ "mtCol", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to color", (void*) MAP_COL },
+
+ /* MapTo for Material MTex */
+
{ "mtNor", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to normals", (void*) MAP_NORM },
{ "mtCsp", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
@@ -183,6 +191,18 @@
"How texture maps to displacement", (void*) MAP_DISPLACE },
{ "mtWarp", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to warp", (void*) MAP_WARP },
+
+ /* MapTo for World MTex */
+
+ { "mtBlend", (getter) MTex_getWorldMapToFlag, (setter) MTex_setWorldMapToFlag,
+ "Texture affects color progression of background", (void*) WOMAP_BLEND },
+ { "mtHoriz", (getter) MTex_getWorldMapToFlag, (setter) MTex_setWorldMapToFlag,
+ "Texture affects color of the horizon", (void*) WOMAP_HORIZ },
+ { "mtZenUp", (getter) MTex_getWorldMapToFlag, (setter) MTex_setWorldMapToFlag,
+ "Texture affects color of the zenith above", (void*) WOMAP_ZENUP },
+ { "mtZenDown", (getter) MTex_getWorldMapToFlag, (setter) MTex_setWorldMapToFlag,
+ "Texture affects color of the zenith below", (void*) WOMAP_ZENDOWN },
+
{ NULL, NULL, NULL, NULL, NULL }
};
@@ -323,19 +343,37 @@
{
int texco;
- if( !PyInt_Check( value ) ) {
+ if( !PyInt_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"Value must be a member of Texture.TexCo dictionary" );
- }
texco = PyInt_AsLong( value ) ;
- if (texco != TEXCO_ORCO && texco != TEXCO_REFL && texco != TEXCO_NORM &&
- texco != TEXCO_GLOB && texco != TEXCO_UV && texco != TEXCO_OBJECT &&
- texco != TEXCO_STRESS && texco != TEXCO_TANGENT && texco != TEXCO_WINDOW &&
- texco != TEXCO_VIEW && texco != TEXCO_STICKY )
- return EXPP_ReturnIntError( PyExc_ValueError,
- "Value must be a member of Texture.TexCo dictionary" );
+ switch ( self->type ) {
+ case ID_MA :
+ if( texco != TEXCO_ORCO && texco != TEXCO_REFL &&
+ texco != TEXCO_NORM && texco != TEXCO_GLOB &&
+ texco != TEXCO_UV && texco != TEXCO_OBJECT &&
+ texco != TEXCO_STRESS && texco != TEXCO_TANGENT &&
+ texco != TEXCO_WINDOW && texco != TEXCO_VIEW &&
+ texco != TEXCO_STICKY )
+ return EXPP_ReturnIntError( PyExc_ValueError,
+ "Value must be a member of Texture.TexCo dictionary" );
+ break;
+ case ID_LA :
+ if( texco != TEXCO_VIEW && texco != TEXCO_GLOB &&
+ texco != TEXCO_OBJECT )
+ return EXPP_ReturnIntError( PyExc_ValueError,
+ "Value must be a member of Texture.TexCo dictionary" );
+ break;
+ default: /* ID_WO */
+ if( texco != TEXCO_VIEW && texco != TEXCO_GLOB &&
+ texco != TEXCO_ANGMAP && texco != TEXCO_OBJECT &&
+ texco != TEXCO_H_SPHEREMAP && texco != TEXCO_H_TUBEMAP )
+ return EXPP_ReturnIntError( PyExc_ValueError,
+ "Value must be a member of Texture.TexCo dictionary" );
+ break;
+ }
self->mtex->texco = (short)texco;
@@ -468,18 +506,13 @@
if ( !PyInt_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
- "Value must be member of Texture.BlendModes dictionary" );
+ "Value must be member of Texture.BlendModes dictionary" );
n = PyInt_AsLong(value);
-/* if (n != MTEX_BLEND && n != MTEX_MUL && n != MTEX_ADD &&
- n != MTEX_SUB && n != MTEX_DIV && n != MTEX_DARK &&
- n != MTEX_DIFF && n != MTEX_LIGHT && n != MTEX_SCREEN)*/
if (n < 0 || n > 8)
- {
return EXPP_ReturnIntError( PyExc_ValueError,
- "Value must be member of Texture.BlendModes dictionary" );
- }
+ "Value must be member of Texture.BlendModes dictionary" );
self->mtex->blendtype = (short)n;
@@ -675,19 +708,33 @@
static PyObject *MTex_getFlag( BPy_MTex *self, void *closure )
{
- return PyBool_FromLong( self->mtex->texflag & (GET_INT_FROM_POINTER(closure)) );
+ int flag = GET_INT_FROM_POINTER(closure);
+
+ if( self->type != ID_MA &&
+ flag & ( MTEX_VIEWSPACE | MTEX_DUPLI_MAPTO | MTEX_OB_DUPLI_ORIG ) )
+ return EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "attribute only vaild for material MTex object" );
+
+ return PyBool_FromLong( self->mtex->texflag & flag );
}
static int MTex_setFlag( BPy_MTex *self, PyObject *value, void *closure)
{
+ int flag = GET_INT_FROM_POINTER(closure);
+
+ if( self->type != ID_MA &&
+ flag & ( MTEX_VIEWSPACE | MTEX_DUPLI_MAPTO | MTEX_OB_DUPLI_ORIG ) )
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "attribute only vaild for material MTex object" );
+
if ( !PyBool_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected a bool");
if ( value == Py_True )
- self->mtex->texflag |= GET_INT_FROM_POINTER(closure);
+ self->mtex->texflag |= flag;
else
- self->mtex->texflag &= ~(GET_INT_FROM_POINTER(closure));
+ self->mtex->texflag &= ~flag;
return 0;
}
@@ -798,9 +845,9 @@
{
int flag = GET_INT_FROM_POINTER(closure);
- if( self->type != ID_MA )
+ if( self->type == ID_LA && flag != MAP_COL )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
- "not a material MTex object" );
+ "attribute not available for a lamp MTex" );
if ( self->mtex->mapto & flag )
return PyInt_FromLong( ( self->mtex->maptoneg & flag ) ? -1 : 1 );
@@ -808,14 +855,25 @@
return PyInt_FromLong( 0 );
}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list