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:
authorBastien Montagne <montagne29@wanadoo.fr>2013-05-12 19:52:05 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2013-05-12 19:52:05 +0400
commitbbd533d4acc9ddd9942a338a59888fcbb1a73aa4 (patch)
treef759976c68225c1a4ba9738bd80fc72ca82d1733
parent128a1c185619e5e5722f963a8eb304beeead9af4 (diff)
Fix for [#35238] Blender does not save custom orientations from "view"
Actually more a feature request... Now create orientations operator has an additional option, use_view, when this one is enabled it will use current view instead of active object to create the new space. Also made some cleanup (made some funcs static).
-rw-r--r--source/blender/editors/include/ED_transform.h3
-rw-r--r--source/blender/editors/transform/transform.h4
-rw-r--r--source/blender/editors/transform/transform_ops.c21
-rw-r--r--source/blender/editors/transform/transform_orientations.c80
4 files changed, 66 insertions, 42 deletions
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index 74c150d9a00..e613a44b1c3 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -123,7 +123,8 @@ struct ReportList;
void BIF_clearTransformOrientation(struct bContext *C);
void BIF_removeTransformOrientation(struct bContext *C, struct TransformOrientation *ts);
void BIF_removeTransformOrientationIndex(struct bContext *C, int index);
-void BIF_createTransformOrientation(struct bContext *C, struct ReportList *reports, char *name, int use, int overwrite);
+void BIF_createTransformOrientation(struct bContext *C, struct ReportList *reports, char *name, int use_view,
+ int use, int overwrite);
void BIF_selectTransformOrientation(struct bContext *C, struct TransformOrientation *ts);
void BIF_selectTransformOrientationValue(struct bContext *C, int orientation);
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 26f36db2f4c..583a6a47036 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -725,10 +725,6 @@ void getViewVector(TransInfo *t, float coord[3], float vec[3]);
void initTransformOrientation(struct bContext *C, TransInfo *t);
-struct TransformOrientation *createObjectSpace(struct bContext *C, struct ReportList *reports, char *name, int overwrite);
-struct TransformOrientation *createMeshSpace(struct bContext *C, struct ReportList *reports, char *name, int overwrite);
-struct TransformOrientation *createBoneSpace(struct bContext *C, struct ReportList *reports, char *name, int overwrite);
-
/* Those two fill in mat and return non-zero on success */
bool createSpaceNormal(float mat[3][3], const float normal[3]);
bool createSpaceNormalTangent(float mat[3][3], float normal[3], float tangent[3]);
diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index 4f46e969c3c..e2668416cfc 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -252,7 +252,8 @@ static int create_orientation_exec(bContext *C, wmOperator *op)
char name[MAX_NAME];
int use = RNA_boolean_get(op->ptr, "use");
int overwrite = RNA_boolean_get(op->ptr, "overwrite");
-
+ int use_view = RNA_boolean_get(op->ptr, "use_view");
+
RNA_string_get(op->ptr, "name", name);
if (use && !CTX_wm_view3d(C)) {
@@ -260,7 +261,7 @@ static int create_orientation_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- BIF_createTransformOrientation(C, op->reports, name, use, overwrite);
+ BIF_createTransformOrientation(C, op->reports, name, use_view, use, overwrite);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C));
@@ -268,11 +269,6 @@ static int create_orientation_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
-static int create_orientation_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
- return create_orientation_exec(C, op);
-}
-
static void TRANSFORM_OT_create_orientation(struct wmOperatorType *ot)
{
/* identifiers */
@@ -282,14 +278,15 @@ static void TRANSFORM_OT_create_orientation(struct wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* api callbacks */
- ot->invoke = create_orientation_invoke;
ot->exec = create_orientation_exec;
ot->poll = ED_operator_areaactive;
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Text to insert at the cursor position");
- RNA_def_boolean(ot->srna, "use", 0, "Use after creation", "Select orientation after its creation");
- RNA_def_boolean(ot->srna, "overwrite", 0, "Overwrite previous", "Overwrite previously created orientation with same name");
+ RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of the new custom orientation");
+ RNA_def_boolean(ot->srna, "use_view", FALSE, "Use View",
+ "Use the current view instead of the active object to create the new orientation");
+ RNA_def_boolean(ot->srna, "use", FALSE, "Use after creation", "Select orientation after its creation");
+ RNA_def_boolean(ot->srna, "overwrite", FALSE, "Overwrite previous",
+ "Overwrite previously created orientation with same name");
}
static void transformops_exit(bContext *C, wmOperator *op)
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c
index 343592d4501..25c4682a588 100644
--- a/source/blender/editors/transform/transform_orientations.c
+++ b/source/blender/editors/transform/transform_orientations.c
@@ -100,31 +100,32 @@ static void uniqueOrientationName(ListBase *lb, char *name)
sizeof(((TransformOrientation *)NULL)->name));
}
-void BIF_createTransformOrientation(bContext *C, ReportList *reports, char *name, int use, int overwrite)
+static TransformOrientation *createViewSpace(bContext *C, ReportList *UNUSED(reports), char *name, int overwrite)
{
- Object *obedit = CTX_data_edit_object(C);
- Object *ob = CTX_data_active_object(C);
- TransformOrientation *ts = NULL;
-
- if (obedit) {
- if (obedit->type == OB_MESH)
- ts = createMeshSpace(C, reports, name, overwrite);
- else if (obedit->type == OB_ARMATURE)
- ts = createBoneSpace(C, reports, name, overwrite);
- }
- else if (ob && (ob->mode & OB_MODE_POSE)) {
- ts = createBoneSpace(C, reports, name, overwrite);
- }
- else {
- ts = createObjectSpace(C, reports, name, overwrite);
- }
-
- if (use && ts != NULL) {
- BIF_selectTransformOrientation(C, ts);
+ RegionView3D *rv3d = CTX_wm_region_view3d(C);
+ float mat[3][3];
+
+ if (!rv3d)
+ return NULL;
+
+ copy_m3_m4(mat, rv3d->viewinv);
+ normalize_m3(mat);
+
+ if (!name[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! */
+ strncpy(name, v3d->camera->id.name + 2, MAX_NAME);
+ }
+ else {
+ strcpy(name, "Custom View");
+ }
}
+
+ return addMatrixSpace(C, mat, name, overwrite);
}
-TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(reports), char *name, int overwrite)
+static TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(reports), char *name, int overwrite)
{
Base *base = CTX_data_active_base(C);
Object *ob;
@@ -133,9 +134,8 @@ TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(reports)
if (base == NULL)
return NULL;
-
ob = base->object;
-
+
copy_m3_m4(mat, ob->obmat);
normalize_m3(mat);
@@ -147,7 +147,7 @@ TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(reports)
return addMatrixSpace(C, mat, name, overwrite);
}
-TransformOrientation *createBoneSpace(bContext *C, ReportList *reports, char *name, int overwrite)
+static TransformOrientation *createBoneSpace(bContext *C, ReportList *reports, char *name, int overwrite)
{
float mat[3][3];
float normal[3], plane[3];
@@ -166,7 +166,7 @@ TransformOrientation *createBoneSpace(bContext *C, ReportList *reports, char *na
return addMatrixSpace(C, mat, name, overwrite);
}
-TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, char *name, int overwrite)
+static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, char *name, int overwrite)
{
float mat[3][3];
float normal[3], plane[3];
@@ -260,6 +260,36 @@ bool createSpaceNormalTangent(float mat[3][3], float normal[3], float tangent[3]
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)
+{
+ TransformOrientation *ts = NULL;
+
+ if (use_view) {
+ ts = createViewSpace(C, reports, name, overwrite);
+ }
+ else {
+ Object *obedit = CTX_data_edit_object(C);
+ Object *ob = CTX_data_active_object(C);
+ if (obedit) {
+ if (obedit->type == OB_MESH)
+ ts = createMeshSpace(C, reports, name, overwrite);
+ else if (obedit->type == OB_ARMATURE)
+ ts = createBoneSpace(C, reports, name, overwrite);
+ }
+ else if (ob && (ob->mode & OB_MODE_POSE)) {
+ ts = createBoneSpace(C, reports, name, overwrite);
+ }
+ else {
+ ts = createObjectSpace(C, reports, name, overwrite);
+ }
+ }
+
+ if (use && ts != NULL) {
+ BIF_selectTransformOrientation(C, ts);
+ }
+}
+
TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], char name[], int overwrite)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;