void BKE_mesh_boundbox_calc(Mesh *me, float r_loc[3], float r_size[3]) { BoundBox *bb; float min[3], max[3]; float mloc[3], msize[3]; if (me->bb == NULL) me->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); bb = me->bb; if (!r_loc) r_loc = mloc; if (!r_size) r_size = msize; INIT_MINMAX(min, max); if (!BKE_mesh_minmax(me, min, max)) { min[0] = min[1] = min[2] = -1.0f; max[0] = max[1] = max[2] = 1.0f; } mid_v3_v3v3(r_loc, min, max); r_size[0] = (max[0] - min[0]) / 2.0f; r_size[1] = (max[1] - min[1]) / 2.0f; r_size[2] = (max[2] - min[2]) / 2.0f; BKE_boundbox_init_from_minmax(bb, min, max); bb->flag &= ~BOUNDBOX_DIRTY; }
static void boundbox_lattice(Object *ob) { BoundBox *bb; Lattice *lt; float min[3], max[3]; if (ob->bb == NULL) ob->bb = MEM_mallocN(sizeof(BoundBox), "Lattice boundbox"); bb = ob->bb; lt = ob->data; INIT_MINMAX(min, max); BKE_lattice_minmax_dl(ob, lt, min, max); BKE_boundbox_init_from_minmax(bb, min, max); }
/** Compute bounding box of all MetaElems/MetaBalls. * * Bounding box is computed from polygonized surface. Object *ob is * basic MetaBall (usually with name Meta). All other MetaBalls (with * names Meta.001, Meta.002, etc) are included in this Bounding Box. */ void BKE_mball_texspace_calc(Object *ob) { DispList *dl; BoundBox *bb; float *data, min[3], max[3] /*, loc[3], size[3] */; int tot; bool do_it = false; if (ob->bb == NULL) ob->bb = MEM_callocN(sizeof(BoundBox), "mb boundbox"); bb = ob->bb; /* Weird one, this. */ /* INIT_MINMAX(min, max); */ (min)[0] = (min)[1] = (min)[2] = 1.0e30f; (max)[0] = (max)[1] = (max)[2] = -1.0e30f; dl = ob->curve_cache->disp.first; while (dl) { tot = dl->nr; if (tot) do_it = true; data = dl->verts; while (tot--) { /* Also weird... but longer. From utildefines. */ minmax_v3v3_v3(min, max, data); data += 3; } dl = dl->next; } if (!do_it) { min[0] = min[1] = min[2] = -1.0f; max[0] = max[1] = max[2] = 1.0f; } #if 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; size[0] = (max[0] - min[0]) / 2.0f; size[1] = (max[1] - min[1]) / 2.0f; size[2] = (max[2] - min[2]) / 2.0f; #endif BKE_boundbox_init_from_minmax(bb, min, max); }