== Python Script Links ==

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.
This commit is contained in:
2008-09-18 22:33:49 +00:00
parent ec6bd008c1
commit 6ff74f4527
8 changed files with 30 additions and 44 deletions

View File

@@ -141,7 +141,7 @@ short pupmenu(char *instr); // will be general callback
/* scene.c */ /* scene.c */
#include "DNA_sequence_types.h" #include "DNA_sequence_types.h"
void free_editing(struct Editing *ed); // scenes and sequences problem... 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); int BPY_call_importloader(char *name);

View File

@@ -201,7 +201,7 @@ short pupmenu(char *instr){ return 0;} // will be general callback
/* scene.c */ /* scene.c */
#include "DNA_sequence_types.h" #include "DNA_sequence_types.h"
void free_editing(struct Editing *ed){} // scenes and sequences problem... 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*/ /*editmesh_lib.c*/
void EM_select_face(struct EditFace *efa, int sel) {} void EM_select_face(struct EditFace *efa, int sel) {}

View 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) */ /* no full animation update, this to enable render code to work (render code calls own animation updates) */
/* do we need FRAMECHANGED in set_scene? */ /* 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 */ /* called from creator.c */
@@ -570,7 +570,7 @@ void scene_update_for_newframe(Scene *sce, unsigned int lay)
/* object ipos are calculated in where_is_object */ /* object ipos are calculated in where_is_object */
do_all_data_ipos(); 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 */ /* sets first, we allow per definition current scene to have dependencies on sets */
for(sce= sce->set; sce; sce= sce->set) for(sce= sce->set; sce; sce= sce->set)

View File

@@ -100,7 +100,7 @@ extern "C" {
void BPY_clear_bad_scriptlinks( struct Text *byebye ); void BPY_clear_bad_scriptlinks( struct Text *byebye );
int BPY_has_onload_script( void ); 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 ); int BPY_check_all_scriptlinks( struct Text *text );
void BPY_do_pyscript( struct ID *id, short event ); void BPY_do_pyscript( struct ID *id, short event );
void BPY_free_scriptlink( struct ScriptLink *slink ); void BPY_free_scriptlink( struct ScriptLink *slink );

View File

@@ -2163,8 +2163,14 @@ void BPY_clear_bad_scriptlinks( struct Text *byebye )
* For the scene, only the current active scene the scripts are * For the scene, only the current active scene the scripts are
* executed (if any). * 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->object ), event );
DoAllScriptsFromList( &( G.main->lamp ), event ); DoAllScriptsFromList( &( G.main->lamp ), event );
DoAllScriptsFromList( &( G.main->camera ), event ); DoAllScriptsFromList( &( G.main->camera ), event );
@@ -2180,9 +2186,12 @@ void BPY_do_all_scripts( short event )
* "import sys; sys.setcheckinterval(sys.maxint)" */ * "import sys; sys.setcheckinterval(sys.maxint)" */
if (event == SCRIPT_RENDER) { if (event == SCRIPT_RENDER) {
_Py_CheckInterval = PyInt_GetMax(); _Py_CheckInterval = PyInt_GetMax();
if (!anim)
disable_frame_changed = 1;
} }
else if (event == SCRIPT_POSTRENDER) { else if (event == SCRIPT_POSTRENDER) {
_Py_CheckInterval = 100; /* Python default */ _Py_CheckInterval = 100; /* Python default */
disable_frame_changed = 0;
} }
return; return;

View File

@@ -481,7 +481,6 @@ PyObject *RenderData_Render( BPy_RenderData * self )
set_scene( oldsce ); set_scene( oldsce );
} }
else { /* background mode (blender -b file.blend -P script) */ else { /* background mode (blender -b file.blend -P script) */
int slink_flag = 0;
Render *re= RE_NewRender(G.scene->id.name); Render *re= RE_NewRender(G.scene->id.name);
int end_frame = G.scene->r.efra; 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; G.scene->r.efra = G.scene->r.sfra;
if (G.f & G_DOSCRIPTLINKS) { if (G.f & G_DOSCRIPTLINKS)
BPY_do_all_scripts(SCRIPT_RENDER); BPY_do_all_scripts(SCRIPT_RENDER, 0);
G.f &= ~G_DOSCRIPTLINKS; /* avoid FRAMECHANGED events*/
slink_flag = 1;
}
tstate = PyEval_SaveThread(); tstate = PyEval_SaveThread();
RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra); RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra);
if (slink_flag) { BPY_do_all_scripts(SCRIPT_POSTRENDER, 0);
G.f |= G_DOSCRIPTLINKS;
BPY_do_all_scripts(SCRIPT_POSTRENDER);
}
G.scene->r.efra = end_frame; 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"); "start frame must be less or equal to end frame");
if (G.f & G_DOSCRIPTLINKS) if (G.f & G_DOSCRIPTLINKS)
BPY_do_all_scripts(SCRIPT_RENDER); BPY_do_all_scripts(SCRIPT_RENDER, 1);
tstate = PyEval_SaveThread(); tstate = PyEval_SaveThread();
RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra); RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra);
if (G.f & G_DOSCRIPTLINKS) if (G.f & G_DOSCRIPTLINKS)
BPY_do_all_scripts(SCRIPT_POSTRENDER); BPY_do_all_scripts(SCRIPT_POSTRENDER, 1);
} }
PyEval_RestoreThread(tstate); PyEval_RestoreThread(tstate);

View File

@@ -1274,15 +1274,8 @@ void BIF_store_spare(void)
/* set up display, render an image or scene */ /* set up display, render an image or scene */
void BIF_do_render(int anim) 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(); BIF_store_spare();
@@ -1294,8 +1287,8 @@ void BIF_do_render(int anim)
} }
if(G.scene->r.dither_intensity != 0.0f) if(G.scene->r.dither_intensity != 0.0f)
BIF_redraw_render_rect(); 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) void do_ogl_view3d_render(Render *re, View3D *v3d, int winx, int winy)

View File

@@ -618,23 +618,14 @@ int main(int argc, char **argv)
if (G.scene) { if (G.scene) {
if (a < argc) { if (a < argc) {
int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a]))); int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
int slink_flag= 0;
Render *re= RE_NewRender(G.scene->id.name); Render *re= RE_NewRender(G.scene->id.name);
if (G.f & G_DOSCRIPTLINKS) { if (G.f & G_DOSCRIPTLINKS)
BPY_do_all_scripts(SCRIPT_RENDER); BPY_do_all_scripts(SCRIPT_RENDER, 0);
/* avoid FRAMECHANGED slink event
* (should only be triggered in anims): */
G.f &= ~G_DOSCRIPTLINKS;
slink_flag= 1;
}
RE_BlenderAnim(re, G.scene, frame, frame); RE_BlenderAnim(re, G.scene, frame, frame);
if (slink_flag) { BPY_do_all_scripts(SCRIPT_POSTRENDER, 0);
G.f |= G_DOSCRIPTLINKS;
BPY_do_all_scripts(SCRIPT_POSTRENDER);
}
} }
} else { } else {
printf("\nError: no blend loaded. cannot use '-f'.\n"); 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); Render *re= RE_NewRender(G.scene->id.name);
if (G.f & G_DOSCRIPTLINKS) 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); RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra);
if (G.f & G_DOSCRIPTLINKS) if (G.f & G_DOSCRIPTLINKS)
BPY_do_all_scripts(SCRIPT_POSTRENDER); BPY_do_all_scripts(SCRIPT_POSTRENDER, 1);
} else { } else {
printf("\nError: no blend loaded. cannot use '-a'.\n"); printf("\nError: no blend loaded. cannot use '-a'.\n");
} }