[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25593] trunk/blender/source/blender: moved shape key insert function into BKE_object.h

Campbell Barton ideasman42 at gmail.com
Mon Dec 28 16:26:36 CET 2009


Revision: 25593
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25593
Author:   campbellbarton
Date:     2009-12-28 16:26:36 +0100 (Mon, 28 Dec 2009)

Log Message:
-----------
moved shape key insert function into BKE_object.h

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_key.h
    trunk/blender/source/blender/blenkernel/BKE_object.h
    trunk/blender/source/blender/blenkernel/intern/key.c
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/editors/include/ED_object.h
    trunk/blender/source/blender/editors/mesh/meshtools.c
    trunk/blender/source/blender/editors/object/object_modifier.c
    trunk/blender/source/blender/editors/object/object_shapekey.c

Modified: trunk/blender/source/blender/blenkernel/BKE_key.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_key.h	2009-12-28 10:44:02 UTC (rev 25592)
+++ trunk/blender/source/blender/blenkernel/BKE_key.h	2009-12-28 15:26:36 UTC (rev 25593)
@@ -59,7 +59,7 @@
 float *do_ob_key(struct Scene *scene, struct Object *ob);
 
 struct Key *ob_get_key(struct Object *ob);
-struct KeyBlock *add_keyblock(struct Scene *scene, struct Key *key);
+struct KeyBlock *add_keyblock(struct Key *key);
 struct KeyBlock *ob_get_keyblock(struct Object *ob);
 struct KeyBlock *ob_get_reference_keyblock(struct Object *ob);
 struct KeyBlock *key_get_keyblock(struct Key *key, int index);
@@ -68,6 +68,14 @@
 // needed for the GE
 void do_rel_key(int start, int end, int tot, char *basispoin, struct Key *key, struct KeyBlock *actkb, int mode);
 
+/* conversion functions */
+void key_to_mesh(struct KeyBlock *kb, struct Mesh *me);
+void mesh_to_key(struct Mesh *me, struct KeyBlock *kb);
+void key_to_latt(struct KeyBlock *kb, struct Lattice *lt);
+void latt_to_key(struct Lattice *lt, struct KeyBlock *kb);
+void key_to_curve(struct KeyBlock *kb, struct Curve  *cu, struct ListBase *nurb);
+void curve_to_key(struct Curve *cu, struct KeyBlock *kb, struct ListBase *nurb);
+
 #ifdef __cplusplus
 };
 #endif

Modified: trunk/blender/source/blender/blenkernel/BKE_object.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_object.h	2009-12-28 10:44:02 UTC (rev 25592)
+++ trunk/blender/source/blender/blenkernel/BKE_object.h	2009-12-28 15:26:36 UTC (rev 25593)
@@ -120,6 +120,7 @@
 
 int object_insert_ptcache(struct Object *ob);
 // void object_delete_ptcache(struct Object *ob, int index);
+int object_insert_shape_key(struct Scene *scene, struct Object *ob, int from_mix);
 
 
 #ifdef __cplusplus

Modified: trunk/blender/source/blender/blenkernel/intern/key.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/key.c	2009-12-28 10:44:02 UTC (rev 25592)
+++ trunk/blender/source/blender/blenkernel/intern/key.c	2009-12-28 15:26:36 UTC (rev 25593)
@@ -1395,7 +1395,7 @@
 	return NULL;
 }
 
-KeyBlock *add_keyblock(Scene *scene, Key *key)
+KeyBlock *add_keyblock(Key *key)
 {
 	KeyBlock *kb;
 	float curpos= -0.1;
@@ -1516,3 +1516,185 @@
 	/* return the path */
 	return RNA_path_from_ID_to_property(&ptr, prop);
 }
+
+
+/* conversion functions */
+
+/************************* Lattice ************************/
+void latt_to_key(Lattice *lt, KeyBlock *kb)
+{
+	BPoint *bp;
+	float *fp;
+	int a, tot;
+
+	tot= lt->pntsu*lt->pntsv*lt->pntsw;
+	if(tot==0) return;
+
+	if(kb->data) MEM_freeN(kb->data);
+
+	kb->data= MEM_callocN(lt->key->elemsize*tot, "kb->data");
+	kb->totelem= tot;
+
+	bp= lt->def;
+	fp= kb->data;
+	for(a=0; a<kb->totelem; a++, fp+=3, bp++) {
+		VECCOPY(fp, bp->vec);
+	}
+}
+
+void key_to_latt(KeyBlock *kb, Lattice *lt)
+{
+	BPoint *bp;
+	float *fp;
+	int a, tot;
+
+	bp= lt->def;
+	fp= kb->data;
+
+	tot= lt->pntsu*lt->pntsv*lt->pntsw;
+	tot= MIN2(kb->totelem, tot);
+
+	for(a=0; a<tot; a++, fp+=3, bp++) {
+		VECCOPY(bp->vec, fp);
+	}
+}
+
+/************************* Curve ************************/
+void curve_to_key(Curve *cu, KeyBlock *kb, ListBase *nurb)
+{
+	Nurb *nu;
+	BezTriple *bezt;
+	BPoint *bp;
+	float *fp;
+	int a, tot;
+
+	/* count */
+	tot= count_curveverts(nurb);
+	if(tot==0) return;
+
+	if(kb->data) MEM_freeN(kb->data);
+
+	kb->data= MEM_callocN(cu->key->elemsize*tot, "kb->data");
+	kb->totelem= tot;
+
+	nu= nurb->first;
+	fp= kb->data;
+	while(nu) {
+
+		if(nu->bezt) {
+			bezt= nu->bezt;
+			a= nu->pntsu;
+			while(a--) {
+				VECCOPY(fp, bezt->vec[0]);
+				fp+= 3;
+				VECCOPY(fp, bezt->vec[1]);
+				fp+= 3;
+				VECCOPY(fp, bezt->vec[2]);
+				fp+= 3;
+				fp[0]= bezt->alfa;
+				fp+= 3;	/* alphas */
+				bezt++;
+			}
+		}
+		else {
+			bp= nu->bp;
+			a= nu->pntsu*nu->pntsv;
+			while(a--) {
+				VECCOPY(fp, bp->vec);
+				fp[3]= bp->alfa;
+
+				fp+= 4;
+				bp++;
+			}
+		}
+		nu= nu->next;
+	}
+}
+
+void key_to_curve(KeyBlock *kb, Curve  *cu, ListBase *nurb)
+{
+	Nurb *nu;
+	BezTriple *bezt;
+	BPoint *bp;
+	float *fp;
+	int a, tot;
+
+	nu= nurb->first;
+	fp= kb->data;
+
+	tot= count_curveverts(nurb);
+
+	tot= MIN2(kb->totelem, tot);
+
+	while(nu && tot>0) {
+
+		if(nu->bezt) {
+			bezt= nu->bezt;
+			a= nu->pntsu;
+			while(a-- && tot>0) {
+				VECCOPY(bezt->vec[0], fp);
+				fp+= 3;
+				VECCOPY(bezt->vec[1], fp);
+				fp+= 3;
+				VECCOPY(bezt->vec[2], fp);
+				fp+= 3;
+				bezt->alfa= fp[0];
+				fp+= 3;	/* alphas */
+
+				tot-= 3;
+				bezt++;
+			}
+		}
+		else {
+			bp= nu->bp;
+			a= nu->pntsu*nu->pntsv;
+			while(a-- && tot>0) {
+				VECCOPY(bp->vec, fp);
+				bp->alfa= fp[3];
+
+				fp+= 4;
+				tot--;
+				bp++;
+			}
+		}
+		nu= nu->next;
+	}
+}
+
+/************************* Mesh ************************/
+void mesh_to_key(Mesh *me, KeyBlock *kb)
+{
+	MVert *mvert;
+	float *fp;
+	int a;
+
+	if(me->totvert==0) return;
+
+	if(kb->data) MEM_freeN(kb->data);
+
+	kb->data= MEM_callocN(me->key->elemsize*me->totvert, "kb->data");
+	kb->totelem= me->totvert;
+
+	mvert= me->mvert;
+	fp= kb->data;
+	for(a=0; a<kb->totelem; a++, fp+=3, mvert++) {
+		VECCOPY(fp, mvert->co);
+
+	}
+}
+
+void key_to_mesh(KeyBlock *kb, Mesh *me)
+{
+	MVert *mvert;
+	float *fp;
+	int a, tot;
+
+	mvert= me->mvert;
+	fp= kb->data;
+
+	tot= MIN2(kb->totelem, me->totvert);
+
+	for(a=0; a<tot; a++, fp+=3, mvert++) {
+		VECCOPY(mvert->co, fp);
+	}
+}

Modified: trunk/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/object.c	2009-12-28 10:44:02 UTC (rev 25592)
+++ trunk/blender/source/blender/blenkernel/intern/object.c	2009-12-28 15:26:36 UTC (rev 25593)
@@ -47,6 +47,7 @@
 #include "DNA_constraint_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_group_types.h"
+#include "DNA_key_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_material_types.h"
@@ -2629,3 +2630,96 @@
 	BLI_freelinkN(&ob->pc_ids, link);
 }
 #endif
+
+/* shape key utility function */
+
+/************************* Mesh ************************/
+static void insert_meshkey(Scene *scene, Object *ob, int from_mix)
+{
+	Mesh *me= ob->data;
+	Key *key= me->key;
+	KeyBlock *kb;
+	int newkey= 0;
+
+	if(key == NULL) {
+		key= me->key= add_key((ID *)me);
+		key->type= KEY_RELATIVE;
+		newkey= 1;
+	}
+
+	kb= add_keyblock(key);
+
+	if(newkey || from_mix==FALSE) {
+		/* create from mesh */
+		mesh_to_key(me, kb);
+	}
+	else {
+		/* copy from current values */
+		kb->data= do_ob_key(scene, ob);
+		kb->totelem= me->totvert;
+	}
+}
+/************************* Lattice ************************/
+static void insert_lattkey(Scene *scene, Object *ob, int from_mix)
+{
+	Lattice *lt= ob->data;
+	Key *key= lt->key;
+	KeyBlock *kb;
+	int newkey= 0;
+
+	if(key==NULL) {
+		key= lt->key= add_key( (ID *)lt);
+		key->type= KEY_RELATIVE;
+		newkey= 1;
+	}
+
+	kb= add_keyblock(key);
+
+	if(newkey || from_mix==FALSE) {
+		/* create from lattice */
+		latt_to_key(lt, kb);
+	}
+	else {
+		/* copy from current values */
+		kb->totelem= lt->pntsu*lt->pntsv*lt->pntsw;
+		kb->data= do_ob_key(scene, ob);
+	}
+}
+/************************* Curve ************************/
+static void insert_curvekey(Scene *scene, Object *ob, int from_mix)
+{
+	Curve *cu= ob->data;
+	Key *key= cu->key;
+	KeyBlock *kb;
+	ListBase *lb= (cu->editnurb)? cu->editnurb: &cu->nurb;
+	int newkey= 0;
+
+	if(key==NULL) {
+		key= cu->key= add_key( (ID *)cu);
+		key->type = KEY_RELATIVE;
+		newkey= 1;
+	}
+
+	kb= add_keyblock(key);
+
+	if(newkey || from_mix==FALSE) {
+		/* create from curve */
+		curve_to_key(cu, kb, lb);
+	}
+	else {
+		/* copy from current values */
+		kb->totelem= count_curveverts(lb);
+		kb->data= do_ob_key(scene, ob);
+	}
+
+}
+
+int object_insert_shape_key(Scene *scene, Object *ob, int from_mix)
+{
+	if(ob->type==OB_MESH)						insert_meshkey(scene, ob, from_mix);
+	else if ELEM(ob->type, OB_CURVE, OB_SURF)	insert_curvekey(scene, ob, from_mix);
+	else if(ob->type==OB_LATTICE)				insert_lattkey(scene, ob, from_mix);
+	else return 0;
+	return 1;
+}
+

Modified: trunk/blender/source/blender/editors/include/ED_object.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_object.h	2009-12-28 10:44:02 UTC (rev 25592)
+++ trunk/blender/source/blender/editors/include/ED_object.h	2009-12-28 15:26:36 UTC (rev 25593)
@@ -110,7 +110,7 @@
 int  mouse_lattice(struct bContext *C, short mval[2], int extend);
 void undo_push_lattice(struct bContext *C, char *name);
 
-/* object_shapekey.c */
+/* key.c */
 void key_to_mesh(struct KeyBlock *kb, struct Mesh *me);
 void mesh_to_key(struct Mesh *me, struct KeyBlock *kb);
 void key_to_latt(struct KeyBlock *kb, struct Lattice *lt);

Modified: trunk/blender/source/blender/editors/mesh/meshtools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/meshtools.c	2009-12-28 10:44:02 UTC (rev 25592)
+++ trunk/blender/source/blender/editors/mesh/meshtools.c	2009-12-28 15:26:36 UTC (rev 25593)
@@ -588,7 +588,7 @@
 		key->type= KEY_RELATIVE;
 
 		/* first key added, so it was the basis. initialise it with the existing mesh */
-		kb= add_keyblock(scene, key);
+		kb= add_keyblock(key);
 		mesh_to_key(me, kb);
 	}
 	
@@ -604,7 +604,7 @@
 				
 				if (!dm) continue;
 					
-				kb= add_keyblock(scene, key);
+				kb= add_keyblock(key);
 				strcpy(kb->name, base->object->id.name+2);
 				BLI_uniquename(&key->block, kb, "Key", '.', offsetof(KeyBlock, name), 32);
 				

Modified: trunk/blender/source/blender/editors/object/object_modifier.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_modifier.c	2009-12-28 10:44:02 UTC (rev 25592)
+++ trunk/blender/source/blender/editors/object/object_modifier.c	2009-12-28 15:26:36 UTC (rev 25593)
@@ -370,11 +370,11 @@
 			key->type= KEY_RELATIVE;
 			/* if that was the first key block added, then it was the basis.
 			 * Initialise it with the mesh, and add another for the modifier */
-			kb= add_keyblock(scene, key);
+			kb= add_keyblock(key);
 			mesh_to_key(me, kb);
 		}
 
-		kb= add_keyblock(scene, key);
+		kb= add_keyblock(key);
 		DM_to_meshkey(dm, me, kb);
 		
 		dm->release(dm);

Modified: trunk/blender/source/blender/editors/object/object_shapekey.c

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list