forked from bartvdbraak/blender
Adding back more functionalities for transform orientations.
Create new orientation is now Ctrl-Alt-Space (Alt-Space is select orientation and the old ctrl-shift-c is taken by add constraints). New orientation panel in 3d view sidebar (nkey) has operator buttons for select, create and delete. Eventually, this should become a list. Note that orientation operators are missing notifiers to properly redraw the 3d view and its header properly.
This commit is contained in:
parent
31b77420ea
commit
be3000773b
@ -1285,6 +1285,26 @@ class VIEW3D_PT_background_image(bpy.types.Panel):
|
|||||||
col.itemR(bg, "offset_x", text="X")
|
col.itemR(bg, "offset_x", text="X")
|
||||||
col.itemR(bg, "offset_y", text="Y")
|
col.itemR(bg, "offset_y", text="Y")
|
||||||
|
|
||||||
|
class VIEW3D_PT_transform_orientations(bpy.types.Panel):
|
||||||
|
__space_type__ = 'VIEW_3D'
|
||||||
|
__region_type__ = 'UI'
|
||||||
|
__label__ = "Transform Orientations"
|
||||||
|
__default_closed__ = True
|
||||||
|
|
||||||
|
def poll(self, context):
|
||||||
|
view = context.space_data
|
||||||
|
return (view)
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
|
||||||
|
view = context.space_data
|
||||||
|
|
||||||
|
col = layout.column()
|
||||||
|
col.itemO("TFM_OT_select_orientation", text="Select")
|
||||||
|
col.itemO("TFM_OT_create_orientation", text="Create")
|
||||||
|
col.itemO("TFM_OT_delete_orientation", text="Delete")
|
||||||
|
|
||||||
bpy.types.register(VIEW3D_HT_header) # Header
|
bpy.types.register(VIEW3D_HT_header) # Header
|
||||||
|
|
||||||
bpy.types.register(VIEW3D_MT_view) #View Menus
|
bpy.types.register(VIEW3D_MT_view) #View Menus
|
||||||
@ -1360,3 +1380,4 @@ bpy.types.register(VIEW3D_PT_3dview_display)
|
|||||||
bpy.types.register(VIEW3D_PT_3dview_meshdisplay)
|
bpy.types.register(VIEW3D_PT_3dview_meshdisplay)
|
||||||
bpy.types.register(VIEW3D_PT_3dview_curvedisplay)
|
bpy.types.register(VIEW3D_PT_3dview_curvedisplay)
|
||||||
bpy.types.register(VIEW3D_PT_background_image)
|
bpy.types.register(VIEW3D_PT_background_image)
|
||||||
|
bpy.types.register(VIEW3D_PT_transform_orientations)
|
@ -111,10 +111,12 @@ int BIF_snappingSupported(struct Object *obedit);
|
|||||||
|
|
||||||
struct TransformOrientation;
|
struct TransformOrientation;
|
||||||
struct bContext;
|
struct bContext;
|
||||||
|
struct ReportList;
|
||||||
|
|
||||||
void BIF_clearTransformOrientation(struct bContext *C);
|
void BIF_clearTransformOrientation(struct bContext *C);
|
||||||
void BIF_removeTransformOrientation(struct bContext *C, struct TransformOrientation *ts);
|
void BIF_removeTransformOrientation(struct bContext *C, struct TransformOrientation *ts);
|
||||||
void BIF_manageTransformOrientation(struct bContext *C, int confirm, int set);
|
void BIF_removeTransformOrientationIndex(struct bContext *C, int index);
|
||||||
|
void BIF_createTransformOrientation(struct bContext *C, struct ReportList *reports, char *name, int use, int overwrite);
|
||||||
int BIF_menuselectTransformOrientation(void);
|
int BIF_menuselectTransformOrientation(void);
|
||||||
void BIF_selectTransformOrientation(struct bContext *C, struct TransformOrientation *ts);
|
void BIF_selectTransformOrientation(struct bContext *C, struct TransformOrientation *ts);
|
||||||
void BIF_selectTransformOrientationValue(struct bContext *C, int orientation);
|
void BIF_selectTransformOrientationValue(struct bContext *C, int orientation);
|
||||||
|
@ -886,7 +886,7 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case B_TRANSFORMSPACEADD:
|
case B_TRANSFORMSPACEADD:
|
||||||
BIF_manageTransformOrientation(C, 1, 0);
|
BIF_createTransformOrientation(C, NULL, "", 1, 0);
|
||||||
break;
|
break;
|
||||||
case B_TRANSFORMSPACECLEAR:
|
case B_TRANSFORMSPACECLEAR:
|
||||||
BIF_clearTransformOrientation(C);
|
BIF_clearTransformOrientation(C);
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
struct TransInfo;
|
struct TransInfo;
|
||||||
struct TransData;
|
struct TransData;
|
||||||
|
struct TransformOrientation;
|
||||||
struct TransSnap;
|
struct TransSnap;
|
||||||
struct NumInput;
|
struct NumInput;
|
||||||
struct Object;
|
struct Object;
|
||||||
@ -54,6 +55,7 @@ struct bContext;
|
|||||||
struct wmEvent;
|
struct wmEvent;
|
||||||
struct wmTimer;
|
struct wmTimer;
|
||||||
struct ARegion;
|
struct ARegion;
|
||||||
|
struct ReportList;
|
||||||
|
|
||||||
typedef struct NDofInput {
|
typedef struct NDofInput {
|
||||||
int flag;
|
int flag;
|
||||||
@ -663,18 +665,17 @@ int handleNDofInput(NDofInput *n, struct wmEvent *event);
|
|||||||
|
|
||||||
void initTransformOrientation(struct bContext *C, TransInfo *t);
|
void initTransformOrientation(struct bContext *C, TransInfo *t);
|
||||||
|
|
||||||
int manageObjectSpace(struct bContext *C, int confirm, int set);
|
struct TransformOrientation *createObjectSpace(struct bContext *C, struct ReportList *reports, char *name, int overwrite);
|
||||||
int manageMeshSpace(struct bContext *C, int confirm, int set);
|
struct TransformOrientation *createMeshSpace(struct bContext *C, struct ReportList *reports, char *name, int overwrite);
|
||||||
int manageBoneSpace(struct bContext *C, int confirm, int set);
|
struct TransformOrientation *createBoneSpace(struct bContext *C, struct ReportList *reports, char *name, int overwrite);
|
||||||
|
|
||||||
/* Those two fill in mat and return non-zero on success */
|
/* Those two fill in mat and return non-zero on success */
|
||||||
int createSpaceNormal(float mat[3][3], float normal[3]);
|
int createSpaceNormal(float mat[3][3], float normal[3]);
|
||||||
int createSpaceNormalTangent(float mat[3][3], float normal[3], float tangent[3]);
|
int createSpaceNormalTangent(float mat[3][3], float normal[3], float tangent[3]);
|
||||||
|
|
||||||
int addMatrixSpace(struct bContext *C, float mat[3][3], char name[]);
|
struct TransformOrientation *addMatrixSpace(struct bContext *C, float mat[3][3], char name[], int overwrite);
|
||||||
int addObjectSpace(struct bContext *C, struct Object *ob);
|
int addObjectSpace(struct bContext *C, struct Object *ob);
|
||||||
void applyTransformOrientation(const struct bContext *C, TransInfo *t);
|
void applyTransformOrientation(const struct bContext *C, float mat[3][3], char *name);
|
||||||
|
|
||||||
|
|
||||||
#define ORIENTATION_NONE 0
|
#define ORIENTATION_NONE 0
|
||||||
#define ORIENTATION_NORMAL 1
|
#define ORIENTATION_NORMAL 1
|
||||||
|
@ -412,6 +412,9 @@ int calc_manipulator_stats(const bContext *C)
|
|||||||
if(ob && totsel) {
|
if(ob && totsel) {
|
||||||
|
|
||||||
switch(v3d->twmode) {
|
switch(v3d->twmode) {
|
||||||
|
|
||||||
|
case V3D_MANIP_GLOBAL:
|
||||||
|
break; /* nothing to do */
|
||||||
|
|
||||||
case V3D_MANIP_NORMAL:
|
case V3D_MANIP_NORMAL:
|
||||||
if(obedit || ob->mode & OB_MODE_POSE) {
|
if(obedit || ob->mode & OB_MODE_POSE) {
|
||||||
@ -473,8 +476,12 @@ int calc_manipulator_stats(const bContext *C)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: /* V3D_MANIP_CUSTOM */
|
default: /* V3D_MANIP_CUSTOM */
|
||||||
// XXX applyTransformOrientation(C, t);
|
{
|
||||||
break;
|
float mat[3][3];
|
||||||
|
applyTransformOrientation(C, mat, NULL);
|
||||||
|
Mat4CpyMat3(rv3d->twmat, mat);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -152,8 +152,9 @@ void TFM_OT_select_orientation(struct wmOperatorType *ot)
|
|||||||
|
|
||||||
/* identifiers */
|
/* identifiers */
|
||||||
ot->name = "Select Orientation";
|
ot->name = "Select Orientation";
|
||||||
ot->description= "Select orientation type.";
|
ot->description= "Select transformation orientation.";
|
||||||
ot->idname = "TFM_OT_select_orientation";
|
ot->idname = "TFM_OT_select_orientation";
|
||||||
|
ot->flag = OPTYPE_UNDO;
|
||||||
|
|
||||||
/* api callbacks */
|
/* api callbacks */
|
||||||
ot->invoke = select_orientation_invoke;
|
ot->invoke = select_orientation_invoke;
|
||||||
@ -164,6 +165,92 @@ void TFM_OT_select_orientation(struct wmOperatorType *ot)
|
|||||||
RNA_def_enum_funcs(prop, select_orientation_itemf);
|
RNA_def_enum_funcs(prop, select_orientation_itemf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int delete_orientation_exec(bContext *C, wmOperator *op)
|
||||||
|
{
|
||||||
|
View3D *v3d = CTX_wm_view3d(C);
|
||||||
|
int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
|
||||||
|
|
||||||
|
BIF_removeTransformOrientationIndex(C, selected_index);
|
||||||
|
|
||||||
|
return OPERATOR_FINISHED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int delete_orientation_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||||
|
{
|
||||||
|
return delete_orientation_exec(C, op);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int delete_orientation_poll(bContext *C)
|
||||||
|
{
|
||||||
|
int selected_index = -1;
|
||||||
|
View3D *v3d = CTX_wm_view3d(C);
|
||||||
|
|
||||||
|
if (ED_operator_areaactive(C) == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
|
if(v3d) {
|
||||||
|
selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
|
||||||
|
}
|
||||||
|
|
||||||
|
return selected_index >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TFM_OT_delete_orientation(struct wmOperatorType *ot)
|
||||||
|
{
|
||||||
|
/* identifiers */
|
||||||
|
ot->name = "Delete Orientation";
|
||||||
|
ot->description= "Delete transformation orientation.";
|
||||||
|
ot->idname = "TFM_OT_delete_orientation";
|
||||||
|
ot->flag = OPTYPE_UNDO;
|
||||||
|
|
||||||
|
/* api callbacks */
|
||||||
|
ot->invoke = delete_orientation_invoke;
|
||||||
|
ot->exec = delete_orientation_exec;
|
||||||
|
ot->poll = delete_orientation_poll;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int create_orientation_exec(bContext *C, wmOperator *op)
|
||||||
|
{
|
||||||
|
char name[36];
|
||||||
|
int use = RNA_boolean_get(op->ptr, "use");
|
||||||
|
int overwrite = RNA_boolean_get(op->ptr, "overwrite");
|
||||||
|
|
||||||
|
RNA_string_get(op->ptr, "name", name);
|
||||||
|
|
||||||
|
BIF_createTransformOrientation(C, op->reports, name, use, overwrite);
|
||||||
|
|
||||||
|
/* Do we need more refined tags? */
|
||||||
|
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
|
||||||
|
|
||||||
|
return OPERATOR_FINISHED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int create_orientation_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||||
|
{
|
||||||
|
return create_orientation_exec(C, op);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TFM_OT_create_orientation(struct wmOperatorType *ot)
|
||||||
|
{
|
||||||
|
/* identifiers */
|
||||||
|
ot->name = "Create Orientation";
|
||||||
|
ot->description= "Create transformation orientation from selection.";
|
||||||
|
ot->idname = "TFM_OT_create_orientation";
|
||||||
|
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", "", 35, "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");
|
||||||
|
}
|
||||||
|
|
||||||
static void transformops_exit(bContext *C, wmOperator *op)
|
static void transformops_exit(bContext *C, wmOperator *op)
|
||||||
{
|
{
|
||||||
saveTransform(C, op->customdata, op);
|
saveTransform(C, op->customdata, op);
|
||||||
@ -643,6 +730,8 @@ void transform_operatortypes(void)
|
|||||||
WM_operatortype_append(TFM_OT_edge_slide);
|
WM_operatortype_append(TFM_OT_edge_slide);
|
||||||
|
|
||||||
WM_operatortype_append(TFM_OT_select_orientation);
|
WM_operatortype_append(TFM_OT_select_orientation);
|
||||||
|
WM_operatortype_append(TFM_OT_create_orientation);
|
||||||
|
WM_operatortype_append(TFM_OT_delete_orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void transform_keymap_for_space(struct wmWindowManager *wm, struct wmKeyMap *keymap, int spaceid)
|
void transform_keymap_for_space(struct wmWindowManager *wm, struct wmKeyMap *keymap, int spaceid)
|
||||||
@ -675,6 +764,9 @@ void transform_keymap_for_space(struct wmWindowManager *wm, struct wmKeyMap *key
|
|||||||
|
|
||||||
km = WM_keymap_add_item(keymap, "TFM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
|
km = WM_keymap_add_item(keymap, "TFM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
|
||||||
|
|
||||||
|
km = WM_keymap_add_item(keymap, "TFM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
|
||||||
|
RNA_boolean_set(km->ptr, "use", 1);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SPACE_ACTION:
|
case SPACE_ACTION:
|
||||||
km= WM_keymap_add_item(keymap, "TFM_OT_transform", GKEY, KM_PRESS, 0, 0);
|
km= WM_keymap_add_item(keymap, "TFM_OT_transform", GKEY, KM_PRESS, 0, 0);
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
|
|
||||||
@ -43,6 +44,7 @@
|
|||||||
#include "BKE_utildefines.h"
|
#include "BKE_utildefines.h"
|
||||||
#include "BKE_armature.h"
|
#include "BKE_armature.h"
|
||||||
#include "BKE_context.h"
|
#include "BKE_context.h"
|
||||||
|
#include "BKE_report.h"
|
||||||
|
|
||||||
#include "BLI_arithb.h"
|
#include "BLI_arithb.h"
|
||||||
#include "BLI_blenlib.h"
|
#include "BLI_blenlib.h"
|
||||||
@ -67,108 +69,131 @@
|
|||||||
|
|
||||||
void BIF_clearTransformOrientation(bContext *C)
|
void BIF_clearTransformOrientation(bContext *C)
|
||||||
{
|
{
|
||||||
|
View3D *v3d = CTX_wm_view3d(C);
|
||||||
|
|
||||||
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
|
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
|
||||||
BLI_freelistN(transform_spaces);
|
BLI_freelistN(transform_spaces);
|
||||||
|
|
||||||
// TRANSFORM_FIX_ME
|
|
||||||
// Need to loop over all view3d
|
// Need to loop over all view3d
|
||||||
// if (G.vd->twmode >= V3D_MANIP_CUSTOM)
|
if(v3d && v3d->twmode >= V3D_MANIP_CUSTOM) {
|
||||||
// G.vd->twmode = V3D_MANIP_GLOBAL; /* fallback to global */
|
v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BIF_manageTransformOrientation(bContext *C, int confirm, int set) {
|
TransformOrientation* findOrientationName(bContext *C, char *name)
|
||||||
|
{
|
||||||
|
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
|
||||||
|
TransformOrientation *ts= NULL;
|
||||||
|
|
||||||
|
for (ts = transform_spaces->first; ts; ts = ts->next) {
|
||||||
|
if (strncmp(ts->name, name, 35) == 0) {
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void uniqueOrientationName(bContext *C, char *name)
|
||||||
|
{
|
||||||
|
if (findOrientationName(C, name) != NULL)
|
||||||
|
{
|
||||||
|
char tempname[64];
|
||||||
|
int number;
|
||||||
|
char *dot;
|
||||||
|
|
||||||
|
|
||||||
|
number = strlen(name);
|
||||||
|
|
||||||
|
if (number && isdigit(name[number-1]))
|
||||||
|
{
|
||||||
|
dot = strrchr(name, '.'); // last occurrence
|
||||||
|
if (dot)
|
||||||
|
*dot=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (number = 1; number <= 999; number++)
|
||||||
|
{
|
||||||
|
sprintf(tempname, "%s.%03d", name, number);
|
||||||
|
if (findOrientationName(C, tempname) == NULL)
|
||||||
|
{
|
||||||
|
BLI_strncpy(name, tempname, 32);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BIF_createTransformOrientation(bContext *C, ReportList *reports, char *name, int use, int overwrite)
|
||||||
|
{
|
||||||
Object *obedit = CTX_data_edit_object(C);
|
Object *obedit = CTX_data_edit_object(C);
|
||||||
Object *ob = CTX_data_active_object(C);
|
Object *ob = CTX_data_active_object(C);
|
||||||
int index = -1;
|
TransformOrientation *ts = NULL;
|
||||||
|
|
||||||
if (obedit) {
|
if (obedit) {
|
||||||
if (obedit->type == OB_MESH)
|
if (obedit->type == OB_MESH)
|
||||||
index = manageMeshSpace(C, confirm, set);
|
ts = createMeshSpace(C, reports, name, overwrite);
|
||||||
else if (obedit->type == OB_ARMATURE)
|
else if (obedit->type == OB_ARMATURE)
|
||||||
index = manageBoneSpace(C, confirm, set);
|
ts = createBoneSpace(C, reports, name, overwrite);
|
||||||
}
|
}
|
||||||
else if (ob && (ob->mode & OB_MODE_POSE)) {
|
else if (ob && (ob->mode & OB_MODE_POSE)) {
|
||||||
index = manageBoneSpace(C, confirm, set);
|
ts = createBoneSpace(C, reports, name, overwrite);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
index = manageObjectSpace(C, confirm, set);
|
ts = createObjectSpace(C, reports, name, overwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set && index != -1)
|
if (use && ts != NULL)
|
||||||
{
|
{
|
||||||
BIF_selectTransformOrientationValue(C, V3D_MANIP_CUSTOM + index);
|
BIF_selectTransformOrientation(C, ts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int manageObjectSpace(bContext *C, int confirm, int set) {
|
TransformOrientation *createObjectSpace(bContext *C, ReportList *reports, char *name, int overwrite) {
|
||||||
Base *base = CTX_data_active_base(C);
|
Base *base = CTX_data_active_base(C);
|
||||||
|
Object *ob;
|
||||||
|
float mat[3][3];
|
||||||
|
|
||||||
if (base == NULL)
|
if (base == NULL)
|
||||||
return -1;
|
return NULL;
|
||||||
|
|
||||||
//XXX if (confirm == 0) {
|
|
||||||
// if (set && pupmenu("Custom Orientation %t|Add and Use Active Object%x1") != 1) {
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
// else if (set == 0 && pupmenu("Custom Orientation %t|Add Active Object%x1") != 1) {
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
return addObjectSpace(C, base->object);
|
ob = base->object;
|
||||||
|
|
||||||
|
Mat3CpyMat4(mat, ob->obmat);
|
||||||
|
Mat3Ortho(mat);
|
||||||
|
|
||||||
|
/* use object name if no name is given */
|
||||||
|
if (name[0] == 0)
|
||||||
|
{
|
||||||
|
strncpy(name, ob->id.name+2, 35);
|
||||||
|
}
|
||||||
|
|
||||||
|
return addMatrixSpace(C, mat, name, overwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return 1 on confirm */
|
TransformOrientation *createBoneSpace(bContext *C, ReportList *reports, char *name, int overwrite) {
|
||||||
int confirmSpace(int set, char text[])
|
|
||||||
{
|
|
||||||
char menu[64];
|
|
||||||
|
|
||||||
if (set) {
|
|
||||||
sprintf(menu, "Custom Orientation %%t|Add and Use %s%%x1", text);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sprintf(menu, "Custom Orientation %%t|Add %s%%x1", text);
|
|
||||||
}
|
|
||||||
|
|
||||||
//XXX if (pupmenu(menu) == 1) {
|
|
||||||
return 1;
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
int manageBoneSpace(bContext *C, int confirm, int set) {
|
|
||||||
float mat[3][3];
|
float mat[3][3];
|
||||||
float normal[3], plane[3];
|
float normal[3], plane[3];
|
||||||
char name[36] = "";
|
|
||||||
int index;
|
|
||||||
|
|
||||||
getTransformOrientation(C, normal, plane, 0);
|
getTransformOrientation(C, normal, plane, 0);
|
||||||
|
|
||||||
if (confirm == 0 && confirmSpace(set, "Bone") == 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (createSpaceNormalTangent(mat, normal, plane) == 0) {
|
if (createSpaceNormalTangent(mat, normal, plane) == 0) {
|
||||||
//XXX error("Cannot use zero-length bone");
|
BKE_reports_prepend(reports, "Cannot use zero-length bone");
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(name, "Bone");
|
if (name[0] == 0)
|
||||||
|
{
|
||||||
|
strcpy(name, "Bone");
|
||||||
|
}
|
||||||
|
|
||||||
/* Input name */
|
return addMatrixSpace(C, mat, name, overwrite);
|
||||||
//XXX sbutton(name, 1, 35, "name: ");
|
|
||||||
|
|
||||||
index = addMatrixSpace(C, mat, name);
|
|
||||||
return index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int manageMeshSpace(bContext *C, int confirm, int set) {
|
TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, char *name, int overwrite) {
|
||||||
float mat[3][3];
|
float mat[3][3];
|
||||||
float normal[3], plane[3];
|
float normal[3], plane[3];
|
||||||
char name[36] = "";
|
|
||||||
int index;
|
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
type = getTransformOrientation(C, normal, plane, 0);
|
type = getTransformOrientation(C, normal, plane, 0);
|
||||||
@ -176,51 +201,44 @@ int manageMeshSpace(bContext *C, int confirm, int set) {
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ORIENTATION_VERT:
|
case ORIENTATION_VERT:
|
||||||
if (confirm == 0 && confirmSpace(set, "vertex") == 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (createSpaceNormal(mat, normal) == 0) {
|
if (createSpaceNormal(mat, normal) == 0) {
|
||||||
// XXX error("Cannot use vertex with zero-length normal");
|
BKE_reports_prepend(reports, "Cannot use vertex with zero-length normal");
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(name, "Vertex");
|
if (name[0] == 0)
|
||||||
|
{
|
||||||
|
strcpy(name, "Vertex");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ORIENTATION_EDGE:
|
case ORIENTATION_EDGE:
|
||||||
if (confirm == 0 && confirmSpace(set, "Edge") == 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (createSpaceNormalTangent(mat, normal, plane) == 0) {
|
if (createSpaceNormalTangent(mat, normal, plane) == 0) {
|
||||||
// XXX error("Cannot use zero-length edge");
|
BKE_reports_prepend(reports, "Cannot use zero-length edge");
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(name, "Edge");
|
if (name[0] == 0)
|
||||||
|
{
|
||||||
|
strcpy(name, "Edge");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ORIENTATION_FACE:
|
case ORIENTATION_FACE:
|
||||||
if (confirm == 0 && confirmSpace(set, "Face") == 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (createSpaceNormalTangent(mat, normal, plane) == 0) {
|
if (createSpaceNormalTangent(mat, normal, plane) == 0) {
|
||||||
// XXX error("Cannot use zero-area face");
|
BKE_reports_prepend(reports, "Cannot use zero-area face");
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(name, "Face");
|
if (name[0] == 0)
|
||||||
|
{
|
||||||
|
strcpy(name, "Face");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Input name */
|
return addMatrixSpace(C, mat, name, overwrite);
|
||||||
//XXX sbutton(name, 1, 35, "name: ");
|
|
||||||
|
|
||||||
index = addMatrixSpace(C, mat, name);
|
|
||||||
return index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int createSpaceNormal(float mat[3][3], float normal[3])
|
int createSpaceNormal(float mat[3][3], float normal[3])
|
||||||
@ -271,32 +289,17 @@ int createSpaceNormalTangent(float mat[3][3], float normal[3], float tangent[3])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TransformOrientation* addMatrixSpace(bContext *C, float mat[3][3], char name[], int overwrite) {
|
||||||
int addObjectSpace(bContext *C, Object *ob) {
|
|
||||||
float mat[3][3];
|
|
||||||
char name[36] = "";
|
|
||||||
|
|
||||||
Mat3CpyMat4(mat, ob->obmat);
|
|
||||||
Mat3Ortho(mat);
|
|
||||||
|
|
||||||
strncpy(name, ob->id.name+2, 35);
|
|
||||||
|
|
||||||
/* Input name */
|
|
||||||
//XXX sbutton(name, 1, 35, "name: ");
|
|
||||||
|
|
||||||
return addMatrixSpace(C, mat, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
int addMatrixSpace(bContext *C, float mat[3][3], char name[]) {
|
|
||||||
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
|
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
|
||||||
TransformOrientation *ts;
|
TransformOrientation *ts = NULL;
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
/* if name is found in list, reuse that transform space */
|
if (overwrite)
|
||||||
for (index = 0, ts = transform_spaces->first; ts; ts = ts->next, index++) {
|
{
|
||||||
if (strncmp(ts->name, name, 35) == 0) {
|
ts = findOrientationName(C, name);
|
||||||
break;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
uniqueOrientationName(C, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if not, create a new one */
|
/* if not, create a new one */
|
||||||
@ -310,31 +313,61 @@ int addMatrixSpace(bContext *C, float mat[3][3], char name[]) {
|
|||||||
/* copy matrix into transform space */
|
/* copy matrix into transform space */
|
||||||
Mat3CpyMat3(ts->mat, mat);
|
Mat3CpyMat3(ts->mat, mat);
|
||||||
|
|
||||||
ED_undo_push(C, "Add/Update Transform Orientation");
|
return ts;
|
||||||
|
|
||||||
return index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target) {
|
void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target) {
|
||||||
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
|
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
|
||||||
TransformOrientation *ts = transform_spaces->first;
|
TransformOrientation *ts = transform_spaces->first;
|
||||||
//int selected_index = (G.vd->twmode - V3D_MANIP_CUSTOM);
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) {
|
for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) {
|
||||||
if (ts == target) {
|
if (ts == target) {
|
||||||
// Transform_fix_me NEED TO DO THIS FOR ALL VIEW3D
|
View3D *v3d = CTX_wm_view3d(C);
|
||||||
// if (selected_index == i) {
|
if(v3d) {
|
||||||
// G.vd->twmode = V3D_MANIP_GLOBAL; /* fallback to global */
|
int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
|
||||||
// }
|
|
||||||
// else if (selected_index > i)
|
// Transform_fix_me NEED TO DO THIS FOR ALL VIEW3D
|
||||||
// G.vd->twmode--;
|
if (selected_index == i) {
|
||||||
|
v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */
|
||||||
|
}
|
||||||
|
else if (selected_index > i) {
|
||||||
|
v3d->twmode--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
BLI_freelinkN(transform_spaces, ts);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BIF_removeTransformOrientationIndex(bContext *C, int index) {
|
||||||
|
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
|
||||||
|
TransformOrientation *ts = transform_spaces->first;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) {
|
||||||
|
if (i == index) {
|
||||||
|
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--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
BLI_freelinkN(transform_spaces, ts);
|
BLI_freelinkN(transform_spaces, ts);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ED_undo_push(C, "Remove Transform Orientation");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) {
|
void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) {
|
||||||
@ -433,7 +466,7 @@ int BIF_countTransformOrientation(const bContext *C) {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyTransformOrientation(const bContext *C, TransInfo *t) {
|
void applyTransformOrientation(const bContext *C, float mat[3][3], char *name) {
|
||||||
TransformOrientation *ts;
|
TransformOrientation *ts;
|
||||||
View3D *v3d = CTX_wm_view3d(C);
|
View3D *v3d = CTX_wm_view3d(C);
|
||||||
int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
|
int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
|
||||||
@ -442,8 +475,11 @@ void applyTransformOrientation(const bContext *C, TransInfo *t) {
|
|||||||
if (selected_index >= 0) {
|
if (selected_index >= 0) {
|
||||||
for (i = 0, ts = CTX_data_scene(C)->transform_spaces.first; ts; ts = ts->next, i++) {
|
for (i = 0, ts = CTX_data_scene(C)->transform_spaces.first; ts; ts = ts->next, i++) {
|
||||||
if (selected_index == i) {
|
if (selected_index == i) {
|
||||||
strcpy(t->spacename, ts->name);
|
|
||||||
Mat3CpyMat3(t->spacemtx, ts->mat);
|
if (name)
|
||||||
|
strcpy(name, ts->name);
|
||||||
|
|
||||||
|
Mat3CpyMat3(mat, ts->mat);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -558,7 +594,7 @@ void initTransformOrientation(bContext *C, TransInfo *t)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: /* V3D_MANIP_CUSTOM */
|
default: /* V3D_MANIP_CUSTOM */
|
||||||
applyTransformOrientation(C, t);
|
applyTransformOrientation(C, t->spacemtx, t->spacename);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user