Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-30 16:45:13 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-30 16:45:13 +0400
commitfdf6ea916db3225e2cee437cdb19b3fbee84db41 (patch)
treeef343448ff7e1d1909889590757527b29e0193b3 /source
parentb14dc8f3d97d6010c842e9137034d3ff3747e68a (diff)
added Geometry as a BGE module, removed its dependency on gen_utils.c
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/api2_2x/Blender.c2
-rw-r--r--source/blender/python/api2_2x/Geometry.c128
-rw-r--r--source/blender/python/api2_2x/Geometry.h2
-rw-r--r--source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp2
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Application.cpp1
-rw-r--r--source/gameengine/Ketsji/CMakeLists.txt1
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp9
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.h1
-rw-r--r--source/gameengine/Ketsji/SConscript1
9 files changed, 96 insertions, 51 deletions
diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c
index 2e44f0635e5..fd316eb484f 100644
--- a/source/blender/python/api2_2x/Blender.c
+++ b/source/blender/python/api2_2x/Blender.c
@@ -1092,7 +1092,7 @@ void M_Blender_Init(void)
PyDict_SetItemString(dict, "Mesh", Mesh_Init());
PyDict_SetItemString(dict, "Metaball", Metaball_Init());
PyDict_SetItemString(dict, "Mathutils", Mathutils_Init("Blender.Mathutils"));
- PyDict_SetItemString(dict, "Geometry", Geometry_Init());
+ PyDict_SetItemString(dict, "Geometry", Geometry_Init("Blender.Geometry"));
PyDict_SetItemString(dict, "Modifier", Modifier_Init());
PyDict_SetItemString(dict, "NMesh", NMesh_Init());
PyDict_SetItemString(dict, "Node", Node_Init());
diff --git a/source/blender/python/api2_2x/Geometry.c b/source/blender/python/api2_2x/Geometry.c
index 89c63870d59..d568472c838 100644
--- a/source/blender/python/api2_2x/Geometry.c
+++ b/source/blender/python/api2_2x/Geometry.c
@@ -38,9 +38,6 @@
#include "BKE_displist.h"
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
-
-/* needed for EXPP_ReturnPyObjError and EXPP_check_sequence_consistency */
-#include "gen_utils.h"
#include "BKE_utildefines.h"
#include "BLI_boxpack2d.h"
@@ -76,13 +73,32 @@ struct PyMethodDef M_Geometry_methods[] = {
{"BoxPack2D", ( PyCFunction ) M_Geometry_BoxPack2D, METH_O, M_Geometry_BoxPack2D_doc},
{NULL, NULL, 0, NULL}
};
+
+#if (PY_VERSION_HEX >= 0x03000000)
+static struct PyModuleDef M_Geometry_module_def = {
+ {}, /* m_base */
+ "Geometry", /* m_name */
+ M_Geometry_doc, /* m_doc */
+ 0, /* m_size */
+ M_Geometry_methods, /* m_methods */
+ 0, /* m_reload */
+ 0, /* m_traverse */
+ 0, /* m_clear */
+ 0, /* m_free */
+};
+#endif
+
/*----------------------------MODULE INIT-------------------------*/
-PyObject *Geometry_Init(void)
+PyObject *Geometry_Init(const char *from)
{
PyObject *submodule;
-
- submodule = Py_InitModule3("Blender.Geometry",
- M_Geometry_methods, M_Geometry_doc);
+
+#if (PY_VERSION_HEX >= 0x03000000)
+ submodule = PyModule_Create(&M_Geometry_module_def);
+#else
+ submodule = Py_InitModule3(from, M_Geometry_methods, M_Geometry_doc);
+#endif
+
return (submodule);
}
@@ -92,7 +108,7 @@ static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * polyLineSeq )
{
PyObject *tri_list; /*return this list of tri's */
PyObject *polyLine, *polyVec;
- int i, len_polylines, len_polypoints;
+ int i, len_polylines, len_polypoints, ls_error = 0;
/* display listbase */
ListBase dispbase={NULL, NULL};
@@ -105,8 +121,8 @@ static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * polyLineSeq )
if(!PySequence_Check(polyLineSeq)) {
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected a sequence of poly lines" );
+ PyErr_SetString( PyExc_TypeError, "expected a sequence of poly lines" );
+ return NULL;
}
len_polylines = PySequence_Size( polyLineSeq );
@@ -116,19 +132,20 @@ static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * polyLineSeq )
if (!PySequence_Check(polyLine)) {
freedisplist(&dispbase);
Py_XDECREF(polyLine); /* may be null so use Py_XDECREF*/
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "One or more of the polylines is not a sequence of Mathutils.Vector's" );
+ PyErr_SetString( PyExc_TypeError, "One or more of the polylines is not a sequence of Mathutils.Vector's" );
+ return NULL;
}
len_polypoints= PySequence_Size( polyLine );
if (len_polypoints>0) { /* dont bother adding edges as polylines */
+#if 0
if (EXPP_check_sequence_consistency( polyLine, &vector_Type ) != 1) {
freedisplist(&dispbase);
Py_DECREF(polyLine);
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "A point in one of the polylines is not a Mathutils.Vector type" );
+ PyErr_SetString( PyExc_TypeError, "A point in one of the polylines is not a Mathutils.Vector type" );
+ return NULL;
}
-
+#endif
dl= MEM_callocN(sizeof(DispList), "poly disp");
BLI_addtail(&dispbase, dl);
dl->type= DL_INDEX3;
@@ -141,13 +158,17 @@ static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * polyLineSeq )
for( index = 0; index<len_polypoints; ++index, fp+=3) {
polyVec= PySequence_GetItem( polyLine, index );
-
- fp[0] = ((VectorObject *)polyVec)->vec[0];
- fp[1] = ((VectorObject *)polyVec)->vec[1];
- if( ((VectorObject *)polyVec)->size > 2 )
- fp[2] = ((VectorObject *)polyVec)->vec[2];
- else
- fp[2]= 0.0f; /* if its a 2d vector then set the z to be zero */
+ if(VectorObject_Check(polyVec)) {
+ fp[0] = ((VectorObject *)polyVec)->vec[0];
+ fp[1] = ((VectorObject *)polyVec)->vec[1];
+ if( ((VectorObject *)polyVec)->size > 2 )
+ fp[2] = ((VectorObject *)polyVec)->vec[2];
+ else
+ fp[2]= 0.0f; /* if its a 2d vector then set the z to be zero */
+ }
+ else {
+ ls_error= 1;
+ }
totpoints++;
Py_DECREF(polyVec);
@@ -156,7 +177,12 @@ static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * polyLineSeq )
Py_DECREF(polyLine);
}
- if (totpoints) {
+ if(ls_error) {
+ freedisplist(&dispbase); /* possible some dl was allocated */
+ PyErr_SetString( PyExc_TypeError, "A point in one of the polylines is not a Mathutils.Vector type" );
+ return NULL;
+ }
+ else if (totpoints) {
/* now make the list to return */
filldisplist(&dispbase, &dispbase);
@@ -167,8 +193,8 @@ static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * polyLineSeq )
tri_list= PyList_New(dl->parts);
if( !tri_list ) {
freedisplist(&dispbase);
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "Geometry.PolyFill failed to make a new list" );
+ PyErr_SetString( PyExc_RuntimeError, "Geometry.PolyFill failed to make a new list" );
+ return NULL;
}
index= 0;
@@ -181,6 +207,7 @@ static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * polyLineSeq )
freedisplist(&dispbase);
} else {
/* no points, do this so scripts dont barf */
+ freedisplist(&dispbase); /* possible some dl was allocated */
tri_list= PyList_New(0);
}
@@ -197,9 +224,10 @@ static PyObject *M_Geometry_LineIntersect2D( PyObject * self, PyObject * args )
&vector_Type, &line_a2,
&vector_Type, &line_b1,
&vector_Type, &line_b2)
- )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected 4 vector types\n" ) );
+ ) {
+ PyErr_SetString( PyExc_TypeError, "expected 4 vector types\n" );
+ return NULL;
+ }
a1x= line_a1->vec[0];
a1y= line_a1->vec[1];
@@ -293,10 +321,10 @@ static PyObject *M_Geometry_ClosestPointOnLine( PyObject * self, PyObject * args
&vector_Type, &pt,
&vector_Type, &line_1,
&vector_Type, &line_2)
- )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected 3 vector types\n" ) );
-
+ ) {
+ PyErr_SetString( PyExc_TypeError, "expected 3 vector types\n" );
+ return NULL;
+ }
/* accept 2d verts */
if (pt->size==3) { VECCOPY(pt_in, pt->vec);}
else { pt_in[2]=0.0; VECCOPY2D(pt_in, pt->vec) }
@@ -325,9 +353,10 @@ static PyObject *M_Geometry_PointInTriangle2D( PyObject * self, PyObject * args
&vector_Type, &tri_p1,
&vector_Type, &tri_p2,
&vector_Type, &tri_p3)
- )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected 4 vector types\n" ) );
+ ) {
+ PyErr_SetString( PyExc_TypeError, "expected 4 vector types\n" );
+ return NULL;
+ }
return PyInt_FromLong(IsectPT2Df(pt_vec->vec, tri_p1->vec, tri_p2->vec, tri_p3->vec));
}
@@ -342,9 +371,10 @@ static PyObject *M_Geometry_PointInQuad2D( PyObject * self, PyObject * args )
&vector_Type, &quad_p2,
&vector_Type, &quad_p3,
&vector_Type, &quad_p4)
- )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected 5 vector types\n" ) );
+ ) {
+ PyErr_SetString( PyExc_TypeError, "expected 5 vector types\n" );
+ return NULL;
+ }
return PyInt_FromLong(IsectPQ2Df(pt_vec->vec, quad_p1->vec, quad_p2->vec, quad_p3->vec, quad_p4->vec));
}
@@ -357,9 +387,10 @@ static int boxPack_FromPyObject(PyObject * value, boxPack **boxarray )
/* Error checking must alredy be done */
- if( !PyList_Check( value ) )
- return EXPP_ReturnIntError( PyExc_TypeError,
- "can only back a list of [x,y,x,w]" );
+ if( !PyList_Check( value ) ) {
+ PyErr_SetString( PyExc_TypeError, "can only back a list of [x,y,x,w]" );
+ return -1;
+ }
len = PyList_Size( value );
@@ -370,8 +401,8 @@ static int boxPack_FromPyObject(PyObject * value, boxPack **boxarray )
list_item = PyList_GET_ITEM( value, i );
if( !PyList_Check( list_item ) || PyList_Size( list_item ) < 4 ) {
MEM_freeN(*boxarray);
- return EXPP_ReturnIntError( PyExc_TypeError,
- "can only back a list of [x,y,x,w]" );
+ PyErr_SetString( PyExc_TypeError, "can only back a list of [x,y,x,w]" );
+ return -1;
}
box = (*boxarray)+i;
@@ -381,8 +412,8 @@ static int boxPack_FromPyObject(PyObject * value, boxPack **boxarray )
if (!PyNumber_Check(item_1) || !PyNumber_Check(item_2)) {
MEM_freeN(*boxarray);
- return EXPP_ReturnIntError( PyExc_TypeError,
- "can only back a list of 2d boxes [x,y,x,w]" );
+ PyErr_SetString( PyExc_TypeError, "can only back a list of 2d boxes [x,y,x,w]" );
+ return -1;
}
box->w = (float)PyFloat_AsDouble( item_1 );
@@ -418,9 +449,10 @@ static PyObject *M_Geometry_BoxPack2D( PyObject * self, PyObject * boxlist )
int len;
int error;
- if(!PyList_Check(boxlist))
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected a sequence of boxes [[x,y,w,h], ... ]" );
+ if(!PyList_Check(boxlist)) {
+ PyErr_SetString( PyExc_TypeError, "expected a sequence of boxes [[x,y,w,h], ... ]" );
+ return NULL;
+ }
len = PyList_Size( boxlist );
diff --git a/source/blender/python/api2_2x/Geometry.h b/source/blender/python/api2_2x/Geometry.h
index e9e365cc9ae..ebfb054c54a 100644
--- a/source/blender/python/api2_2x/Geometry.h
+++ b/source/blender/python/api2_2x/Geometry.h
@@ -34,6 +34,6 @@
#include <Python.h>
#include "Mathutils.h"
-PyObject *Geometry_Init( void );
+PyObject *Geometry_Init( const char *from );
#endif /* EXPP_Geometry_H */
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
index 2337ab49ee9..641938253b7 100644
--- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
+++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
@@ -368,6 +368,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
initGameKeys();
initPythonConstraintBinding();
initMathutils();
+ initGeometry();
initBGL();
#ifdef WITH_FFMPEG
initVideoTexture();
@@ -671,6 +672,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
initGameKeys();
initPythonConstraintBinding();
initMathutils();
+ initGeometry();
initBGL();
#ifdef WITH_FFMPEG
initVideoTexture();
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
index 907ba99e63b..af8b94857b9 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
@@ -693,6 +693,7 @@ bool GPG_Application::startEngine(void)
initGameKeys();
initPythonConstraintBinding();
initMathutils();
+ initGeometry();
initBGL();
#ifdef WITH_FFMPEG
initVideoTexture();
diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt
index c4623b5b6fe..abc2b44825e 100644
--- a/source/gameengine/Ketsji/CMakeLists.txt
+++ b/source/gameengine/Ketsji/CMakeLists.txt
@@ -28,6 +28,7 @@ FILE(GLOB SRC *.cpp)
SET(SRC
${SRC}
../../../source/blender/python/api2_2x/Mathutils.c
+ ../../../source/blender/python/api2_2x/Geometry.c
../../../source/blender/python/api2_2x/constant.c
../../../source/blender/python/api2_2x/euler.c
../../../source/blender/python/api2_2x/matrix.c
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index b17d4042bb6..f5d32e36fc5 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -86,6 +86,7 @@
extern "C" {
#include "Mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use.
+ #include "Geometry.h" // Blender.Geometry module copied here so the blenderlayer can use.
#include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */
#include "BGL.h"
}
@@ -1407,7 +1408,7 @@ PyObject *KXpy_import(PyObject *self, PyObject *args)
/* quick hack for GamePython modules
TODO: register builtin modules properly by ExtendInittab */
if (!strcmp(name, "GameLogic") || !strcmp(name, "GameKeys") || !strcmp(name, "PhysicsConstraints") ||
- !strcmp(name, "Rasterizer") || !strcmp(name, "Mathutils") || !strcmp(name, "BGL")) {
+ !strcmp(name, "Rasterizer") || !strcmp(name, "Mathutils") || !strcmp(name, "BGL") || !strcmp(name, "Geometry")) {
return PyImport_ImportModuleEx(name, globals, locals, fromlist);
}
@@ -1725,6 +1726,7 @@ static void clearGameModules()
clearModule(modules, "GameKeys");
clearModule(modules, "VideoTexture");
clearModule(modules, "Mathutils");
+ clearModule(modules, "Geometry");
clearModule(modules, "BGL");
PyErr_Clear(); // incase some of these were alredy removed.
#endif
@@ -2051,6 +2053,11 @@ PyObject* initMathutils()
return Mathutils_Init("Mathutils"); // Use as a top level module in BGE
}
+PyObject* initGeometry()
+{
+ return Geometry_Init("Geometry"); // Use as a top level module in BGE
+}
+
PyObject* initBGL()
{
return BGL_Init("BGL"); // Use as a top level module in BGE
diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h
index 11360197b95..3253ac8f711 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.h
+++ b/source/gameengine/Ketsji/KX_PythonInit.h
@@ -45,6 +45,7 @@ PyObject* initGameKeys();
PyObject* initRasterizer(class RAS_IRasterizer* rasty,class RAS_ICanvas* canvas);
PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level, struct Main *maggie, int argc, char** argv);
PyObject* initMathutils();
+PyObject* initGeometry();
PyObject* initBGL();
PyObject* initVideoTexture(void);
void exitGamePlayerPythonScripting();
diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript
index d97f13b0758..dd7297080e5 100644
--- a/source/gameengine/Ketsji/SConscript
+++ b/source/gameengine/Ketsji/SConscript
@@ -9,6 +9,7 @@ defs = ''
# Mathutils C files.
sources.extend([\
'#source/blender/python/api2_2x/Mathutils.c',\
+ '#source/blender/python/api2_2x/Geometry.c',\
'#source/blender/python/api2_2x/constant.c',\
'#source/blender/python/api2_2x/euler.c',\
'#source/blender/python/api2_2x/matrix.c',\