Uses RNA to draw object bound dimensions fields on 3D view Panel. #117871
|
@ -81,6 +81,10 @@ class OBJECT_PT_transform(ObjectButtonsPanel, Panel):
|
|||
row.use_property_decorate = False
|
||||
row.prop(ob, "lock_scale", text="", emboss=False, icon='DECORATE_UNLOCKED')
|
||||
|
||||
col = layout.column()
|
||||
row = col.row(align=True)
|
||||
row.prop(ob, "dimensions")
|
||||
row.use_property_decorate = False
|
||||
|
||||
class OBJECT_PT_delta_transform(ObjectButtonsPanel, Panel):
|
||||
bl_label = "Delta Transform"
|
||||
|
|
|
@ -3647,6 +3647,12 @@ void BKE_object_dimensions_set_ex(Object *ob,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset the bounds, so will get the new ones*/
|
||||
ob->runtime->bounds_eval.reset();
|
||||
|
||||
/* calculate local matrix so when getting bounds the scale match */
|
||||
BKE_object_to_mat4(ob, ob->object_to_world);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,6 @@
|
|||
enum {
|
||||
B_REDR = 2,
|
||||
B_TRANSFORM_PANEL_MEDIAN = 1008,
|
||||
B_TRANSFORM_PANEL_DIMS = 1009,
|
||||
};
|
||||
|
||||
/* All must start w/ location */
|
||||
|
@ -99,10 +98,6 @@ union TransformMedian {
|
|||
/* temporary struct for storing transform properties */
|
||||
|
||||
struct TransformProperties {
|
||||
float ob_obmat_orig[4][4];
|
||||
float ob_dims_orig[3];
|
||||
float ob_scale_orig[3];
|
||||
float ob_dims[3];
|
||||
blender::Vector<float> vertex_weights;
|
||||
/* Floats only (treated as an array). */
|
||||
TransformMedian ve_median, median;
|
||||
|
@ -1187,75 +1182,6 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
|
|||
|
||||
#undef TRANSFORM_MEDIAN_ARRAY_LEN
|
||||
|
||||
static void v3d_object_dimension_buts(bContext *C, uiLayout *layout, View3D *v3d, Object *ob)
|
||||
{
|
||||
uiBlock *block = (layout) ? uiLayoutAbsoluteBlock(layout) : nullptr;
|
||||
TransformProperties *tfp = v3d_transform_props_ensure(v3d);
|
||||
|
||||
if (block) {
|
||||
BLI_assert(C == nullptr);
|
||||
int yi = 200;
|
||||
const int butw = 200;
|
||||
const int buth = 20 * UI_SCALE_FAC;
|
||||
|
||||
BKE_object_dimensions_eval_cached_get(ob, tfp->ob_dims);
|
||||
copy_v3_v3(tfp->ob_dims_orig, tfp->ob_dims);
|
||||
copy_v3_v3(tfp->ob_scale_orig, ob->scale);
|
||||
copy_m4_m4(tfp->ob_obmat_orig, ob->object_to_world);
|
||||
|
||||
uiDefBut(block,
|
||||
UI_BTYPE_LABEL,
|
||||
0,
|
||||
IFACE_("Dimensions:"),
|
||||
0,
|
||||
yi -= buth,
|
||||
butw,
|
||||
buth,
|
||||
nullptr,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"");
|
||||
UI_block_align_begin(block);
|
||||
const float lim = FLT_MAX;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
uiBut *but;
|
||||
const char text[3] = {char('X' + i), ':', '\0'};
|
||||
but = uiDefButF(block,
|
||||
UI_BTYPE_NUM,
|
||||
B_TRANSFORM_PANEL_DIMS,
|
||||
text,
|
||||
0,
|
||||
yi -= buth,
|
||||
butw,
|
||||
buth,
|
||||
&(tfp->ob_dims[i]),
|
||||
0.0f,
|
||||
lim,
|
||||
"");
|
||||
UI_but_number_step_size_set(but, 10);
|
||||
UI_but_number_precision_set(but, 3);
|
||||
UI_but_unit_type_set(but, PROP_UNIT_LENGTH);
|
||||
}
|
||||
UI_block_align_end(block);
|
||||
}
|
||||
else { /* apply */
|
||||
int axis_mask = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (tfp->ob_dims[i] == tfp->ob_dims_orig[i]) {
|
||||
axis_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
BKE_object_dimensions_set_ex(
|
||||
ob, tfp->ob_dims, axis_mask, tfp->ob_scale_orig, tfp->ob_obmat_orig);
|
||||
|
||||
PointerRNA obptr = RNA_id_pointer_create(&ob->id);
|
||||
PropertyRNA *prop = RNA_struct_find_property(&obptr, "scale");
|
||||
RNA_property_update(C, &obptr, prop);
|
||||
}
|
||||
}
|
||||
|
||||
#define B_VGRP_PNL_EDIT_SINGLE 8 /* or greater */
|
||||
|
||||
static void do_view3d_vgroup_buttons(bContext *C, void * /*arg*/, int event)
|
||||
|
@ -1478,7 +1404,7 @@ static void view3d_panel_vgroup(const bContext *C, Panel *panel)
|
|||
}
|
||||
}
|
||||
|
||||
static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
|
||||
static void v3d_transform_butsR(uiLayout *layout, Object *ob, PointerRNA *ptr)
|
||||
{
|
||||
uiLayout *split, *colsub;
|
||||
|
||||
|
@ -1583,6 +1509,13 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
|
|||
UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY,
|
||||
"",
|
||||
ICON_DECORATE_UNLOCKED);
|
||||
|
||||
/* Dimensions and editmode are mostly the same check. */
|
||||
if (OB_TYPE_SUPPORT_EDITMODE(ob->type) || ELEM(ob->type, OB_VOLUME, OB_CURVES, OB_POINTCLOUD)) {
|
||||
split = uiLayoutSplit(layout, 0.8f, false);
|
||||
colsub = uiLayoutColumn(split, true);
|
||||
uiItemR(colsub, ptr, "dimensions", UI_ITEM_NONE, nullptr, ICON_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
static void v3d_posearmature_buts(uiLayout *layout, Object *ob)
|
||||
|
@ -1604,7 +1537,7 @@ static void v3d_posearmature_buts(uiLayout *layout, Object *ob)
|
|||
/* XXX: RNA buts show data in native types (i.e. quaternion, 4-component axis/angle, etc.)
|
||||
* but old-school UI shows in eulers always. Do we want to be able to still display in Eulers?
|
||||
* Maybe needs RNA/UI options to display rotations as different types. */
|
||||
v3d_transform_butsR(col, &pchanptr);
|
||||
v3d_transform_butsR(col, ob, &pchanptr);
|
||||
}
|
||||
|
||||
static void v3d_editarmature_buts(uiLayout *layout, Object *ob)
|
||||
|
@ -1708,11 +1641,6 @@ static void do_view3d_region_buttons(bContext *C, void * /*index*/, int event)
|
|||
DEG_id_tag_update(static_cast<ID *>(ob->data), ID_RECALC_GEOMETRY);
|
||||
}
|
||||
break;
|
||||
case B_TRANSFORM_PANEL_DIMS:
|
||||
if (ob) {
|
||||
v3d_object_dimension_buts(C, nullptr, v3d, ob);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* default for now */
|
||||
|
@ -1759,14 +1687,7 @@ static void view3d_panel_transform(const bContext *C, Panel *panel)
|
|||
}
|
||||
else {
|
||||
PointerRNA obptr = RNA_id_pointer_create(&ob->id);
|
||||
v3d_transform_butsR(col, &obptr);
|
||||
|
||||
/* Dimensions and editmode are mostly the same check. */
|
||||
if (OB_TYPE_SUPPORT_EDITMODE(ob->type) || ELEM(ob->type, OB_VOLUME, OB_CURVES, OB_POINTCLOUD))
|
||||
{
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
v3d_object_dimension_buts(nullptr, col, v3d, ob);
|
||||
}
|
||||
v3d_transform_butsR(col, ob, &obptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1244,6 +1244,7 @@ static void rna_Object_dimensions_set(PointerRNA *ptr, const float *value)
|
|||
{
|
||||
Object *ob = static_cast<Object *>(ptr->data);
|
||||
BKE_object_dimensions_set(ob, value, 0);
|
||||
|
||||
}
|
||||
|
||||
static int rna_Object_location_editable(PointerRNA *ptr, int index)
|
||||
|
@ -3245,11 +3246,8 @@ static void rna_def_object(BlenderRNA *brna)
|
|||
RNA_def_property_float_funcs(
|
||||
prop, "rna_Object_dimensions_get", "rna_Object_dimensions_set", nullptr);
|
||||
RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
|
||||
RNA_def_property_ui_text(prop,
|
||||
"Dimensions",
|
||||
"Absolute bounding box dimensions of the object.\n"
|
||||
"Warning: Assigning to it or its members multiple consecutive times "
|
||||
"will not work correctly, as this needs up-to-date evaluated data");
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Dimensions", "Absolute bounding box dimensions of the object.");
|
||||
RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
|
||||
|
||||
/* delta transforms */
|
||||
|
|
Loading…
Reference in New Issue