- added boundbox_set_from_min_max function

- fix DerivedMesh.getMinMax implementations to set min & max when
   there are no vertices
 - mesh boundbox calc was wrong in some cases, messed up HOMEKEY
   and localview zooming
This commit is contained in:
Daniel Dunbar
2005-07-18 17:33:51 +00:00
parent 02ab203c98
commit 06c7653be1
8 changed files with 78 additions and 103 deletions

View File

@@ -91,6 +91,7 @@ void where_is_object_simul(struct Object *ob);
void what_does_parent(struct Object *ob);
struct BoundBox *unit_boundbox(void);
void boundbox_set_from_min_max(struct BoundBox *bb, float min[3], float max[3]);
void minmax_object(struct Object *ob, float *min, float *max);
void solve_tracking (struct Object *ob, float targetmat[][4]);
void solve_constraints (struct Object *ob, short obtype, void *obdata, float ctime);

View File

@@ -97,8 +97,12 @@ static void meshDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3])
Mesh *me = mdm->ob->data;
int i;
for (i=0; i<me->totvert; i++) {
DO_MINMAX(mdm->verts[i].co, min_r, max_r);
if (me->totvert) {
for (i=0; i<me->totvert; i++) {
DO_MINMAX(mdm->verts[i].co, min_r, max_r);
}
} else {
min_r[0] = min_r[1] = min_r[2] = max_r[0] = max_r[1] = max_r[2] = 0.0;
}
}
@@ -580,8 +584,12 @@ static void emDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3])
EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
EditVert *eve;
for (eve= emdm->em->verts.first; eve; eve= eve->next) {
DO_MINMAX(eve->co, min_r, max_r);
if (emdm->em->verts.first) {
for (eve= emdm->em->verts.first; eve; eve= eve->next) {
DO_MINMAX(eve->co, min_r, max_r);
}
} else {
min_r[0] = min_r[1] = min_r[2] = max_r[0] = max_r[1] = max_r[2] = 0.0;
}
}
static int emDM_getNumVerts(DerivedMesh *dm)
@@ -872,8 +880,12 @@ static void ssDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3])
SSDerivedMesh *ssdm = (SSDerivedMesh*) dm;
int i;
for (i=0; i<ssdm->dlm->totvert; i++) {
DO_MINMAX(ssdm->dlm->mvert[i].co, min_r, max_r);
if (ssdm->dlm->totvert) {
for (i=0; i<ssdm->dlm->totvert; i++) {
DO_MINMAX(ssdm->dlm->mvert[i].co, min_r, max_r);
}
} else {
min_r[0] = min_r[1] = min_r[2] = max_r[0] = max_r[1] = max_r[2] = 0.0;
}
}

View File

@@ -320,28 +320,20 @@ void tex_space_curve(Curve *cu)
dl= dl->next;
}
if(doit) {
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;
}
else {
loc[0]= loc[1]= loc[2]= 0.0f;
size[0]= size[1]= size[2]= 1.0f;
if(!doit) {
min[0] = min[1] = min[2] = -1.0f;
max[0] = max[1] = max[2] = 1.0f;
}
bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= loc[0]-size[0];
bb->vec[4][0]=bb->vec[5][0]=bb->vec[6][0]=bb->vec[7][0]= loc[0]+size[0];
loc[0]= (min[0]+max[0])/2.0f;
loc[1]= (min[1]+max[1])/2.0f;
loc[2]= (min[2]+max[2])/2.0f;
bb->vec[0][1]=bb->vec[1][1]=bb->vec[4][1]=bb->vec[5][1]= loc[1]-size[1];
bb->vec[2][1]=bb->vec[3][1]=bb->vec[6][1]=bb->vec[7][1]= loc[1]+size[1];
size[0]= (max[0]-min[0])/2.0f;
size[1]= (max[1]-min[1])/2.0f;
size[2]= (max[2]-min[2])/2.0f;
bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= loc[2]-size[2];
bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= loc[2]+size[2];
boundbox_set_from_min_max(bb, min, max);
if(cu->texflag & CU_AUTOSPACE) {
VECCOPY(cu->loc, loc);

View File

@@ -1418,6 +1418,7 @@ float calc_taper(Object *taperobj, int cur, int tot)
void makeDispListMesh(Object *ob)
{
MVert *deformedMVerts = NULL;
float min[3], max[3];
Mesh *me;
if(!ob || (ob->flag&OB_FROMDUPLI) || ob->type!=OB_MESH) return;
@@ -1457,30 +1458,15 @@ void makeDispListMesh(Object *ob)
}
}
{
BoundBox *bb=0;
float min[3], max[3];
INIT_MINMAX(min, max);
INIT_MINMAX(min, max);
if (me->derived) {
me->derived->getMinMax(me->derived, min, max);
bb= mesh_get_bb(ob->data);
boundbox_set_from_min_max(mesh_get_bb(ob->data), min, max);
} else if (ob->derivedDeform) {
ob->derivedDeform->getMinMax(ob->derivedDeform, min, max);
if (me->derived) {
me->derived->getMinMax(me->derived, min, max);
} else if (ob->derivedDeform) {
ob->derivedDeform->getMinMax(ob->derivedDeform, min, max);
}
if(bb) {
bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= min[0];
bb->vec[4][0]=bb->vec[5][0]=bb->vec[6][0]=bb->vec[7][0]= max[0];
bb->vec[0][1]=bb->vec[1][1]=bb->vec[4][1]=bb->vec[5][1]= min[1];
bb->vec[2][1]=bb->vec[3][1]=bb->vec[6][1]=bb->vec[7][1]= max[1];
bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= min[2];
bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= max[2];
}
boundbox_set_from_min_max(mesh_get_bb(ob->data), min, max);
}
build_particle_system(ob);
@@ -2092,14 +2078,7 @@ static void boundbox_displist(Object *ob)
}
if(bb) {
bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= min[0];
bb->vec[4][0]=bb->vec[5][0]=bb->vec[6][0]=bb->vec[7][0]= max[0];
bb->vec[0][1]=bb->vec[1][1]=bb->vec[4][1]=bb->vec[5][1]= min[1];
bb->vec[2][1]=bb->vec[3][1]=bb->vec[6][1]=bb->vec[7][1]= max[1];
bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= min[2];
bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= max[2];
boundbox_set_from_min_max(bb, min, max);
}
}

View File

@@ -217,29 +217,20 @@ void tex_space_mball(Object *ob)
dl= dl->next;
}
if(doit) {
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;
}
else {
loc[0]= loc[1]= loc[2]= 0.0f;
size[0]= size[1]= size[2]= 1.0f;
if(!doit) {
min[0] = min[1] = min[2] = -1.0f;
max[0] = max[1] = max[2] = 1.0f;
}
bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= loc[0]-size[0];
bb->vec[4][0]=bb->vec[5][0]=bb->vec[6][0]=bb->vec[7][0]= loc[0]+size[0];
loc[0]= (min[0]+max[0])/2.0f;
loc[1]= (min[1]+max[1])/2.0f;
loc[2]= (min[2]+max[2])/2.0f;
bb->vec[0][1]=bb->vec[1][1]=bb->vec[4][1]=bb->vec[5][1]= loc[1]-size[1];
bb->vec[2][1]=bb->vec[3][1]=bb->vec[6][1]=bb->vec[7][1]= loc[1]+size[1];
size[0]= (max[0]-min[0])/2.0f;
size[1]= (max[1]-min[1])/2.0f;
size[2]= (max[2]-min[2])/2.0f;
bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= loc[2]-size[2];
bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= loc[2]+size[2];
boundbox_set_from_min_max(bb, min, max);
}
void make_orco_mball(Object *ob)

View File

@@ -351,28 +351,20 @@ void boundbox_mesh(Mesh *me, float *loc, float *size)
DO_MINMAX(mvert->co, min, max);
}
if(me->totvert) {
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;
if(!me->totvert) {
min[0] = min[1] = min[2] = -1.0f;
max[0] = max[1] = max[2] = 1.0f;
}
else {
loc[0]= loc[1]= loc[2]= 0.0;
size[0]= size[1]= size[2]= 0.0;
}
bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= loc[0]-size[0];
bb->vec[4][0]=bb->vec[5][0]=bb->vec[6][0]=bb->vec[7][0]= loc[0]+size[0];
bb->vec[0][1]=bb->vec[1][1]=bb->vec[4][1]=bb->vec[5][1]= loc[1]-size[1];
bb->vec[2][1]=bb->vec[3][1]=bb->vec[6][1]=bb->vec[7][1]= loc[1]+size[1];
bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= loc[2]-size[2];
bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= loc[2]+size[2];
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);
}
void tex_space_mesh(Mesh *me)

View File

@@ -1679,21 +1679,26 @@ void what_does_parent(Object *ob)
BoundBox *unit_boundbox()
{
BoundBox *bb;
float min[3] = {-1,-1,-1}, max[3] = {-1,-1,-1};
bb= MEM_mallocN(sizeof(BoundBox), "bb");
bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= -1.0;
bb->vec[4][0]=bb->vec[5][0]=bb->vec[6][0]=bb->vec[7][0]= 1.0;
bb->vec[0][1]=bb->vec[1][1]=bb->vec[4][1]=bb->vec[5][1]= -1.0;
bb->vec[2][1]=bb->vec[3][1]=bb->vec[6][1]=bb->vec[7][1]= 1.0;
bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= -1.0;
bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= 1.0;
boundbox_set_from_min_max(bb, min, max);
return bb;
}
void boundbox_set_from_min_max(BoundBox *bb, float min[3], float max[3])
{
bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= min[0];
bb->vec[4][0]=bb->vec[5][0]=bb->vec[6][0]=bb->vec[7][0]= max[0];
bb->vec[0][1]=bb->vec[1][1]=bb->vec[4][1]=bb->vec[5][1]= min[1];
bb->vec[2][1]=bb->vec[3][1]=bb->vec[6][1]=bb->vec[7][1]= max[1];
bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= min[2];
bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= max[2];
}
void minmax_object(Object *ob, float *min, float *max)
{
BoundBox bb;

View File

@@ -593,6 +593,9 @@ static void ccgDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) {
int i, edgeSize = ccgSubSurf_getEdgeSize(ss);
int gridSize = ccgSubSurf_getGridSize(ss);
if (!ccgSubSurf_getNumVerts(ss))
min_r[0] = min_r[1] = min_r[2] = max_r[0] = max_r[1] = max_r[2] = 0.0;
for (; !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) {
CCGVert *v = ccgVertIterator_getCurrent(vi);
float *co = ccgSubSurf_getVertData(ss, v);