[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [10783] trunk/blender: Key.c/ h - Removed unneeded functions.

Campbell Barton cbarton at metavr.com
Sat May 26 14:58:46 CEST 2007


Revision: 10783
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bforge-svn&revision=10783
Author:   campbellbarton
Date:     2007-05-26 14:58:46 +0200 (Sat, 26 May 2007)

Log Message:
-----------
Key.c/h - Removed unneeded functions. and ipo in struct wasnt being used.
Lattice.c - removed warning
Mesh.c - (own error) when running me.update(key="...") didnt update the right keyframe.

mesh_cleanup.py - Bugfix from a report by plumiferos that started uncovering all the memory leaks.
Removing NAN verts didnt work with mesh keyframes.

Modified Paths:
--------------
    trunk/blender/release/scripts/mesh_cleanup.py
    trunk/blender/source/blender/python/api2_2x/Key.c
    trunk/blender/source/blender/python/api2_2x/Key.h
    trunk/blender/source/blender/python/api2_2x/Lattice.c
    trunk/blender/source/blender/python/api2_2x/Mesh.c

Modified: trunk/blender/release/scripts/mesh_cleanup.py
===================================================================
--- trunk/blender/release/scripts/mesh_cleanup.py	2007-05-26 04:39:31 UTC (rev 10782)
+++ trunk/blender/release/scripts/mesh_cleanup.py	2007-05-26 12:58:46 UTC (rev 10783)
@@ -196,7 +196,7 @@
 	
 	return False
 
-def fix_nan_verts(me):
+def fix_nan_verts__internal(me):
 	rem_nan = 0
 	for v in me.verts:
 		co = v.co
@@ -206,9 +206,46 @@
 				rem_nan += 1
 	return rem_nan
 
+def fix_nan_verts(me):
+	rem_nan = 0
+	key = me.key
+	if key:
+		# Find the object, and get a mesh thats thinked to the oblink.
+		# this is a bit crap but needed to set the active key.
+		me_oblink = None
+		for ob in bpy.data.objects:
+			me_oblink = ob.getData(mesh=1)
+			if me_oblink == me:
+				me = me_oblink
+				break
+		if not me_oblink:
+			ob = None
+	
+	if key and ob:
+		blocks = key.blocks
+		# print blocks
+		orig_pin = ob.pinShape
+		orig_shape = ob.activeShape
+		orig_relative = key.relative
+		ob.pinShape = True
+		for i, block in enumerate(blocks):
+			ob.activeShape = i+1
+			ob.makeDisplayList()
+			rem_nan += fix_nan_verts__internal(me)
+			me.update(block.name) # get the new verts
+		ob.pinShape	= orig_pin
+		ob.activeShape = orig_shape
+		key.relative = orig_relative
+		
+	else: # No keys, simple operation
+		rem_nan = fix_nan_verts__internal(me)
+	
+	return rem_nan
+
 def fix_nan_uvs(me):
 	rem_nan = 0
 	if me.faceUV:
+		orig_uvlayer = me.activeUVLayer
 		for uvlayer in me.getUVLayerNames():
 			me.activeUVLayer = uvlayer
 			for f in me.faces:
@@ -217,6 +254,7 @@
 						if isnan(uv[i]):
 							uv[i] = 0.0
 							rem_nan += 1
+		me.activeUVLayer = orig_uvlayer
 	return rem_nan
 
 

Modified: trunk/blender/source/blender/python/api2_2x/Key.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Key.c	2007-05-26 04:39:31 UTC (rev 10782)
+++ trunk/blender/source/blender/python/api2_2x/Key.c	2007-05-26 12:58:46 UTC (rev 10783)
@@ -289,25 +289,14 @@
 	NULL
 };
 
-static PyObject *new_Key(Key * oldkey)
+PyObject *Key_CreatePyObject( Key * blenkey )
 {
-	BPy_Key *k = PyObject_NEW( BPy_Key, &Key_Type );
-
-	if( !oldkey ) {
-		k->key = 0;
-	} else {
-		k->key = oldkey;
-	}
-	return ( PyObject * ) k;
+	BPy_Key *bpykey = PyObject_NEW( BPy_Key, &Key_Type );
+	/* blenkey may be NULL so be careful */
+	bpykey->key = blenkey;
+	return ( PyObject * ) bpykey;
 }
 
-PyObject *Key_CreatePyObject( Key * k )
-{
-	BPy_Key *key = ( BPy_Key * ) new_Key( k );
-
-	return ( PyObject * ) key;
-}
-
 static void Key_dealloc( BPy_Key * self )
 {
 	PyObject_DEL( self );
@@ -325,15 +314,9 @@
 
 static PyObject *Key_getIpo( BPy_Key * self )
 {
-	BPy_Ipo *new_ipo;
-
-	if (self->key->ipo) {
-		new_ipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type );
-		new_ipo->ipo = self->key->ipo;
-		return (PyObject *) new_ipo;
-	} else {
-		Py_RETURN_NONE;
-	}
+	if (self->key->ipo)
+		Ipo_CreatePyObject( self->key->ipo );
+	Py_RETURN_NONE;
 }
 
 static int Key_setIpo( BPy_Key * self, PyObject * value )
@@ -404,22 +387,14 @@
 }
 
 /* ------------ Key Block Functions -------------- */
-
-static PyObject *new_KeyBlock( KeyBlock * keyblock, Key *key)
+PyObject *KeyBlock_CreatePyObject( KeyBlock * keyblock, Key *parentKey )
 {
-	BPy_KeyBlock *kb = PyObject_NEW( BPy_KeyBlock, &KeyBlock_Type );
-	kb->key = key;
-	kb->keyblock = keyblock; /* keyblock maye be NULL, thats ok */
-	return ( PyObject * ) kb;
+	BPy_KeyBlock *bpykb = PyObject_NEW( BPy_KeyBlock, &KeyBlock_Type );
+	bpykb->key = parentKey;
+	bpykb->keyblock = keyblock; /* keyblock maye be NULL, thats ok */
+	return ( PyObject * ) bpykb;
 }
 
-PyObject *KeyBlock_CreatePyObject( KeyBlock * kb, Key *parentKey )
-{
-	BPy_KeyBlock *keyBlock = ( BPy_KeyBlock * ) new_KeyBlock( kb, parentKey );
-
-	return ( PyObject * ) keyBlock;
-}
-
 static PyObject *KeyBlock_getCurval( BPy_KeyBlock * self ) {
 	return PyFloat_FromDouble( self->keyblock->curval );
 }

Modified: trunk/blender/source/blender/python/api2_2x/Key.h
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Key.h	2007-05-26 04:39:31 UTC (rev 10782)
+++ trunk/blender/source/blender/python/api2_2x/Key.h	2007-05-26 12:58:46 UTC (rev 10783)
@@ -50,7 +50,7 @@
 	Key * key;			/* libdata must be second */
 	/* Object *object;*/		/* for vertex grouping info, since it's stored on the object */
 	/*PyObject *keyBlock;*/
-	PyObject *ipo;
+	/*PyObject *ipo;*/
 } BPy_Key;
 
 typedef struct {

Modified: trunk/blender/source/blender/python/api2_2x/Lattice.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Lattice.c	2007-05-26 04:39:31 UTC (rev 10782)
+++ trunk/blender/source/blender/python/api2_2x/Lattice.c	2007-05-26 12:58:46 UTC (rev 10783)
@@ -677,7 +677,7 @@
 
 static PyObject *Lattice_getAxisType(BPy_Lattice * self, void * type)
 {
-	char interp_type = (char)NULL;
+	char interp_type = 0;
 	switch ( (int)type ) {
 	case 0:
 		interp_type = self->lattice->typeu;

Modified: trunk/blender/source/blender/python/api2_2x/Mesh.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Mesh.c	2007-05-26 04:39:31 UTC (rev 10782)
+++ trunk/blender/source/blender/python/api2_2x/Mesh.c	2007-05-26 12:58:46 UTC (rev 10783)
@@ -5408,15 +5408,13 @@
 				"Cannot update the key for this mesh, it has no shape keys");
 		
 		for (kb = key->block.first; kb; kb=kb->next)
-			if (strcmp(blockname, kb->name))
+			if (strcmp(blockname, kb->name)==0)
 				break;
 		
 		if (!kb)
 			return EXPP_ReturnPyObjError( PyExc_ValueError,
 				"This requested key to update does not exist");
 		
-		printf("KEYBLOCKNAME %s\n", kb->name);
-		
 		for(i=0, co= kb->data; i<me->totvert; i++, mv++, co++)
 			VECCOPY(*co, mv->co);
 	} else {





More information about the Bf-blender-cvs mailing list