Transform: support for custom matrix property

Needed for situations when we can't use the orientation.

With extrude the initial extrusion recalculates normals for edges
and vertices which then don't give a useful axis.
This commit is contained in:
Campbell Barton 2018-11-01 07:24:10 +11:00
parent 798cd8a723
commit eb8ddaee4c
6 changed files with 30 additions and 2 deletions

View File

@ -2218,7 +2218,13 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
orientation = V3D_MANIP_CUSTOM + orientation_index_custom;
BLI_assert(orientation >= V3D_MANIP_CUSTOM);
}
RNA_enum_set(op->ptr, "constraint_orientation", orientation);
RNA_float_set_array(op->ptr, "constraint_matrix", &t->spacemtx[0][0]);
/* Use 'constraint_matrix' instead. */
if (orientation != V3D_MANIP_CUSTOM_MATRIX) {
RNA_enum_set(op->ptr, "constraint_orientation", orientation);
}
if (t->con.mode & CON_APPLY) {
if (t->con.mode & CON_AXIS0) {

View File

@ -701,6 +701,10 @@ void setUserConstraint(TransInfo *t, short orientation, int mode, const char fte
BLI_snprintf(text, sizeof(text), ftext, IFACE_("gimbal"));
setConstraint(t, t->spacemtx, mode, text);
break;
case V3D_MANIP_CUSTOM_MATRIX:
BLI_snprintf(text, sizeof(text), ftext, IFACE_("custom matrix"));
setConstraint(t, t->spacemtx, mode, text);
break;
case V3D_MANIP_CUSTOM:
{
char orientation_str[128];

View File

@ -1486,8 +1486,15 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
t->around = V3D_AROUND_CENTER_BOUNDS;
}
if (op && ((prop = RNA_struct_find_property(op->ptr, "constraint_orientation")) &&
if (op && ((prop = RNA_struct_find_property(op->ptr, "constraint_matrix")) &&
RNA_property_is_set(op->ptr, prop)))
{
RNA_property_float_get_array(op->ptr, prop, &t->spacemtx[0][0]);
t->current_orientation = V3D_MANIP_CUSTOM_MATRIX;
t->custom_orientation = 0;
}
else if (op && ((prop = RNA_struct_find_property(op->ptr, "constraint_orientation")) &&
RNA_property_is_set(op->ptr, prop)))
{
short orientation = RNA_property_enum_get(op->ptr, prop);
TransformOrientation *custom_orientation = NULL;

View File

@ -563,9 +563,15 @@ void Transform_Properties(struct wmOperatorType *ot, int flags)
if (flags & P_CONSTRAINT) {
RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
/* Set by 'constraint_orientation' or gizmo which acts on non-standard orientation. */
prop = RNA_def_float_matrix(ot->srna, "constraint_matrix", 3, 3, NULL, 0.0f, 0.0f, "Matrix", "", 0.0f, 0.0f);
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
prop = RNA_def_property(ot->srna, "constraint_orientation", PROP_ENUM, PROP_NONE);
RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
}
if (flags & P_MIRROR) {

View File

@ -487,6 +487,10 @@ void initTransformOrientation(bContext *C, TransInfo *t)
ED_view3d_cursor3d_calc_mat3(t->scene, CTX_wm_view3d(C), t->spacemtx);
break;
}
case V3D_MANIP_CUSTOM_MATRIX:
/* Already set. */
BLI_strncpy(t->spacename, IFACE_("custom"), sizeof(t->spacename));
break;
case V3D_MANIP_CUSTOM:
BLI_strncpy(t->spacename, t->custom_orientation->name, sizeof(t->spacename));

View File

@ -507,6 +507,7 @@ enum {
#define V3D_MANIP_VIEW 3
#define V3D_MANIP_GIMBAL 4
#define V3D_MANIP_CURSOR 5
#define V3D_MANIP_CUSTOM_MATRIX (V3D_MANIP_CUSTOM - 1) /* Runtime only, never saved to DNA. */
#define V3D_MANIP_CUSTOM 1024
/* View3d.mpr_flag (also) */