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>2006-07-01 19:29:04 +0400
committerCampbell Barton <ideasman42@gmail.com>2006-07-01 19:29:04 +0400
commit7809809e8abe422c929f86ea88a422602ef5dd29 (patch)
treede2035d33faada8453f300772388f5a3d42cf705 /source
parent2174b90307fc1885f8ef998c681d11cdfb897184 (diff)
Added a scanfill wraper to Mathutils, allows you to fill polylines without using Meshes .fill() function.
Takes a list of polylines and returns a list of face index triplets. Added this so using mesh.fill() could be avoided since it requires making an object, linking to the scene and cycling editmode for every NGon imported. Since this is so close to release, It might be good if ken, willian or stivs takes a look at the function to make sure its ok. - Ran 100's of times for importing lightwave models but would be good to doublecheck.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/api2_2x/Mathutils.c103
-rw-r--r--source/blender/python/api2_2x/Mathutils.h1
-rw-r--r--source/blender/python/api2_2x/doc/Mathutils.py11
3 files changed, 115 insertions, 0 deletions
diff --git a/source/blender/python/api2_2x/Mathutils.c b/source/blender/python/api2_2x/Mathutils.c
index 7042150cbaf..7188a999cd2 100644
--- a/source/blender/python/api2_2x/Mathutils.c
+++ b/source/blender/python/api2_2x/Mathutils.c
@@ -36,6 +36,12 @@
#include "PIL_time.h"
#include "BLI_rand.h"
#include "BKE_utildefines.h"
+
+/* Used for PolyFill */
+#include "BKE_displist.h"
+#include "MEM_guardedalloc.h"
+#include "BLI_blenlib.h"
+
#include "gen_utils.h"
//-------------------------DOC STRINGS ---------------------------
@@ -71,6 +77,7 @@ static char M_Mathutils_TriangleArea_doc[] = "(v1, v2, v3) - returns the area si
static char M_Mathutils_TriangleNormal_doc[] = "(v1, v2, v3) - returns the normal of the 3D triangle defined";
static char M_Mathutils_QuadNormal_doc[] = "(v1, v2, v3, v4) - returns the normal of the 3D quad defined";
static char M_Mathutils_LineIntersect_doc[] = "(v1, v2, v3, v4) - returns a tuple with the points on each line respectively closest to the other";
+static char M_Mathutils_PolyFill_doc[] = "(veclist_list) - takes a list of polylines (each point a vector) and returns the point indicies for a polyline filled with triangles";
static char M_Mathutils_Point_doc[] = "Creates a 2d or 3d point object";
//-----------------------METHOD DEFINITIONS ----------------------
struct PyMethodDef M_Mathutils_methods[] = {
@@ -105,6 +112,7 @@ struct PyMethodDef M_Mathutils_methods[] = {
{"TriangleNormal", ( PyCFunction ) M_Mathutils_TriangleNormal, METH_VARARGS, M_Mathutils_TriangleNormal_doc},
{"QuadNormal", ( PyCFunction ) M_Mathutils_QuadNormal, METH_VARARGS, M_Mathutils_QuadNormal_doc},
{"LineIntersect", ( PyCFunction ) M_Mathutils_LineIntersect, METH_VARARGS, M_Mathutils_LineIntersect_doc},
+ {"PolyFill", ( PyCFunction ) M_Mathutils_PolyFill, METH_VARARGS, M_Mathutils_PolyFill_doc},
{"Point", (PyCFunction) M_Mathutils_Point, METH_VARARGS, M_Mathutils_Point_doc},
{NULL, NULL, 0, NULL}
};
@@ -157,6 +165,7 @@ PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec)
return newVectorObject(vecNew, vec->size, Py_NEW);
}
//This is a helper for point/matrix translation
+
PyObject *column_point_multiplication(MatrixObject * mat, PointObject* pt)
{
float ptNew[4], ptCopy[4];
@@ -1526,6 +1535,100 @@ PyObject *M_Mathutils_LineIntersect( PyObject * self, PyObject * args )
"2D/3D vectors only\n" ) );
}
}
+
+
+//----------------------------------Mathutils.PolyFill() -------------------
+/* PolyFill function, uses Blenders scanfill to fill multiple poly lines */
+PyObject *M_Mathutils_PolyFill( PyObject * self, PyObject * args )
+{
+ PyObject *tri_list; /*return this list of tri's */
+ PyObject *polyLineList, *polyLine, *polyVec;
+ int i, len_polylines, len_polypoints;
+
+ /* display listbase */
+ ListBase dispbase={NULL, NULL};
+ DispList *dl;
+ float *fp; /*pointer to the array of malloced dl->verts to set the points from the vectors */
+ int index, *dl_face, totpoints=0;
+
+
+ dispbase.first= dispbase.last= NULL;
+
+
+ if( !PyArg_ParseTuple ( args, "O!", &PyList_Type, &polyLineList) ) {
+ freedisplist(&dispbase);
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected a list of poly lines" );
+ }
+
+
+ if (EXPP_check_sequence_consistency( polyLineList, &PyList_Type ) != 1)
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected a list of lists of vectors" );
+
+ len_polylines = PySequence_Size( polyLineList );
+
+ for( i = 0; i < len_polylines; ++i ) {
+ polyLine= PySequence_GetItem( polyLineList, i );
+
+ if (EXPP_check_sequence_consistency( polyLine, &vector_Type ) != 1)
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected a list of poly lines" );
+
+ len_polypoints= PySequence_Size( polyLine );
+
+ dl= MEM_callocN(sizeof(DispList), "poly disp");
+ BLI_addtail(&dispbase, dl);
+ dl->type= DL_INDEX3;
+ dl->nr= len_polypoints;
+ dl->type= DL_POLY;
+ dl->parts= 1; /* no faces, 1 edge loop */
+ dl->col= 0; /* no material */
+ dl->verts= fp= MEM_callocN( sizeof(float)*3*len_polypoints, "dl verts");
+ dl->index= MEM_callocN(sizeof(int)*3*len_polypoints, "dl index");
+
+ 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 */
+
+ totpoints++;
+ }
+ }
+
+ if (totpoints) {
+ /* now make the list to return */
+ filldisplist(&dispbase, &dispbase);
+
+
+ /* The faces are stored in a new DisplayList
+ thats added to the head of the listbase */
+ dl= dispbase.first;
+
+ tri_list= PyList_New(dl->parts);
+ index= 0;
+
+ dl_face= dl->index;
+ while(index < dl->parts) {
+ PyList_SetItem(tri_list, index, Py_BuildValue("iii", dl_face[0], dl_face[1], dl_face[2]) );
+ dl_face+= 3;
+ index++;
+ }
+ freedisplist(&dispbase);
+ } else {
+ /* no points, do this so scripts dont barf */
+ tri_list= PyList_New(0);
+ }
+
+ return tri_list;
+}
+
+
//---------------------------------NORMALS FUNCTIONS--------------------
//----------------------------------Mathutils.QuadNormal() -------------------
PyObject *M_Mathutils_QuadNormal( PyObject * self, PyObject * args )
diff --git a/source/blender/python/api2_2x/Mathutils.h b/source/blender/python/api2_2x/Mathutils.h
index 84890267ed2..88630d3928d 100644
--- a/source/blender/python/api2_2x/Mathutils.h
+++ b/source/blender/python/api2_2x/Mathutils.h
@@ -72,6 +72,7 @@ PyObject *M_Mathutils_TriangleArea( PyObject * self, PyObject * args );
PyObject *M_Mathutils_TriangleNormal( PyObject * self, PyObject * args );
PyObject *M_Mathutils_QuadNormal( PyObject * self, PyObject * args );
PyObject *M_Mathutils_LineIntersect( PyObject * self, PyObject * args );
+PyObject *M_Mathutils_PolyFill( PyObject * self, PyObject * args );
PyObject *M_Mathutils_Point(PyObject * self, PyObject * args);
//DEPRECATED
PyObject *M_Mathutils_CopyMat(PyObject * self, PyObject * args);
diff --git a/source/blender/python/api2_2x/doc/Mathutils.py b/source/blender/python/api2_2x/doc/Mathutils.py
index eb3653434b0..adfd4da42b9 100644
--- a/source/blender/python/api2_2x/doc/Mathutils.py
+++ b/source/blender/python/api2_2x/doc/Mathutils.py
@@ -114,6 +114,17 @@ def LineIntersect(vec1, vec2, vec3, vec4):
@return: A tuple with the points on each line respectively closest to the other.
"""
+def PolyFill(polylines):
+ """
+ Takes a list of polylines and calculates triangles that would fill in the polylines.
+ Multiple lines can be used to make holes inside a polyline, or fill in 2 seperate lines at once.
+ @type polylines: List of lists containing vectors, each representing a closed polyline.
+ @rtype: list
+ @return: a list if tuples each a tuple of 3 ints representing a triangle indexing the points given.
+ @note: 2D Vectors will have an assumed Z axis of zero, 4D Vectors W axis is ignored.
+ """
+
+
def CopyVec(vector):
"""
Create a copy of the Vector object.