Add real boundbox support to lattice, and update armature one.

* draw lattice boundingboxes in 3dView [if "show_bounds" is used -- an option previously pretty useless for lattices]
* give proper values for lattice objects ".bound_box" in bpy
* give proper values for armature objects ".bound_box" in bpy
* lets users use "Dimensions" [in 3dView Transform panel] on lattices and armatures
* remove redundant calculations in "boundbox_armature()"

Armatures boundingboxes were already drawn in 3dView, if "show_bounds" was used.

Based on report T45735: Lattice's bounding_box doesn't update,
and a comment in code by @campbellbarton ("later we may want to add dimensions for lattice, armature etc too").

Revision: https://developer.blender.org/D1460
This commit is contained in:
Philipp Oeser 2015-08-13 18:12:08 +02:00 committed by Bastien Montagne
parent d2383ec6c0
commit 3fa0a1a5bc
Notes: blender-bot 2023-10-12 12:49:04 +02:00
Referenced by issue #47683, Regression displaying bone-children in dupli-groups
6 changed files with 41 additions and 18 deletions

View File

@ -80,6 +80,7 @@ void BKE_lattice_modifiers_calc(struct Scene *scene, struct Object *ob);
struct MDeformVert *BKE_lattice_deform_verts_get(struct Object *lattice);
struct BPoint *BKE_lattice_active_point_get(struct Lattice *lt);
struct BoundBox *BKE_lattice_boundbox_get(struct Object *ob);
void BKE_lattice_minmax(struct Lattice *lt, float min[3], float max[3]);
void BKE_lattice_center_median(struct Lattice *lt, float cent[3]);
void BKE_lattice_center_bounds(struct Lattice *lt, float cent[3]);

View File

@ -2182,39 +2182,27 @@ static int minmax_armature(Object *ob, float r_min[3], float r_max[3])
return (BLI_listbase_is_empty(&ob->pose->chanbase) == false);
}
static void boundbox_armature(Object *ob, float loc[3], float size[3])
static void boundbox_armature(Object *ob)
{
BoundBox *bb;
float min[3], max[3];
float mloc[3], msize[3];
if (ob->bb == NULL)
ob->bb = MEM_callocN(sizeof(BoundBox), "Armature boundbox");
ob->bb = MEM_mallocN(sizeof(BoundBox), "Armature boundbox");
bb = ob->bb;
if (!loc)
loc = mloc;
if (!size)
size = msize;
INIT_MINMAX(min, max);
if (!minmax_armature(ob, min, max)) {
min[0] = min[1] = min[2] = -1.0f;
max[0] = max[1] = max[2] = 1.0f;
}
mid_v3_v3v3(loc, min, max);
size[0] = (max[0] - min[0]) / 2.0f;
size[1] = (max[1] - min[1]) / 2.0f;
size[2] = (max[2] - min[2]) / 2.0f;
BKE_boundbox_init_from_minmax(bb, min, max);
}
BoundBox *BKE_armature_boundbox_get(Object *ob)
{
boundbox_armature(ob, NULL, NULL);
boundbox_armature(ob);
return ob->bb;
}

View File

@ -61,6 +61,7 @@
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
#include "BKE_deform.h"
@ -1138,6 +1139,30 @@ void BKE_lattice_center_median(Lattice *lt, float cent[3])
mul_v3_fl(cent, 1.0f / (float)numVerts);
}
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(lt, min, max);
BKE_boundbox_init_from_minmax(bb, min, max);
}
BoundBox *BKE_lattice_boundbox_get(Object *ob)
{
boundbox_lattice(ob);
return ob->bb;
}
void BKE_lattice_minmax(Lattice *lt, float min[3], float max[3])
{
int i, numVerts;

View File

@ -114,6 +114,7 @@
#include "BKE_material.h"
#include "BKE_camera.h"
#include "BKE_image.h"
#include "BKE_lattice.h"
#ifdef WITH_MOD_FLUID
#include "LBM_fluidsim.h"
@ -2652,6 +2653,12 @@ BoundBox *BKE_object_boundbox_get(Object *ob)
else if (ob->type == OB_MBALL) {
bb = ob->bb;
}
else if (ob->type == OB_LATTICE) {
bb = BKE_lattice_boundbox_get(ob);
}
else if (ob->type == OB_ARMATURE) {
bb = BKE_armature_boundbox_get(ob);
}
return bb;
}

View File

@ -7233,6 +7233,9 @@ static void draw_bounding_volume(Object *ob, char type)
else if (ob->type == OB_ARMATURE) {
bb = BKE_armature_boundbox_get(ob);
}
else if (ob->type == OB_LATTICE) {
bb = BKE_lattice_boundbox_get(ob);
}
else {
const float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {1.0f, 1.0f, 1.0f};
bb = &bb_local;

View File

@ -992,9 +992,8 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
if (ptr->type == &RNA_Object) {
Object *ob = ptr->data;
/* dimensions and material support just happen to be the same checks
* later we may want to add dimensions for lattice, armature etc too */
if (OB_TYPE_SUPPORT_MATERIAL(ob->type)) {
/* dimensions and editmode just happen to be the same checks */
if (OB_TYPE_SUPPORT_EDITMODE(ob->type)) {
uiItemR(layout, ptr, "dimensions", 0, NULL, ICON_NONE);
}
}