[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20960] branches/blender2.5/blender/source : Some generic modules from blender 2. 4x building with py3k and mostly working.

Campbell Barton ideasman42 at gmail.com
Wed Jun 17 22:33:34 CEST 2009


Revision: 20960
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20960
Author:   campbellbarton
Date:     2009-06-17 22:33:34 +0200 (Wed, 17 Jun 2009)

Log Message:
-----------
Some generic modules from blender 2.4x building with py3k and mostly working.
* Mathutils, Geometry, BGL, Mostly working, some //XXX comments for things to fix with py3

python import override (bpy_internal_import.c) so you can import python internal scripts from the BGE and running blender normally.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/python/SConscript
    branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c
    branches/blender2.5/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
    branches/blender2.5/blender/source/gameengine/Ketsji/SConscript

Added Paths:
-----------
    branches/blender2.5/blender/source/blender/python/generic/
    branches/blender2.5/blender/source/blender/python/generic/BGL.c
    branches/blender2.5/blender/source/blender/python/generic/BGL.h
    branches/blender2.5/blender/source/blender/python/generic/Geometry.c
    branches/blender2.5/blender/source/blender/python/generic/Geometry.h
    branches/blender2.5/blender/source/blender/python/generic/Mathutils.c
    branches/blender2.5/blender/source/blender/python/generic/Mathutils.h
    branches/blender2.5/blender/source/blender/python/generic/bpy_internal_import.c
    branches/blender2.5/blender/source/blender/python/generic/bpy_internal_import.h
    branches/blender2.5/blender/source/blender/python/generic/euler.c
    branches/blender2.5/blender/source/blender/python/generic/euler.h
    branches/blender2.5/blender/source/blender/python/generic/matrix.c
    branches/blender2.5/blender/source/blender/python/generic/matrix.h
    branches/blender2.5/blender/source/blender/python/generic/quat.c
    branches/blender2.5/blender/source/blender/python/generic/quat.h
    branches/blender2.5/blender/source/blender/python/generic/vector.c
    branches/blender2.5/blender/source/blender/python/generic/vector.h

Modified: branches/blender2.5/blender/source/blender/python/SConscript
===================================================================
--- branches/blender2.5/blender/source/blender/python/SConscript	2009-06-17 19:46:39 UTC (rev 20959)
+++ branches/blender2.5/blender/source/blender/python/SConscript	2009-06-17 20:33:34 UTC (rev 20960)
@@ -14,4 +14,8 @@
 	defs.append('Py_TRACE_REFS')
 
 env.BlenderLib( libname = 'bf_python', sources = Split(sources), includes = Split(incs), defines = defs, libtype = ['core'], priority = [140])
-
+
+
+# generic  XXX todo, BGE currently uses these externally
+# sources = env.Glob('generic/*.c')
+# env.BlenderLib( libname = 'bf_gen_python', sources = Split(sources), includes = Split(incs), defines = defs, libtype = ['core'], priority = [140])

Added: branches/blender2.5/blender/source/blender/python/generic/BGL.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/generic/BGL.c	                        (rev 0)
+++ branches/blender2.5/blender/source/blender/python/generic/BGL.c	2009-06-17 20:33:34 UTC (rev 20960)
@@ -0,0 +1,1605 @@
+/* 
+ * $Id: BGL.c 20922 2009-06-16 07:16:51Z campbellbarton $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * This is a new part of Blender.
+ *
+ * Contributor(s): Willian P. Germano
+ *
+ * ***** END GPL LICENSE BLOCK *****
+*/
+
+/* This file is the Blender.BGL part of opy_draw.c, from the old
+ * bpython/intern dir, with minor changes to adapt it to the new Python
+ * implementation.  The BGL submodule "wraps" OpenGL functions and constants,
+ * allowing script writers to make OpenGL calls in their Python scripts. */
+
+#include "BGL.h" /*This must come first */
+
+#include "MEM_guardedalloc.h"
+
+static int type_size( int type );
+static Buffer *make_buffer( int type, int ndimensions, int *dimensions );
+
+static char Method_Buffer_doc[] =
+	"(type, dimensions, [template]) - Create a new Buffer object\n\n\
+(type) - The format to store data in\n\
+(dimensions) - An int or sequence specifying the dimensions of the buffer\n\
+[template] - A sequence of matching dimensions to the buffer to be created\n\
+  which will be used to initialize the Buffer.\n\n\
+If a template is not passed in all fields will be initialized to 0.\n\n\
+The type should be one of GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT, or GL_DOUBLE.\n\
+If the dimensions are specified as an int a linear buffer will be\n\
+created. If a sequence is passed for the dimensions the buffer\n\
+will have len(sequence) dimensions, where the size for each dimension\n\
+is determined by the value in the sequence at that index.\n\n\
+For example, passing [100, 100] will create a 2 dimensional\n\
+square buffer. Passing [16, 16, 32] will create a 3 dimensional\n\
+buffer which is twice as deep as it is wide or high.";
+
+static PyObject *Method_Buffer( PyObject * self, PyObject * args );
+
+/* Buffer sequence methods */
+
+static int Buffer_len( PyObject * self );
+static PyObject *Buffer_item( PyObject * self, int i );
+static PyObject *Buffer_slice( PyObject * self, int begin, int end );
+static int Buffer_ass_item( PyObject * self, int i, PyObject * v );
+static int Buffer_ass_slice( PyObject * self, int begin, int end,
+			     PyObject * seq );
+
+static PySequenceMethods Buffer_SeqMethods = {
+	( inquiry ) Buffer_len,	/*sq_length */
+	( binaryfunc ) 0,	/*sq_concat */
+	( ssizeargfunc ) 0,	/*sq_repeat */
+	( ssizeargfunc ) Buffer_item,	/*sq_item */
+	( ssizessizeargfunc ) Buffer_slice,	/*sq_slice */
+	( ssizeobjargproc ) Buffer_ass_item,	/*sq_ass_item */
+	( ssizessizeobjargproc ) Buffer_ass_slice,	/*sq_ass_slice */
+};
+
+static void Buffer_dealloc( PyObject * self );
+static PyObject *Buffer_tolist( PyObject * self );
+static PyObject *Buffer_dimensions( PyObject * self );
+static PyObject *Buffer_getattr( PyObject * self, char *name );
+static PyObject *Buffer_repr( PyObject * self );
+
+PyTypeObject buffer_Type = {
+	PyObject_HEAD_INIT( NULL )      /* required python macro */
+	0,	/*ob_size */
+	"buffer",		/*tp_name */
+	sizeof( Buffer ),	/*tp_basicsize */
+	0,			/*tp_itemsize */
+	( destructor ) Buffer_dealloc,	/*tp_dealloc */
+	( printfunc ) 0,	/*tp_print */
+	( getattrfunc ) Buffer_getattr,	/*tp_getattr */
+	( setattrfunc ) 0,	/*tp_setattr */
+	0,		/*tp_compare */
+	( reprfunc ) Buffer_repr,	/*tp_repr */
+	0,			/*tp_as_number */
+	&Buffer_SeqMethods,	/*tp_as_sequence */
+};
+
+/* #ifndef __APPLE__ */
+
+#define BGL_Wrap(nargs, funcname, ret, arg_list) \
+static PyObject *Method_##funcname (PyObject *self, PyObject *args) {\
+	arg_def##nargs arg_list; \
+	ret_def_##ret; \
+	if(!PyArg_ParseTuple(args, arg_str##nargs arg_list, arg_ref##nargs arg_list)) return NULL;\
+	ret_set_##ret gl##funcname (arg_var##nargs arg_list);\
+	ret_ret_##ret; \
+}
+
+#define BGLU_Wrap(nargs, funcname, ret, arg_list) \
+static PyObject *Method_##funcname (PyObject *self, PyObject *args) {\
+	arg_def##nargs arg_list; \
+	ret_def_##ret; \
+	if(!PyArg_ParseTuple(args, arg_str##nargs arg_list, arg_ref##nargs arg_list)) return NULL;\
+	ret_set_##ret glu##funcname (arg_var##nargs arg_list);\
+	ret_ret_##ret; \
+}
+
+/* #endif */
+
+/********/
+static int type_size(int type)
+{
+	switch (type) {
+		case GL_BYTE: 
+		  return sizeof(char);
+		case GL_SHORT: 
+		  return sizeof(short);
+		case GL_INT: 
+		  return sizeof(int);
+		case GL_FLOAT: 
+		  return sizeof(float);
+		case GL_DOUBLE:
+		  return sizeof(double);
+	}
+	return -1;
+}
+
+static Buffer *make_buffer(int type, int ndimensions, int *dimensions)
+{
+	Buffer *buffer;
+	void *buf= NULL;
+	int i, size, length;
+ 
+	length= 1;
+	for (i=0; i<ndimensions; i++) 
+		length*= dimensions[i];
+ 
+	size= type_size(type);
+ 
+	buf= MEM_mallocN(length*size, "Buffer buffer");
+ 
+	buffer= (Buffer *) PyObject_NEW(Buffer, &buffer_Type);
+	buffer->parent= NULL;
+	buffer->ndimensions= ndimensions;
+	buffer->dimensions= dimensions;
+	buffer->type= type;
+	buffer->buf.asvoid= buf;
+ 
+	for (i= 0; i<length; i++) {
+		if (type==GL_BYTE) 
+			buffer->buf.asbyte[i]= 0;
+		else if (type==GL_SHORT) 
+			buffer->buf.asshort[i]= 0;
+		else if (type==GL_INT) 
+			buffer->buf.asint[i]= 0;
+		else if (type==GL_FLOAT) 
+		    buffer->buf.asfloat[i]= 0.0f;
+		else if (type==GL_DOUBLE)
+			buffer->buf.asdouble[i]= 0.0;
+	}
+	return buffer;
+}
+
+static PyObject *Method_Buffer (PyObject *self, PyObject *args)
+{
+	PyObject *length_ob= NULL, *template= NULL;
+	Buffer *buffer;
+	
+	int i, type;
+	int *dimensions = 0, ndimensions = 0;
+	
+	if (!PyArg_ParseTuple(args, "iO|O", &type, &length_ob, &template)) {
+		PyErr_SetString(PyExc_AttributeError, "expected an int and one or two PyObjects");
+		return NULL;
+	}
+	if (type!=GL_BYTE && type!=GL_SHORT && type!=GL_INT && type!=GL_FLOAT && type!=GL_DOUBLE) {
+		PyErr_SetString(PyExc_AttributeError, "invalid first argument type, should be one of GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT or GL_DOUBLE");
+		return NULL;
+	}
+
+	if (PyNumber_Check(length_ob)) {
+		ndimensions= 1;
+		dimensions= MEM_mallocN(ndimensions*sizeof(int), "Buffer dimensions");
+		dimensions[0]= PyLong_AsLong(length_ob);
+	} else if (PySequence_Check(length_ob)) {
+		ndimensions= PySequence_Length(length_ob);
+		dimensions= MEM_mallocN(ndimensions*sizeof(int), "Buffer dimensions");
+		for (i=0; i<ndimensions; i++) {
+			PyObject *ob= PySequence_GetItem(length_ob, i);
+
+			if (!PyNumber_Check(ob)) dimensions[i]= 1;
+			else dimensions[i]= PyLong_AsLong(ob);
+			Py_DECREF(ob);
+		}
+	}
+	
+	buffer= make_buffer(type, ndimensions, dimensions);
+	if (template && ndimensions) {
+		if (Buffer_ass_slice((PyObject *) buffer, 0, dimensions[0], template)) {
+			Py_DECREF(buffer);
+			return NULL;
+		}
+	}
+	
+	return (PyObject *) buffer;
+}
+
+/*@ Buffer sequence methods */
+
+static int Buffer_len(PyObject *self)
+{
+	Buffer *buf= (Buffer *) self;
+	return buf->dimensions[0];
+}
+
+static PyObject *Buffer_item(PyObject *self, int i)
+{
+	Buffer *buf= (Buffer *) self;
+
+	if (i >= buf->dimensions[0]) {
+		PyErr_SetString(PyExc_IndexError, "array index out of range");
+		return NULL;
+	}
+
+	if (buf->ndimensions==1) {
+		switch (buf->type) {
+			case GL_BYTE: return Py_BuildValue("b", buf->buf.asbyte[i]);
+			case GL_SHORT: return Py_BuildValue("h", buf->buf.asshort[i]);
+			case GL_INT: return Py_BuildValue("i", buf->buf.asint[i]);
+			case GL_FLOAT: return PyFloat_FromDouble(buf->buf.asfloat[i]);
+			case GL_DOUBLE: return Py_BuildValue("d", buf->buf.asdouble[i]);
+		}
+	} else {
+		Buffer *newbuf;
+		int j, length, size;
+ 
+		length= 1;
+		for (j=1; j<buf->ndimensions; j++) {
+			length*= buf->dimensions[j];
+		}
+		size= type_size(buf->type);
+
+		newbuf= (Buffer *) PyObject_NEW(Buffer, &buffer_Type);
+    
+		Py_INCREF(self);
+		newbuf->parent= self;
+
+		newbuf->ndimensions= buf->ndimensions-1;
+		newbuf->type= buf->type;
+		newbuf->buf.asvoid= buf->buf.asbyte + i*length*size;
+		newbuf->dimensions= MEM_mallocN(newbuf->ndimensions*sizeof(int),
+			"Buffer dimensions");
+		memcpy(newbuf->dimensions, buf->dimensions+1,
+			newbuf->ndimensions*sizeof(int));
+
+		return (PyObject *) newbuf;
+	}
+  
+	return NULL;
+}
+
+static PyObject *Buffer_slice(PyObject *self, int begin, int end)
+{
+	Buffer *buf= (Buffer *) self;
+	PyObject *list;
+	int count;
+	
+	if (begin<0) begin= 0;
+	if (end>buf->dimensions[0]) 
+		end= buf->dimensions[0];
+	if (begin>end) begin= end;
+	  
+	list= PyList_New(end-begin);
+
+	for (count= begin; count<end; count++)
+		PyList_SetItem(list, count-begin, Buffer_item(self, count));
+	
+	return list;
+}
+
+static int Buffer_ass_item(PyObject *self, int i, PyObject *v)
+{
+	Buffer *buf= (Buffer *) self;
+	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list