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:
authorAlexander Pinzon Fernandez <apinzonf@gmail.com>2013-12-11 20:10:22 +0400
committerAlexander Pinzon Fernandez <apinzonf@gmail.com>2013-12-11 20:10:22 +0400
commit2658a3c1b44717f497f187a38000c804eb37bbba (patch)
treeee55c673feabced8b6ec8bf9a8aa4d82a3cda3db /source/blender/editors/transform
parent4005cb1c6a63a217df0e887c741beee2c1359301 (diff)
parent09b859d03f0ee138c4273ef8460e91d9888387a1 (diff)
Merge branch 'master' into soc-2013-sketch_meshsoc-2013-sketch_mesh
Conflicts: release/scripts/addons source/blender/blenloader/intern/readfile.c source/blender/blenloader/intern/writefile.c source/blender/editors/object/object_modifier.c source/blender/makesrna/intern/rna_modifier.c source/blender/modifiers/intern/MOD_laplaciandeform.c
Diffstat (limited to 'source/blender/editors/transform')
-rw-r--r--source/blender/editors/transform/transform.c8
-rw-r--r--source/blender/editors/transform/transform.h9
-rw-r--r--source/blender/editors/transform/transform_constraints.c10
-rw-r--r--source/blender/editors/transform/transform_conversions.c44
-rw-r--r--source/blender/editors/transform/transform_generics.c10
-rw-r--r--source/blender/editors/transform/transform_manipulator.c5
-rw-r--r--source/blender/editors/transform/transform_ops.c6
-rw-r--r--source/blender/editors/transform/transform_orientations.c233
-rw-r--r--source/blender/editors/transform/transform_snap.c2
9 files changed, 166 insertions, 161 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 2756685e9f6..2ae94fb6d5a 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -1468,7 +1468,7 @@ int calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], float
t->mode = TFM_DUMMY;
- initTransInfo(C, t, NULL, NULL); // internal data, mouse, vectors
+ initTransInfo(C, t, NULL, NULL);
/* avoid doing connectivity lookups (when V3D_LOCAL is set) */
t->around = V3D_CENTER;
@@ -1758,7 +1758,7 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
ED_region_visible_rect(ar, &rect);
- BLF_width_and_height_default(printable, &printable_size[0], &printable_size[1]);
+ BLF_width_and_height_default(printable, BLF_DRAW_STR_DUMMY_MAX, &printable_size[0], &printable_size[1]);
xco = rect.xmax - (int)printable_size[0] - 10;
yco = rect.ymax - (int)printable_size[1] - 10;
@@ -1970,9 +1970,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
t->launch_event = LEFTMOUSE;
}
- if (!initTransInfo(C, t, op, event)) { /* internal data, mouse, vectors */
- return 0;
- }
+ initTransInfo(C, t, op, event);
if (t->spacetype == SPACE_VIEW3D) {
//calc_manipulator_stats(curarea);
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index ab5f034c836..1e7052926b3 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -615,7 +615,7 @@ void setInputPostFct(MouseInput *mi, void (*post)(struct TransInfo *t, float val
/*********************** Generics ********************************/
-int initTransInfo(struct bContext *C, TransInfo *t, struct wmOperator *op, const struct wmEvent *event);
+void initTransInfo(struct bContext *C, TransInfo *t, struct wmOperator *op, const struct wmEvent *event);
void postTrans(struct bContext *C, TransInfo *t);
void resetTransModal(TransInfo *t);
void resetTransRestrictions(TransInfo *t);
@@ -648,8 +648,9 @@ void initTransformOrientation(struct bContext *C, TransInfo *t);
bool createSpaceNormal(float mat[3][3], const float normal[3]);
bool createSpaceNormalTangent(float mat[3][3], const float normal[3], const float tangent[3]);
-struct TransformOrientation *addMatrixSpace(struct bContext *C, float mat[3][3], char name[], int overwrite);
-void applyTransformOrientation(const struct bContext *C, float mat[3][3], char *name);
+struct TransformOrientation *addMatrixSpace(struct bContext *C, float mat[3][3],
+ const char *name, const bool overwrite);
+bool applyTransformOrientation(const struct bContext *C, float mat[3][3], char r_name[64]);
#define ORIENTATION_NONE 0
#define ORIENTATION_NORMAL 1
@@ -657,7 +658,7 @@ void applyTransformOrientation(const struct bContext *C, float mat[3][3], char *
#define ORIENTATION_EDGE 3
#define ORIENTATION_FACE 4
-int getTransformOrientation(const struct bContext *C, float normal[3], float plane[3], int activeOnly);
+int getTransformOrientation(const struct bContext *C, float normal[3], float plane[3], const bool activeOnly);
void freeEdgeSlideTempFaces(EdgeSlideData *sld);
void freeEdgeSlideVerts(TransInfo *t);
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c
index 4ba87eb8c39..894145c9e9d 100644
--- a/source/blender/editors/transform/transform_constraints.c
+++ b/source/blender/editors/transform/transform_constraints.c
@@ -576,7 +576,15 @@ void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[])
void setAxisMatrixConstraint(TransInfo *t, int mode, const char text[])
{
if (t->total == 1) {
- setConstraint(t, t->data->axismtx, mode, text);
+ float axismtx[3][3];
+ if (t->flag & T_EDIT) {
+ mul_m3_m3m3(axismtx, t->obedit_mat, t->data->axismtx);
+ }
+ else {
+ copy_m3_m3(axismtx, t->data->axismtx);
+ }
+
+ setConstraint(t, axismtx, mode, text);
}
else {
BLI_strncpy(t->con.text + 1, text, sizeof(t->con.text) - 1);
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 06da1edbcdc..c41b4deca31 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -5071,7 +5071,7 @@ void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob,
/* get flags used for inserting keyframes */
flag = ANIM_get_keyframing_flags(scene, 1);
- /* add datasource override for the camera object */
+ /* add datasource override for the object */
ANIM_relative_keyingset_add_source(&dsources, id, NULL, NULL);
if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (active_ks)) {
@@ -5143,6 +5143,22 @@ void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob,
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
}
+ /* only calculate paths if there are paths to be recalculated,
+ * assuming that since we've autokeyed the transforms this is
+ * now safe to apply...
+ *
+ * NOTE: only do this when there's context info
+ */
+ if (C && (ob->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS)) {
+ //ED_objects_clear_paths(C); // XXX for now, don't need to clear
+ ED_objects_recalculate_paths(C, scene);
+
+ /* XXX: there's potential here for problems with unkeyed rotations/scale,
+ * but for now (until proper data-locality for baking operations),
+ * this should be a better fix for T24451 and T37755
+ */
+ }
+
/* free temp info */
BLI_freelistN(&dsources);
}
@@ -5787,7 +5803,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
/* do nothing */
}
else { /* Objects */
- int i, recalcObPaths = 0;
+ int i;
BLI_assert(t->flag & (T_OBJECT | T_TEXTURE));
@@ -5824,11 +5840,8 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
/* Set autokey if necessary */
if (!canceled) {
autokeyframe_ob_cb_func(C, t->scene, (View3D *)t->view, ob, t->mode);
-
- /* only calculate paths if there are paths to be recalculated */
- if (ob->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS)
- recalcObPaths = 1;
}
+
/* restore rigid body transform */
if (ob->rigidbody_object && canceled) {
float ctime = BKE_scene_frame_get(t->scene);
@@ -5836,25 +5849,6 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
BKE_rigidbody_aftertrans_update(ob, td->ext->oloc, td->ext->orot, td->ext->oquat, td->ext->orotAxis, td->ext->orotAngle);
}
}
-
- /* recalculate motion paths for objects (if necessary)
- * NOTE: only do this when there is context info
- */
- if (C && recalcObPaths) {
- //ED_objects_clear_paths(C); // XXX for now, don't need to clear
- ED_objects_recalculate_paths(C, t->scene);
-
- /* recalculating the frame positions means we loose our original transform if its not auto-keyed [#24451]
- * this hack re-applies it, which is annoying, only alternatives are...
- * - don't recalc paths.
- * - have an BKE_object_handle_update() which gives is the new transform without touching the objects.
- * - only recalc paths on auto-keying.
- * - ED_objects_recalculate_paths could backup/restore transforms.
- * - re-apply the transform which is simplest in this case. (2 lines below)
- */
- t->redraw |= TREDRAW_HARD;
- transformApply(C, t);
- }
}
clear_trans_object_base_flags(t);
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index 95b6067f2c4..0ff94fb4f1c 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -1029,8 +1029,12 @@ static int initTransInfo_edit_pet_to_flag(const int proportional)
}
}
-/* the *op can be NULL */
-int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event)
+/**
+ * Setup internal data, mouse, vectors
+ *
+ * \note \a op and \a event can be NULL
+ */
+void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event)
{
Scene *sce = CTX_data_scene(C);
ToolSettings *ts = CTX_data_tool_settings(C);
@@ -1321,8 +1325,6 @@ int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
setTransformViewMatrices(t);
initNumInput(&t->num);
-
- return 1;
}
/* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index 132a46441e6..5ac97ed4e26 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -642,8 +642,9 @@ int calc_manipulator_stats(const bContext *C)
default: /* V3D_MANIP_CUSTOM */
{
float mat[3][3];
- applyTransformOrientation(C, mat, NULL);
- copy_m4_m3(rv3d->twmat, mat);
+ if (applyTransformOrientation(C, mat, NULL)) {
+ copy_m4_m3(rv3d->twmat, mat);
+ }
break;
}
}
diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index 106024cd3e2..3a83445ba5f 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -533,7 +533,7 @@ void Transform_Properties(struct wmOperatorType *ot, int flags)
}
}
- if (flags & P_OPTIONS) {
+ if ((flags & P_OPTIONS) && !(flags & P_NO_TEXSPACE)) {
RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Texture Space", "Edit Object data texture space");
prop = RNA_def_boolean(ot->srna, "remove_on_cancel", 0, "Remove on Cancel", "Remove elements on cancel");
RNA_def_property_flag(prop, PROP_HIDDEN);
@@ -617,7 +617,7 @@ static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot)
RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
- Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS);
+ Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_NO_TEXSPACE);
}
static void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
@@ -703,7 +703,7 @@ static void TRANSFORM_OT_bend(struct wmOperatorType *ot)
/* api callbacks */
ot->invoke = transform_invoke;
- ot->exec = transform_exec;
+ // ot->exec = transform_exec; // unsupported
ot->modal = transform_modal;
ot->cancel = transform_cancel;
ot->poll = ED_operator_region_view3d_active;
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c
index cd6a2e6712e..be8bc460764 100644
--- a/source/blender/editors/transform/transform_orientations.c
+++ b/source/blender/editors/transform/transform_orientations.c
@@ -26,6 +26,7 @@
#include <string.h>
+#include <stddef.h>
#include <ctype.h>
#include "MEM_guardedalloc.h"
@@ -40,7 +41,9 @@
#include "DNA_view3d_types.h"
#include "BLI_math.h"
-#include "BLI_blenlib.h"
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_path_util.h"
#include "BLI_utildefines.h"
#include "BKE_action.h"
@@ -49,6 +52,8 @@
#include "BKE_context.h"
#include "BKE_editmesh.h"
#include "BKE_report.h"
+#include "BKE_main.h"
+#include "BKE_screen.h"
#include "BLF_translation.h"
@@ -78,15 +83,7 @@ void BIF_clearTransformOrientation(bContext *C)
static TransformOrientation *findOrientationName(ListBase *lb, const char *name)
{
- TransformOrientation *ts = NULL;
-
- for (ts = lb->first; ts; ts = ts->next) {
- if (strncmp(ts->name, name, sizeof(ts->name) - 1) == 0) {
- return ts;
- }
- }
-
- return NULL;
+ return BLI_findstring(lb, name, offsetof(TransformOrientation, name));
}
static bool uniqueOrientationNameCheck(void *arg, const char *name)
@@ -100,7 +97,8 @@ static void uniqueOrientationName(ListBase *lb, char *name)
sizeof(((TransformOrientation *)NULL)->name));
}
-static TransformOrientation *createViewSpace(bContext *C, ReportList *UNUSED(reports), char *name, int overwrite)
+static TransformOrientation *createViewSpace(bContext *C, ReportList *UNUSED(reports),
+ const char *name, const bool overwrite)
{
RegionView3D *rv3d = CTX_wm_region_view3d(C);
float mat[3][3];
@@ -111,21 +109,22 @@ static TransformOrientation *createViewSpace(bContext *C, ReportList *UNUSED(rep
copy_m3_m4(mat, rv3d->viewinv);
normalize_m3(mat);
- if (!name[0]) {
+ if (name[0] == 0) {
View3D *v3d = CTX_wm_view3d(C);
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
/* If an object is used as camera, then this space is the same as object space! */
- BLI_strncpy(name, v3d->camera->id.name + 2, MAX_NAME);
+ name = v3d->camera->id.name + 2;
}
else {
- strcpy(name, "Custom View");
+ name = "Custom View";
}
}
return addMatrixSpace(C, mat, name, overwrite);
}
-static TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(reports), char *name, int overwrite)
+static TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(reports),
+ const char *name, const bool overwrite)
{
Base *base = CTX_data_active_base(C);
Object *ob;
@@ -141,13 +140,14 @@ static TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(r
/* use object name if no name is given */
if (name[0] == 0) {
- BLI_strncpy(name, ob->id.name + 2, MAX_ID_NAME - 2);
+ name = ob->id.name + 2;
}
return addMatrixSpace(C, mat, name, overwrite);
}
-static TransformOrientation *createBoneSpace(bContext *C, ReportList *reports, char *name, int overwrite)
+static TransformOrientation *createBoneSpace(bContext *C, ReportList *reports,
+ const char *name, const bool overwrite)
{
float mat[3][3];
float normal[3], plane[3];
@@ -160,13 +160,14 @@ static TransformOrientation *createBoneSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
- strcpy(name, "Bone");
+ name = "Bone";
}
return addMatrixSpace(C, mat, name, overwrite);
}
-static TransformOrientation *createCurveSpace(bContext *C, ReportList *reports, char *name, int overwrite)
+static TransformOrientation *createCurveSpace(bContext *C, ReportList *reports,
+ const char *name, const bool overwrite)
{
float mat[3][3];
float normal[3], plane[3];
@@ -179,14 +180,15 @@ static TransformOrientation *createCurveSpace(bContext *C, ReportList *reports,
}
if (name[0] == 0) {
- strcpy(name, "Curve");
+ name = "Curve";
}
return addMatrixSpace(C, mat, name, overwrite);
}
-static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, char *name, int overwrite)
+static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports,
+ const char *name, const bool overwrite)
{
float mat[3][3];
float normal[3], plane[3];
@@ -202,7 +204,7 @@ static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
- strcpy(name, "Vertex");
+ name = "Vertex";
}
break;
case ORIENTATION_EDGE:
@@ -212,7 +214,7 @@ static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
- strcpy(name, "Edge");
+ name = "Edge";
}
break;
case ORIENTATION_FACE:
@@ -222,7 +224,7 @@ static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
- strcpy(name, "Face");
+ name = "Face";
}
break;
default:
@@ -288,8 +290,9 @@ bool createSpaceNormalTangent(float mat[3][3], const float normal[3], const floa
return true;
}
-/* name must be a MAX_NAME length string! */
-void BIF_createTransformOrientation(bContext *C, ReportList *reports, char *name, int use_view, int use, int overwrite)
+void BIF_createTransformOrientation(bContext *C, ReportList *reports,
+ const char *name, const bool use_view,
+ const bool activate, const bool overwrite)
{
TransformOrientation *ts = NULL;
@@ -315,21 +318,25 @@ void BIF_createTransformOrientation(bContext *C, ReportList *reports, char *name
}
}
- if (use && ts != NULL) {
+ if (activate && ts != NULL) {
BIF_selectTransformOrientation(C, ts);
}
}
-TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], char name[], int overwrite)
+TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3],
+ const char *name, const bool overwrite)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
TransformOrientation *ts = NULL;
+ char name_unique[sizeof(ts->name)];
if (overwrite) {
ts = findOrientationName(transform_spaces, name);
}
else {
- uniqueOrientationName(transform_spaces, name);
+ BLI_strncpy(name_unique, name, sizeof(name_unique));
+ uniqueOrientationName(transform_spaces, name_unique);
+ name = name_unique;
}
/* if not, create a new one */
@@ -347,29 +354,14 @@ TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], char name[],
void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target)
{
- ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
- TransformOrientation *ts;
- int i;
-
- for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) {
- if (ts == target) {
- View3D *v3d = CTX_wm_view3d(C);
- if (v3d) {
- int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
-
- // Transform_fix_me NEED TO DO THIS FOR ALL VIEW3D
- if (selected_index == i) {
- v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */
- }
- else if (selected_index > i) {
- v3d->twmode--;
- }
-
- }
+ Scene *scene = CTX_data_scene(C);
+ ListBase *transform_spaces = &scene->transform_spaces;
+ const int i = BLI_findindex(transform_spaces, target);
- BLI_freelinkN(transform_spaces, ts);
- break;
- }
+ if (i != -1) {
+ Main *bmain = CTX_data_main(C);
+ BKE_screen_view3d_main_twmode_remove(&bmain->screen, scene, i);
+ BLI_freelinkN(transform_spaces, target);
}
}
@@ -379,36 +371,18 @@ void BIF_removeTransformOrientationIndex(bContext *C, int index)
TransformOrientation *ts = BLI_findlink(transform_spaces, index);
if (ts) {
- View3D *v3d = CTX_wm_view3d(C);
- if (v3d) {
- int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
-
- // Transform_fix_me NEED TO DO THIS FOR ALL VIEW3D
- if (selected_index == index) {
- v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */
- }
- else if (selected_index > index) {
- v3d->twmode--;
- }
-
- }
-
- BLI_freelinkN(transform_spaces, ts);
+ BIF_removeTransformOrientation(C, ts);
}
}
void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
- View3D *v3d = CTX_wm_view3d(C);
- TransformOrientation *ts;
- int i;
-
- for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) {
- if (ts == target) {
- v3d->twmode = V3D_MANIP_CUSTOM + i;
- break;
- }
+ const int i = BLI_findindex(transform_spaces, target);
+
+ if (i != -1) {
+ View3D *v3d = CTX_wm_view3d(C);
+ v3d->twmode = V3D_MANIP_CUSTOM + i;
}
}
@@ -422,42 +396,37 @@ void BIF_selectTransformOrientationValue(bContext *C, int orientation)
int BIF_countTransformOrientation(const bContext *C)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
- TransformOrientation *ts;
- int count = 0;
-
- for (ts = transform_spaces->first; ts; ts = ts->next) {
- count++;
- }
-
- return count;
+ return BLI_countlist(transform_spaces);
}
-void applyTransformOrientation(const bContext *C, float mat[3][3], char name[MAX_NAME])
+bool applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name)
{
- TransformOrientation *ts;
View3D *v3d = CTX_wm_view3d(C);
int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
- int i;
-
- if (selected_index >= 0) {
- for (i = 0, ts = CTX_data_scene(C)->transform_spaces.first; ts; ts = ts->next, i++) {
- if (selected_index == i) {
-
- if (name) {
- BLI_strncpy(name, ts->name, MAX_NAME);
- }
-
- copy_m3_m3(mat, ts->mat);
- break;
- }
+
+ ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
+ TransformOrientation *ts = BLI_findlink(transform_spaces, selected_index);
+
+ BLI_assert(selected_index >= 0);
+
+ if (ts) {
+ if (r_name) {
+ BLI_strncpy(r_name, ts->name, MAX_NAME);
}
+
+ copy_m3_m3(mat, ts->mat);
+ return true;
+ }
+ else {
+ /* invalid index, can happen sometimes */
+ return false;
}
}
-static int count_bone_select(bArmature *arm, ListBase *lb, int do_it)
+static int count_bone_select(bArmature *arm, ListBase *lb, const bool do_it)
{
Bone *bone;
- int do_next;
+ bool do_next;
int total = 0;
for (bone = lb->first; bone; bone = bone->next) {
@@ -468,7 +437,9 @@ static int count_bone_select(bArmature *arm, ListBase *lb, int do_it)
if (bone->flag & BONE_SELECTED) {
bone->flag |= BONE_TRANSFORM;
total++;
- do_next = FALSE; // no transform on children if one parent bone is selected
+
+ /* no transform on children if one parent bone is selected */
+ do_next = false;
}
}
}
@@ -487,25 +458,25 @@ void initTransformOrientation(bContext *C, TransInfo *t)
switch (t->current_orientation) {
case V3D_MANIP_GLOBAL:
unit_m3(t->spacemtx);
- strcpy(t->spacename, IFACE_("global"));
+ BLI_strncpy(t->spacename, IFACE_("global"), sizeof(t->spacename));
break;
case V3D_MANIP_GIMBAL:
unit_m3(t->spacemtx);
if (gimbal_axis(ob, t->spacemtx)) {
- strcpy(t->spacename, IFACE_("gimbal"));
+ BLI_strncpy(t->spacename, IFACE_("gimbal"), sizeof(t->spacename));
break;
}
/* fall-through */ /* no gimbal fallthrough to normal */
case V3D_MANIP_NORMAL:
if (obedit || (ob && ob->mode & OB_MODE_POSE)) {
- strcpy(t->spacename, IFACE_("normal"));
+ BLI_strncpy(t->spacename, IFACE_("normal"), sizeof(t->spacename));
ED_getTransformOrientationMatrix(C, t->spacemtx, (v3d->around == V3D_ACTIVE));
break;
}
/* fall-through */ /* we define 'normal' as 'local' in Object mode */
case V3D_MANIP_LOCAL:
- strcpy(t->spacename, IFACE_("local"));
+ BLI_strncpy(t->spacename, IFACE_("local"), sizeof(t->spacename));
if (ob) {
copy_m3_m4(t->spacemtx, ob->obmat);
@@ -522,7 +493,7 @@ void initTransformOrientation(bContext *C, TransInfo *t)
RegionView3D *rv3d = t->ar->regiondata;
float mat[3][3];
- strcpy(t->spacename, IFACE_("view"));
+ BLI_strncpy(t->spacename, IFACE_("view"), sizeof(t->spacename));
copy_m3_m4(mat, rv3d->viewinv);
normalize_m3(mat);
copy_m3_m3(t->spacemtx, mat);
@@ -532,12 +503,17 @@ void initTransformOrientation(bContext *C, TransInfo *t)
}
break;
default: /* V3D_MANIP_CUSTOM */
- applyTransformOrientation(C, t->spacemtx, t->spacename);
+ if (applyTransformOrientation(C, t->spacemtx, t->spacename)) {
+ /* pass */
+ }
+ else {
+ unit_m3(t->spacemtx);
+ }
break;
}
}
-int getTransformOrientation(const bContext *C, float normal[3], float plane[3], int activeOnly)
+int getTransformOrientation(const bContext *C, float normal[3], float plane[3], const bool activeOnly)
{
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
@@ -601,7 +577,6 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
else if (em->bm->totvertsel == 3) {
BMVert *v1 = NULL, *v2 = NULL, *v3 = NULL;
BMIter iter;
- float cotangent[3];
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
@@ -612,11 +587,37 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
v2 = eve;
}
else {
+ float no_test[3];
+
+ float tan_a[3], tan_b[3], tan_c[3];
+ float len_a, len_b, len_c;
+ const float *tan_best;
+
+
v3 = eve;
+ sub_v3_v3v3(tan_a, v2->co, v1->co);
+ sub_v3_v3v3(tan_b, v3->co, v2->co);
+ sub_v3_v3v3(tan_c, v1->co, v3->co);
+ cross_v3_v3v3(normal, tan_b, tan_a);
+
+ /* check if the normal is pointing opposite to vert normals */
+ no_test[0] = v1->no[0] + v2->no[0] + v3->no[0];
+ no_test[1] = v1->no[1] + v2->no[1] + v3->no[1];
+ no_test[2] = v1->no[2] + v2->no[2] + v3->no[2];
+ if (dot_v3v3(no_test, normal) < 0.0f) {
+ negate_v3(normal);
+ }
+
+ /* always give the plane to the 2 most distant verts */
+ len_a = len_squared_v3(tan_a);
+ len_b = len_squared_v3(tan_b);
+ len_c = len_squared_v3(tan_c);
+
+ tan_best = MAX3_PAIR(len_a, len_b, len_c,
+ tan_a, tan_b, tan_c);
+
+ copy_v3_v3(plane, tan_best);
- sub_v3_v3v3(plane, v2->co, v1->co);
- sub_v3_v3v3(cotangent, v3->co, v2->co);
- cross_v3_v3v3(normal, cotangent, plane);
break;
}
}
@@ -663,9 +664,9 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
else {
v2 = eve;
- copy_v3_v3(plane, v1->no);
- add_v3_v3(plane, v2->no);
- sub_v3_v3v3(normal, v2->co, v1->co);
+ copy_v3_v3(normal, v1->no);
+ add_v3_v3(normal, v2->no);
+ sub_v3_v3v3(plane, v2->co, v1->co);
break;
}
}
@@ -864,7 +865,7 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
else {
int totsel;
- totsel = count_bone_select(arm, &arm->bonebase, 1);
+ totsel = count_bone_select(arm, &arm->bonebase, true);
if (totsel) {
/* use channels to get stats */
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 4cda56028ca..b7dd8b7dc13 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -1972,7 +1972,7 @@ static void removeDoublesPeel(ListBase *depth_peels)
for (peel = depth_peels->first; peel; peel = peel->next) {
DepthPeel *next_peel = peel->next;
- if (next_peel && ABS(peel->depth - next_peel->depth) < 0.0015f) {
+ if (next_peel && fabsf(peel->depth - next_peel->depth) < 0.0015f) {
peel->next = next_peel->next;
if (next_peel->next) {