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:
authorMartin Poirier <theeth@yahoo.com>2009-10-13 02:33:32 +0400
committerMartin Poirier <theeth@yahoo.com>2009-10-13 02:33:32 +0400
commit3a1216a2f299025c992561f55c0bb29034c79bdf (patch)
treefa8248f553582e5442810853a8e7f084c28bd947 /source/blender/editors/transform
parent1fc616351ba8ead153c0c951a91cfadcd740cc17 (diff)
Project option for snap to faces.
This is similar to the old retopo all option but uses the snapping code and not the openGL depth buffer (it's thus more precise). Not sure if making it available as a snap option is sensible, this is up for discussion. NOTE: it will get slow fast on large meshes, we need to plug in an acceleration structure into snapping. This will need an icon too.
Diffstat (limited to 'source/blender/editors/transform')
-rw-r--r--source/blender/editors/transform/transform.c1
-rw-r--r--source/blender/editors/transform/transform.h2
-rw-r--r--source/blender/editors/transform/transform_conversions.c7
-rw-r--r--source/blender/editors/transform/transform_generics.c341
-rw-r--r--source/blender/editors/transform/transform_ops.c34
-rw-r--r--source/blender/editors/transform/transform_snap.c115
6 files changed, 273 insertions, 227 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 0b7a672a0b6..4c24d366162 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -2605,7 +2605,6 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
center = td->center;
}
else {
- /* !TODO! Make this if not rely on G */
if(around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
center = td->center;
}
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 60786127e3a..5cee1f51b0a 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -87,6 +87,7 @@ typedef struct TransSnap {
short modeTarget;
short mode;
short align;
+ short project;
short status;
float snapPoint[3]; /* snapping from this point */
float snapTarget[3]; /* to this point */
@@ -578,6 +579,7 @@ void snapGrid(TransInfo *t, float *val);
void snapGridAction(TransInfo *t, float *val, GearsType action);
void initSnapping(struct TransInfo *t, struct wmOperator *op);
+void applyProject(TransInfo *t);
void applySnapping(TransInfo *t, float *vec);
void resetSnapping(TransInfo *t);
int handleSnapping(TransInfo *t, struct wmEvent *event);
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 51ce87803fd..826fcb0c2dd 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -125,7 +125,6 @@
#include "ED_object.h"
#include "ED_markers.h"
#include "ED_mesh.h"
-#include "ED_retopo.h"
#include "ED_types.h"
#include "ED_uvedit.h"
#include "ED_view3d.h"
@@ -4478,12 +4477,6 @@ void special_aftertrans_update(TransInfo *t)
if (t->obedit) {
if (cancelled==0) {
EM_automerge(t->scene, t->obedit, 1);
-#if 0 // TRANSFORM_FIX_ME
- /* when snapping, delay retopo until after automerge */
- if (G.qual & LR_CTRLKEY) {
- retopo_do_all();
- }
-#endif
}
}
}
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index c3ceea1a0c8..20d136e4790 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -91,7 +91,6 @@
#include "ED_keyframing.h"
#include "ED_markers.h"
#include "ED_mesh.h"
-#include "ED_retopo.h"
#include "ED_particle.h"
#include "ED_screen_types.h"
#include "ED_space_api.h"
@@ -617,201 +616,201 @@ void recalcData(TransInfo *t)
}
}
}
- else if (t->obedit) {
- if ELEM(t->obedit->type, OB_CURVE, OB_SURF) {
- Curve *cu= t->obedit->data;
- Nurb *nu= cu->editnurb->first;
-
- DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA); /* sets recalc flags */
-
- if (t->state == TRANS_CANCEL) {
- while(nu) {
- calchandlesNurb(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
- nu= nu->next;
- }
- } else {
- /* Normal updating */
- while(nu) {
- test2DNurb(nu);
- calchandlesNurb(nu);
- nu= nu->next;
- }
- /* TRANSFORM_FIX_ME */
- // retopo_do_all();
- }
- }
- else if(t->obedit->type==OB_LATTICE) {
- Lattice *la= t->obedit->data;
- DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA); /* sets recalc flags */
-
- if(la->editlatt->flag & LT_OUTSIDE) outside_lattice(la->editlatt);
+ else if (t->spacetype == SPACE_VIEW3D) {
+
+ /* project */
+ if(t->state != TRANS_CANCEL) {
+ applyProject(t);
}
- else if (t->obedit->type == OB_MESH) {
- if(t->spacetype==SPACE_IMAGE) {
- SpaceImage *sima= t->sa->spacedata.first;
+
+ if (t->obedit) {
+ if ELEM(t->obedit->type, OB_CURVE, OB_SURF) {
+ Curve *cu= t->obedit->data;
+ Nurb *nu= cu->editnurb->first;
- flushTransUVs(t);
- if(sima->flag & SI_LIVE_UNWRAP)
- ED_uvedit_live_unwrap_re_solve();
+ DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA); /* sets recalc flags */
- DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA);
- } else {
- EditMesh *em = ((Mesh*)t->obedit->data)->edit_mesh;
- /* mirror modifier clipping? */
- if(t->state != TRANS_CANCEL) {
- /* TRANSFORM_FIX_ME */
-// if ((G.qual & LR_CTRLKEY)==0) {
-// /* Only retopo if not snapping, Note, this is the only case of G.qual being used, but we have no T_SHIFT_MOD - Campbell */
-// retopo_do_all();
-// }
- clipMirrorModifier(t, t->obedit);
+ if (t->state == TRANS_CANCEL) {
+ while(nu) {
+ calchandlesNurb(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
+ nu= nu->next;
+ }
+ } else {
+ /* Normal updating */
+ while(nu) {
+ test2DNurb(nu);
+ calchandlesNurb(nu);
+ nu= nu->next;
+ }
}
- if((t->options & CTX_NO_MIRROR) == 0 && (t->flag & T_MIRROR))
- editmesh_apply_to_mirror(t);
-
+ }
+ else if(t->obedit->type==OB_LATTICE) {
+ Lattice *la= t->obedit->data;
DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA); /* sets recalc flags */
-
- recalc_editnormals(em);
+
+ if(la->editlatt->flag & LT_OUTSIDE) outside_lattice(la->editlatt);
}
- }
- else if(t->obedit->type==OB_ARMATURE) { /* no recalc flag, does pose */
- bArmature *arm= t->obedit->data;
- ListBase *edbo = arm->edbo;
- EditBone *ebo;
- TransData *td = t->data;
- int i;
-
- /* Ensure all bones are correctly adjusted */
- for (ebo = edbo->first; ebo; ebo = ebo->next){
-
- if ((ebo->flag & BONE_CONNECTED) && ebo->parent){
- /* If this bone has a parent tip that has been moved */
- if (ebo->parent->flag & BONE_TIPSEL){
- VECCOPY (ebo->head, ebo->parent->tail);
- if(t->mode==TFM_BONE_ENVELOPE) ebo->rad_head= ebo->parent->rad_tail;
- }
- /* If this bone has a parent tip that has NOT been moved */
- else{
- VECCOPY (ebo->parent->tail, ebo->head);
- if(t->mode==TFM_BONE_ENVELOPE) ebo->parent->rad_tail= ebo->rad_head;
+ else if (t->obedit->type == OB_MESH) {
+ if(t->spacetype==SPACE_IMAGE) {
+ SpaceImage *sima= t->sa->spacedata.first;
+
+ flushTransUVs(t);
+ if(sima->flag & SI_LIVE_UNWRAP)
+ ED_uvedit_live_unwrap_re_solve();
+
+ DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA);
+ } else {
+ EditMesh *em = ((Mesh*)t->obedit->data)->edit_mesh;
+ /* mirror modifier clipping? */
+ if(t->state != TRANS_CANCEL) {
+ clipMirrorModifier(t, t->obedit);
}
+ if((t->options & CTX_NO_MIRROR) == 0 && (t->flag & T_MIRROR))
+ editmesh_apply_to_mirror(t);
+
+ DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA); /* sets recalc flags */
+
+ recalc_editnormals(em);
}
+ }
+ else if(t->obedit->type==OB_ARMATURE) { /* no recalc flag, does pose */
+ bArmature *arm= t->obedit->data;
+ ListBase *edbo = arm->edbo;
+ EditBone *ebo;
+ TransData *td = t->data;
+ int i;
- /* on extrude bones, oldlength==0.0f, so we scale radius of points */
- ebo->length= VecLenf(ebo->head, ebo->tail);
- if(ebo->oldlength==0.0f) {
- ebo->rad_head= 0.25f*ebo->length;
- ebo->rad_tail= 0.10f*ebo->length;
- ebo->dist= 0.25f*ebo->length;
- if(ebo->parent) {
- if(ebo->rad_head > ebo->parent->rad_tail)
- ebo->rad_head= ebo->parent->rad_tail;
+ /* Ensure all bones are correctly adjusted */
+ for (ebo = edbo->first; ebo; ebo = ebo->next){
+
+ if ((ebo->flag & BONE_CONNECTED) && ebo->parent){
+ /* If this bone has a parent tip that has been moved */
+ if (ebo->parent->flag & BONE_TIPSEL){
+ VECCOPY (ebo->head, ebo->parent->tail);
+ if(t->mode==TFM_BONE_ENVELOPE) ebo->rad_head= ebo->parent->rad_tail;
+ }
+ /* If this bone has a parent tip that has NOT been moved */
+ else{
+ VECCOPY (ebo->parent->tail, ebo->head);
+ if(t->mode==TFM_BONE_ENVELOPE) ebo->parent->rad_tail= ebo->rad_head;
+ }
+ }
+
+ /* on extrude bones, oldlength==0.0f, so we scale radius of points */
+ ebo->length= VecLenf(ebo->head, ebo->tail);
+ if(ebo->oldlength==0.0f) {
+ ebo->rad_head= 0.25f*ebo->length;
+ ebo->rad_tail= 0.10f*ebo->length;
+ ebo->dist= 0.25f*ebo->length;
+ if(ebo->parent) {
+ if(ebo->rad_head > ebo->parent->rad_tail)
+ ebo->rad_head= ebo->parent->rad_tail;
+ }
+ }
+ else if(t->mode!=TFM_BONE_ENVELOPE) {
+ /* if bones change length, lets do that for the deform distance as well */
+ ebo->dist*= ebo->length/ebo->oldlength;
+ ebo->rad_head*= ebo->length/ebo->oldlength;
+ ebo->rad_tail*= ebo->length/ebo->oldlength;
+ ebo->oldlength= ebo->length;
}
}
- else if(t->mode!=TFM_BONE_ENVELOPE) {
- /* if bones change length, lets do that for the deform distance as well */
- ebo->dist*= ebo->length/ebo->oldlength;
- ebo->rad_head*= ebo->length/ebo->oldlength;
- ebo->rad_tail*= ebo->length/ebo->oldlength;
- ebo->oldlength= ebo->length;
- }
- }
-
-
- if (t->mode != TFM_BONE_ROLL)
- {
- /* fix roll */
- for(i = 0; i < t->total; i++, td++)
+
+
+ if (t->mode != TFM_BONE_ROLL)
{
- if (td->extra)
+ /* fix roll */
+ for(i = 0; i < t->total; i++, td++)
{
- float vec[3], up_axis[3];
- float qrot[4];
-
- ebo = td->extra;
- VECCOPY(up_axis, td->axismtx[2]);
-
- if (t->mode != TFM_ROTATION)
+ if (td->extra)
{
- VecSubf(vec, ebo->tail, ebo->head);
- Normalize(vec);
- RotationBetweenVectorsToQuat(qrot, td->axismtx[1], vec);
- QuatMulVecf(qrot, up_axis);
- }
- else
- {
- Mat3MulVecfl(t->mat, up_axis);
+ float vec[3], up_axis[3];
+ float qrot[4];
+
+ ebo = td->extra;
+ VECCOPY(up_axis, td->axismtx[2]);
+
+ if (t->mode != TFM_ROTATION)
+ {
+ VecSubf(vec, ebo->tail, ebo->head);
+ Normalize(vec);
+ RotationBetweenVectorsToQuat(qrot, td->axismtx[1], vec);
+ QuatMulVecf(qrot, up_axis);
+ }
+ else
+ {
+ Mat3MulVecfl(t->mat, up_axis);
+ }
+
+ ebo->roll = ED_rollBoneToVector(ebo, up_axis);
}
-
- ebo->roll = ED_rollBoneToVector(ebo, up_axis);
}
}
+
+ if(arm->flag & ARM_MIRROR_EDIT)
+ transform_armature_mirror_update(t->obedit);
+
}
-
- if(arm->flag & ARM_MIRROR_EDIT)
- transform_armature_mirror_update(t->obedit);
-
- }
- else
- DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA); /* sets recalc flags */
- }
- else if( (t->flag & T_POSE) && t->poseobj) {
- Object *ob= t->poseobj;
- bArmature *arm= ob->data;
-
- /* if animtimer is running, and the object already has animation data,
- * check if the auto-record feature means that we should record 'samples'
- * (i.e. uneditable animation values)
- */
- // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
- if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
- int targetless_ik= (t->flag & T_AUTOIK); // XXX this currently doesn't work, since flags aren't set yet!
-
- animrecord_check_state(t->scene, &ob->id, t->animtimer);
- autokeyframe_pose_cb_func(t->scene, (View3D *)t->view, ob, t->mode, targetless_ik);
- }
-
- /* old optimize trick... this enforces to bypass the depgraph */
- if (!(arm->flag & ARM_DELAYDEFORM)) {
- DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */
+ else
+ DAG_id_flush_update(t->obedit->data, OB_RECALC_DATA); /* sets recalc flags */
}
- else
- where_is_pose(scene, ob);
- }
- else {
- for(base= FIRSTBASE; base; base= base->next) {
- Object *ob= base->object;
+ else if( (t->flag & T_POSE) && t->poseobj) {
+ Object *ob= t->poseobj;
+ bArmature *arm= ob->data;
- /* this flag is from depgraph, was stored in initialize phase, handled in drawview.c */
- if(base->flag & BA_HAS_RECALC_OB)
- ob->recalc |= OB_RECALC_OB;
- if(base->flag & BA_HAS_RECALC_DATA)
- ob->recalc |= OB_RECALC_DATA;
+ /* if animtimer is running, and the object already has animation data,
+ * check if the auto-record feature means that we should record 'samples'
+ * (i.e. uneditable animation values)
+ */
+ // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
+ if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
+ int targetless_ik= (t->flag & T_AUTOIK); // XXX this currently doesn't work, since flags aren't set yet!
+
+ animrecord_check_state(t->scene, &ob->id, t->animtimer);
+ autokeyframe_pose_cb_func(t->scene, (View3D *)t->view, ob, t->mode, targetless_ik);
+ }
- /* if object/base is selected */
- if ((base->flag & SELECT) || (ob->flag & SELECT)) {
- /* if animtimer is running, and the object already has animation data,
- * check if the auto-record feature means that we should record 'samples'
- * (i.e. uneditable animation values)
- */
- // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
- if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
- animrecord_check_state(t->scene, &ob->id, t->animtimer);
- autokeyframe_ob_cb_func(t->scene, (View3D *)t->view, ob, t->mode);
+ /* old optimize trick... this enforces to bypass the depgraph */
+ if (!(arm->flag & ARM_DELAYDEFORM)) {
+ DAG_id_flush_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */
+ }
+ else
+ where_is_pose(scene, ob);
+ }
+ else {
+ for(base= FIRSTBASE; base; base= base->next) {
+ Object *ob= base->object;
+
+ /* this flag is from depgraph, was stored in initialize phase, handled in drawview.c */
+ if(base->flag & BA_HAS_RECALC_OB)
+ ob->recalc |= OB_RECALC_OB;
+ if(base->flag & BA_HAS_RECALC_DATA)
+ ob->recalc |= OB_RECALC_DATA;
+
+ /* if object/base is selected */
+ if ((base->flag & SELECT) || (ob->flag & SELECT)) {
+ /* if animtimer is running, and the object already has animation data,
+ * check if the auto-record feature means that we should record 'samples'
+ * (i.e. uneditable animation values)
+ */
+ // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
+ if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
+ animrecord_check_state(t->scene, &ob->id, t->animtimer);
+ autokeyframe_ob_cb_func(t->scene, (View3D *)t->view, ob, t->mode);
+ }
}
+
+ /* proxy exception */
+ if(ob->proxy)
+ ob->proxy->recalc |= ob->recalc;
+ if(ob->proxy_group)
+ group_tag_recalc(ob->proxy_group->dup_group);
}
-
- /* proxy exception */
- if(ob->proxy)
- ob->proxy->recalc |= ob->recalc;
- if(ob->proxy_group)
- group_tag_recalc(ob->proxy_group->dup_group);
}
+
+ if(t->spacetype==SPACE_VIEW3D && ((View3D*)t->view)->drawtype == OB_SHADED)
+ reshadeall_displist(t->scene);
}
-
- /* update shaded drawmode while transform */
- if(t->spacetype==SPACE_VIEW3D && ((View3D*)t->view)->drawtype == OB_SHADED)
- reshadeall_displist(t->scene);
}
void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)
diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index b0e79b3b062..3408f6cf3f7 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -63,32 +63,6 @@ EnumPropertyItem proportional_mode_types[] = {
{0, NULL, 0, NULL, NULL}
};
-EnumPropertyItem snap_mode_types[] = {
- {SCE_SNAP_TARGET_CLOSEST, "CLOSEST", 0, "Closest", ""},
- {SCE_SNAP_TARGET_CENTER, "CENTER", 0, "Center", ""},
- {SCE_SNAP_TARGET_MEDIAN, "MEDIAN", 0, "Median", ""},
- {SCE_SNAP_TARGET_ACTIVE, "ACTIVE", 0, "Active", ""},
- {0, NULL, 0, NULL, NULL}
-};
-
-EnumPropertyItem proportional_falloff_types[] = {
- {PROP_SMOOTH, "SMOOTH", 0, "Smooth", ""},
- {PROP_SPHERE, "SPHERE", 0, "Sphere", ""},
- {PROP_ROOT, "ROOT", 0, "Root", ""},
- {PROP_SHARP, "SHARP", 0, "Sharp", ""},
- {PROP_LIN, "LINEAR", 0, "Linear", ""},
- {PROP_CONST, "CONSTANT", 0, "Constant", ""},
- {PROP_RANDOM, "RANDOM", 0, "Random", ""},
- {0, NULL, 0, NULL, NULL}
-};
-
-EnumPropertyItem orientation_items[]= {
- {V3D_MANIP_GLOBAL, "GLOBAL", 0, "Global", ""},
- {V3D_MANIP_NORMAL, "NORMAL", 0, "Normal", ""},
- {V3D_MANIP_LOCAL, "LOCAL", 0, "Local", ""},
- {V3D_MANIP_VIEW, "VIEW", 0, "View", ""},
- {0, NULL, 0, NULL, NULL}};
-
char OP_TRANSLATION[] = "TFM_OT_translate";
char OP_ROTATION[] = "TFM_OT_rotate";
char OP_TOSPHERE[] = "TFM_OT_tosphere";
@@ -157,7 +131,8 @@ void TFM_OT_select_orientation(struct wmOperatorType *ot)
ot->exec = select_orientation_exec;
ot->poll = ED_operator_areaactive;
- prop= RNA_def_enum(ot->srna, "orientation", orientation_items, V3D_MANIP_GLOBAL, "Orientation", "DOC_BROKEN");
+ prop= RNA_def_property(ot->srna, "orientation", PROP_ENUM, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation.");
RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
}
@@ -374,7 +349,7 @@ void Properties_Proportional(struct wmOperatorType *ot)
void Properties_Snapping(struct wmOperatorType *ot, short align)
{
RNA_def_boolean(ot->srna, "snap", 0, "Snap to Point", "");
- RNA_def_enum(ot->srna, "snap_mode", snap_mode_types, 0, "Mode", "");
+ RNA_def_enum(ot->srna, "snap_mode", snap_mode_items, 0, "Mode", "");
RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
if (align)
@@ -389,7 +364,8 @@ void Properties_Constraints(struct wmOperatorType *ot)
PropertyRNA *prop;
RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
- prop= RNA_def_enum(ot->srna, "constraint_orientation", orientation_items, V3D_MANIP_GLOBAL, "Orientation", "DOC_BROKEN");
+ 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);
}
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 84dc9e69e7a..0e3f999d47b 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -217,8 +217,69 @@ int handleSnapping(TransInfo *t, wmEvent *event)
return status;
}
+void applyProject(TransInfo *t)
+{
+ /* XXX FLICKER IN OBJECT MODE */
+ if ((t->tsnap.project) && (t->tsnap.status & SNAP_ON) && (t->modifiers & MOD_SNAP_GEARS))
+ {
+ TransData *td = t->data;
+ float tvec[3];
+ float imat[4][4];
+ int i;
+
+ if(t->flag & (T_EDIT|T_POSE)) {
+ Object *ob = t->obedit?t->obedit:t->poseobj;
+ Mat4Invert(imat, ob->obmat);
+ }
+
+ for(i = 0 ; i < t->total; i++, td++) {
+ float iloc[3], loc[3], no[3];
+ float mval[2];
+ int dist = 1000;
+
+ if (td->flag & TD_NOACTION)
+ break;
+
+ if (td->flag & TD_SKIP)
+ continue;
+
+ VECCOPY(iloc, td->loc);
+ if (t->flag & (T_EDIT|T_POSE))
+ {
+ Object *ob = t->obedit?t->obedit:t->poseobj;
+ Mat4MulVecfl(ob->obmat, iloc);
+ }
+ else if (t->flag & T_OBJECT)
+ {
+ VECCOPY(iloc, td->ob->obmat[3]);
+ }
+
+ project_float(t->ar, iloc, mval);
+
+ if (snapObjectsTransform(t, mval, &dist, loc, no, t->tsnap.mode))
+ {
+// if(t->flag & (T_EDIT|T_POSE)) {
+// Mat4MulVecfl(imat, loc);
+// }
+//
+ VecSubf(tvec, loc, iloc);
+
+ Mat3MulVecfl(td->smtx, tvec);
+
+ VecAddf(td->loc, td->loc, tvec);
+ }
+
+ //XXX constraintTransLim(t, td);
+ }
+ }
+}
+
void applySnapping(TransInfo *t, float *vec)
{
+ /* project is not applied this way */
+ if (t->tsnap.project)
+ return;
+
if (t->tsnap.status & SNAP_FORCED)
{
t->tsnap.targetSnap(t);
@@ -305,12 +366,24 @@ void initSnapping(TransInfo *t, wmOperator *op)
RNA_float_get_array(op->ptr, "snap_normal", t->tsnap.snapNormal);
Normalize(t->tsnap.snapNormal);
}
+
+ if (RNA_struct_find_property(op->ptr, "snap_project"))
+ {
+ t->tsnap.project = RNA_boolean_get(op->ptr, "snap_project");
+ }
}
}
else
{
snapping = ((ts->snap_flag & SCE_SNAP) == SCE_SNAP);
t->tsnap.align = ((t->settings->snap_flag & SCE_SNAP_ROTATE) == SCE_SNAP_ROTATE);
+ t->tsnap.project = ((t->settings->snap_flag & SCE_SNAP_PROJECT) == SCE_SNAP_PROJECT);
+ }
+
+ /* force project off when not supported */
+ if (ts->snap_mode != SCE_SNAP_MODE_FACE)
+ {
+ t->tsnap.project = 0;
}
if ((t->spacetype == SPACE_VIEW3D || t->spacetype == SPACE_IMAGE) && // Only 3D view or UV
@@ -537,9 +610,13 @@ void CalcSnapGeometry(TransInfo *t, float *vec)
{
float loc[3];
float no[3];
+ float mval[2];
int found = 0;
int dist = SNAP_MIN_DISTANCE; // Use a user defined value here
+ mval[0] = t->mval[0];
+ mval[1] = t->mval[1];
+
if (t->settings->snap_mode == SCE_SNAP_MODE_VOLUME)
{
ListBase depth_peels;
@@ -550,7 +627,7 @@ void CalcSnapGeometry(TransInfo *t, float *vec)
depth_peels.first = depth_peels.last = NULL;
- peelObjectsTransForm(t, &depth_peels, t->mval);
+ peelObjectsTransForm(t, &depth_peels, mval);
// if (LAST_SNAP_POINT_VALID)
// {
@@ -633,7 +710,7 @@ void CalcSnapGeometry(TransInfo *t, float *vec)
}
else
{
- found = snapObjectsTransform(t, t->mval, &dist, loc, no, t->tsnap.mode);
+ found = snapObjectsTransform(t, mval, &dist, loc, no, t->tsnap.mode);
}
if (found == 1)
@@ -854,7 +931,7 @@ void TargetSnapClosest(TransInfo *t)
}
/*================================================================*/
-int snapFace(ARegion *ar, float v1co[3], float v2co[3], float v3co[3], float *v4co, short mval[2], float ray_start[3], float ray_start_local[3], float ray_normal_local[3], float obmat[][4], float timat[][3], float *loc, float *no, int *dist, float *depth)
+int snapFace(ARegion *ar, float v1co[3], float v2co[3], float v3co[3], float *v4co, float mval[2], float ray_start[3], float ray_start_local[3], float ray_normal_local[3], float obmat[][4], float timat[][3], float *loc, float *no, int *dist, float *depth)
{
float lambda;
int result;
@@ -885,7 +962,7 @@ int snapFace(ARegion *ar, float v1co[3], float v2co[3], float v3co[3], float *v4
new_depth = VecLenf(location, ray_start);
project_int(ar, location, screen_loc);
- new_dist = abs(screen_loc[0] - mval[0]) + abs(screen_loc[1] - mval[1]);
+ new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]);
if (new_dist <= *dist && new_depth < *depth)
{
@@ -905,7 +982,7 @@ int snapFace(ARegion *ar, float v1co[3], float v2co[3], float v3co[3], float *v4
return retval;
}
-int snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2no[3], short mval[2], float ray_start[3], float ray_start_local[3], float ray_normal_local[3], float obmat[][4], float timat[][3], float *loc, float *no, int *dist, float *depth)
+int snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2no[3], float mval[2], float ray_start[3], float ray_start_local[3], float ray_normal_local[3], float obmat[][4], float timat[][3], float *loc, float *no, int *dist, float *depth)
{
float intersect[3] = {0, 0, 0}, ray_end[3], dvec[3];
int result;
@@ -953,7 +1030,7 @@ int snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2n
new_depth = VecLenf(location, ray_start);
project_int(ar, location, screen_loc);
- new_dist = abs(screen_loc[0] - mval[0]) + abs(screen_loc[1] - mval[1]);
+ new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]);
/* 10% threshold if edge is closer but a bit further
* this takes care of series of connected edges a bit slanted w.r.t the viewport
@@ -990,7 +1067,7 @@ int snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2n
return retval;
}
-int snapVertex(ARegion *ar, float vco[3], short vno[3], short mval[2], float ray_start[3], float ray_start_local[3], float ray_normal_local[3], float obmat[][4], float timat[][3], float *loc, float *no, int *dist, float *depth)
+int snapVertex(ARegion *ar, float vco[3], short vno[3], float mval[2], float ray_start[3], float ray_start_local[3], float ray_normal_local[3], float obmat[][4], float timat[][3], float *loc, float *no, int *dist, float *depth)
{
int retval = 0;
float dvec[3];
@@ -1011,7 +1088,7 @@ int snapVertex(ARegion *ar, float vco[3], short vno[3], short mval[2], float ray
new_depth = VecLenf(location, ray_start);
project_int(ar, location, screen_loc);
- new_dist = abs(screen_loc[0] - mval[0]) + abs(screen_loc[1] - mval[1]);
+ new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]);
if (new_dist <= *dist && new_depth < *depth)
{
@@ -1034,7 +1111,7 @@ int snapVertex(ARegion *ar, float vco[3], short vno[3], short mval[2], float ray
return retval;
}
-int snapArmature(short snap_mode, ARegion *ar, Object *ob, bArmature *arm, float obmat[][4], float ray_start[3], float ray_normal[3], short mval[2], float *loc, float *no, int *dist, float *depth)
+int snapArmature(short snap_mode, ARegion *ar, Object *ob, bArmature *arm, float obmat[][4], float ray_start[3], float ray_normal[3], float mval[2], float *loc, float *no, int *dist, float *depth)
{
float imat[4][4];
float ray_start_local[3], ray_normal_local[3];
@@ -1099,7 +1176,7 @@ int snapArmature(short snap_mode, ARegion *ar, Object *ob, bArmature *arm, float
return retval;
}
-int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, EditMesh *em, float obmat[][4], float ray_start[3], float ray_normal[3], short mval[2], float *loc, float *no, int *dist, float *depth)
+int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, EditMesh *em, float obmat[][4], float ray_start[3], float ray_normal[3], float mval[2], float *loc, float *no, int *dist, float *depth)
{
int retval = 0;
int totvert = dm->getNumVerts(dm);
@@ -1333,7 +1410,7 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E
return retval;
}
-int snapObject(Scene *scene, ARegion *ar, Object *ob, int editobject, float obmat[][4], float ray_start[3], float ray_normal[3], short mval[2], float *loc, float *no, int *dist, float *depth)
+int snapObject(Scene *scene, ARegion *ar, Object *ob, int editobject, float obmat[][4], float ray_start[3], float ray_normal[3], float mval[2], float *loc, float *no, int *dist, float *depth)
{
ToolSettings *ts= scene->toolsettings;
int retval = 0;
@@ -1365,7 +1442,7 @@ int snapObject(Scene *scene, ARegion *ar, Object *ob, int editobject, float obma
return retval;
}
-int snapObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, short mval[2], int *dist, float *loc, float *no, SnapMode mode) {
+int snapObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, float mval[2], int *dist, float *loc, float *no, SnapMode mode) {
Base *base;
float depth = FLT_MAX;
int retval = 0;
@@ -1382,7 +1459,7 @@ int snapObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, short mv
base= FIRSTBASE;
for ( base = FIRSTBASE; base != NULL; base = base->next ) {
- if ( BASE_SELECTABLE(v3d, base) && (base->flag & (BA_HAS_RECALC_OB|BA_HAS_RECALC_DATA)) == 0 && ((mode == SNAP_NOT_SELECTED && (base->flag & (SELECT|BA_WAS_SEL)) == 0) || (mode == SNAP_NOT_OBEDIT && base != BASACT)) ) {
+ if ( BASE_SELECTABLE(v3d, base) && (base->flag & (BA_HAS_RECALC_OB|BA_HAS_RECALC_DATA)) == 0 && ((mode == SNAP_NOT_SELECTED && (base->flag & (SELECT|BA_WAS_SEL)) == 0) || (ELEM(mode, SNAP_ALL, SNAP_NOT_OBEDIT) && base != BASACT)) ) {
Object *ob = base->object;
if (ob->transflag & OB_DUPLI)
@@ -1407,12 +1484,12 @@ int snapObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, short mv
return retval;
}
-int snapObjectsTransform(TransInfo *t, short mval[2], int *dist, float *loc, float *no, SnapMode mode)
+int snapObjectsTransform(TransInfo *t, float mval[2], int *dist, float *loc, float *no, SnapMode mode)
{
return snapObjects(t->scene, t->view, t->ar, t->obedit, mval, dist, loc, no, mode);
}
-int snapObjectsContext(bContext *C, short mval[2], int *dist, float *loc, float *no, SnapMode mode)
+int snapObjectsContext(bContext *C, float mval[2], int *dist, float *loc, float *no, SnapMode mode)
{
ScrArea *sa = CTX_wm_area(C);
View3D *v3d = sa->spacedata.first;
@@ -1477,7 +1554,7 @@ void addDepthPeel(ListBase *depth_peels, float depth, float p[3], float no[3], O
peel->flag = 0;
}
-int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_start[3], float ray_normal[3], short mval[2], ListBase *depth_peels)
+int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_start[3], float ray_normal[3], float mval[2], ListBase *depth_peels)
{
int retval = 0;
int totvert = dm->getNumVerts(dm);
@@ -1585,7 +1662,7 @@ int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_sta
return retval;
}
-int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, ListBase *depth_peels, short mval[2])
+int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, ListBase *depth_peels, float mval[2])
{
Base *base;
int retval = 0;
@@ -1666,12 +1743,12 @@ int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, ListBase
return retval;
}
-int peelObjectsTransForm(TransInfo *t, ListBase *depth_peels, short mval[2])
+int peelObjectsTransForm(TransInfo *t, ListBase *depth_peels, float mval[2])
{
return peelObjects(t->scene, t->view, t->ar, t->obedit, depth_peels, mval);
}
-int peelObjectsContext(bContext *C, ListBase *depth_peels, short mval[2])
+int peelObjectsContext(bContext *C, ListBase *depth_peels, float mval[2])
{
ScrArea *sa = CTX_wm_area(C);
View3D *v3d = sa->spacedata.first;