[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13611] branches/pynodes/source/blender/ python/api2_2x/Node.c: == Pynodes ==

Willian Padovani Germano wpgermano at gmail.com
Fri Feb 8 21:36:20 CET 2008


Revision: 13611
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13611
Author:   ianwill
Date:     2008-02-08 21:36:20 +0100 (Fri, 08 Feb 2008)

Log Message:
-----------
== Pynodes ==

More work on the scripting side, to make it more robust and also nicer to program. Ongoing.

Current state of this and basically how to create pynode scripts explained here: http://wiki.blender.org/index.php/BlenderDev/PyNodes/API

Modified Paths:
--------------
    branches/pynodes/source/blender/python/api2_2x/Node.c

Modified: branches/pynodes/source/blender/python/api2_2x/Node.c
===================================================================
--- branches/pynodes/source/blender/python/api2_2x/Node.c	2008-02-08 20:15:07 UTC (rev 13610)
+++ branches/pynodes/source/blender/python/api2_2x/Node.c	2008-02-08 20:36:20 UTC (rev 13611)
@@ -74,9 +74,9 @@
 	for (pos = 0, a = 0; pos< len; pos++, a++) {
 		/* default socket values: */
 		s_name = NULL;
-		s_val[0] = s_val[1] = s_val[2] = s_val[3] = 1.0f;
 		s_min = 0.0f;
 		s_max = 0.0f;
+		s_val[0] = s_val[1] = s_val[2] = s_val[3] = 1.0f;
 
 		item = PyTuple_GetItem(tuple, pos);
 
@@ -89,8 +89,8 @@
 		arg = PySequence_Tuple(item);
 
 		if (!PyArg_ParseTuple(arg, "s|iffffff", &s_name, &s_type,
-					&s_val[0], &s_val[1], &s_val[2], &s_val[3],
-					&s_min, &s_max)) {
+					&s_min, &s_max,
+					&s_val[0], &s_val[1], &s_val[2], &s_val[3] )) {
 			PyErr_SetString(PyExc_AttributeError, "socket definitions require a string and optionally an int and 6 floats");
 			retval = -1;
 			Py_DECREF(arg);
@@ -99,12 +99,12 @@
 
 		newsocks[a].name = BLI_strdupn(s_name, NODE_MAXSTR);
 		newsocks[a].type = s_type;
+		newsocks[a].min = s_min;
+		newsocks[a].max = s_max;
 		newsocks[a].val1 = s_val[0];
 		newsocks[a].val2 = s_val[1];
 		newsocks[a].val3 = s_val[2];
 		newsocks[a].val4 = s_val[3];
-		newsocks[a].min = s_min;
-		newsocks[a].max = s_max;
 		newsocks[a].limit = limit;
 
 		Py_DECREF(arg);
@@ -218,9 +218,15 @@
 	{"input", (getter)Map_socketdef_getter, (setter)Map_socketdef,
 		"Set this node's input sockets (list of lists or tuples)",
 		(void *)'I'},
+	{"i" /*alias*/, (getter)Map_socketdef_getter, (setter)Map_socketdef,
+		"Set this node's input sockets (list of lists or tuples)",
+		(void *)'I'},
 	{"output", (getter)Map_socketdef_getter, (setter)Map_socketdef,
 		"Set this node's output sockets (list of lists or tuples)",
 		(void *)'O'},
+	{"o" /*alias*/, (getter)Map_socketdef_getter, (setter)Map_socketdef,
+		"Set this node's output sockets (list of lists or tuples)",
+		(void *)'O'},
 	{NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 };
 
@@ -365,15 +371,12 @@
 		_idx = sockinmap_has_key(self, idx);
 	}
 	else if(PyInt_Check(idx)) {
-		PyErr_SetString(PyExc_ValueError, "int index not implemented");
-		Py_RETURN_NONE;
+		return EXPP_ReturnPyObjError(PyExc_ValueError, "int index not implemented");
 	}
 	else if (PySlice_Check(idx)) {
-		PyErr_SetString(PyExc_ValueError, "slices not implemented");
-		Py_RETURN_NONE;
+		return EXPP_ReturnPyObjError(PyExc_ValueError, "slices not implemented");
 	} else {
-		PyErr_SetString(PyExc_IndexError, "index must be string");
-		Py_RETURN_NONE;
+		return EXPP_ReturnPyObjError(PyExc_IndexError, "index must be an int or a string");
 	}
 
 	if(_idx<0) {
@@ -561,8 +564,10 @@
 	items = PySequence_Fast_ITEMS(val);
 
 	for (i = 0; i < len; i++) {
-		if (!PyNumber_Check(items[i]))
+		if (!PyNumber_Check(items[i])) {
+			Py_DECREF(val);
 			return EXPP_ReturnIntError(PyExc_AttributeError, "expected a *numeric* tuple or list");
+		}
 	}
 
 	switch(self->node->typeinfo->outputs[_idx].type) {
@@ -715,11 +720,11 @@
 #define TEXTURE				4
 #define PIXEL				5
 #define COLOR				6
-#define SPECULAR			7
-#define MIRROR				8
-#define AMBIENT				9
-#define AMBIENTFACTOR		10
-#define EMITFACTOR			11
+#define SPECULAR_COLOR		7
+#define MIRROR_COLOR		8
+#define AMBIENT_COLOR		9
+#define AMBIENT				10
+#define EMIT				11
 #define DISPLACE			12
 #define STRAND				13
 #define STRESS				14
@@ -758,19 +763,19 @@
 			case COLOR:
 				obj = Py_BuildValue("(fff)", self->shi->r, self->shi->g, self->shi->b);
 				break;
-			case SPECULAR:
+			case SPECULAR_COLOR:
 				obj = Py_BuildValue("(fff)", self->shi->specr, self->shi->specg, self->shi->specb);
 				break;
-			case MIRROR:
+			case MIRROR_COLOR:
 				obj = Py_BuildValue("(fff)", self->shi->mirr, self->shi->mirg, self->shi->mirb);
 				break;
-			case AMBIENT:
+			case AMBIENT_COLOR:
 				obj = Py_BuildValue("(fff)", self->shi->ambr, self->shi->ambg, self->shi->ambb);
 				break;
-			case AMBIENTFACTOR:
+			case AMBIENT:
 				obj = PyFloat_FromDouble((double)(self->shi->amb));
 				break;
-			case EMITFACTOR:
+			case EMIT:
 				obj = PyFloat_FromDouble((double)(self->shi->emit));
 				break;
 			case DISPLACE:
@@ -851,18 +856,30 @@
 }
 
 static PyGetSetDef BPy_Node_getseters[] = {
-	{"ins",
+	{"input",
 		(getter)Node_GetInputMap, (setter)NULL,
-		"Get the ShadeInput mapping (dictionary)",
+		"Get the input sockets mapping (dictionary)",
 		NULL},
-	{"outs",
+	{"i", /* alias */
+		(getter)Node_GetInputMap, (setter)NULL,
+		"Get the input sockets mapping (dictionary)",
+		NULL},
+	{"output",
 		(getter)Node_GetOutputMap, (setter)NULL,
-		"Get the ShadeInput mapping (dictionary)",
+		"Get the output sockets mapping (dictionary)",
 		NULL},
+	{"o", /* alias */
+		(getter)Node_GetOutputMap, (setter)NULL,
+		"Get the output sockets mapping (dictionary)",
+		NULL},
 	{"shi",
 		(getter)Node_GetShi, (setter)NULL,
-		"Get the ShadeInput (ShadeInput)",
+		"Get the Shade Input data (ShadeInput)",
 		NULL},
+	{"s", /* alias */
+		(getter)Node_GetShi, (setter)NULL,
+		"Get the Shade Input data (ShadeInput)",
+		NULL},
 	{NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 };
 
@@ -871,19 +888,19 @@
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the current texture coordinate (tuple)",
 	  (void*)TEXTURE},
-	{"texture_global",
+	{"textureGlobal",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the current global texture coordinate (tuple)",
 	  (void*)GLOBALTEXTURE},
-	{"surface_normal",
+	{"surfaceNormal",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the current surface normal (tuple)",
 	  (void*)SURFACENORMAL},
-	{"view_normal",
+	{"viewNormal",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the current view normal (tuple)",
 	  (void*)VIEWNORMAL},
-	{"surface_view_vec",
+	{"surfaceViewVector",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the vector pointing to the viewpoint from the point being shaded (tuple)",
 	  (void*)SURFACEVIEWVECTOR},
@@ -895,26 +912,26 @@
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the color for the point being shaded (tuple)",
 	  (void*)COLOR},
-	{"specular",
+	{"specularColor",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the specular color for the point being shaded (tuple)",
-	  (void*)SPECULAR},
-	{"mirror",
+	  (void*)SPECULAR_COLOR},
+	{"mirrorColor",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the mirror color for the point being shaded (tuple)",
-	  (void*)MIRROR},
-	{"ambient",
+	  (void*)MIRROR_COLOR},
+	{"ambientColor",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the ambient color for the point being shaded (tuple)",
-	  (void*)AMBIENT},
-	{"ambient_factor",
+	  (void*)AMBIENT_COLOR},
+	{"ambient",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the ambient factor for the point being shaded (float)",
-	  (void*)AMBIENTFACTOR},
-	{"emit_factor",
+	  (void*)AMBIENT},
+	{"emit",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the emit factor for the point being shaded (float)",
-	  (void*)EMITFACTOR},
+	  (void*)EMIT},
 	{"displace",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the displace vector for the point being shaded (tuple)",
@@ -931,35 +948,35 @@
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the tangent vector (tuple)",
 	  (void*)TANGENT},
-	{"surface_d",
+	{"surfaceD",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the surface d (tuple of tuples)",
 	  (void*)SURFACE_D},
-	{"texture_d",
+	{"textureD",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the texture d (tuple of tuples)",
 	  (void*)TEXTURE_D},
-	{"texture_global_d",
+	{"textureGlobalD",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the global texture d (tuple of tuples)",
 	  (void*)GLOBALTEXTURE_D},
-	{"reflection_d",
+	{"reflectionD",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the reflection d (tuple of tuples)",
 	  (void*)REFLECTION_D},
-	{"normal_d",
+	{"normalD",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the normal d (tuple of tuples)",
 	  (void*)NORMAL_D},
-	{"sticky_d",
+	{"stickyD",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the sticky d (tuple of tuples)",
 	  (void*)STICKY_D},
-	{"refract_d",
+	{"refractD",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the refract d (tuple of tuples)",
 	  (void*)REFRACT_D},
-	{"strand_d",
+	{"strandD",
 	  (getter)ShadeInput_getAttribute, (setter)NULL,
 	  "Get the strand d (tuple)",
 	  (void*)STRAND_D},





More information about the Bf-blender-cvs mailing list