Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-08-01 15:00:36 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-08-01 15:00:36 +0400
commitd25747ee751096de2e417a7da1316bf5bf81c25a (patch)
tree516d8fe68d3384a222da32a3e72e1d05aa717db8 /source/blender/blenkernel
parente56913fe3961e9ab34b15e5317d83e9110e20857 (diff)
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.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_curve.h4
-rw-r--r--source/blender/blenkernel/BKE_mesh.h5
-rw-r--r--source/blender/blenkernel/intern/curve.c117
-rw-r--r--source/blender/blenkernel/intern/mesh.c86
4 files changed, 179 insertions, 33 deletions
diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index e83ea4b809c..bcc92b477a7 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -107,5 +107,9 @@ int clamp_nurb_order_v( struct Nurb *nu);
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
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 3b6cf8803d8..8c5979222f0 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -140,7 +140,12 @@ int mesh_layers_menu_charlen(struct CustomData *data, int type); /* use this to
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
}
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 4142ad7128f..1a30e85c5c4 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -276,7 +276,7 @@ void tex_space_curve(Curve *cu)
{
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 @@ void tex_space_curve(Curve *cu)
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 @@ ListBase *BKE_curve_nurbs(Curve *cu)
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);
+ }
+ }
+ }
+}
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 66e8c10206c..ab7b0694836 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -320,33 +320,22 @@ void make_local_mesh(Mesh *me)
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 @@ void tex_space_mesh(Mesh *me)
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 @@ float *get_mesh_orco_verts(Object *ob)
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 @@ void transform_mesh_orco_verts(Mesh *me, float (*orco)[3], int totvert, int inve
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 @@ void mesh_pmv_off(Object *ob, Mesh *me)
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);
+ }
+ }
+ }
+}