[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11206] branches/pyapi_devel/source/ blender/python/api2_2x: more BPy_Color stuff- tested color arithmetic, color.tint(col2, factor) and replaced Mesh' s color type with this BPy_Color pytype.

Campbell Barton cbarton at metavr.com
Tue Jul 10 11:45:11 CEST 2007


Revision: 11206
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11206
Author:   campbellbarton
Date:     2007-07-10 11:45:11 +0200 (Tue, 10 Jul 2007)

Log Message:
-----------
more BPy_Color stuff- tested color arithmetic, color.tint(col2, factor) and replaced Mesh's color type with this BPy_Color pytype.

also check the color is valid in more places (its data has not been removed)

Modified Paths:
--------------
    branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c
    branches/pyapi_devel/source/blender/python/api2_2x/Material.c
    branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c
    branches/pyapi_devel/source/blender/python/api2_2x/Mesh.h
    branches/pyapi_devel/source/blender/python/api2_2x/Types.c
    branches/pyapi_devel/source/blender/python/api2_2x/color.c
    branches/pyapi_devel/source/blender/python/api2_2x/color.h

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c	2007-07-10 08:45:47 UTC (rev 11205)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c	2007-07-10 09:45:11 UTC (rev 11206)
@@ -187,7 +187,7 @@
 static PyObject *Lamp_getHaloInt( BPy_Lamp * self );
 static PyObject *Lamp_getQuad1( BPy_Lamp * self );
 static PyObject *Lamp_getQuad2( BPy_Lamp * self );
-static PyObject *Lamp_getCol( BPy_Lamp * self );
+static BPy_Color *Lamp_getCol( BPy_Lamp * self );
 static PyObject *Lamp_getIpo( BPy_Lamp * self );
 static PyObject *Lamp_getComponent( BPy_Lamp * self, void * closure );
 static PyObject *Lamp_insertIpoKey( BPy_Lamp * self, PyObject * args );
@@ -803,10 +803,10 @@
 					"couldn't get Lamp.quad2 attribute" ) );
 }
 
-static PyObject *Lamp_getCol( BPy_Lamp * self )
+static BPy_Color *Lamp_getCol( BPy_Lamp * self )
 {
 	if (!self->color)
-		self->color = newColorObject(NULL, 3, 0, 0, (PyObject *)self);
+		self->color = (BPy_Color *)newColorObject(NULL, 3, 0, 0, (PyObject *)self);
 	
 	return self->color;
 }
@@ -1031,7 +1031,7 @@
 {
 	if (!self->color) {
 		int ret;
-		self->color = newColorObject(NULL, 3, 0, 0, (PyObject *)self);
+		self->color = (BPy_Color *)newColorObject(NULL, 3, 0, 0, (PyObject *)self);
 		ret = setColorObject(self->color, value);
 		Py_DECREF(self->color);
 		self->color = NULL;

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Material.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Material.c	2007-07-10 08:45:47 UTC (rev 11205)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Material.c	2007-07-10 09:45:11 UTC (rev 11206)
@@ -847,7 +847,6 @@
 PyObject *Material_CreatePyObject( struct Material *mat )
 {
 	BPy_Material *pymat;
-	float *col[3], *amb[3], *spec[3], *mir[3], *sss[3];
 
 	pymat = ( BPy_Material * ) PyObject_NEW( BPy_Material,
 						 &Material_Type );
@@ -914,10 +913,10 @@
 static PyObject *Material_getRGBCol( BPy_Material * self )
 {
 	if (self->col)
-		return EXPP_incr_ret(self->col);
+		return EXPP_incr_ret((PyObject *)self->col);
 	
-	self->col = newColorObject(NULL, 3, COLOR_MAT_DIFF, 0, (PyObject *)self);
-	return self->col; 
+	self->col = (BPy_Color *)newColorObject(NULL, 3, COLOR_MAT_DIFF, 0, (PyObject *)self);
+	return (PyObject *)self->col; 
 	
 }
 
@@ -930,28 +929,28 @@
 static PyObject *Material_getSpecCol( BPy_Material * self )
 {
 	if (self->spec)
-		return EXPP_incr_ret(self->spec);
+		return EXPP_incr_ret((PyObject *)self->spec);
 	
-	self->spec = newColorObject(NULL, 3, COLOR_MAT_SPEC, 0, (PyObject *)self);
-	return self->spec;
+	self->spec = (BPy_Color *)newColorObject(NULL, 3, COLOR_MAT_SPEC, 0, (PyObject *)self);
+	return (PyObject *)self->spec;
 }
 
 static PyObject *Material_getMirCol( BPy_Material * self )
 {
 	if (self->mir)
-		return EXPP_incr_ret(self->mir);
+		return EXPP_incr_ret((PyObject *)self->mir);
 	
-	self->mir = newColorObject(NULL, 3, COLOR_MAT_MIR, 0, (PyObject *)self);
-	return self->mir;
+	self->mir = (BPy_Color *)newColorObject(NULL, 3, COLOR_MAT_MIR, 0, (PyObject *)self);
+	return (PyObject *)self->mir;
 }
 
 static PyObject *Material_getSssCol( BPy_Material * self )
 {
 	if (self->sss)
-		return EXPP_incr_ret(self->sss);
+		return EXPP_incr_ret((PyObject *)self->sss);
 	
-	self->sss = newColorObject(NULL, 3, COLOR_MAT_SSS, 0, (PyObject *)self);
-	return self->sss;
+	self->sss = (BPy_Color *)newColorObject(NULL, 3, COLOR_MAT_SSS, 0, (PyObject *)self);
+	return (PyObject *)self->sss;
 }
 
 /* SSS */
@@ -1640,7 +1639,7 @@
 {
 	if (!self->col) {
 		int ret;
-		self->col = newColorObject(NULL, 3, COLOR_MAT_DIFF, 0, (PyObject *)self);
+		self->col = (BPy_Color *)newColorObject(NULL, 3, COLOR_MAT_DIFF, 0, (PyObject *)self);
 		ret = setColorObject(self->col, value);
 		Py_DECREF(self->col);
 		self->col=NULL;
@@ -1654,7 +1653,7 @@
 {
 	if (!self->spec) {
 		int ret;
-		self->spec = newColorObject(NULL, 3, COLOR_MAT_SPEC, 0, (PyObject *)self);
+		self->spec = (BPy_Color *)newColorObject(NULL, 3, COLOR_MAT_SPEC, 0, (PyObject *)self);
 		ret = setColorObject(self->spec, value);
 		Py_DECREF(self->spec);
 		self->spec=NULL;
@@ -1668,7 +1667,7 @@
 {
 	if (!self->mir) {
 		int ret;
-		self->mir = newColorObject(NULL, 3, COLOR_MAT_MIR, 0, (PyObject *)self);
+		self->mir = (BPy_Color *)newColorObject(NULL, 3, COLOR_MAT_MIR, 0, (PyObject *)self);
 		ret = setColorObject(self->mir, value);
 		Py_DECREF(self->mir);
 		self->mir=NULL;
@@ -1682,7 +1681,7 @@
 {
 	if (!self->sss) {
 		int ret;
-		self->mir = newColorObject(NULL, 3, COLOR_MAT_SSS, 0, (PyObject *)self);
+		self->mir = (BPy_Color *)newColorObject(NULL, 3, COLOR_MAT_SSS, 0, (PyObject *)self);
 		ret = setColorObject(self->sss, value);
 		Py_DECREF(self->sss);
 		self->sss=NULL;

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c	2007-07-10 08:45:47 UTC (rev 11205)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c	2007-07-10 09:45:11 UTC (rev 11206)
@@ -90,6 +90,7 @@
 #include "gen_library.h"
 #include "multires.h"
 #include "bpy_list.h"
+#include "color.h"
 
 /* EXPP Mesh defines */
 
@@ -585,338 +586,6 @@
 
 /************************************************************************
  *
- * Color attributes
- *
- ************************************************************************/
-
-static MCol *MCol_get_pointer(BPy_MCol * self)
-{
-	MFace *face = MFace_get_pointer(self->bpyface);
-	
-	if (!face)
-		return NULL; /* error set */
-	
-	if (!self->bpyface->bpymesh->mesh->mcol)
-		return (MCol *)EXPP_ReturnPyObjError(
-				PyExc_RuntimeError, "the face this MCol used has been removed." );
-	
-	if (self->face_index==4 && face->v4==0)
-		return (MCol *)EXPP_ReturnPyObjError(
-				PyExc_RuntimeError, "the face this MCol used has been replaced with a triangle." );
-	
-	return &self->bpyface->bpymesh->mesh->mcol[(self->bpyface->index*4) + self->face_index];
-}
-
-
-/*
- * get a color attribute
- */
-
-static PyObject *MCol_getAttr( BPy_MCol * self, void *type )
-{
-	unsigned char param;
-	MCol * color = MCol_get_pointer(self);
-	
-	if (!color)
-		return NULL; /* error set */
-	
-	// MESH_DEL_CHECK_PY(self->bpymesh->mesh);
-	
-	switch( (long)type ) {
-    case 'R':	/* these are backwards, but that how it works */
-		param = color->b;
-		break;
-    case 'G':
-		param = color->g;
-		break;
-    case 'B':	/* these are backwards, but that how it works */
-		param = color->r;
-		break;
-    case 'A':
-		param = color->a;
-		break;
-	default:
-		{
-			char errstr[1024];
-			sprintf( errstr, "undefined type '%d' in MCol_getAttr",
-					(int)((long)type & 0xff));
-			return EXPP_ReturnPyObjError( PyExc_RuntimeError, errstr );
-		}
-	}
-
-	return PyInt_FromLong( param ); 
-}
-
-/*
- * set a color attribute
- */
-
-static int MCol_setAttr( BPy_MCol * self, PyObject * value, void * type )
-{
-	unsigned char *param;
-	MCol * color = MCol_get_pointer(self);
-	
-	if (!color)
-		return -1; /* error set */
-	
-	// MESH_DEL_CHECK_INT(self->bpymesh->mesh);
-	
-	switch( (long)type ) {
-    case 'R':	/* these are backwards, but that how it works */
-		param = (unsigned char *)&color->b;
-		break;
-    case 'G':
-		param = (unsigned char *)&color->g;
-		break;
-    case 'B':	/* these are backwards, but that how it works */
-		param = (unsigned char *)&color->r;
-		break;
-    case 'A':
-		param = (unsigned char *)&color->a;
-		break;
-	default:
-		{
-			char errstr[1024];
-			sprintf( errstr, "undefined type '%d' in MCol_setAttr",
-					(int)((long)type & 0xff));
-			return EXPP_ReturnIntError( PyExc_RuntimeError, errstr );
-		}
-	}
-
-	return EXPP_setIValueClamped( value, param, 0, 255, 'b' );
-}
-
-/************************************************************************
- *
- * Python MCol_Type attributes get/set structure
- *
- ************************************************************************/
-
-static PyGetSetDef BPy_MCol_getseters[] = {
-	{"r",
-	 (getter)MCol_getAttr, (setter)MCol_setAttr,
-	 "red component",
-	 (void *)'R'},
-	{"g",
-	 (getter)MCol_getAttr, (setter)MCol_setAttr,
-	 "green component",
-	 (void *)'G'},
-	{"b",
-	 (getter)MCol_getAttr, (setter)MCol_setAttr,
-	 "blue component",
-	 (void *)'B'},
-	{"a",
-	 (getter)MCol_getAttr, (setter)MCol_setAttr,
-	 "alpha component",
-	 (void *)'A'},
-	{NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
-};
-
-static void MCol_dealloc( BPy_MCol * self )
-{
-	Py_DECREF( (PyObject *)self->bpyface );
-	PyObject_DEL( self );
-}
-
-/*----------------------------object[]---------------------------
-  sequence accessor (get)*/
-static PyObject *MCol_item(BPy_MCol * self, int i)
-{
-	unsigned char param;
-	MCol * color = MCol_get_pointer(self);
-	
-	if (!color)
-		return NULL; /* error set */
-	// MESH_DEL_CHECK_PY(self->bpymesh->mesh);
-	
-	switch (i) {
-	case 0:
-		param = color->b;
-		break;
-	case 1:
-		param = color->g;
-		break;
-	case 2:
-		param = color->r;
-		break;
-	case 3:
-		param = color->a;
-		break;	
-	default:
-		return EXPP_ReturnPyObjError(PyExc_IndexError,
-			"vector[index] = x: assignment index out of range\n");
-	}
-	
-	return PyInt_FromLong( param );
-}
-
-/*----------------------------object[]-------------------------
-  sequence accessor (set)*/
-static int MCol_ass_item(BPy_MCol * self, int i, PyObject * value)
-{
-	unsigned char *param;
-	MCol * color = MCol_get_pointer(self);
-	
-	if (!color)
-		return -1; /* error set */
-	
-	// MESH_DEL_CHECK_INT(self->bpymesh->mesh);
-	
-	switch (i) {
-	case 0:
-		param = (unsigned char *)&color->b; /* reversed? why */
-		break;
-	case 1:
-		param = (unsigned char *)&color->g;
-		break;
-	case 2:
-		param = (unsigned char *)&color->r; /* reversed? why */
-		break;
-	case 3:
-		param = (unsigned char *)&color->a;
-		break;	
-	default:
-		{
-			return EXPP_ReturnIntError( PyExc_RuntimeError, "Index out of range" );
-		}
-	}
-	return EXPP_setIValueClamped( value, param, 0, 255, 'b' );
-}
-
-/************************************************************************
- *
- * Python MCol_Type methods
- *
- ************************************************************************/
-
-static PyObject *MCol_repr( BPy_MCol * self )
-{
-	MCol * color = MCol_get_pointer(self);
-	
-	if (!color) {
-		PyErr_Clear();
-		return PyString_FromString("[MCol <deleted>]"); 
-	}

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list