[Bf-committers] Patch for Python bug #1347, ipoCurve.evaluate(time) missing.

Philip Wainwright bf-committers@blender.org
Sun, 06 Jun 2004 17:45:27 +0100


This is a multi-part message in MIME format.
--------------000802010902000406010902
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi all,

First time contributor, I have a patch which provides the above missing 
method and a Python test script.


Philip.

--------------000802010902000406010902
Content-Type: text/plain;
 name="ipo.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ipo.py"

# test out the patch of 6/6/2004 which provide evaluate
# to the Ipocurve object.

from Blender import Ipo

#obtain all ipos
allIpos = Ipo.get()

if not allIpos:
    print "NO IPOS !"
else:
    #evaluate all curves in first IPO
    ipoCurves = allIpos[0].getCurves();

    print "IPO curve evaluation at frame 100 for IPO "+allIpos[0].getName()

    for ipoCurve in ipoCurves:
        print "Ipo curve "+ipoCurve.getName()+" = "+str(ipoCurve.evaluate(100))

    #evaluate first ipo curve at frame 600 
    print "First ipo curve ("+ipoCurves[0].getName()+") at frame 600  = "+str(ipoCurves[0].evaluate(600))

--------------000802010902000406010902
Content-Type: text/plain;
 name="patch.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="patch.txt"

Index: source/blender/python/api2_2x/Ipocurve.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Ipocurve.c,v
retrieving revision 1.15
diff -u -r1.15 Ipocurve.c
--- source/blender/python/api2_2x/Ipocurve.c	29 Apr 2004 04:50:28 -0000	1.15
+++ source/blender/python/api2_2x/Ipocurve.c	6 Jun 2004 16:46:56 -0000
@@ -83,6 +83,7 @@
 					    PyObject * args);
 static PyObject *IpoCurve_getExtrapolation (C_IpoCurve * self);
 static PyObject *IpoCurve_getPoints (C_IpoCurve * self);
+static PyObject *IpoCurve_evaluate (C_IpoCurve * self, PyObject * args);
 
 /*****************************************************************************/
 /* Python C_IpoCurve methods table:                                          */
@@ -109,6 +110,8 @@
    "(str) - Change IpoCurve Data name"},
   {"getPoints", (PyCFunction) IpoCurve_getPoints, METH_NOARGS,
    "(str) - Change IpoCurve Data name"},
+  {"evaluate", (PyCFunction) IpoCurve_evaluate, METH_VARARGS,
+   "(float) - Evaluate curve at given time"},
   {NULL, NULL, 0, NULL}
 };
 
@@ -155,7 +158,7 @@
 static PyObject *
 M_IpoCurve_New (PyObject * self, PyObject * args)
 {
-
+http://gateway/localPages/index.html
 
   return 0;
 }
@@ -525,4 +528,27 @@
 IpoCurve_FromPyObject (PyObject * pyobj)
 {
   return ((C_IpoCurve *) pyobj)->ipocurve;
+}
+
+/***************************************************************************/
+/*Function:      IpoCurve_evaluate                                         */
+/*Description:   This evaluates the value of the IPO curve at the given    */
+/*               time.                                                     */
+/***************************************************************************/
+static PyObject *
+IpoCurve_evaluate (C_IpoCurve * self, PyObject * args)
+{
+
+  float time = 0;
+  double eval = 0;
+
+  /* expecting float */
+  if (!PyArg_ParseTuple (args, "f", &time))
+    return (EXPP_ReturnPyObjError
+	    (PyExc_TypeError, "expected float argument"));
+
+  eval= (double)eval_icu(self->ipocurve, time);
+
+  return  PyFloat_FromDouble(eval);
+  
 }

--------------000802010902000406010902--