== Python Script Links ==
authorWillian Padovani Germano <wpgermano@gmail.com>
Thu, 18 Sep 2008 22:33:49 +0000 (22:33 +0000)
committerWillian Padovani Germano <wpgermano@gmail.com>
Thu, 18 Sep 2008 22:33:49 +0000 (22:33 +0000)
Bug #17599:
Summary: Python constraints, good in 2.46 not working anymore in 2.47
http://projects.blender.org/tracker/?func=detail&atid=125&aid=17599&group_id=9

Improved my old hack to avoid frame changed scriptlinks from running when rendering stills, should fix this bug. It also causes REDRAW scriptlinks to be executed during renders, but that conforms to how FRAMECHANGED ones work.

BTW: this can still be improved. The current system meant to disable all Python functionality at once needs imo to be replaced by one that allows to enable / disable per feature (scriptlinks, pyconstraints, pynodes, etc.). A better way to inform scriptlinks about what is going on (render, anim, render anim, etc.) would also help. Will discuss with others.

source/blender/blenkernel/BKE_bad_level_calls.h
source/blender/blenkernel/bad_level_call_stubs/stubs.c
source/blender/blenkernel/intern/scene.c
source/blender/python/BPY_extern.h
source/blender/python/BPY_interface.c
source/blender/python/api2_2x/sceneRender.c
source/blender/src/renderwin.c
source/creator/creator.c

index 8dee9a27f49cba1ea1ed4cabaa9b680efd4453d8..0b623526562aae11bc5fe3e772aae55bd404072b 100644 (file)
@@ -141,7 +141,7 @@ short pupmenu(char *instr);  // will be general callback
 /* scene.c */
 #include "DNA_sequence_types.h"
 void free_editing(struct Editing *ed); // scenes and sequences problem...
-void BPY_do_all_scripts (short int event);
+void BPY_do_all_scripts (short int event, short int anim);
 int BPY_call_importloader(char *name);
 
 
index f4beca262d7a97d4c8b389fb7b75fc32ba5c81c3..ae336d0fc26f5f4237b3f45b65e504c193c674aa 100644 (file)
@@ -201,7 +201,7 @@ short pupmenu(char *instr){ return 0;}  // will be general callback
 /* scene.c */
 #include "DNA_sequence_types.h"
 void free_editing(struct Editing *ed){}        // scenes and sequences problem...
-void BPY_do_all_scripts (short int event){}
+void BPY_do_all_scripts (short int event, short int anim){}
 
 /*editmesh_lib.c*/
 void EM_select_face(struct EditFace *efa, int sel) {}
index 553107dd2648aa782251243f34a72664ebcec1bb..701e8ecb31193143bce01a9413a84f4840a585df 100644 (file)
@@ -350,7 +350,7 @@ void set_scene_bg(Scene *sce)
        /* no full animation update, this to enable render code to work (render code calls own animation updates) */
        
        /* do we need FRAMECHANGED in set_scene? */
-//     if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
+//     if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
 }
 
 /* called from creator.c */
@@ -570,8 +570,8 @@ void scene_update_for_newframe(Scene *sce, unsigned int lay)
        /* object ipos are calculated in where_is_object */
        do_all_data_ipos();
        
-       if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
-       
+       if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
+
        /* sets first, we allow per definition current scene to have dependencies on sets */
        for(sce= sce->set; sce; sce= sce->set)
                scene_update(sce, lay);
index 4b96ef3fdf0bca0849f44102b2d58a71598c4a39..146093d6b99a80b6b0c3f74cff60beaf12936844 100644 (file)
@@ -100,7 +100,7 @@ extern "C" {
 
        void BPY_clear_bad_scriptlinks( struct Text *byebye );
        int BPY_has_onload_script( void );
-       void BPY_do_all_scripts( short event );
+       void BPY_do_all_scripts( short event, short anim );
        int BPY_check_all_scriptlinks( struct Text *text );
        void BPY_do_pyscript( struct ID *id, short event );
        void BPY_free_scriptlink( struct ScriptLink *slink );
index 041ba0699286358a8b650195e2d2bd1cef64a780..c0dab4df6512a0fdf281af6429c2f5d933cdfe53 100644 (file)
@@ -2163,8 +2163,14 @@ void BPY_clear_bad_scriptlinks( struct Text *byebye )
 *      For the scene, only the current active scene the scripts are 
 *      executed (if any).
 *****************************************************************************/
-void BPY_do_all_scripts( short event )
+void BPY_do_all_scripts( short event, short anim )
 {
+       /* during stills rendering we disable FRAMECHANGED events */
+       static char disable_frame_changed = 0;
+
+       if ((event == SCRIPT_FRAMECHANGED) && disable_frame_changed)
+               return;
+
        DoAllScriptsFromList( &( G.main->object ), event );
        DoAllScriptsFromList( &( G.main->lamp ), event );
        DoAllScriptsFromList( &( G.main->camera ), event );
@@ -2180,9 +2186,12 @@ void BPY_do_all_scripts( short event )
         * "import sys; sys.setcheckinterval(sys.maxint)" */
        if (event == SCRIPT_RENDER) {
                _Py_CheckInterval = PyInt_GetMax();
+               if (!anim)
+                       disable_frame_changed = 1;
        }
        else if (event == SCRIPT_POSTRENDER) {
                _Py_CheckInterval = 100; /* Python default */
+               disable_frame_changed = 0;
        }
 
        return;
index 22e165cbe9fc96b31bb3d909bd6f738d73d99ecc..7958e66b44fbf434778c23a7c9ddc485737160f9 100644 (file)
@@ -481,7 +481,6 @@ PyObject *RenderData_Render( BPy_RenderData * self )
                set_scene( oldsce );
        }
        else { /* background mode (blender -b file.blend -P script) */
-               int slink_flag = 0;
                Render *re= RE_NewRender(G.scene->id.name);
 
                int end_frame = G.scene->r.efra;
@@ -492,20 +491,14 @@ PyObject *RenderData_Render( BPy_RenderData * self )
 
                G.scene->r.efra = G.scene->r.sfra;
 
-               if (G.f & G_DOSCRIPTLINKS) {
-                       BPY_do_all_scripts(SCRIPT_RENDER);
-                       G.f &= ~G_DOSCRIPTLINKS; /* avoid FRAMECHANGED events*/
-                       slink_flag = 1;
-               }
+               if (G.f & G_DOSCRIPTLINKS)
+                       BPY_do_all_scripts(SCRIPT_RENDER, 0);
 
                tstate = PyEval_SaveThread();
 
                RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra);
 
-               if (slink_flag) {
-                       G.f |= G_DOSCRIPTLINKS;
-                       BPY_do_all_scripts(SCRIPT_POSTRENDER);
-               }
+               BPY_do_all_scripts(SCRIPT_POSTRENDER, 0);
 
                G.scene->r.efra = end_frame;
        }
@@ -603,13 +596,13 @@ PyObject *RenderData_RenderAnim( BPy_RenderData * self )
                                "start frame must be less or equal to end frame");
 
                if (G.f & G_DOSCRIPTLINKS)
-                       BPY_do_all_scripts(SCRIPT_RENDER);
+                       BPY_do_all_scripts(SCRIPT_RENDER, 1);
 
                tstate = PyEval_SaveThread();
                RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra);
 
                if (G.f & G_DOSCRIPTLINKS)
-                       BPY_do_all_scripts(SCRIPT_POSTRENDER);
+                       BPY_do_all_scripts(SCRIPT_POSTRENDER, 1);
        }
 
        PyEval_RestoreThread(tstate);
index 334845003285fcb35f637f452f90ee14cd5c16d1..c26eedd26fd53217698486c7db19202cfe1da582 100644 (file)
@@ -1274,16 +1274,9 @@ void BIF_store_spare(void)
 /* set up display, render an image or scene */
 void BIF_do_render(int anim)
 {
-       int slink_flag = 0;
+       if (G.f & G_DOSCRIPTLINKS)
+               BPY_do_all_scripts(SCRIPT_RENDER, anim);
 
-       if (G.f & G_DOSCRIPTLINKS) {
-               BPY_do_all_scripts(SCRIPT_RENDER);
-               if (!anim) { /* avoid FRAMECHANGED slink in render callback */
-                       G.f &= ~G_DOSCRIPTLINKS;
-                       slink_flag = 1;
-               }
-       }
-       
        BIF_store_spare();
 
        do_render(anim);
@@ -1294,8 +1287,8 @@ void BIF_do_render(int anim)
        }
        if(G.scene->r.dither_intensity != 0.0f)
                BIF_redraw_render_rect();
-       if (slink_flag) G.f |= G_DOSCRIPTLINKS;
-       if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_POSTRENDER);
+
+       if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_POSTRENDER, anim);
 }
 
 void do_ogl_view3d_render(Render *re, View3D *v3d, int winx, int winy)
index f27dee946ed77551221a8887ba12584e25346709..ac81557110f7ef4a45d298c49bda313b04e3aa0d 100644 (file)
@@ -618,23 +618,14 @@ int main(int argc, char **argv)
                                if (G.scene) {
                                        if (a < argc) {
                                                int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
-                                               int slink_flag= 0;
                                                Render *re= RE_NewRender(G.scene->id.name);
 
-                                               if (G.f & G_DOSCRIPTLINKS) {
-                                                       BPY_do_all_scripts(SCRIPT_RENDER);
-                                                       /* avoid FRAMECHANGED slink event
-                                                        * (should only be triggered in anims): */
-                                                       G.f &= ~G_DOSCRIPTLINKS;
-                                                       slink_flag= 1;
-                                               }
+                                               if (G.f & G_DOSCRIPTLINKS)
+                                                       BPY_do_all_scripts(SCRIPT_RENDER, 0);
 
                                                RE_BlenderAnim(re, G.scene, frame, frame);
 
-                                               if (slink_flag) {
-                                                       G.f |= G_DOSCRIPTLINKS;
-                                                       BPY_do_all_scripts(SCRIPT_POSTRENDER);
-                                               }
+                                               BPY_do_all_scripts(SCRIPT_POSTRENDER, 0);
                                        }
                                } else {
                                        printf("\nError: no blend loaded. cannot use '-f'.\n");
@@ -645,12 +636,12 @@ int main(int argc, char **argv)
                                        Render *re= RE_NewRender(G.scene->id.name);
 
                                        if (G.f & G_DOSCRIPTLINKS)
-                                               BPY_do_all_scripts(SCRIPT_RENDER);
+                                               BPY_do_all_scripts(SCRIPT_RENDER, 1);
 
                                        RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra);
 
                                        if (G.f & G_DOSCRIPTLINKS)
-                                               BPY_do_all_scripts(SCRIPT_POSTRENDER);
+                                               BPY_do_all_scripts(SCRIPT_POSTRENDER, 1);
                                } else {
                                        printf("\nError: no blend loaded. cannot use '-a'.\n");
                                }