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:
Diffstat (limited to 'source/blender/editors/transform/transform_snap.c')
-rw-r--r--source/blender/editors/transform/transform_snap.c98
1 files changed, 59 insertions, 39 deletions
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 5cb3f262ced..f128b903183 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -272,17 +272,19 @@ void applyProject(TransInfo *t)
{
/* XXX FLICKER IN OBJECT MODE */
if ((t->tsnap.project) && activeSnap(t) && (t->flag & T_NO_PROJECT) == 0) {
- TransData *td = t->data;
float tvec[3];
- float imat[4][4];
int i;
-
+
+ FOREACH_TRANS_DATA_CONTAINER(t, tc) {
+ TransData *td = tc->data;
+
+ float imat[4][4];
if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
+ Object *ob = tc->obedit ? tc->obedit : tc->poseobj;
invert_m4_m4(imat, ob->obmat);
}
- for (i = 0; i < t->total; i++, td++) {
+ for (i = 0; i < tc->data_len; i++, td++) {
float iloc[3], loc[3], no[3];
float mval_fl[2];
float dist_px = TRANSFORM_DIST_MAX_PX;
@@ -298,7 +300,7 @@ void applyProject(TransInfo *t)
copy_v3_v3(iloc, td->loc);
if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
+ Object *ob = tc->obedit ? tc->obedit : tc->poseobj;
mul_m4_v3(ob->obmat, iloc);
}
else if (t->flag & T_OBJECT) {
@@ -340,6 +342,7 @@ void applyProject(TransInfo *t)
//XXX constraintTransLim(t, td);
}
+ }
}
}
@@ -347,7 +350,6 @@ void applyGridAbsolute(TransInfo *t)
{
float grid_size = 0.0f;
GearsType grid_action;
- TransData *td;
float (*obmat)[4] = NULL;
bool use_obmat = false;
int i;
@@ -368,13 +370,16 @@ void applyGridAbsolute(TransInfo *t)
if (grid_size == 0.0f)
return;
+ FOREACH_TRANS_DATA_CONTAINER(t, tc) {
+ TransData *td;
+
if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
+ Object *ob = tc->obedit ? tc->obedit : tc->poseobj;
obmat = ob->obmat;
use_obmat = true;
}
- for (i = 0, td = t->data; i < t->total; i++, td++) {
+ for (i = 0, td = tc->data; i < tc->data_len; i++, td++) {
float iloc[3], loc[3], tvec[3];
if (td->flag & TD_NOACTION)
@@ -405,6 +410,7 @@ void applyGridAbsolute(TransInfo *t)
mul_m3_v3(td->smtx, tvec);
add_v3_v3(td->loc, tvec);
}
+ }
}
void applySnapping(TransInfo *t, float *vec)
@@ -501,7 +507,8 @@ static bool bm_face_is_snap_target(BMFace *f, void *UNUSED(user_data))
static void initSnappingMode(TransInfo *t)
{
ToolSettings *ts = t->settings;
- Object *obedit = t->obedit;
+ /* All obedit types will match. */
+ const int obedit_type = t->data_container->obedit ? t->data_container->obedit->type : -1;
ViewLayer *view_layer = t->view_layer;
Base *base_act = view_layer->basact;
@@ -532,10 +539,10 @@ static void initSnappingMode(TransInfo *t)
/* Edit mode */
if (t->tsnap.applySnap != NULL && // A snapping function actually exist
- (obedit != NULL && ELEM(obedit->type, OB_MESH, OB_ARMATURE, OB_CURVE, OB_LATTICE, OB_MBALL)) ) // Temporary limited to edit mode meshes, armature, curves, mballs
+ ((obedit_type != -1) && ELEM(obedit_type, OB_MESH, OB_ARMATURE, OB_CURVE, OB_LATTICE, OB_MBALL)) ) // Temporary limited to edit mode meshes, armature, curves, mballs
{
/* Exclude editmesh if using proportional edit */
- if ((obedit->type == OB_MESH) && (t->flag & T_PROP_EDIT)) {
+ if ((obedit_type == OB_MESH) && (t->flag & T_PROP_EDIT)) {
t->tsnap.modeSelect = SNAP_NOT_ACTIVE;
}
else {
@@ -544,13 +551,13 @@ static void initSnappingMode(TransInfo *t)
}
/* Particles edit mode*/
else if (t->tsnap.applySnap != NULL && // A snapping function actually exist
- (obedit == NULL && base_act && base_act->object && base_act->object->mode & OB_MODE_PARTICLE_EDIT))
+ ((obedit_type == -1) && base_act && base_act->object && base_act->object->mode & OB_MODE_PARTICLE_EDIT))
{
t->tsnap.modeSelect = SNAP_ALL;
}
/* Object mode */
else if (t->tsnap.applySnap != NULL && // A snapping function actually exist
- (obedit == NULL) ) // Object Mode
+ (obedit_type == -1) ) // Object Mode
{
/* In "Edit Strokes" mode, Snap tool can perform snap to selected or active objects (see T49632)
* TODO: perform self snap in gpencil_strokes */
@@ -863,7 +870,8 @@ static float TranslationBetween(TransInfo *UNUSED(t), const float p1[3], const f
return len_squared_v3v3(p1, p2);
}
-static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3])
+static float RotationBetween(
+ TransInfo *t, const float p1[3], const float p2[3])
{
float angle, start[3], end[3];
@@ -874,7 +882,7 @@ static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3])
if (t->con.applyRot != NULL && (t->con.mode & CON_APPLY)) {
float axis[3], tmp[3];
- t->con.applyRot(t, NULL, axis, NULL);
+ t->con.applyRot(t, NULL, NULL, axis, NULL);
project_v3_v3v3(tmp, end, axis);
sub_v3_v3v3(end, end, tmp);
@@ -977,14 +985,14 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
t->tsnap.status &= ~POINT_INIT;
}
}
- else if (t->spacetype == SPACE_IMAGE && t->obedit != NULL && t->obedit->type == OB_MESH) {
+ else if (t->spacetype == SPACE_IMAGE && t->obedit_type == OB_MESH) {
/* same as above but for UV's */
Image *ima = ED_space_image(t->sa->spacedata.first);
float co[2];
UI_view2d_region_to_view(&t->ar->v2d, t->mval[0], t->mval[1], &co[0], &co[1]);
- if (ED_uvedit_nearest_uv(t->scene, t->obedit, ima, co, t->tsnap.snapPoint)) {
+ if (ED_uvedit_nearest_uv(t->scene, TRANS_DATA_CONTAINER_FIRST_EVIL(t)->obedit, ima, co, t->tsnap.snapPoint)) {
t->tsnap.snapPoint[0] *= t->aspect[0];
t->tsnap.snapPoint[1] *= t->aspect[1];
@@ -1059,11 +1067,6 @@ static void TargetSnapActive(TransInfo *t)
/* Only need to calculate once */
if ((t->tsnap.status & TARGET_INIT) == 0) {
if (calculateCenterActive(t, true, t->tsnap.snapTarget)) {
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- mul_m4_v3(ob->obmat, t->tsnap.snapTarget);
- }
-
TargetSnapOffset(t, NULL);
t->tsnap.status |= TARGET_INIT;
@@ -1081,23 +1084,34 @@ static void TargetSnapMedian(TransInfo *t)
{
// Only need to calculate once
if ((t->tsnap.status & TARGET_INIT) == 0) {
- TransData *td = NULL;
- int i;
+ int i_accum = 0;
t->tsnap.snapTarget[0] = 0;
t->tsnap.snapTarget[1] = 0;
t->tsnap.snapTarget[2] = 0;
-
- for (td = t->data, i = 0; i < t->total && td->flag & TD_SELECTED; i++, td++) {
- add_v3_v3(t->tsnap.snapTarget, td->center);
- }
-
- mul_v3_fl(t->tsnap.snapTarget, 1.0 / i);
-
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- mul_m4_v3(ob->obmat, t->tsnap.snapTarget);
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ Object *ob_xform = NULL;
+ if (t->flag & (T_EDIT | T_POSE)) {
+ ob_xform = tc->obedit ? tc->obedit : tc->poseobj;
+ }
+ TransData *td = tc->data;
+ int i;
+ for (i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) {
+ /* TODO(campbell): perform the global transformation once per TransDataContainer */
+ if (ob_xform) {
+ float v[3];
+ mul_v3_m4v3(v, ob_xform->obmat, td->center);
+ add_v3_v3(t->tsnap.snapTarget, v);
+ }
+ else {
+ add_v3_v3(t->tsnap.snapTarget, td->center);
+ }
+ }
+ i_accum += i;
}
+
+ mul_v3_fl(t->tsnap.snapTarget, 1.0 / i_accum);
TargetSnapOffset(t, NULL);
@@ -1110,12 +1124,14 @@ static void TargetSnapClosest(TransInfo *t)
// Only valid if a snap point has been selected
if (t->tsnap.status & POINT_INIT) {
float dist_closest = 0.0f;
- TransData *closest = NULL, *td = NULL;
+ TransData *closest = NULL;
/* Object mode */
if (t->flag & T_OBJECT) {
int i;
- for (td = t->data, i = 0; i < t->total && td->flag & TD_SELECTED; i++, td++) {
+ FOREACH_TRANS_DATA_CONTAINER(t, tc) {
+ TransData *td = tc->data;
+ for (td = tc->data, i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) {
struct BoundBox *bb = BKE_object_boundbox_get(td->ob);
/* use boundbox if possible */
@@ -1157,17 +1173,20 @@ static void TargetSnapClosest(TransInfo *t)
}
}
}
+ }
}
else {
+ FOREACH_TRANS_DATA_CONTAINER(t, tc) {
+ TransData *td = tc->data;
int i;
- for (td = t->data, i = 0; i < t->total && td->flag & TD_SELECTED; i++, td++) {
+ for (i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) {
float loc[3];
float dist;
copy_v3_v3(loc, td->center);
if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
+ Object *ob = tc->obedit ? tc->obedit : tc->poseobj;
mul_m4_v3(ob->obmat, loc);
}
@@ -1181,6 +1200,7 @@ static void TargetSnapClosest(TransInfo *t)
dist_closest = dist;
}
}
+ }
}
TargetSnapOffset(t, closest);