[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16603] trunk/blender/source: == Python Script Links ==

Willian Padovani Germano wpgermano at gmail.com
Fri Sep 19 00:33:51 CEST 2008


Revision: 16603
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16603
Author:   ianwill
Date:     2008-09-19 00:33:49 +0200 (Fri, 19 Sep 2008)

Log Message:
-----------
== 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.

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

Modified: trunk/blender/source/blender/blenkernel/BKE_bad_level_calls.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_bad_level_calls.h	2008-09-18 21:45:57 UTC (rev 16602)
+++ trunk/blender/source/blender/blenkernel/BKE_bad_level_calls.h	2008-09-18 22:33:49 UTC (rev 16603)
@@ -141,7 +141,7 @@
 /* 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);
 
 

Modified: trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c
===================================================================
--- trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c	2008-09-18 21:45:57 UTC (rev 16602)
+++ trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c	2008-09-18 22:33:49 UTC (rev 16603)
@@ -201,7 +201,7 @@
 /* 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) {}

Modified: trunk/blender/source/blender/blenkernel/intern/scene.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/scene.c	2008-09-18 21:45:57 UTC (rev 16602)
+++ trunk/blender/source/blender/blenkernel/intern/scene.c	2008-09-18 22:33:49 UTC (rev 16603)
@@ -350,7 +350,7 @@
 	/* 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 @@
 	/* 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);

Modified: trunk/blender/source/blender/python/BPY_extern.h
===================================================================
--- trunk/blender/source/blender/python/BPY_extern.h	2008-09-18 21:45:57 UTC (rev 16602)
+++ trunk/blender/source/blender/python/BPY_extern.h	2008-09-18 22:33:49 UTC (rev 16603)
@@ -100,7 +100,7 @@
 
 	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 );

Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c	2008-09-18 21:45:57 UTC (rev 16602)
+++ trunk/blender/source/blender/python/BPY_interface.c	2008-09-18 22:33:49 UTC (rev 16603)
@@ -2163,8 +2163,14 @@
 *	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 @@
 	 * "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;

Modified: trunk/blender/source/blender/python/api2_2x/sceneRender.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/sceneRender.c	2008-09-18 21:45:57 UTC (rev 16602)
+++ trunk/blender/source/blender/python/api2_2x/sceneRender.c	2008-09-18 22:33:49 UTC (rev 16603)
@@ -481,7 +481,6 @@
 		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 @@
 
 		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 @@
 				"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);

Modified: trunk/blender/source/blender/src/renderwin.c
===================================================================
--- trunk/blender/source/blender/src/renderwin.c	2008-09-18 21:45:57 UTC (rev 16602)
+++ trunk/blender/source/blender/src/renderwin.c	2008-09-18 22:33:49 UTC (rev 16603)
@@ -1274,16 +1274,9 @@
 /* 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 @@
 	}
 	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)

Modified: trunk/blender/source/creator/creator.c
===================================================================
--- trunk/blender/source/creator/creator.c	2008-09-18 21:45:57 UTC (rev 16602)
+++ trunk/blender/source/creator/creator.c	2008-09-18 22:33:49 UTC (rev 16603)
@@ -618,23 +618,14 @@
 				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 @@
 					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");
 				}





More information about the Bf-blender-cvs mailing list