Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-09-03 21:18:49 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-09-03 21:23:18 +0300
commitc3fef001ee926fc183255b623f56da9fc5fcbb73 (patch)
tree493dcccebf779cb52f462a01c79407350da65286
parent54ad5766669a23976b9a9fab379bb44ba740c9be (diff)
View-Selected: use custom bones boundbox
Support using custom pose-bone transform and object when calculating view bounds.
-rw-r--r--source/blender/blenkernel/BKE_armature.h2
-rw-r--r--source/blender/blenkernel/BKE_object.h1
-rw-r--r--source/blender/blenkernel/intern/armature.c39
-rw-r--r--source/blender/blenkernel/intern/object.c41
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c20
5 files changed, 57 insertions, 46 deletions
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index a834a83ca00..2a674e5c2b9 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -80,6 +80,8 @@ struct bArmature *BKE_armature_copy(struct bArmature *arm);
/* Bounding box. */
struct BoundBox *BKE_armature_boundbox_get(struct Object *ob);
+bool BKE_pose_minmax(struct Object *ob, float r_min[3], float r_max[3], bool use_hidden, bool use_select);
+
int bone_autoside_name(char name[64], int strip_number, short axis, float head, float tail);
struct Bone *BKE_armature_find_bone_name(struct bArmature *arm, const char *name);
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 9482ec778d3..15ebfb54f41 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -142,6 +142,7 @@ bool BKE_boundbox_ray_hit_check(
float *r_lambda);
void BKE_boundbox_calc_center_aabb(const struct BoundBox *bb, float r_cent[3]);
void BKE_boundbox_calc_size_aabb(const struct BoundBox *bb, float r_size[3]);
+void BKE_boundbox_minmax(const struct BoundBox *bb, float obmat[4][4], float r_min[3], float r_max[3]);
struct BoundBox *BKE_object_boundbox_get(struct Object *ob);
void BKE_object_dimensions_get(struct Object *ob, float vec[3]);
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 232d0e21490..9bb8726cdb3 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -2209,6 +2209,45 @@ BoundBox *BKE_armature_boundbox_get(Object *ob)
return ob->bb;
}
+bool BKE_pose_minmax(Object *ob, float r_min[3], float r_max[3], bool use_hidden, bool use_select)
+{
+ bool changed = false;
+
+ if (ob->pose) {
+ bArmature *arm = ob->data;
+ bPoseChannel *pchan;
+
+ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ /* XXX pchan->bone may be NULL for duplicated bones, see duplicateEditBoneObjects() comment
+ * (editarmature.c:2592)... Skip in this case too! */
+ if (pchan->bone &&
+ (!((use_hidden == false) && (PBONE_VISIBLE(arm, pchan->bone) == false)) &&
+ !((use_select == true) && ((pchan->bone->flag & BONE_SELECTED) == 0))))
+ {
+ bPoseChannel *pchan_tx = (pchan->custom && pchan->custom_tx) ? pchan->custom_tx : pchan;
+ BoundBox *bb_custom = pchan->custom ? BKE_object_boundbox_get(pchan->custom) : NULL;
+
+ if (bb_custom) {
+ float mat[4][4];
+ mul_m4_m4m4(mat, ob->obmat, pchan_tx->pose_mat);
+ BKE_boundbox_minmax(bb_custom, mat, r_min, r_max);
+ }
+ else {
+ float vec[3];
+ mul_v3_m4v3(vec, ob->obmat, pchan_tx->pose_head);
+ minmax_v3v3_v3(r_min, r_max, vec);
+ mul_v3_m4v3(vec, ob->obmat, pchan_tx->pose_tail);
+ minmax_v3v3_v3(r_min, r_max, vec);
+ }
+
+ changed = true;
+ }
+ }
+ }
+
+ return changed;
+}
+
/************** Graph evaluation ********************/
bPoseChannel *BKE_armature_ik_solver_find_root(
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 63a66de28dd..fa20607ce30 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2655,6 +2655,16 @@ void BKE_boundbox_calc_size_aabb(const BoundBox *bb, float r_size[3])
r_size[2] = 0.5f * fabsf(bb->vec[0][2] - bb->vec[1][2]);
}
+void BKE_boundbox_minmax(const BoundBox *bb, float obmat[4][4], float r_min[3], float r_max[3])
+{
+ int i;
+ for (i = 0; i < 8; i++) {
+ float vec[3];
+ mul_v3_m4v3(vec, obmat, bb->vec[i]);
+ minmax_v3v3_v3(r_min, r_max, vec);
+ }
+}
+
BoundBox *BKE_object_boundbox_get(Object *ob)
{
BoundBox *bb = NULL;
@@ -2730,7 +2740,6 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3], const bool us
{
BoundBox bb;
float vec[3];
- int a;
bool changed = false;
switch (ob->type) {
@@ -2739,11 +2748,7 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3], const bool us
case OB_SURF:
{
bb = *BKE_curve_boundbox_get(ob);
-
- for (a = 0; a < 8; a++) {
- mul_m4_v3(ob->obmat, bb.vec[a]);
- minmax_v3v3_v3(min_r, max_r, bb.vec[a]);
- }
+ BKE_boundbox_minmax(&bb, ob->obmat, min_r, max_r);
changed = true;
break;
}
@@ -2766,23 +2771,7 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3], const bool us
}
case OB_ARMATURE:
{
- if (ob->pose) {
- bArmature *arm = ob->data;
- bPoseChannel *pchan;
-
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- /* XXX pchan->bone may be NULL for duplicated bones, see duplicateEditBoneObjects() comment
- * (editarmature.c:2592)... Skip in this case too! */
- if (pchan->bone && !((use_hidden == false) && (PBONE_VISIBLE(arm, pchan->bone) == false))) {
- mul_v3_m4v3(vec, ob->obmat, pchan->pose_head);
- minmax_v3v3_v3(min_r, max_r, vec);
- mul_v3_m4v3(vec, ob->obmat, pchan->pose_tail);
- minmax_v3v3_v3(min_r, max_r, vec);
-
- changed = true;
- }
- }
- }
+ changed = BKE_pose_minmax(ob, min_r, max_r, use_hidden, false);
break;
}
case OB_MESH:
@@ -2791,11 +2780,7 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3], const bool us
if (me) {
bb = *BKE_mesh_boundbox_get(ob);
-
- for (a = 0; a < 8; a++) {
- mul_m4_v3(ob->obmat, bb.vec[a]);
- minmax_v3v3_v3(min_r, max_r, bb.vec[a]);
- }
+ BKE_boundbox_minmax(&bb, ob->obmat, min_r, max_r);
changed = true;
}
break;
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 811eb7e731e..a14d3eab281 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -44,6 +44,7 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
+#include "BKE_armature.h"
#include "BKE_camera.h"
#include "BKE_context.h"
#include "BKE_font.h"
@@ -3042,24 +3043,7 @@ static int viewselected_exec(bContext *C, wmOperator *op)
ok = ED_view3d_minmax_verts(obedit, min, max); /* only selected */
}
else if (ob && (ob->mode & OB_MODE_POSE)) {
- if (ob->pose) {
- bArmature *arm = ob->data;
- bPoseChannel *pchan;
- float vec[3];
-
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- if (pchan->bone->flag & BONE_SELECTED) {
- if (pchan->bone->layer & arm->layer) {
- bPoseChannel *pchan_tx = pchan->custom_tx ? pchan->custom_tx : pchan;
- ok = 1;
- mul_v3_m4v3(vec, ob->obmat, pchan_tx->pose_head);
- minmax_v3v3_v3(min, max, vec);
- mul_v3_m4v3(vec, ob->obmat, pchan_tx->pose_tail);
- minmax_v3v3_v3(min, max, vec);
- }
- }
- }
- }
+ ok = BKE_pose_minmax(ob, min, max, true, true);
}
else if (BKE_paint_select_face_test(ob)) {
ok = paintface_minmax(ob, min, max);