[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41943] trunk/blender/source: pydrivers: ' frame' is now in the driver namespace,
Daniel Salazar - 3Developer.com
zanqdo at gmail.com
Thu Nov 17 08:10:29 CET 2011
ohh! so good :D are new drivers like #frame not creating a property now then?
cheers!
Daniel Salazar
3Developer.com
On Thu, Nov 17, 2011 at 1:08 AM, Campbell Barton <ideasman42 at gmail.com> wrote:
> Revision: 41943
> http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41943
> Author: campbellbarton
> Date: 2011-11-17 07:08:09 +0000 (Thu, 17 Nov 2011)
> Log Message:
> -----------
> pydrivers: 'frame' is now in the driver namespace,
>
> - no need to link to scenes when using a frame from the pydriver, this made linking rigs for eg, quite messy.
> - advantage that we get subframe values (where scenes from was fixed to a whole number).
>
> Modified Paths:
> --------------
> trunk/blender/source/blender/blenkernel/intern/fcurve.c
> trunk/blender/source/blender/editors/interface/interface_anim.c
> trunk/blender/source/blender/python/BPY_extern.h
> trunk/blender/source/blender/python/intern/bpy_driver.c
> trunk/blender/source/blender/python/intern/bpy_driver.h
> trunk/blender/source/blenderplayer/bad_level_call_stubs/stubs.c
>
> Modified: trunk/blender/source/blender/blenkernel/intern/fcurve.c
> ===================================================================
> --- trunk/blender/source/blender/blenkernel/intern/fcurve.c 2011-11-17 06:08:58 UTC (rev 41942)
> +++ trunk/blender/source/blender/blenkernel/intern/fcurve.c 2011-11-17 07:08:09 UTC (rev 41943)
> @@ -1576,7 +1576,7 @@
> * - "evaltime" is the frame at which F-Curve is being evaluated
> * - has to return a float value
> */
> -static float evaluate_driver (ChannelDriver *driver, float UNUSED(evaltime))
> +static float evaluate_driver (ChannelDriver *driver, const float evaltime)
> {
> DriverVar *dvar;
>
> @@ -1663,8 +1663,10 @@
> /* this evaluates the expression using Python,and returns its result:
> * - on errors it reports, then returns 0.0f
> */
> - driver->curval= BPY_driver_exec(driver);
> + driver->curval= BPY_driver_exec(driver, evaltime);
> }
> +#else /* WITH_PYTHON*/
> + (void)evaltime;
> #endif /* WITH_PYTHON*/
> }
> break;
> @@ -2087,7 +2089,7 @@
> /* Evaluate and return the value of the given F-Curve at the specified frame ("evaltime")
> * Note: this is also used for drivers
> */
> -float evaluate_fcurve (FCurve *fcu, float evaltime)
> +float evaluate_fcurve (FCurve *fcu, float evaltime)
> {
> float cvalue= 0.0f;
> float devaltime;
>
> Modified: trunk/blender/source/blender/editors/interface/interface_anim.c
> ===================================================================
> --- trunk/blender/source/blender/editors/interface/interface_anim.c 2011-11-17 06:08:58 UTC (rev 41942)
> +++ trunk/blender/source/blender/editors/interface/interface_anim.c 2011-11-17 07:08:09 UTC (rev 41943)
> @@ -164,24 +164,7 @@
> /* set the expression */
> // TODO: need some way of identifying variables used
> BLI_strncpy_utf8(driver->expression, str, sizeof(driver->expression));
> -
> - /* FIXME: for now, assume that
> - * - for expressions, users are likely to be using "frame" -> current frame" as a variable
> - * - driver_add_new_variable() adds a single-prop variable by default
> - */
> - {
> - DriverVar *dvar;
> - DriverTarget *dtar;
> -
> - dvar = driver_add_new_variable(driver);
> - BLI_strncpy(dvar->name, "frame", sizeof(dvar->name));
> -
> - dtar = &dvar->targets[0];
> - dtar->id = (ID *)CTX_data_scene(C); // XXX: should we check that C is valid first?
> - dtar->idtype= ID_SCE;
> - dtar->rna_path = BLI_sprintfN("frame_current");
> - }
> -
> +
> /* updates */
> driver->flag |= DRIVER_FLAG_RECOMPILE;
> WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME, NULL);
>
> Modified: trunk/blender/source/blender/python/BPY_extern.h
> ===================================================================
> --- trunk/blender/source/blender/python/BPY_extern.h 2011-11-17 06:08:58 UTC (rev 41942)
> +++ trunk/blender/source/blender/python/BPY_extern.h 2011-11-17 07:08:09 UTC (rev 41943)
> @@ -74,7 +74,7 @@
> void BPY_app_handlers_reset(const short do_all);
>
> void BPY_driver_reset(void);
> -float BPY_driver_exec(struct ChannelDriver *driver);
> +float BPY_driver_exec(struct ChannelDriver *driver, const float evaltime);
>
> int BPY_button_exec(struct bContext *C, const char *expr, double *value, const short verbose);
> int BPY_string_exec(struct bContext *C, const char *expr);
>
> Modified: trunk/blender/source/blender/python/intern/bpy_driver.c
> ===================================================================
> --- trunk/blender/source/blender/python/intern/bpy_driver.c 2011-11-17 06:08:58 UTC (rev 41942)
> +++ trunk/blender/source/blender/python/intern/bpy_driver.c 2011-11-17 07:08:09 UTC (rev 41943)
> @@ -91,6 +91,29 @@
> return 0;
> }
>
> +/* note, this function should do nothing most runs, only when changing frame */
> +static PyObject *bpy_pydriver_InternStr__frame= NULL;
> +
> +static void bpy_pydriver_update_dict(const float evaltime)
> +{
> + /* not thread safe but neither is python */
> + static float evaltime_prev= FLT_MAX;
> +
> + if (evaltime_prev != evaltime) {
> +
> + /* currently only update the frame */
> + if (bpy_pydriver_InternStr__frame == NULL) {
> + bpy_pydriver_InternStr__frame= PyUnicode_FromString("frame");
> + }
> +
> + PyDict_SetItem(bpy_pydriver_Dict,
> + bpy_pydriver_InternStr__frame,
> + PyFloat_FromDouble(evaltime));
> +
> + evaltime_prev= evaltime;
> + }
> +}
> +
> /* Update function, it gets rid of pydrivers global dictionary, forcing
> * BPY_driver_exec to recreate it. This function is used to force
> * reloading the Blender text module "pydrivers.py", if available, so
> @@ -110,6 +133,11 @@
> bpy_pydriver_Dict= NULL;
> }
>
> + if (bpy_pydriver_InternStr__frame) {
> + Py_DECREF(bpy_pydriver_InternStr__frame);
> + bpy_pydriver_InternStr__frame= NULL;
> + }
> +
> if (use_gil)
> PyGILState_Release(gilstate);
>
> @@ -139,7 +167,7 @@
> * now release the GIL on python operator execution instead, using
> * PyEval_SaveThread() / PyEval_RestoreThread() so we dont lock up blender.
> */
> -float BPY_driver_exec(ChannelDriver *driver)
> +float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
> {
> PyObject *driver_vars=NULL;
> PyObject *retval= NULL;
> @@ -183,6 +211,10 @@
> }
> }
>
> + /* update global namespace */
> + bpy_pydriver_update_dict(evaltime);
> +
> +
> if (driver->expr_comp==NULL)
> driver->flag |= DRIVER_FLAG_RECOMPILE;
>
> @@ -246,6 +278,7 @@
> }
> }
>
> +
> #if 0 // slow, with this can avoid all Py_CompileString above.
> /* execute expression to get a value */
> retval= PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars);
>
> Modified: trunk/blender/source/blender/python/intern/bpy_driver.h
> ===================================================================
> --- trunk/blender/source/blender/python/intern/bpy_driver.h 2011-11-17 06:08:58 UTC (rev 41942)
> +++ trunk/blender/source/blender/python/intern/bpy_driver.h 2011-11-17 07:08:09 UTC (rev 41943)
> @@ -33,7 +33,7 @@
> extern PyObject *bpy_pydriver_Dict;
>
> /* externals */
> -float BPY_driver_exec(struct ChannelDriver *driver);
> +float BPY_driver_exec(struct ChannelDriver *driver, const float evaltime);
> void BPY_driver_reset(void);
>
> #endif // BPY_DRIVER_H
>
> Modified: trunk/blender/source/blenderplayer/bad_level_call_stubs/stubs.c
> ===================================================================
> --- trunk/blender/source/blenderplayer/bad_level_call_stubs/stubs.c 2011-11-17 06:08:58 UTC (rev 41942)
> +++ trunk/blender/source/blenderplayer/bad_level_call_stubs/stubs.c 2011-11-17 07:08:09 UTC (rev 41943)
> @@ -454,7 +454,7 @@
> void BPY_id_release(struct Text *text) {}
> int BPY_context_member_get(struct Context *C, const char *member, struct bContextDataResult *result) { return 0; }
> void BPY_pyconstraint_target(struct bPythonConstraint *con, struct bConstraintTarget *ct) {}
> -float BPY_driver_exec(struct ChannelDriver *driver) {return 0.0f;} /* might need this one! */
> +float BPY_driver_exec(struct ChannelDriver *driver, const float evaltime) {return 0.0f;} /* might need this one! */
> void BPY_DECREF(void *pyob_ptr) {}
> void BPY_pyconstraint_exec(struct bPythonConstraint *con, struct bConstraintOb *cob, struct ListBase *targets) {}
> void macro_wrapper(struct wmOperatorType *ot, void *userdata) {} ;
>
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>
More information about the Bf-committers
mailing list