[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11175] branches/pyapi_devel/source/ blender/python/api2_2x: replacing rgbTuple with a new color type,
Campbell Barton
cbarton at metavr.com
Thu Jul 5 20:14:35 CEST 2007
Revision: 11175
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11175
Author: campbellbarton
Date: 2007-07-05 20:14:35 +0200 (Thu, 05 Jul 2007)
Log Message:
-----------
replacing rgbTuple with a new color type,
This is more like a the existing Vector type, this is not finished but compiles and can me used to change material and lamp colors.
* can be wrapped/non wrapped.
* non wrapped types are not clamped so "col1 = (col2+col3)/2" works.
* can be used for material, lamp, colorband, mtex, mesh-face color, colorband, and world colors.
* will have HSV access as well as RGB
* will have functions col1.tint(col2, 0.25) and col.invert()
points to the data it comes from so keeping track of removed data is possible.
Modified Paths:
--------------
branches/pyapi_devel/source/blender/python/api2_2x/Blender.c
branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c
branches/pyapi_devel/source/blender/python/api2_2x/Lamp.h
branches/pyapi_devel/source/blender/python/api2_2x/Material.c
branches/pyapi_devel/source/blender/python/api2_2x/Material.h
branches/pyapi_devel/source/blender/python/api2_2x/Types.c
branches/pyapi_devel/source/blender/python/api2_2x/bpy_list.h
branches/pyapi_devel/source/blender/python/api2_2x/gen_utils.c
branches/pyapi_devel/source/blender/python/api2_2x/layer_set.h
branches/pyapi_devel/source/blender/python/api2_2x/vector.c
branches/pyapi_devel/source/blender/python/api2_2x/vector.h
Added Paths:
-----------
branches/pyapi_devel/source/blender/python/api2_2x/color.c
branches/pyapi_devel/source/blender/python/api2_2x/color.h
Removed Paths:
-------------
branches/pyapi_devel/source/blender/python/api2_2x/rgbTuple.c
branches/pyapi_devel/source/blender/python/api2_2x/rgbTuple.h
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Blender.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Blender.c 2007-07-05 13:51:21 UTC (rev 11174)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Blender.c 2007-07-05 18:14:35 UTC (rev 11175)
@@ -95,6 +95,7 @@
#include "Types.h"
#include "bpy_list.h"
#include "layer_set.h"
+#include "color.h"
/**********************************************************/
/* Python API function prototypes for the Blender module. */
@@ -980,4 +981,5 @@
BPyList_Init();
LayerSet_Init();
+ Color_Init();
}
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c 2007-07-05 13:51:21 UTC (rev 11174)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c 2007-07-05 18:14:35 UTC (rev 11175)
@@ -252,7 +252,7 @@
(getter)Lamp_getClipStart, (setter)Lamp_setClipStart,
"Lamp shadow map clip start",
NULL},
- {"col",
+ {"color",
(getter)Lamp_getCol, (setter)Lamp_setCol,
"Lamp RGB color triplet",
NULL},
@@ -550,7 +550,6 @@
PyObject *Lamp_CreatePyObject( Lamp * lamp )
{
BPy_Lamp *pylamp;
- float *rgb[3];
pylamp = ( BPy_Lamp * ) PyObject_NEW( BPy_Lamp, &Lamp_Type );
@@ -559,14 +558,7 @@
"couldn't create BPy_Lamp object" );
pylamp->lamp = lamp;
-
- rgb[0] = &lamp->r;
- rgb[1] = &lamp->g;
- rgb[2] = &lamp->b;
-
- pylamp->color = ( BPy_rgbTuple * ) rgbTuple_New( rgb );
- Py_INCREF(pylamp->color);
-
+ pylamp->color = NULL; /* only init when used */
return ( PyObject * ) pylamp;
}
@@ -813,7 +805,10 @@
static PyObject *Lamp_getCol( BPy_Lamp * self )
{
- return rgbTuple_getCol( self->color );
+ if (!self->color)
+ self->color = newColorObject(NULL, 3, 0, 0, (PyObject *)self);
+
+ return self->color;
}
static int Lamp_setType( BPy_Lamp * self, PyObject * value )
@@ -1032,9 +1027,18 @@
"unknown color component specified" );
}
-static int Lamp_setCol( BPy_Lamp * self, PyObject * args )
+static int Lamp_setCol( BPy_Lamp * self, PyObject * value )
{
- return rgbTuple_setCol( self->color, args );
+ if (!self->color) {
+ int ret;
+ self->color = newColorObject(NULL, 3, 0, 0, (PyObject *)self);
+ ret = setColorObject(self->color, value);
+ Py_DECREF(self->color);
+ self->color = NULL;
+ return ret;
+ } else {
+ return setColorObject(self->color, value);
+ }
}
/*****************************************************************************/
@@ -1044,7 +1048,6 @@
/*****************************************************************************/
static void Lamp_dealloc( BPy_Lamp * self )
{
- Py_DECREF( self->color );
PyObject_DEL( self );
}
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Lamp.h
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Lamp.h 2007-07-05 13:51:21 UTC (rev 11174)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Lamp.h 2007-07-05 18:14:35 UTC (rev 11175)
@@ -35,7 +35,7 @@
#include <Python.h>
#include "DNA_lamp_types.h"
-#include "rgbTuple.h"
+#include "color.h"
extern PyTypeObject Lamp_Type;
@@ -46,7 +46,7 @@
typedef struct {
PyObject_HEAD /* required py macro */
Lamp * lamp; /* libdata must be second */
- BPy_rgbTuple *color;
+ BPy_Color *color; /* color data, lazy init */
} BPy_Lamp;
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Material.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Material.c 2007-07-05 13:51:21 UTC (rev 11174)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Material.c 2007-07-05 18:14:35 UTC (rev 11175)
@@ -831,11 +831,11 @@
/*****************************************************************************/
static void Material_dealloc( BPy_Material * self )
{
- Py_DECREF( self->col );
- Py_DECREF( self->amb );
- Py_DECREF( self->spec );
- Py_DECREF( self->mir );
- Py_DECREF( self->sss );
+ Py_XDECREF( self->col );
+ Py_XDECREF( self->amb );
+ Py_XDECREF( self->spec );
+ Py_XDECREF( self->mir );
+ Py_XDECREF( self->sss );
PyObject_DEL( self );
}
@@ -857,39 +857,14 @@
"couldn't create BPy_Material object" );
pymat->material = mat;
-
- col[0] = &mat->r;
- col[1] = &mat->g;
- col[2] = &mat->b;
-
- amb[0] = &mat->ambr;
- amb[1] = &mat->ambg;
- amb[2] = &mat->ambb;
-
- spec[0] = &mat->specr;
- spec[1] = &mat->specg;
- spec[2] = &mat->specb;
-
- mir[0] = &mat->mirr;
- mir[1] = &mat->mirg;
- mir[2] = &mat->mirb;
- sss[0] = &mat->sss_col[0];
- sss[1] = &mat->sss_col[1];
- sss[2] = &mat->sss_col[2];
-
- pymat->col = ( BPy_rgbTuple * ) rgbTuple_New( col );
- pymat->amb = ( BPy_rgbTuple * ) rgbTuple_New( amb );
- pymat->spec = ( BPy_rgbTuple * ) rgbTuple_New( spec );
- pymat->mir = ( BPy_rgbTuple * ) rgbTuple_New( mir );
- pymat->sss = ( BPy_rgbTuple * ) rgbTuple_New( sss );
+ /* lazy init */
+ pymat->col = NULL;
+ pymat->amb = NULL;
+ pymat->spec = NULL;
+ pymat->mir = NULL;
+ pymat->sss = NULL;
- Py_INCREF(pymat->col);
- Py_INCREF(pymat->amb);
- Py_INCREF(pymat->spec);
- Py_INCREF(pymat->mir);
- Py_INCREF(pymat->sss);
-
return ( PyObject * ) pymat;
}
@@ -905,14 +880,7 @@
static PyObject *Material_getLightGroup( BPy_Material * self )
{
- PyObject *attr =
- Group_CreatePyObject( self->material->group );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "couldn't get Material.lightGroup attribute" );
+ return Group_CreatePyObject( self->material->group );
}
static PyObject *Material_getMode(BPy_Material *self, void *flag)
@@ -933,7 +901,6 @@
return 0;
}
-
static PyObject *Material_getIpo( BPy_Material * self )
{
Ipo *ipo = self->material->ipo;
@@ -946,7 +913,12 @@
static PyObject *Material_getRGBCol( BPy_Material * self )
{
- return rgbTuple_getCol( self->col );
+ if (self->col)
+ return EXPP_incr_ret(self->col);
+
+ self->col = newColorObject(NULL, 3, COLOR_MAT_DIFF, 0, (PyObject *)self);
+ return self->col;
+
}
/*
@@ -957,17 +929,29 @@
*/
static PyObject *Material_getSpecCol( BPy_Material * self )
{
- return rgbTuple_getCol( self->spec );
+ if (self->spec)
+ return EXPP_incr_ret(self->spec);
+
+ self->spec = newColorObject(NULL, 3, COLOR_MAT_SPEC, 0, (PyObject *)self);
+ return self->spec;
}
static PyObject *Material_getMirCol( BPy_Material * self )
{
- return rgbTuple_getCol( self->mir );
+ if (self->mir)
+ return EXPP_incr_ret(self->mir);
+
+ self->mir = newColorObject(NULL, 3, COLOR_MAT_MIR, 0, (PyObject *)self);
+ return self->mir;
}
static PyObject *Material_getSssCol( BPy_Material * self )
{
- return rgbTuple_getCol( self->sss );
+ if (self->sss)
+ return EXPP_incr_ret(self->sss);
+
+ self->sss = newColorObject(NULL, 3, COLOR_MAT_SSS, 0, (PyObject *)self);
+ return self->sss;
}
/* SSS */
@@ -1066,10 +1050,6 @@
Py_RETURN_NONE;
}
-static int Material_setRGBCol( BPy_Material * self, PyObject * value )
-{
- return rgbTuple_setCol( self->col, value );
-}
/*
* get floating point attributes
@@ -1524,7 +1504,6 @@
*/
static PyObject *getIntAttr( BPy_Material *self, void *type )
{
- PyObject *attr = NULL;
int param;
struct Material *mat = self->material;
@@ -1568,13 +1547,7 @@
"undefined type in getIntAttr" );
}
- attr = PyInt_FromLong( param );
-
- if( attr )
- return attr;
-
- return EXPP_ReturnPyObjError( PyExc_MemoryError,
- "PyInt_FromLong() failed!" );
+ return PyInt_FromLong( param );
}
@@ -1663,24 +1636,60 @@
return EXPP_setIValueClamped( value, param, min, max, size );
}
+static int Material_setRGBCol( BPy_Material * self, PyObject * value )
+{
+ if (!self->col) {
+ int ret;
+ self->col = newColorObject(NULL, 3, COLOR_MAT_DIFF, 0, (PyObject *)self);
+ ret = setColorObject(self->col, value);
+ Py_DECREF(self->col);
+ self->col=NULL;
+ return ret;
+ } else {
+ return setColorObject(self->col, value);
+ }
+}
-
-
-
-
static int Material_setSpecCol( BPy_Material * self, PyObject * value )
{
- return rgbTuple_setCol( self->spec, value );
+ if (!self->spec) {
+ int ret;
+ self->spec = newColorObject(NULL, 3, COLOR_MAT_SPEC, 0, (PyObject *)self);
+ ret = setColorObject(self->spec, value);
+ Py_DECREF(self->spec);
+ self->spec=NULL;
+ return ret;
+ } else {
+ return setColorObject(self->spec, value);
+ }
}
static int Material_setMirCol( BPy_Material * self, PyObject * value )
{
- return rgbTuple_setCol( self->mir, value );
+ if (!self->mir) {
+ int ret;
+ self->mir = newColorObject(NULL, 3, COLOR_MAT_MIR, 0, (PyObject *)self);
+ ret = setColorObject(self->mir, value);
+ Py_DECREF(self->mir);
+ self->mir=NULL;
+ return ret;
+ } else {
+ return setColorObject(self->mir, value);
+ }
}
static int Material_setSssCol( BPy_Material * self, PyObject * value )
{
- return rgbTuple_setCol( self->sss, value );
+ if (!self->sss) {
+ int ret;
+ self->mir = newColorObject(NULL, 3, COLOR_MAT_SSS, 0, (PyObject *)self);
+ ret = setColorObject(self->sss, value);
+ Py_DECREF(self->sss);
+ self->sss=NULL;
+ return ret;
+ } else {
+ return setColorObject(self->sss, value);
+ }
}
static int Material_setLightGroup( BPy_Material * self, PyObject * value )
{
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Material.h
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Material.h 2007-07-05 13:51:21 UTC (rev 11174)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Material.h 2007-07-05 18:14:35 UTC (rev 11175)
@@ -37,7 +37,7 @@
#include "DNA_object_types.h"
#include "DNA_material_types.h"
#include "DNA_texture_types.h" /* colorband */
-#include "rgbTuple.h"
+#include "color.h"
/*****************************************************************************/
/* Python BPy_Material structure definition: */
@@ -45,7 +45,7 @@
typedef struct {
PyObject_HEAD
Material * material; /* libdata must be second */
- BPy_rgbTuple *col, *amb, *spec, *mir, *sss;
+ BPy_Color *col, *amb, *spec, *mir, *sss;
} BPy_Material;
extern PyTypeObject Material_Type; /* The Material PyType Object */
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Types.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Types.c 2007-07-05 13:51:21 UTC (rev 11174)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list