diff options
Diffstat (limited to 'source/blender/editors/transform/transform.h')
-rw-r--r-- | source/blender/editors/transform/transform.h | 210 |
1 files changed, 152 insertions, 58 deletions
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index b1b1dd36bf0..df2fa1da43d 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -37,11 +37,17 @@ #include "ED_numinput.h" #include "ED_view3d.h" +#include "RE_engine.h" + #include "DNA_listBase.h" +#include "DEG_depsgraph.h" + /* ************************** Types ***************************** */ +struct Depsgraph; struct TransInfo; +struct TransDataContainer; struct TransData; struct TransformOrientation; struct TransSnap; @@ -50,6 +56,7 @@ struct Object; struct View3D; struct ScrArea; struct Scene; +struct ViewLayer; struct bConstraint; struct wmKeyMap; struct wmKeyConfig; @@ -58,9 +65,13 @@ struct wmEvent; struct wmTimer; struct ARegion; struct ReportList; +struct RNG; struct EditBone; +struct RenderEngineType; struct SnapObjectContext; +#include "DNA_object_enums.h" + /* transinfo->redraw */ typedef enum { TREDRAW_NOTHING = 0, @@ -100,7 +111,7 @@ typedef struct TransSnap { * \note Return value can be anything, * where the smallest absolute value defines whats closest. */ - float (*distance)(struct TransInfo *, const float p1[3], const float p2[3]); + float (*distance)(struct TransInfo *t, const float p1[3], const float p2[3]); /** * Re-usable snap context data. @@ -118,14 +129,16 @@ typedef struct TransCon { /* the one in TransInfo is not garanty to stay the same (Rotates change it) */ int mode; /* Mode flags of the Constraint */ void (*drawExtra)(struct TransInfo *t); + + /* Note: if 'tc' is NULL, 'td' must also be NULL. */ /* For constraints that needs to draw differently from the other * uses this instead of the generic draw function */ - void (*applyVec)(struct TransInfo *t, struct TransData *td, const float in[3], float out[3], float pvec[3]); + void (*applyVec)(struct TransInfo *t, struct TransDataContainer *tc, struct TransData *td, const float in[3], float out[3], float pvec[3]); /* Apply function pointer for linear vectorial transformation */ /* The last three parameters are pointers to the in/out/printable vectors */ - void (*applySize)(struct TransInfo *t, struct TransData *td, float smat[3][3]); + void (*applySize)(struct TransInfo *t, struct TransDataContainer *tc, struct TransData *td, float smat[3][3]); /* Apply function pointer for size transformation */ - void (*applyRot)(struct TransInfo *t, struct TransData *td, float vec[3], float *angle); + void (*applyRot)(struct TransInfo *t, struct TransDataContainer *tc, struct TransData *td, float vec[3], float *angle); /* Apply function pointer for rotation transformation */ } TransCon; @@ -261,10 +274,6 @@ typedef struct EdgeSlideData { SlideOrigData orig_data; - float perc; - - bool use_even; - bool flipped; int curr_sv_index; @@ -272,6 +281,12 @@ typedef struct EdgeSlideData { int curr_side_unclamp; } EdgeSlideData; +typedef struct EdgeSlideParams { + float perc; + + bool use_even; + bool flipped; +} EdgeSlideParams; typedef struct TransDataVertSlideVert { /* TransDataGenericSlideVert */ @@ -293,17 +308,19 @@ typedef struct VertSlideData { SlideOrigData orig_data; - float perc; - - bool use_even; - bool flipped; - int curr_sv_index; /* result of ED_view3d_ob_project_mat_get */ float proj_mat[4][4]; } VertSlideData; +typedef struct VertSlideParams { + float perc; + + bool use_even; + bool flipped; +} VertSlideParams; + typedef struct BoneInitData { struct EditBone *bone; float tail[3]; @@ -364,16 +381,80 @@ typedef struct MouseInput { typedef struct TransCustomData { void *data; - void (*free_cb)(struct TransInfo *, struct TransCustomData *); + void (*free_cb)(struct TransInfo *, struct TransDataContainer *tc, struct TransCustomData *custom_data); unsigned int use_free : 1; } TransCustomData; typedef struct TransCenterData { - float local[3], global[3]; + float global[3]; unsigned int is_set : 1; } TransCenterData; +/** + * Rule of thumb for choosing between mode/type: + * - If transform mode uses the data, assign to `mode` + * (typically in transform.c). + * - If conversion uses the data as an extension to the #TransData, assign to `type` + * (typically in transform_conversion.c). + */ +typedef struct TransCustomDataContainer { + /** Owned by the mode (grab, scale, bend... ).*/ + union { + TransCustomData mode, first_elem; + }; + TransCustomData type; +} TransCustomDataContainer; +#define TRANS_CUSTOM_DATA_ELEM_MAX (sizeof(TransCustomDataContainer) / sizeof(TransCustomData)) + +typedef struct TransDataContainer { + /** + * Use for cases we care about the active, eg: active vert of active mesh. + * if set this will _always_ be the first item in the array. + */ + bool is_active; + + /** Transformed data (array). */ + TransData *data; + /** Total number of transformed data. */ + int data_len; + + /** Transformed data extension (array). */ + TransDataExtension *data_ext; + /** Transformed data for 2d (array). */ + TransData2D *data_2d; + + struct Object *obedit; + + /** + * Use when #T_LOCAL_MATRIX is set. + * Typically: 'obedit->obmat' or 'poseobj->obmat', but may be used elsewhere too. + */ + bool use_local_mat; + float mat[4][4]; + float imat[4][4]; + /** 3x3 copies of matrices above. */ + float mat3[3][3]; + float imat3[3][3]; + + /** Normalized 'mat3' */ + float mat3_unit[3][3]; + + /** if 't->flag & T_POSE', this denotes pose object */ + struct Object *poseobj; + + /** Center of transformation (in local-space), Calculated from #TransInfo.center_global. */ + float center_local[3]; + + TransCustomDataContainer custom; +} TransDataContainer; + typedef struct TransInfo { + TransDataContainer *data_container; + int data_container_len; + /** Combine length of all #TransDataContainer.data_len + * Use to check if nothing is selected or if we have a single selection. */ + int data_len_all; + int mode; /* current mode */ int flag; /* generic flags for special behaviors */ int modifiers; /* special modifiers, by function, not key */ @@ -384,10 +465,6 @@ typedef struct TransInfo { /* transform function pointer */ eRedrawFlag (*handleEvent)(struct TransInfo *, const struct wmEvent *); /* event handler function pointer RETURN 1 if redraw is needed */ - int total; /* total number of transformed data */ - TransData *data; /* transformed data (array) */ - TransDataExtension *ext; /* transformed data extension (array) */ - TransData2D *data2d; /* transformed data for 2d (array) */ TransCon con; /* transformed constraint */ TransSnap tsnap; NumInput num; /* numerical input */ @@ -397,7 +474,6 @@ typedef struct TransInfo { char proptext[20]; /* proportional falloff text */ float aspect[3]; /* spaces using non 1:1 aspect, (uv's, f-curve, movie-clip... etc) * use for conversion and snapping. */ - float center[3]; /* center of transformation (in local-space) */ float center_global[3]; /* center of transformation (in global-space) */ float center2d[2]; /* center in screen coordinates */ /* Lazy initialize center data for when we need other center values. @@ -415,7 +491,8 @@ typedef struct TransInfo { short persp; short around; char spacetype; /* spacetype where transforming is */ - char helpline; /* helpline modes (not to be confused with hotline) */ + char helpline; /* Choice of custom cursor with or without a help line from the manipulator to the mouse position. */ + short obedit_type; /* Avoid looking inside TransDataContainer obedit. */ float vec[3]; /* translation, to show for widget */ float mat[3][3]; /* rot/rescale, to show for widget */ @@ -423,36 +500,19 @@ typedef struct TransInfo { float spacemtx[3][3]; /* orientation matrix of the current space */ char spacename[64]; /* name of the current space, MAX_NAME */ - struct Object *poseobj; /* if t->flag & T_POSE, this denotes pose object */ - - /** - * Rule of thumb for choosing between mode/type: - * - If transform mode uses the data, assign to `mode` - * (typically in transform.c). - * - If conversion uses the data as an extension to the #TransData, assign to `type` - * (typically in transform_conversion.c). - */ - struct { - /* owned by the mode (grab, scale, bend... )*/ - union { - TransCustomData mode, first_elem; - }; - /* owned by the type (mesh, armature, nla...) */ - TransCustomData type; - } custom; -#define TRANS_CUSTOM_DATA_ELEM_MAX (sizeof(((TransInfo *)NULL)->custom) / sizeof(TransCustomData)) - /*************** NEW STUFF *********************/ short launch_event; /* event type used to launch transform */ short current_orientation; - short twtype; /* backup from view3d, to restore on end */ + TransformOrientation *custom_orientation; /* this gets used when current_orientation is V3D_MANIP_CUSTOM */ + short twflag; /* backup from view3d, to restore on end */ short prop_mode; short mirror; float values[4]; + float values_modal_offset[4]; /* Offset applied ontop of modal input. */ float auto_values[4]; float axis[3]; float axis_orig[3]; /* TransCon can change 'axis', store the original value here */ @@ -463,19 +523,25 @@ typedef struct TransInfo { struct bContext *context; /* Only valid (non null) during an operator called function. */ struct ScrArea *sa; struct ARegion *ar; + struct Depsgraph *depsgraph; struct Scene *scene; + struct ViewLayer *view_layer; struct ToolSettings *settings; struct wmTimer *animtimer; struct wmKeyMap *keymap; /* so we can do lookups for header text */ struct ReportList *reports; /* assign from the operator, or can be NULL */ int mval[2]; /* current mouse position */ float zfac; /* use for 3d view */ - struct Object *obedit; - float obedit_mat[3][3]; /* normalized editmode matrix (T_EDIT only) */ void *draw_handle_apply; void *draw_handle_view; void *draw_handle_pixel; void *draw_handle_cursor; + + /** Currently only used for random curve of proportional editing. */ + struct RNG *rng; + + /** Typically for mode settings. */ + TransCustomDataContainer custom; } TransInfo; @@ -489,15 +555,20 @@ typedef struct TransInfo { /* transinfo->flag */ #define T_OBJECT (1 << 0) +/** \note We could remove 'T_EDIT' and use 'obedit_type', for now ensure they're in sync. */ #define T_EDIT (1 << 1) #define T_POSE (1 << 2) #define T_TEXTURE (1 << 3) /* transforming the camera while in camera view */ #define T_CAMERA (1 << 4) + /* transforming the 3D cursor. */ +#define T_CURSOR (1 << 5) // trans on points, having no rotation/scale #define T_POINTS (1 << 6) - // for manipulator exceptions, like scaling using center point, drawing help lines -#define T_USES_MANIPULATOR (1 << 7) +/** + * Apply matrix #TransDataContainer.matrix, this avoids having to have duplicate check all over + * that happen to apply to spesiifc modes (edit & pose for eg). */ +#define T_LOCAL_MATRIX (1 << 7) /* restrictions flags */ #define T_ALL_RESTRICTIONS ((1 << 8)|(1 << 9)|(1 << 10)) @@ -536,6 +607,8 @@ typedef struct TransInfo { /** #TransInfo.center has been set, don't change it. */ #define T_OVERRIDE_CENTER (1 << 25) +#define T_MODAL_CURSOR_SET (1 << 26) + /* TransInfo->modifiers */ #define MOD_CONSTRAINT_SELECT 0x01 #define MOD_PRECISION 0x02 @@ -635,10 +708,14 @@ void flushTransSeq(TransInfo *t); void flushTransTracking(TransInfo *t); void flushTransMasking(TransInfo *t); void flushTransPaintCurve(TransInfo *t); -void restoreBones(TransInfo *t); +void restoreBones(TransDataContainer *tc); -/*********************** exported from transform_manipulator.c ********** */ -bool gimbal_axis(struct Object *ob, float gmat[3][3]); /* return 0 when no gimbal for selection */ +/*********************** transform_manipulator.c ********** */ + +#define MANIPULATOR_AXIS_LINE_WIDTH 2.0f + +/* return 0 when no gimbal for selection */ +bool gimbal_axis(struct Object *ob, float gmat[3][3]); /*********************** TransData Creation and General Handling *********** */ void createTransData(struct bContext *C, TransInfo *t); @@ -649,13 +726,13 @@ int special_transform_moving(TransInfo *t); void transform_autoik_update(TransInfo *t, short mode); bool transdata_check_local_islands(TransInfo *t, short around); -int count_set_pose_transflags(int *out_mode, short around, struct Object *ob); +int count_set_pose_transflags(struct Object *ob, const int mode, const short around, bool has_translate_rotate[2]); /* auto-keying stuff used by special_aftertrans_update */ void autokeyframe_ob_cb_func( - struct bContext *C, struct Scene *scene, struct View3D *v3d, struct Object *ob, int tmode); + struct bContext *C, struct Scene *scene, struct ViewLayer *view_layer, struct Object *ob, int tmode); void autokeyframe_pose_cb_func( - struct bContext *C, struct Scene *scene, struct View3D *v3d, struct Object *ob, int tmode, short targetless_ik); + struct bContext *C, struct Scene *scene, struct Object *ob, int tmode, short targetless_ik); /*********************** Constraints *****************************/ @@ -743,7 +820,9 @@ void setInputPostFct(MouseInput *mi, void (*post)(struct TransInfo *t, float val /*********************** Generics ********************************/ +void initTransDataContainers_FromObjectData(TransInfo *t); void initTransInfo(struct bContext *C, TransInfo *t, struct wmOperator *op, const struct wmEvent *event); +void freeTransCustomDataForMode(TransInfo *t); void postTrans(struct bContext *C, TransInfo *t); void resetTransModal(TransInfo *t); void resetTransRestrictions(TransInfo *t); @@ -758,9 +837,7 @@ void restoreTransObjects(TransInfo *t); void recalcData(TransInfo *t); void calculateCenter2D(TransInfo *t); -void calculateCenterGlobal( - TransInfo *t, const float center_local[3], - float r_center_global[3]); +void calculateCenterLocal(TransInfo *t, const float center_global[3]); const TransCenterData *transformCenter_from_type(TransInfo *t, int around); void calculateCenter(TransInfo *t); @@ -789,7 +866,7 @@ bool createSpaceNormalTangent(float mat[3][3], const float normal[3], const floa 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], int index); +bool applyTransformOrientation(const struct TransformOrientation *ts, float r_mat[3][3], char r_name[64]); #define ORIENTATION_NONE 0 #define ORIENTATION_NORMAL 1 @@ -801,19 +878,36 @@ int getTransformOrientation_ex(const struct bContext *C, float normal[3], float int getTransformOrientation(const struct bContext *C, float normal[3], float plane[3]); void freeEdgeSlideTempFaces(EdgeSlideData *sld); -void freeEdgeSlideVerts(TransInfo *t, TransCustomData *custom_data); +void freeEdgeSlideVerts(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data); void projectEdgeSlideData(TransInfo *t, bool is_final); void freeVertSlideTempFaces(VertSlideData *sld); -void freeVertSlideVerts(TransInfo *t, TransCustomData *custom_data); +void freeVertSlideVerts(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data); void projectVertSlideData(TransInfo *t, bool is_final); /* TODO. transform_queries.c */ bool checkUseAxisMatrix(TransInfo *t); -#define TRANSFORM_DIST_MAX_PX 1000.0f #define TRANSFORM_SNAP_MAX_PX 100.0f #define TRANSFORM_DIST_INVALID -FLT_MAX +/* Temp macros. */ + +/* This is to be replaced, just to get things compiling early on. */ +#define TRANS_DATA_CONTAINER_FIRST_EVIL(t) (&(t)->data_container[0]) +#define TRANS_DATA_CONTAINER_FIRST_OK(t) (&(t)->data_container[0]) +/* For cases we _know_ there is only one handle. */ +#define TRANS_DATA_CONTAINER_FIRST_SINGLE(t) (BLI_assert((t)->data_container_len == 1), (&(t)->data_container[0])) + +#define FOREACH_TRANS_DATA_CONTAINER(t, th) \ + for (TransDataContainer *tc = t->data_container, *tc_end = t->data_container + t->data_container_len; \ + th != tc_end; \ + th++) + +#define FOREACH_TRANS_DATA_CONTAINER_INDEX(t, th, i) \ + for (TransDataContainer *tc = ((i = 0), t->data_container), *tc_end = t->data_container + t->data_container_len; \ + th != tc_end; \ + th++, i++) + #endif |