[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11325] branches/pyapi_devel/source/ blender: * Texture refactor (lotsa constants!) WIP (added constants, nicer float get/set, use BPy_Color for the color)
Campbell Barton
cbarton at metavr.com
Fri Jul 20 23:01:31 CEST 2007
Revision: 11325
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11325
Author: campbellbarton
Date: 2007-07-20 23:01:31 +0200 (Fri, 20 Jul 2007)
Log Message:
-----------
* Texture refactor (lotsa constants!) WIP (added constants, nicer float get/set, use BPy_Color for the color)
* Added utility function - EXPP_PyNumber_AsDouble
At the moment some parts of the API support PyNumbers and others require PyFloat/Int types only.
This can get a number from anything that impliments the PyNumber protocol, but has the advantage that it wont always convert to a PyFloat (Which is the normal way with the Python API and isnt that fast as well as taking ~3-4 LOC each time you need to get a float)
* Added util function EXPP_setVec2, EXPP_setVec3, EXPP_setVec4, which assigns floats from a python object - so each Python assignment function dosnt need to do list/typle/vector size/type checks. Use for assigning color, coords etc.
* renamed Mathutils functions to make them the same as other BPy func's newVectorObject -> Vector_CreatePyObject. VectorObject -> BPy_Vector
Modified Paths:
--------------
branches/pyapi_devel/source/blender/makesdna/DNA_texture_types.h
branches/pyapi_devel/source/blender/python/BPY_interface.c
branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c
branches/pyapi_devel/source/blender/python/api2_2x/Blender.c
branches/pyapi_devel/source/blender/python/api2_2x/Bone.c
branches/pyapi_devel/source/blender/python/api2_2x/CurNurb.c
branches/pyapi_devel/source/blender/python/api2_2x/Effect.c
branches/pyapi_devel/source/blender/python/api2_2x/Font.c
branches/pyapi_devel/source/blender/python/api2_2x/Font.h
branches/pyapi_devel/source/blender/python/api2_2x/Geometry.c
branches/pyapi_devel/source/blender/python/api2_2x/Key.c
branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c
branches/pyapi_devel/source/blender/python/api2_2x/Lattice.c
branches/pyapi_devel/source/blender/python/api2_2x/Material.c
branches/pyapi_devel/source/blender/python/api2_2x/Mathutils.c
branches/pyapi_devel/source/blender/python/api2_2x/Mathutils.h
branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c
branches/pyapi_devel/source/blender/python/api2_2x/Metaball.c
branches/pyapi_devel/source/blender/python/api2_2x/Metaball.h
branches/pyapi_devel/source/blender/python/api2_2x/Modifier.c
branches/pyapi_devel/source/blender/python/api2_2x/Object.c
branches/pyapi_devel/source/blender/python/api2_2x/Pose.c
branches/pyapi_devel/source/blender/python/api2_2x/Scene.c
branches/pyapi_devel/source/blender/python/api2_2x/Texture.c
branches/pyapi_devel/source/blender/python/api2_2x/Texture.h
branches/pyapi_devel/source/blender/python/api2_2x/Types.c
branches/pyapi_devel/source/blender/python/api2_2x/Window.c
branches/pyapi_devel/source/blender/python/api2_2x/World.c
branches/pyapi_devel/source/blender/python/api2_2x/color.c
branches/pyapi_devel/source/blender/python/api2_2x/color.h
branches/pyapi_devel/source/blender/python/api2_2x/euler.c
branches/pyapi_devel/source/blender/python/api2_2x/euler.h
branches/pyapi_devel/source/blender/python/api2_2x/gen_utils.c
branches/pyapi_devel/source/blender/python/api2_2x/gen_utils.h
branches/pyapi_devel/source/blender/python/api2_2x/matrix.c
branches/pyapi_devel/source/blender/python/api2_2x/matrix.h
branches/pyapi_devel/source/blender/python/api2_2x/quat.c
branches/pyapi_devel/source/blender/python/api2_2x/quat.h
branches/pyapi_devel/source/blender/python/api2_2x/vector.c
branches/pyapi_devel/source/blender/python/api2_2x/vector.h
Modified: branches/pyapi_devel/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- branches/pyapi_devel/source/blender/makesdna/DNA_texture_types.h 2007-07-20 20:32:28 UTC (rev 11324)
+++ branches/pyapi_devel/source/blender/makesdna/DNA_texture_types.h 2007-07-20 21:01:31 UTC (rev 11325)
@@ -287,6 +287,10 @@
#define TEX_BANDNOISE 2
#define TEX_RINGNOISE 3
+/* tex->stype in texture.c - cloud types */
+#define TEX_DEFAULT 0
+#define TEX_COLOR 1
+
/* tex->stype in texture.c - marble types */
#define TEX_SOFT 0
#define TEX_SHARP 1
@@ -301,6 +305,17 @@
#define TEX_HALO 5
#define TEX_RAD 6
+/* tex->stype in texture.c - stucci types */
+#define TEX_PLASTIC 0
+#define TEX_WALLIN 1
+#define TEX_WALLOUT 2
+
+/* tex->stype in texture.c - voronoi types */
+#define TEX_INTENSITY 0
+#define TEX_COL1 1
+#define TEX_COL2 2
+#define TEX_COL3 3
+
/* wrap */
#define MTEX_FLAT 0
#define MTEX_CUBE 1
Modified: branches/pyapi_devel/source/blender/python/BPY_interface.c
===================================================================
--- branches/pyapi_devel/source/blender/python/BPY_interface.c 2007-07-20 20:32:28 UTC (rev 11324)
+++ branches/pyapi_devel/source/blender/python/BPY_interface.c 2007-07-20 21:01:31 UTC (rev 11325)
@@ -75,6 +75,7 @@
#include "api2_2x/IDProp.h"
#include "api2_2x/matrix.h"
+#include "api2_2x/gen_utils.h"
#include "api2_2x/gen_library.h"
#include "blendef.h"
#include "BKE_utildefines.h"
@@ -1263,7 +1264,7 @@
PyObject *globals;
PyObject *gval;
PyObject *pyargs, *retval;
- MatrixObject *retmat;
+ BPy_Matrix *retmat;
int row, col;
if ( !con->text ) return;
@@ -1271,8 +1272,8 @@
globals = CreateGlobalDictionary();
- srcmat = newMatrixObject( (float*)ownermat, 4, 4, (PyObject *)NULL );
- tarmat = newMatrixObject( (float*)targetmat, 4, 4, (PyObject *)NULL );
+ srcmat = Matrix_CreatePyObject( (float*)ownermat, 4, 4, (PyObject *)NULL );
+ tarmat = Matrix_CreatePyObject( (float*)targetmat, 4, 4, (PyObject *)NULL );
idprop = BPy_Wrap_IDProperty( NULL, con->prop, NULL);
/* since I can't remember what the armature weakrefs do, I'll just leave this here
@@ -1341,7 +1342,7 @@
}
- if (!PyObject_TypeCheck(retval, &matrix_Type)) {
+ if (!PyObject_TypeCheck(retval, &Matrix_Type)) {
printf("Error in PyConstraint - doConstraint: Function not returning a matrix!\n");
con->flag |= PYCON_SCRIPTERROR;
ReleaseGlobalDictionary( globals );
@@ -1353,7 +1354,7 @@
return;
}
- retmat = (MatrixObject*) retval;
+ retmat = (BPy_Matrix *) retval;
if (retmat->rowSize != 4 || retmat->colSize != 4) {
printf("Error in PyConstraint - doConstraint: Matrix returned is the wrong size!\n");
con->flag |= PYCON_SCRIPTERROR;
@@ -1393,7 +1394,7 @@
PyObject *globals;
PyObject *gval, *gval2;
PyObject *pyargs, *retval;
- MatrixObject *retmat;
+ BPy_Matrix *retmat;
bPoseChannel *pchan;
int row, col;
@@ -1409,7 +1410,7 @@
pchan = NULL;
subtar = PyPoseBone_FromPosechannel( pchan );
- tarmat = newMatrixObject( (float*)targetmat, 4, 4, (PyObject *)NULL );
+ tarmat = Matrix_CreatePyObject( (float*)targetmat, 4, 4, (PyObject *)NULL );
idprop = BPy_Wrap_IDProperty( NULL, con->prop, NULL);
/* since I can't remember what the armature weakrefs do, I'll just leave this here
@@ -1494,7 +1495,7 @@
return -1;
}
- if (!PyObject_TypeCheck(retval, &matrix_Type)) {
+ if (!PyObject_TypeCheck(retval, &Matrix_Type)) {
ReleaseGlobalDictionary( globals );
Py_XDECREF( tar );
@@ -1505,7 +1506,7 @@
return -1;
}
- retmat = (MatrixObject*) retval;
+ retmat = (BPy_Matrix *) retval;
if (retmat->rowSize != 4 || retmat->colSize != 4) {
printf("Error in PyConstraint - doTarget: Matrix returned is the wrong size!\n");
con->flag |= PYCON_SCRIPTERROR;
@@ -1660,7 +1661,7 @@
float BPY_pydriver_eval(IpoDriver *driver)
{
char *expr = NULL;
- PyObject *retval, *floatval, *bpy_ob = NULL;
+ PyObject *retval, *bpy_ob = NULL;
float result = 0.0f; /* default return */
int setitem_retval;
@@ -1698,15 +1699,11 @@
return pydriver_error(driver);
}
- floatval = PyNumber_Float(retval);
- Py_DECREF(retval);
-
- if (floatval == NULL)
+ result = ( float )EXPP_PyNumber_AsDouble( retval );
+
+ if (result == -1 && PyErr_Occurred())
return pydriver_error(driver);
- result = (float)PyFloat_AsDouble(floatval);
- Py_DECREF(floatval);
-
/* remove 'self', since this dict is also used by py buttons */
if (setitem_retval == 0) PyDict_DelItemString(bpy_pydriver_Dict, "self");
Modified: branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c 2007-07-20 20:32:28 UTC (rev 11324)
+++ branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c 2007-07-20 21:01:31 UTC (rev 11325)
@@ -142,16 +142,14 @@
}
for( j = 0; j < 3; j++ ) {
PyObject *obj2 = PySequence_ITEM( obj1, j );
- PyObject *num = PyNumber_Float( obj2 );
- Py_DECREF( obj2 );
- if( !num ) {
+ if( !PyNumber_Check(obj2) ) {
Py_DECREF( obj1 );
+ Py_DECREF( obj2 );
return EXPP_ReturnIntError( PyExc_ValueError,
"expected float parameter" );
}
- vec[i][j] = ( float )PyFloat_AsDouble( num );
- Py_DECREF( num );
+ vec[i][j] = ( float )EXPP_PyNumber_AsDouble( obj2 );
}
Py_DECREF( obj1 );
}
@@ -195,14 +193,11 @@
for( i = 0; i < 2; i++ ) {
PyObject *obj = PySequence_ITEM( args, i );
- PyObject *num = PyNumber_Float( obj );
- Py_DECREF( obj );
-
- if( !num )
- return EXPP_ReturnIntError( PyExc_ValueError,
- "expected float parameter" );
- vec[i] = ( float )PyFloat_AsDouble( num );
- Py_DECREF( num );
+ vec[i] = ( float )EXPP_PyNumber_AsDouble( obj );
+ if (vec[i]==-1 && PyErr_Occurred()) {
+ Py_DECREF(obj);
+ return -1;
+ }
}
for( i = 0; i < 2; i++ ) {
@@ -228,13 +223,11 @@
static int BezTriple_setTilt( BPy_BezTriple * self, PyObject *value )
{
- PyObject *num = PyNumber_Float( value );
-
- if( !num )
- return EXPP_ReturnIntError( PyExc_TypeError, "expected a float" );
-
- self->beztriple->alfa = (float)PyFloat_AsDouble( num );
- Py_DECREF( num );
+ float f = ( float )EXPP_PyNumber_AsDouble( value );
+ if (f ==-1 && PyErr_Occurred())
+ return -1;
+
+ self->beztriple->alfa = f;
return 0;
}
@@ -245,13 +238,11 @@
static int BezTriple_setWeight( BPy_BezTriple * self, PyObject *value )
{
- PyObject *num = PyNumber_Float( value );
-
- if( !num )
- return EXPP_ReturnIntError( PyExc_TypeError, "expected a float" );
-
- self->beztriple->weight = (float)PyFloat_AsDouble( num );
- Py_DECREF( num );
+ float f = ( float )EXPP_PyNumber_AsDouble( value );
+ if (f ==-1 && PyErr_Occurred())
+ return -1;
+
+ self->beztriple->weight = f;
return 0;
}
@@ -262,13 +253,11 @@
static int BezTriple_setRadius( BPy_BezTriple * self, PyObject *value )
{
- PyObject *num = PyNumber_Float( value );
-
- if( !num )
- return EXPP_ReturnIntError( PyExc_TypeError, "expected a float" );
-
- self->beztriple->radius = (float)PyFloat_AsDouble( num );
- Py_DECREF( num );
+ float f = ( float )EXPP_PyNumber_AsDouble( value );
+ if (f ==-1 && PyErr_Occurred())
+ return -1;
+
+ self->beztriple->radius = f;
return 0;
}
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Blender.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Blender.c 2007-07-20 20:32:28 UTC (rev 11324)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Blender.c 2007-07-20 21:01:31 UTC (rev 11325)
@@ -971,7 +971,7 @@
PyDict_SetItemString(dict, "Types", Types_Init());
PyDict_SetItemString(dict, "Text", Text_Init());
Text3d_Init();
- PyDict_SetItemString(dict, "Texture", Texture_Init());
+ Texture_Init();
PyDict_SetItemString(dict, "Window", Window_Init());
World_Init();
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Bone.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Bone.c 2007-07-20 20:32:28 UTC (rev 11324)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Bone.c 2007-07-20 21:01:31 UTC (rev 11325)
@@ -136,18 +136,18 @@
static PyObject *EditBone_getHead(BPy_EditBone *self)
{
if (self->editbone){
- return newVectorObject(self->editbone->head, 3, Py_None);
+ return Vector_CreatePyObject(self->editbone->head, 3, Py_None);
}else{
- return newVectorObject(self->head, 3, (PyObject *)NULL);
+ return Vector_CreatePyObject(self->head, 3, (PyObject *)NULL);
}
}
//------------------------EditBone.head (set)
static int EditBone_setHead(BPy_EditBone *self, PyObject *value)
{
- VectorObject *vec = NULL;
+ BPy_Vector *vec = NULL;
int x;
- if (!PyArg_Parse(value, "O!", &vector_Type, &vec))
+ if (!PyArg_Parse(value, "O!", &Vector_Type, &vec))
goto AttributeError;
if (vec->size != 3)
goto AttributeError2;
@@ -175,18 +175,18 @@
static PyObject *EditBone_getTail(BPy_EditBone *self)
{
if (self->editbone){
- return newVectorObject(self->editbone->tail, 3, Py_None);
+ return Vector_CreatePyObject(self->editbone->tail, 3, Py_None);
}else{
- return newVectorObject(self->tail, 3, (PyObject *)NULL);
+ return Vector_CreatePyObject(self->tail, 3, (PyObject *)NULL);
}
}
//------------------------EditBone.tail (set)
static int EditBone_setTail(BPy_EditBone *self, PyObject *value)
{
- VectorObject *vec = NULL;
+ BPy_Vector *vec = NULL;
int x;
- if (!PyArg_Parse(value, "O!", &vector_Type, &vec))
+ if (!PyArg_Parse(value, "O!", &Vector_Type, &vec))
goto AttributeError;
if (vec->size != 3)
goto AttributeError2;
@@ -337,7 +337,7 @@
vec_roll_to_mat3(axis, self->roll, boneMatrix);
}
- return newMatrixObject((float*)boneMatrix, 3, 3, (PyObject *)NULL);
+ return Matrix_CreatePyObject((float*)boneMatrix, 3, 3, (PyObject *)NULL);
}
//------------------------EditBone.matrix (set)
static int EditBone_setMatrix(BPy_EditBone *self, PyObject *value)
@@ -345,12 +345,12 @@
PyObject *matrix;
float roll, length, vec[3], axis[3], mat3[3][3];
- if (!PyArg_Parse(value, "O!", &matrix_Type, &matrix))
+ if (!PyArg_Parse(value, "O!", &Matrix_Type, &matrix))
goto AttributeError;
//make sure we have the right sizes
- if (((MatrixObject*)matrix)->rowSize != 3 && ((MatrixObject*)matrix)->colSize != 3){
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list