[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30933] trunk/blender/source/blender: bugfix's
Campbell Barton
ideasman42 at gmail.com
Sun Aug 1 13:00:36 CEST 2010
Revision: 30933
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30933
Author: campbellbarton
Date: 2010-08-01 13:00:36 +0200 (Sun, 01 Aug 2010)
Log Message:
-----------
bugfix's
[#23108] bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN') dosen't work in console
[#23115] Crash when moving armature origin
- setting the armature in editmode would leave editdata in some cases.
- transforming selected linked objects to account for the movement of the obdata was only done for meshes, now do for curves and text3d.
- added utility functions for getting curve & mesh bounds.
- text3d moving center wasn't working at all.
- changed drawobject.c to use BLI_math funcs in more places.
- remove some unused code from operator object.origin_set.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/BKE_curve.h
trunk/blender/source/blender/blenkernel/BKE_mesh.h
trunk/blender/source/blender/blenkernel/intern/curve.c
trunk/blender/source/blender/blenkernel/intern/mesh.c
trunk/blender/source/blender/editors/armature/editarmature.c
trunk/blender/source/blender/editors/include/ED_armature.h
trunk/blender/source/blender/editors/object/object_transform.c
trunk/blender/source/blender/editors/space_view3d/drawobject.c
Modified: trunk/blender/source/blender/blenkernel/BKE_curve.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_curve.h 2010-08-01 10:53:59 UTC (rev 30932)
+++ trunk/blender/source/blender/blenkernel/BKE_curve.h 2010-08-01 11:00:36 UTC (rev 30933)
@@ -107,5 +107,9 @@
ListBase *BKE_curve_nurbs(struct Curve *cu);
+int curve_bounds(struct Curve *cu, float min[3], float max[3]);
+int curve_center_median(struct Curve *cu, float cent[3]);
+int curve_center_bounds(struct Curve *cu, float cent[3]);
+void curve_translate(struct Curve *cu, float offset[3], int do_keys);
#endif
Modified: trunk/blender/source/blender/blenkernel/BKE_mesh.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_mesh.h 2010-08-01 10:53:59 UTC (rev 30932)
+++ trunk/blender/source/blender/blenkernel/BKE_mesh.h 2010-08-01 11:00:36 UTC (rev 30933)
@@ -140,7 +140,12 @@
void mesh_layers_menu_concat(struct CustomData *data, int type, char *str);
int mesh_layers_menu(struct CustomData *data, int type);
+/* vertex level transformations & checks (no derived mesh) */
+int mesh_bounds(struct Mesh *me, float min[3], float max[3]);
+int mesh_center_median(struct Mesh *me, float cent[3]);
+int mesh_center_bounds(struct Mesh *me, float cent[3]);
+void mesh_translate(struct Mesh *me, float offset[3], int do_keys);
#ifdef __cplusplus
}
Modified: trunk/blender/source/blender/blenkernel/intern/curve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/curve.c 2010-08-01 10:53:59 UTC (rev 30932)
+++ trunk/blender/source/blender/blenkernel/intern/curve.c 2010-08-01 11:00:36 UTC (rev 30933)
@@ -276,7 +276,7 @@
{
DispList *dl;
BoundBox *bb;
- float *fp, min[3], max[3], loc[3], size[3];
+ float *fp, min[3], max[3];
int tot, doit= 0;
if(cu->bb==NULL) cu->bb= MEM_callocN(sizeof(BoundBox), "boundbox");
@@ -303,20 +303,15 @@
min[0] = min[1] = min[2] = -1.0f;
max[0] = max[1] = max[2] = 1.0f;
}
-
- loc[0]= (min[0]+max[0])/2.0f;
- loc[1]= (min[1]+max[1])/2.0f;
- loc[2]= (min[2]+max[2])/2.0f;
-
- size[0]= (max[0]-min[0])/2.0f;
- size[1]= (max[1]-min[1])/2.0f;
- size[2]= (max[2]-min[2])/2.0f;
boundbox_set_from_min_max(bb, min, max);
if(cu->texflag & CU_AUTOSPACE) {
- VECCOPY(cu->loc, loc);
- VECCOPY(cu->size, size);
+ mid_v3_v3v3(cu->loc, min, max);
+ cu->size[0]= (max[0]-min[0])/2.0f;
+ cu->size[1]= (max[1]-min[1])/2.0f;
+ cu->size[2]= (max[2]-min[2])/2.0f;
+
cu->rot[0]= cu->rot[1]= cu->rot[2]= 0.0;
if(cu->size[0]==0.0) cu->size[0]= 1.0;
@@ -3107,3 +3102,103 @@
return &cu->nurb;
}
+
+
+/* basic vertex data functions */
+int curve_bounds(Curve *cu, float min[3], float max[3])
+{
+ ListBase *nurb_lb= BKE_curve_nurbs(cu);
+ Nurb *nu;
+
+ INIT_MINMAX(min, max);
+
+ for(nu= nurb_lb->first; nu; nu= nu->next)
+ minmaxNurb(nu, min, max);
+
+ return (nurb_lb->first != NULL);
+}
+
+int curve_center_median(Curve *cu, float cent[3])
+{
+ ListBase *nurb_lb= BKE_curve_nurbs(cu);
+ Nurb *nu;
+ int total= 0;
+
+ zero_v3(cent);
+
+ for(nu= nurb_lb->first; nu; nu= nu->next) {
+ int i;
+
+ if(nu->type == CU_BEZIER) {
+ BezTriple *bezt;
+ i= nu->pntsu;
+ total += i * 3;
+ for(bezt= nu->bezt; i--; bezt++) {
+ add_v3_v3(cent, bezt->vec[0]);
+ add_v3_v3(cent, bezt->vec[1]);
+ add_v3_v3(cent, bezt->vec[2]);
+ }
+ }
+ else {
+ BPoint *bp;
+ i= nu->pntsu*nu->pntsv;
+ total += i;
+ for(bp= nu->bp; i--; bp++) {
+ add_v3_v3(cent, bp->vec);
+ }
+ }
+ }
+
+ mul_v3_fl(cent, 1.0f/(float)total);
+
+ return (total != 0);
+}
+
+int curve_center_bounds(Curve *cu, float cent[3])
+{
+ float min[3], max[3];
+
+ if(curve_bounds(cu, min, max)) {
+ mid_v3_v3v3(cent, min, max);
+ return 1;
+ }
+
+ return 0;
+}
+
+void curve_translate(Curve *cu, float offset[3], int do_keys)
+{
+ ListBase *nurb_lb= BKE_curve_nurbs(cu);
+ Nurb *nu;
+ int i;
+
+ for(nu= nurb_lb->first; nu; nu= nu->next) {
+ BezTriple *bezt;
+ BPoint *bp;
+
+ if(nu->type == CU_BEZIER) {
+ i= nu->pntsu;
+ for(bezt= nu->bezt; i--; bezt++) {
+ add_v3_v3(bezt->vec[0], offset);
+ add_v3_v3(bezt->vec[1], offset);
+ add_v3_v3(bezt->vec[2], offset);
+ }
+ }
+ else {
+ i= nu->pntsu*nu->pntsv;
+ for(bp= nu->bp; i--; bp++) {
+ add_v3_v3(bp->vec, offset);
+ }
+ }
+ }
+
+ if (do_keys && cu->key) {
+ KeyBlock *kb;
+ for (kb=cu->key->block.first; kb; kb=kb->next) {
+ float *fp= kb->data;
+ for (i= kb->totelem; i--; fp+=3) {
+ add_v3_v3(fp, offset);
+ }
+ }
+ }
+}
Modified: trunk/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mesh.c 2010-08-01 10:53:59 UTC (rev 30932)
+++ trunk/blender/source/blender/blenkernel/intern/mesh.c 2010-08-01 11:00:36 UTC (rev 30933)
@@ -320,33 +320,22 @@
void boundbox_mesh(Mesh *me, float *loc, float *size)
{
- MVert *mvert;
BoundBox *bb;
float min[3], max[3];
float mloc[3], msize[3];
- int a;
if(me->bb==0) me->bb= MEM_callocN(sizeof(BoundBox), "boundbox");
bb= me->bb;
-
- INIT_MINMAX(min, max);
if (!loc) loc= mloc;
if (!size) size= msize;
- mvert= me->mvert;
- for(a=0; a<me->totvert; a++, mvert++) {
- DO_MINMAX(mvert->co, min, max);
- }
-
- if(!me->totvert) {
+ if(!mesh_bounds(me, min, max)) {
min[0] = min[1] = min[2] = -1.0f;
max[0] = max[1] = max[2] = 1.0f;
}
- loc[0]= (min[0]+max[0])/2.0f;
- loc[1]= (min[1]+max[1])/2.0f;
- loc[2]= (min[2]+max[2])/2.0f;
+ mid_v3_v3v3(loc, min, max);
size[0]= (max[0]-min[0])/2.0f;
size[1]= (max[1]-min[1])/2.0f;
@@ -369,9 +358,9 @@
else if(size[a]<0.0 && size[a]> -0.00001) size[a]= -0.00001;
}
- VECCOPY(me->loc, loc);
- VECCOPY(me->size, size);
- me->rot[0]= me->rot[1]= me->rot[2]= 0.0;
+ copy_v3_v3(me->loc, loc);
+ copy_v3_v3(me->size, size);
+ zero_v3(me->rot);
}
}
@@ -413,9 +402,7 @@
totvert = MIN2(tme->totvert, me->totvert);
for(a=0; a<totvert; a++, mvert++) {
- vcos[a][0]= mvert->co[0];
- vcos[a][1]= mvert->co[1];
- vcos[a][2]= mvert->co[2];
+ copy_v3_v3(vcos[a], mvert->co);
}
return (float*)vcos;
@@ -431,9 +418,7 @@
if(invert) {
for(a=0; a<totvert; a++) {
float *co = orco[a];
- co[0] = co[0]*size[0] + loc[0];
- co[1] = co[1]*size[1] + loc[1];
- co[2] = co[2]*size[2] + loc[2];
+ madd_v3_v3v3v3(co, loc, co, size);
}
}
else {
@@ -1497,3 +1482,60 @@
me->pv= NULL;
}
}
+
+/* basic vertex data functions */
+int mesh_bounds(Mesh *me, float min[3], float max[3])
+{
+ int i= me->totvert;
+ MVert *mvert;
+ INIT_MINMAX(min, max);
+ for(mvert= me->mvert; i--; mvert++) {
+ DO_MINMAX(mvert->co, min, max);
+ }
+
+ return (me->totvert != 0);
+}
+
+int mesh_center_median(Mesh *me, float cent[3])
+{
+ int i= me->totvert;
+ MVert *mvert;
+ zero_v3(cent);
+ for(mvert= me->mvert; i--; mvert++) {
+ add_v3_v3(cent, mvert->co);
+ }
+ mul_v3_fl(cent, 1.0f/(float)me->totvert);
+
+ return (me->totvert != 0);
+}
+
+int mesh_center_bounds(Mesh *me, float cent[3])
+{
+ float min[3], max[3];
+
+ if(mesh_bounds(me, min, max)) {
+ mid_v3_v3v3(cent, min, max);
+ return 1;
+ }
+
+ return 0;
+}
+
+void mesh_translate(Mesh *me, float offset[3], int do_keys)
+{
+ int i= me->totvert;
+ MVert *mvert;
+ for(mvert= me->mvert; i--; mvert++) {
+ add_v3_v3(mvert->co, offset);
+ }
+
+ if (do_keys && me->key) {
+ KeyBlock *kb;
+ for (kb=me->key->block.first; kb; kb=kb->next) {
+ float *fp= kb->data;
+ for (i= kb->totelem; i--; fp+=3) {
+ add_v3_v3(fp, offset);
+ }
+ }
+ }
+}
Modified: trunk/blender/source/blender/editors/armature/editarmature.c
===================================================================
--- trunk/blender/source/blender/editors/armature/editarmature.c 2010-08-01 10:53:59 UTC (rev 30932)
+++ trunk/blender/source/blender/editors/armature/editarmature.c 2010-08-01 11:00:36 UTC (rev 30933)
@@ -421,34 +421,45 @@
/* exported for use in editors/object/ */
/* 0 == do center, 1 == center new, 2 == center cursor */
-void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode)
+void docenter_armature (Scene *scene, Object *ob, float cursor[3], int centermode, int around)
{
Object *obedit= scene->obedit; // XXX get from context
EditBone *ebone;
bArmature *arm= ob->data;
- float cent[3] = {0.0f, 0.0f, 0.0f};
- float min[3], max[3];
+ float cent[3];
/* Put the armature into editmode */
- if(ob!=obedit)
+ if(ob != obedit) {
ED_armature_to_edit(ob);
+ obedit= NULL; /* we cant use this so behave as if there is no obedit */
+ }
/* Find the centerpoint */
if (centermode == 2) {
- float *fp= give_cursor(scene, v3d);
- copy_v3_v3(cent, fp);
+ copy_v3_v3(cent, cursor);
invert_m4_m4(ob->imat, ob->obmat);
mul_m4_v3(ob->imat, cent);
}
else {
- INIT_MINMAX(min, max);
-
- for (ebone= arm->edbo->first; ebone; ebone=ebone->next) {
- DO_MINMAX(ebone->head, min, max);
- DO_MINMAX(ebone->tail, min, max);
+ if(around==V3D_CENTROID) {
+ int total= 0;
+ zero_v3(cent);
+ for (ebone= arm->edbo->first; ebone; ebone=ebone->next) {
+ total+=2;
+ add_v3_v3(cent, ebone->head);
+ add_v3_v3(cent, ebone->tail);
+ }
+ mul_v3_fl(cent, 1.0f/(float)total);
}
-
- mid_v3_v3v3(cent, min, max);
+ else {
+ float min[3], max[3];
+ INIT_MINMAX(min, max);
+ for (ebone= arm->edbo->first; ebone; ebone=ebone->next) {
+ DO_MINMAX(ebone->head, min, max);
+ DO_MINMAX(ebone->tail, min, max);
+ }
+ mid_v3_v3v3(cent, min, max);
+ }
}
/* Do the adjustments */
@@ -458,16 +469,16 @@
}
/* Turn the list into an armature */
- ED_armature_from_edit(ob);
-
+ if(obedit==NULL) {
+ ED_armature_from_edit(ob);
+ ED_armature_edit_free(ob);
+ }
+
/* Adjust object location for new centerpoint */
if(centermode && obedit==NULL) {
mul_mat3_m4_v3(ob->obmat, cent); /* ommit translation part */
add_v3_v3(ob->loc, cent);
}
- else {
- ED_armature_edit_free(ob);
- }
}
/* ---------------------- */
@@ -2018,7 +2029,6 @@
BLI_freelistN(arm->edbo);
}
-
MEM_freeN(arm->edbo);
arm->edbo= NULL;
}
Modified: trunk/blender/source/blender/editors/include/ED_armature.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_armature.h 2010-08-01 10:53:59 UTC (rev 30932)
+++ trunk/blender/source/blender/editors/include/ED_armature.h 2010-08-01 11:00:36 UTC (rev 30933)
@@ -120,7 +120,7 @@
void transform_armature_mirror_update(struct Object *obedit);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list