[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11463] branches/2-44-stable/blender: * Blender.c - miximum length for save name was too short,

Campbell Barton cbarton at metavr.com
Wed Aug 1 19:33:54 CEST 2007


Revision: 11463
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11463
Author:   campbellbarton
Date:     2007-08-01 19:33:53 +0200 (Wed, 01 Aug 2007)

Log Message:
-----------
* Blender.c - miximum length for save name was too short,

11387 - Draw module fix - so PyString pointers arnt used.

update scripts from trunk, minor fixex/changes.

Modified Paths:
--------------
    branches/2-44-stable/blender/release/scripts/object_random_loc_sz_rot.py
    branches/2-44-stable/blender/release/scripts/slp_import.py
    branches/2-44-stable/blender/release/scripts/uvcalc_lightmap.py
    branches/2-44-stable/blender/source/blender/blenloader/intern/writefile.c
    branches/2-44-stable/blender/source/blender/makesdna/DNA_space_types.h
    branches/2-44-stable/blender/source/blender/python/BPY_extern.h
    branches/2-44-stable/blender/source/blender/python/api2_2x/Blender.c
    branches/2-44-stable/blender/source/blender/python/api2_2x/Draw.c
    branches/2-44-stable/blender/source/blender/python/api2_2x/Draw.h
    branches/2-44-stable/blender/source/blender/python/api2_2x/Effect.c
    branches/2-44-stable/blender/source/blender/src/buttons_editing.c
    branches/2-44-stable/blender/source/blender/src/drawscript.c
    branches/2-44-stable/blender/source/blender/src/space.c

Modified: branches/2-44-stable/blender/release/scripts/object_random_loc_sz_rot.py
===================================================================
--- branches/2-44-stable/blender/release/scripts/object_random_loc_sz_rot.py	2007-08-01 16:42:34 UTC (rev 11462)
+++ branches/2-44-stable/blender/release/scripts/object_random_loc_sz_rot.py	2007-08-01 17:33:53 UTC (rev 11463)
@@ -33,46 +33,67 @@
 # ***** END GPL LICENCE BLOCK *****
 # --------------------------------------------------------------------------
 
+'''
+30 Jun 07 - ZanQdo:
+ - Properly coded axis toggles for Loc random (didn't work at all)
+ - Made Rot input values meaningful (45 will give max 45 degres of rotation)
+ - Pumped up the Scale value limit
+ - Made Scale input values meaningful (15 will give max 15 units bigger model)
+'''
+
 from Blender import Draw, Scene
 from Blender.Mathutils import Rand
 
-def rnd():
-	return Rand()-0.5
+def rnd(flag):
+	Random = Rand()
+	if flag == "LOC":
+		return (Random - 0.5) * 2
+	elif flag == "ROT":
+		return (Random - 0.5) * 0.035
+	elif flag == "SIZE":
+		return (Random - 0.5) * 1.8
 
 def randomize(sel, PREF_LOC, PREF_SIZE, PREF_ROT, PREF_LINK_AXIS, PREF_X_AXIS, PREF_Y_AXIS, PREF_Z_AXIS):
 	for ob in sel:
 		if PREF_LOC:
 			if PREF_LINK_AXIS:
-				rand = PREF_LOC*rnd()
+				rand = PREF_LOC*rnd("LOC")
 				ob.loc = (ob.LocX+(rand*PREF_X_AXIS),  ob.LocY+(rand*PREF_Y_AXIS),  ob.LocZ+(rand*PREF_Z_AXIS))
 			else:
-				ob.loc = (ob.LocX+(PREF_LOC*rnd()),  ob.LocY+(PREF_LOC*rnd()),  ob.LocZ+(PREF_LOC*rnd()))
-				
+				if PREF_X_AXIS:	x= PREF_LOC*rnd("LOC")
+				else:			x= 0
+				if PREF_Y_AXIS:	y= PREF_LOC*rnd("LOC")
+				else:			y= 0
+				if PREF_Z_AXIS:	z= PREF_LOC*rnd("LOC")
+				else:			z= 0
+				ob.loc = (ob.LocX+x,  ob.LocY+y,  ob.LocZ+z)
+		
 		if PREF_SIZE:
 			if PREF_LINK_AXIS:
-				rand = 1 + (PREF_SIZE*rnd())
+				rand = PREF_SIZE*rnd("SIZE")
 				if PREF_X_AXIS:	x= rand
-				else:			x= 1
+				else:			x= 0
 				if PREF_Y_AXIS:	y= rand
-				else:			y= 1
+				else:			y= 0
 				if PREF_Z_AXIS:	z= rand
-				else:			z= 1
-				ob.size = (ob.SizeX*x,  ob.SizeY*y,  ob.SizeZ*z)
+				else:			z= 0
+			
 			else:
-				if PREF_X_AXIS:	x= 1+ PREF_SIZE*rnd()
-				else:			x= 1
-				if PREF_Y_AXIS:	y= 1+ PREF_SIZE*rnd()
-				else:			y= 1
-				if PREF_Z_AXIS:	z= 1+ PREF_SIZE*rnd()
-				else:			z= 1
+				if PREF_X_AXIS:	x= PREF_SIZE*rnd("SIZE")
+				else:			x= 0
+				if PREF_Y_AXIS:	y= PREF_SIZE*rnd("SIZE")
+				else:			y= 0
+				if PREF_Z_AXIS:	z= PREF_SIZE*rnd("SIZE")
+				else:			z= 0
 				
-				ob.size = (ob.SizeX*x,  ob.SizeY*y,  ob.SizeZ*z)
+			ob.size = (abs(ob.SizeX+x),  abs(ob.SizeY+y),  abs(ob.SizeZ+z))
+		
 		if PREF_ROT:
 			if PREF_LINK_AXIS:
-				rand = PREF_ROT*rnd()
+				rand = PREF_ROT*rnd("ROT")
 				ob.rot = (ob.RotX+rand,  ob.RotY+rand,  ob.RotZ+rand)
 			else:
-				ob.rot = (ob.RotX+(PREF_X_AXIS*PREF_ROT*rnd()),  ob.RotY+(PREF_Y_AXIS*PREF_ROT*rnd()),  ob.RotZ+(PREF_Z_AXIS*PREF_ROT*rnd()))
+				ob.rot = (ob.RotX+(PREF_X_AXIS*PREF_ROT*rnd("ROT")),  ob.RotY+(PREF_Y_AXIS*PREF_ROT*rnd("ROT")),  ob.RotZ+(PREF_Z_AXIS*PREF_ROT*rnd("ROT")))
 	
 
 def main():
@@ -89,9 +110,9 @@
 	PREF_Z_AXIS= Draw.Create(1)
 	
 	pup_block = [\
-	('loc:', PREF_LOC, 0.0, 10.0, 'Amount to randomize the location'),\
-	('size:', PREF_SIZE, 0.0, 10.0,  'Amount to randomize the size'),\
-	('rot:', PREF_ROT, 0.0, 10.0, 'Amount to randomize the rotation'),\
+	('loc:', PREF_LOC, 0.0, 100.0, 'Amount to randomize the location'),\
+	('size:', PREF_SIZE, 0.0, 100.0,  'Amount to randomize the size'),\
+	('rot:', PREF_ROT, 0.0, 360.0, 'Amount to randomize the rotation'),\
 	'',\
 	('Link Axis', PREF_LINK_AXIS, 'Use the same random value for each objects XYZ'),\
 	('X Axis', PREF_X_AXIS, 'Enable X axis randomization'),\

Modified: branches/2-44-stable/blender/release/scripts/slp_import.py
===================================================================
--- branches/2-44-stable/blender/release/scripts/slp_import.py	2007-08-01 16:42:34 UTC (rev 11462)
+++ branches/2-44-stable/blender/release/scripts/slp_import.py	2007-08-01 17:33:53 UTC (rev 11463)
@@ -68,7 +68,7 @@
 	file = open(filename, "rb")
 
 	raw = []
-	for line in file.xreadlines():
+	for line in file: #.xreadlines():
 		data = line.split()
 		if data[0] == "vertex":
 			vert = map(float, data[1:])

Modified: branches/2-44-stable/blender/release/scripts/uvcalc_lightmap.py
===================================================================
--- branches/2-44-stable/blender/release/scripts/uvcalc_lightmap.py	2007-08-01 16:42:34 UTC (rev 11462)
+++ branches/2-44-stable/blender/release/scripts/uvcalc_lightmap.py	2007-08-01 17:33:53 UTC (rev 11463)
@@ -221,7 +221,11 @@
 	else:
 		face_groups = []
 	
-	for me in meshes:			
+	for me in meshes:
+		# Add face UV if it does not exist.
+		# All new faces are selected.
+		me.faceUV = True
+			
 		if PREF_SEL_ONLY:
 			faces = [f for f in me.faces if f.sel]
 		else:

Modified: branches/2-44-stable/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/2-44-stable/blender/source/blender/blenloader/intern/writefile.c	2007-08-01 16:42:34 UTC (rev 11462)
+++ branches/2-44-stable/blender/source/blender/blenloader/intern/writefile.c	2007-08-01 17:33:53 UTC (rev 11463)
@@ -1561,6 +1561,8 @@
 					writestruct(wd, DATA, "SpaceText", 1, sl);
 				}
 				else if(sl->spacetype==SPACE_SCRIPT) {
+					SpaceScript *sc = (SpaceScript*)sl;
+					sc->but_refs = NULL;
 					writestruct(wd, DATA, "SpaceScript", 1, sl);
 				}
 				else if(sl->spacetype==SPACE_ACTION) {

Modified: branches/2-44-stable/blender/source/blender/makesdna/DNA_space_types.h
===================================================================
--- branches/2-44-stable/blender/source/blender/makesdna/DNA_space_types.h	2007-08-01 16:42:34 UTC (rev 11462)
+++ branches/2-44-stable/blender/source/blender/makesdna/DNA_space_types.h	2007-08-01 17:33:53 UTC (rev 11463)
@@ -292,9 +292,10 @@
 	struct ScrArea *area;
 	struct Script *script;
 
-	int pad2;
 	short flags, menunr;
-
+	int pad1;
+	
+	void *but_refs;
 } SpaceScript;
 
 typedef struct SpaceTime {

Modified: branches/2-44-stable/blender/source/blender/python/BPY_extern.h
===================================================================
--- branches/2-44-stable/blender/source/blender/python/BPY_extern.h	2007-08-01 16:42:34 UTC (rev 11462)
+++ branches/2-44-stable/blender/source/blender/python/BPY_extern.h	2007-08-01 17:33:53 UTC (rev 11463)
@@ -51,6 +51,26 @@
 extern "C" {
 #endif
 
+	/*These two next functions are important for making sure the Draw module
+	  works correctly.  Before calling any gui callback using the Draw module,
+	  the following code must be executed:
+	  
+		if (some_drawspace_pylist) {
+			BPy_Set_DrawButtonsList(some_drawspace_pylist->but_refs);
+			BPy_Free_DrawButtonsList();
+		}
+		some_drawspace_pylist = PyList_New(0);
+		BPy_Set_DrawButtonsList(some_drawspace_pylist);
+
+      Also, BPy_Free_DrawButtonsList() must be called as necassary when a drawspace
+      with python callbacks is destroyed.
+      
+      This is necassary to avoid blender buttons storing invalid pointers to freed
+      python data.*/
+	void BPy_Set_DrawButtonsList(void *list);
+	void BPy_Free_DrawButtonsList(void);
+
+
 	void BPY_start_python( int argc, char **argv );
 	void BPY_end_python( void );
 	void BPY_post_start_python( void );

Modified: branches/2-44-stable/blender/source/blender/python/api2_2x/Blender.c
===================================================================
--- branches/2-44-stable/blender/source/blender/python/api2_2x/Blender.c	2007-08-01 16:42:34 UTC (rev 11462)
+++ branches/2-44-stable/blender/source/blender/python/api2_2x/Blender.c	2007-08-01 17:33:53 UTC (rev 11463)
@@ -676,7 +676,7 @@
 
 	len = strlen( fname );
 
-	if( len > FILE_MAXFILE )
+	if( len > FILE_MAXDIR + FILE_MAXFILE )
 		return EXPP_ReturnPyObjError( PyExc_AttributeError,
 					      "filename is too long!" );
 	else if( BLI_exists( fname ) && !overwrite )

Modified: branches/2-44-stable/blender/source/blender/python/api2_2x/Draw.c
===================================================================
--- branches/2-44-stable/blender/source/blender/python/api2_2x/Draw.c	2007-08-01 16:42:34 UTC (rev 11462)
+++ branches/2-44-stable/blender/source/blender/python/api2_2x/Draw.c	2007-08-01 17:33:53 UTC (rev 11463)
@@ -134,19 +134,13 @@
 /* CLEVER NUMBUT */
 static PyObject *Method_PupBlock( PyObject * self, PyObject * args );
 
-PyObject * pycallback_weakref_dealloc(PyObject *self, PyObject *weakref);
-/* python callable */
-PyObject * pycallback_weakref_dealloc__pyfunc;
+static uiBlock *Get_uiBlock( void );
 
-static uiBlock *Get_uiBlock( void );
 static void py_slider_update( void *butv, void *data2_unused );
 
 /* hack to get 1 block for the UIBlock, only ever 1 at a time */
 static uiBlock *uiblock=NULL;
 
-/* store weakref's to callbacks here */
-static PyObject *callback_list; 
-
 static char Draw_doc[] = "The Blender.Draw submodule";
 
 static char Method_UIBlock_doc[] = "(drawfunc, x,y) - Popup dialog where buttons can be drawn (expemental)";
@@ -362,6 +356,12 @@
 
 static char Method_Exit_doc[] = "() - Exit the windowing interface";
 
+/*This is needed for button callbacks.  Any button that uses a callback gets added to this list.
+  On the C side of drawing begin, this list should be cleared.
+  Each entry is a tuple of the form (button, callback py object)
+*/
+PyObject *M_Button_List = NULL;
+
 /*
 * here we engage in some macro trickery to define the PyMethodDef table
 */
@@ -602,7 +602,13 @@
 
 static Button *newbutton( void )
 {
-	return ( Button * ) PyObject_NEW( Button, &Button_Type );
+	Button *but = NULL;
+	
+	but = ( Button * ) PyObject_NEW( Button, &Button_Type );
+	but->tooltip[0] = 0; /*NULL-terminate tooltip string*/
+	but->tooltip[255] = 0; /*necassary to insure we always have a NULL-terminated string, as
+	                         according to the docs strncpy doesn't do this for us.*/
+	return but;
 }
 
 /* GUI interface routines */
@@ -623,6 +629,10 @@
 		scrarea_queue_redraw( sc->area );
 	}
 
+	BPy_Set_DrawButtonsList(sc->but_refs);
+	BPy_Free_DrawButtonsList(); /*clear all temp button references*/
+	sc->but_refs = NULL;
+	
 	Py_XDECREF( ( PyObject * ) script->py_draw );
 	Py_XDECREF( ( PyObject * ) script->py_event );
 	Py_XDECREF( ( PyObject * ) script->py_button );
@@ -676,6 +686,13 @@
 			    UI_HELV, curarea->win );
 
 	if( script->py_draw ) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list