[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20055] trunk/blender: python geometry function Geometry.BezierInterp(vec_knot_1, vec_handle_1, vec_handle_2, vec_knot_2, resolution)
Campbell Barton
ideasman42 at gmail.com
Mon May 4 15:01:18 CEST 2009
Revision: 20055
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20055
Author: campbellbarton
Date: 2009-05-04 15:01:18 +0200 (Mon, 04 May 2009)
Log Message:
-----------
python geometry function Geometry.BezierInterp(vec_knot_1, vec_handle_1, vec_handle_2, vec_knot_2, resolution)
can use 2D-4D vectors
Also made 3ds import give a message when no python installed
Modified Paths:
--------------
trunk/blender/release/scripts/3ds_import.py
trunk/blender/source/blender/python/api2_2x/Geometry.c
trunk/blender/source/blender/python/api2_2x/doc/Geometry.py
Modified: trunk/blender/release/scripts/3ds_import.py
===================================================================
--- trunk/blender/release/scripts/3ds_import.py 2009-05-04 10:24:53 UTC (rev 20054)
+++ trunk/blender/release/scripts/3ds_import.py 2009-05-04 13:01:18 UTC (rev 20055)
@@ -133,11 +133,13 @@
import BPyMessages
-import struct
-from struct import calcsize, unpack
+try:
+ from struct import calcsize, unpack
+except:
+ calcsize= unpack= None
-import os
+
# If python version is less than 2.4, try to get set stuff from module
try:
set
@@ -958,7 +960,10 @@
DEBUG= False
if __name__=='__main__' and not DEBUG:
- Blender.Window.FileSelector(load_3ds, 'Import 3DS', '*.3ds')
+ if calcsize==None:
+ Blender.Draw.PupMenu('Error%t|a full python installation not found')
+ else:
+ Blender.Window.FileSelector(load_3ds, 'Import 3DS', '*.3ds')
# For testing compatibility
#load_3ds('/metavr/convert/vehicle/truck_002/TruckTanker1.3DS', False)
@@ -966,6 +971,7 @@
'''
else:
+ import os
# DEBUG ONLY
TIME= Blender.sys.time()
import os
Modified: trunk/blender/source/blender/python/api2_2x/Geometry.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Geometry.c 2009-05-04 10:24:53 UTC (rev 20054)
+++ trunk/blender/source/blender/python/api2_2x/Geometry.c 2009-05-04 13:01:18 UTC (rev 20055)
@@ -40,6 +40,7 @@
#include "BLI_blenlib.h"
#include "BKE_utildefines.h"
+#include "BKE_curve.h"
#include "BLI_boxpack2d.h"
#include "BLI_arithb.h"
@@ -53,6 +54,7 @@
static PyObject *M_Geometry_PointInTriangle2D( PyObject * self, PyObject * args );
static PyObject *M_Geometry_PointInQuad2D( PyObject * self, PyObject * args );
static PyObject *M_Geometry_BoxPack2D( PyObject * self, PyObject * args );
+static PyObject *M_Geometry_BezierInterp( PyObject * self, PyObject * args );
/*-------------------------DOC STRINGS ---------------------------*/
@@ -63,6 +65,7 @@
static char M_Geometry_PointInTriangle2D_doc[] = "(pt, tri_p1, tri_p2, tri_p3) - takes 4 vectors, one is the point and the next 3 define the triangle, only the x and y are used from the vectors";
static char M_Geometry_PointInQuad2D_doc[] = "(pt, quad_p1, quad_p2, quad_p3, quad_p4) - takes 5 vectors, one is the point and the next 4 define the quad, only the x and y are used from the vectors";
static char M_Geometry_BoxPack2D_doc[] = "";
+static char M_Geometry_BezierInterp_doc[] = "";
/*-----------------------METHOD DEFINITIONS ----------------------*/
struct PyMethodDef M_Geometry_methods[] = {
{"PolyFill", ( PyCFunction ) M_Geometry_PolyFill, METH_O, M_Geometry_PolyFill_doc},
@@ -71,6 +74,7 @@
{"PointInTriangle2D", ( PyCFunction ) M_Geometry_PointInTriangle2D, METH_VARARGS, M_Geometry_PointInTriangle2D_doc},
{"PointInQuad2D", ( PyCFunction ) M_Geometry_PointInQuad2D, METH_VARARGS, M_Geometry_PointInQuad2D_doc},
{"BoxPack2D", ( PyCFunction ) M_Geometry_BoxPack2D, METH_O, M_Geometry_BoxPack2D_doc},
+ {"BezierInterp", ( PyCFunction ) M_Geometry_BezierInterp, METH_VARARGS, M_Geometry_BezierInterp_doc},
{NULL, NULL, 0, NULL}
};
@@ -469,3 +473,48 @@
return Py_BuildValue( "ff", tot_width, tot_height);
}
+
+static PyObject *M_Geometry_BezierInterp( PyObject * self, PyObject * args )
+{
+ VectorObject *vec_k1, *vec_h1, *vec_k2, *vec_h2;
+ int resolu;
+ int dims;
+ int i;
+ float *coord_array, *fp;
+
+ float k1[4] = {0.0, 0.0, 0.0, 0.0};
+ float h1[4] = {0.0, 0.0, 0.0, 0.0};
+ float k2[4] = {0.0, 0.0, 0.0, 0.0};
+ float h2[4] = {0.0, 0.0, 0.0, 0.0};
+
+ float a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y, xi, yi, a1,a2,b1,b2, newvec[2];
+ if( !PyArg_ParseTuple ( args, "O!O!O!O!i",
+ &vector_Type, &vec_k1,
+ &vector_Type, &vec_h1,
+ &vector_Type, &vec_h2,
+ &vector_Type, &vec_k2, &resolu) || (resolu<=1)
+ ) {
+ PyErr_SetString( PyExc_TypeError, "expected 4 vector types and an int greater then 1\n" );
+ return NULL;
+ }
+
+ dims= MAX4(vec_k1->size, vec_h1->size, vec_h2->size, vec_k2->size);
+
+ for(i=0; i < vec_k1->size; i++) k1[i]= vec_k1->vec[i];
+ for(i=0; i < vec_h1->size; i++) h1[i]= vec_h1->vec[i];
+ for(i=0; i < vec_k2->size; i++) k2[i]= vec_k2->vec[i];
+ for(i=0; i < vec_h2->size; i++) h2[i]= vec_h2->vec[i];
+
+ coord_array = MEM_callocN(dims * (resolu) * sizeof(float), "BezierInterp");
+ for(i=0; i<dims; i++) {
+ forward_diff_bezier(k1[i], h1[i], h2[i], k2[i], coord_array+i, resolu-1, dims);
+ }
+
+ PyObject* list= PyList_New(resolu);
+ fp= coord_array;
+ for(i=0; i<resolu; i++, fp= fp+dims) {
+ PyList_SET_ITEM(list, i, newVectorObject(fp, dims, Py_NEW));
+ }
+ MEM_freeN(coord_array);
+ return list;
+}
Modified: trunk/blender/source/blender/python/api2_2x/doc/Geometry.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/Geometry.py 2009-05-04 10:24:53 UTC (rev 20054)
+++ trunk/blender/source/blender/python/api2_2x/doc/Geometry.py 2009-05-04 13:01:18 UTC (rev 20055)
@@ -102,4 +102,10 @@
@rtype: tuple
@return: a tuple pair - (width, height) of all the packed boxes.
"""
-
\ No newline at end of file
+def BezierInterp(vec_knot_1, vec_handle_1, vec_handle_2, vec_knot_2, resolution):
+ """
+ Takes 4 vectors representing a bezier curve and returns a list of vector points.
+ @note: any vector size is supported, the largest dimension from the input will be used for all returned vectors/
+ @rtype: list
+ @return: a list of vectors the size of resolution including the start and end points (vec_knot_1 and vec_knot_2)
+ """
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list