add support for active-element in pose mode and armature editmode.
This works most usefully when combined with Normal orientation.
This commit is contained in:
@@ -361,18 +361,35 @@ int calc_manipulator_stats(const bContext *C)
|
||||
else if (obedit->type == OB_ARMATURE) {
|
||||
bArmature *arm = obedit->data;
|
||||
EditBone *ebo;
|
||||
for (ebo = arm->edbo->first; ebo; ebo = ebo->next) {
|
||||
if (EBONE_VISIBLE(arm, ebo)) {
|
||||
if (ebo->flag & BONE_TIPSEL) {
|
||||
calc_tw_center(scene, ebo->tail);
|
||||
totsel++;
|
||||
}
|
||||
if (ebo->flag & BONE_ROOTSEL) {
|
||||
calc_tw_center(scene, ebo->head);
|
||||
totsel++;
|
||||
}
|
||||
if (ebo->flag & BONE_SELECTED) {
|
||||
stats_editbone(rv3d, ebo);
|
||||
|
||||
if ((v3d->around == V3D_ACTIVE) && (ebo = arm->act_edbone)) {
|
||||
/* doesn't check selection or visibility intentionally */
|
||||
if (ebo->flag & BONE_TIPSEL) {
|
||||
calc_tw_center(scene, ebo->tail);
|
||||
totsel++;
|
||||
}
|
||||
if ((ebo->flag & BONE_ROOTSEL) ||
|
||||
((ebo->flag & BONE_TIPSEL) == FALSE)) /* ensure we get at least one point */
|
||||
{
|
||||
calc_tw_center(scene, ebo->head);
|
||||
totsel++;
|
||||
}
|
||||
stats_editbone(rv3d, ebo);
|
||||
}
|
||||
else {
|
||||
for (ebo = arm->edbo->first; ebo; ebo = ebo->next) {
|
||||
if (EBONE_VISIBLE(arm, ebo)) {
|
||||
if (ebo->flag & BONE_TIPSEL) {
|
||||
calc_tw_center(scene, ebo->tail);
|
||||
totsel++;
|
||||
}
|
||||
if (ebo->flag & BONE_ROOTSEL) {
|
||||
calc_tw_center(scene, ebo->head);
|
||||
totsel++;
|
||||
}
|
||||
if (ebo->flag & BONE_SELECTED) {
|
||||
stats_editbone(rv3d, ebo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -480,17 +497,29 @@ int calc_manipulator_stats(const bContext *C)
|
||||
else if (ob && (ob->mode & OB_MODE_POSE)) {
|
||||
bPoseChannel *pchan;
|
||||
int mode = TFM_ROTATION; // mislead counting bones... bah. We don't know the manipulator mode, could be mixed
|
||||
int ok = FALSE;
|
||||
|
||||
if ((ob->lay & v3d->lay) == 0) return 0;
|
||||
|
||||
totsel = count_set_pose_transflags(&mode, 0, ob);
|
||||
if ((v3d->around == V3D_ACTIVE) && (pchan = BKE_pose_channel_active(ob))) {
|
||||
/* doesn't check selection or visibility intentionally */
|
||||
stats_pose(scene, rv3d, pchan);
|
||||
totsel = 1;
|
||||
ok = TRUE;
|
||||
}
|
||||
else {
|
||||
totsel = count_set_pose_transflags(&mode, 0, ob);
|
||||
|
||||
if (totsel) {
|
||||
/* use channels to get stats */
|
||||
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
|
||||
stats_pose(scene, rv3d, pchan);
|
||||
if (totsel) {
|
||||
/* use channels to get stats */
|
||||
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
|
||||
stats_pose(scene, rv3d, pchan);
|
||||
}
|
||||
ok = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
mul_v3_fl(scene->twcent, 1.0f / (float)totsel); // centroid!
|
||||
mul_m4_v3(ob->obmat, scene->twcent);
|
||||
mul_m4_v3(ob->obmat, scene->twmin);
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BKE_action.h"
|
||||
#include "BKE_armature.h"
|
||||
#include "BKE_curve.h"
|
||||
#include "BKE_context.h"
|
||||
@@ -761,29 +762,45 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
|
||||
else if (obedit->type == OB_ARMATURE) {
|
||||
bArmature *arm = obedit->data;
|
||||
EditBone *ebone;
|
||||
int ok = FALSE;
|
||||
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
if (arm->layer & ebone->layer) {
|
||||
if (ebone->flag & BONE_SELECTED) {
|
||||
float tmat[3][3];
|
||||
float vec[3];
|
||||
sub_v3_v3v3(vec, ebone->tail, ebone->head);
|
||||
normalize_v3(vec);
|
||||
add_v3_v3(normal, vec);
|
||||
|
||||
vec_roll_to_mat3(vec, ebone->roll, tmat);
|
||||
add_v3_v3(plane, tmat[2]);
|
||||
/* grr,.but better then duplicate code */
|
||||
#define EBONE_CALC_NORMAL_PLANE { \
|
||||
float tmat[3][3]; \
|
||||
float vec[3]; \
|
||||
sub_v3_v3v3(vec, ebone->tail, ebone->head); \
|
||||
normalize_v3(vec); \
|
||||
add_v3_v3(normal, vec); \
|
||||
\
|
||||
vec_roll_to_mat3(vec, ebone->roll, tmat); \
|
||||
add_v3_v3(plane, tmat[2]); \
|
||||
} (void)0
|
||||
|
||||
|
||||
if (activeOnly && (ebone = arm->act_edbone)) {
|
||||
EBONE_CALC_NORMAL_PLANE;
|
||||
ok = TRUE;
|
||||
}
|
||||
else {
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
if (arm->layer & ebone->layer) {
|
||||
if (ebone->flag & BONE_SELECTED) {
|
||||
EBONE_CALC_NORMAL_PLANE;
|
||||
ok = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
normalize_v3(normal);
|
||||
normalize_v3(plane);
|
||||
if (ok) {
|
||||
normalize_v3(normal);
|
||||
normalize_v3(plane);
|
||||
|
||||
if (!is_zero_v3(plane)) {
|
||||
result = ORIENTATION_EDGE;
|
||||
if (!is_zero_v3(plane)) {
|
||||
result = ORIENTATION_EDGE;
|
||||
}
|
||||
}
|
||||
|
||||
#undef EBONE_CALC_NORMAL_PLANE
|
||||
}
|
||||
|
||||
/* Vectors from edges don't need the special transpose inverse multiplication */
|
||||
@@ -799,19 +816,32 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
|
||||
else if (ob && (ob->mode & OB_MODE_POSE)) {
|
||||
bArmature *arm = ob->data;
|
||||
bPoseChannel *pchan;
|
||||
int totsel;
|
||||
|
||||
totsel = count_bone_select(arm, &arm->bonebase, 1);
|
||||
if (totsel) {
|
||||
float imat[3][3], mat[3][3];
|
||||
float imat[3][3], mat[3][3];
|
||||
int ok = FALSE;
|
||||
|
||||
/* use channels to get stats */
|
||||
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
|
||||
if (pchan->bone && pchan->bone->flag & BONE_TRANSFORM) {
|
||||
add_v3_v3(normal, pchan->pose_mat[2]);
|
||||
add_v3_v3(plane, pchan->pose_mat[1]);
|
||||
if (activeOnly && (pchan = BKE_pose_channel_active(ob))) {
|
||||
add_v3_v3(normal, pchan->pose_mat[2]);
|
||||
add_v3_v3(plane, pchan->pose_mat[1]);
|
||||
ok = TRUE;
|
||||
}
|
||||
else {
|
||||
int totsel;
|
||||
|
||||
totsel = count_bone_select(arm, &arm->bonebase, 1);
|
||||
if (totsel) {
|
||||
/* use channels to get stats */
|
||||
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
|
||||
if (pchan->bone && pchan->bone->flag & BONE_TRANSFORM) {
|
||||
add_v3_v3(normal, pchan->pose_mat[2]);
|
||||
add_v3_v3(plane, pchan->pose_mat[1]);
|
||||
}
|
||||
}
|
||||
ok = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* use for both active & all */
|
||||
if (ok) {
|
||||
negate_v3(plane);
|
||||
|
||||
/* we need the transpose of the inverse for a normal... */
|
||||
|
||||
Reference in New Issue
Block a user