Cleanup: Transform: Rearrange definitions and declarations

This commit is contained in:
Germano Cavalcante 2020-02-15 18:43:58 -03:00
parent 322dc72316
commit 0716394423
Notes: blender-bot 2023-02-14 08:39:23 +01:00
Referenced by issue #74246, Widget Label Textsize is broken if you change the size(bigger or smaller than 11px)
8 changed files with 223 additions and 213 deletions

View File

@ -270,114 +270,6 @@ typedef struct TransDataNla {
int handle;
} TransDataNla;
struct LinkNode;
/* header of TransDataEdgeSlideVert, TransDataEdgeSlideEdge */
typedef struct TransDataGenericSlideVert {
struct BMVert *v;
struct LinkNode **cd_loop_groups;
float co_orig_3d[3];
} TransDataGenericSlideVert;
typedef struct TransDataEdgeSlideVert {
/** #TransDataGenericSlideVert (header) */
struct BMVert *v;
struct LinkNode **cd_loop_groups;
float v_co_orig[3];
/* end generic */
float edge_len;
struct BMVert *v_side[2];
/* add origvert.co to get the original locations */
float dir_side[2][3];
int loop_nr;
} TransDataEdgeSlideVert;
typedef struct EdgeSlideData {
TransDataEdgeSlideVert *sv;
int totsv;
int mval_start[2], mval_end[2];
int curr_sv_index;
/** when un-clamped - use this index: #TransDataEdgeSlideVert.dir_side */
int curr_side_unclamp;
} EdgeSlideData;
typedef struct EdgeSlideParams {
float perc;
bool use_even;
bool flipped;
} EdgeSlideParams;
typedef struct TransDataVertSlideVert {
/** #TransDataGenericSlideVert (header) */
struct BMVert *v;
struct LinkNode **cd_loop_groups;
float co_orig_3d[3];
/* end generic */
float (*co_link_orig_3d)[3];
int co_link_tot;
int co_link_curr;
} TransDataVertSlideVert;
typedef struct VertSlideData {
TransDataVertSlideVert *sv;
int totsv;
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];
float rad_head;
float rad_tail;
float roll;
float head[3];
float dist;
float xwidth;
float zwidth;
} BoneInitData;
typedef struct PoseInitData_Mirror {
/** Points to the bone which this info is initialized & restored to.
* A NULL value is used to terminate the array. */
struct bPoseChannel *pchan;
struct {
float loc[3];
float size[3];
union {
float eul[3];
float quat[4];
float axis_angle[4];
};
float curve_in_x;
float curve_out_x;
float roll1;
float roll2;
} orig;
/**
* An extra offset to apply after mirroring.
* Use with #POSE_MIRROR_RELATIVE.
*/
float offset_mtx[4][4];
} PoseInitData_Mirror;
typedef struct TransData {
/** Distance needed to affect element (for Proportionnal Editing). */
float dist;

View File

@ -1870,13 +1870,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
}
else {
if (t->mode == TFM_EDGE_SLIDE) {
EdgeSlideParams *slp = t->custom.mode.data;
slp->perc = 0.0;
projectEdgeSlideData(t, false);
}
else if (t->mode == TFM_VERT_SLIDE) {
EdgeSlideParams *slp = t->custom.mode.data;
slp->perc = 0.0;
projectVertSlideData(t, false);
}
}

View File

@ -63,6 +63,7 @@ void clipUVData(TransInfo *t);
void flushTransIntFrameActionData(TransInfo *t);
/* transform_convert_armature.c */
void pose_transform_mirror_update(TransInfo *t, TransDataContainer *tc, Object *ob);
void restoreMirrorPoseBones(TransDataContainer *tc);
void restoreBones(TransDataContainer *tc);

View File

@ -45,24 +45,17 @@
#include "transform.h"
#include "transform_convert.h"
bKinematicConstraint *has_targetless_ik(bPoseChannel *pchan)
{
bConstraint *con = pchan->constraints.first;
for (; con; con = con->next) {
if (con->type == CONSTRAINT_TYPE_KINEMATIC && (con->enforce != 0.0f)) {
bKinematicConstraint *data = con->data;
if (data->tar == NULL) {
return data;
}
if (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0) {
return data;
}
}
}
return NULL;
}
typedef struct BoneInitData {
struct EditBone *bone;
float tail[3];
float rad_head;
float rad_tail;
float roll;
float head[3];
float dist;
float xwidth;
float zwidth;
} BoneInitData;
static void add_pose_transdata(
TransInfo *t, bPoseChannel *pchan, Object *ob, TransDataContainer *tc, TransData *td)
@ -218,6 +211,29 @@ static void add_pose_transdata(
td->con = pchan->constraints.first;
}
/* -------------------------------------------------------------------- */
/** \name Pose Auto-IK
* \{ */
bKinematicConstraint *has_targetless_ik(bPoseChannel *pchan)
{
bConstraint *con = pchan->constraints.first;
for (; con; con = con->next) {
if (con->type == CONSTRAINT_TYPE_KINEMATIC && (con->enforce != 0.0f)) {
bKinematicConstraint *data = con->data;
if (data->tar == NULL) {
return data;
}
if (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0) {
return data;
}
}
}
return NULL;
}
/* adds the IK to pchan - returns if added */
static short pose_grab_with_ik_add(bPoseChannel *pchan)
{
@ -406,6 +422,36 @@ static short pose_grab_with_ik(Main *bmain, Object *ob)
return (tot_ik) ? 1 : 0;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Pose Mirror
* \{ */
typedef struct PoseInitData_Mirror {
/** Points to the bone which this info is initialized & restored to.
* A NULL value is used to terminate the array. */
struct bPoseChannel *pchan;
struct {
float loc[3];
float size[3];
union {
float eul[3];
float quat[4];
float axis_angle[4];
};
float curve_in_x;
float curve_out_x;
float roll1;
float roll2;
} orig;
/**
* An extra offset to apply after mirroring.
* Use with #POSE_MIRROR_RELATIVE.
*/
float offset_mtx[4][4];
} PoseInitData_Mirror;
static void pose_mirror_info_init(PoseInitData_Mirror *pid,
bPoseChannel *pchan,
bPoseChannel *pchan_orig,
@ -474,6 +520,89 @@ static void pose_mirror_info_restore(const PoseInitData_Mirror *pid)
}
}
/**
* if pose bone (partial) selected, copy data.
* context; posemode armature, with mirror editing enabled.
*/
void pose_transform_mirror_update(TransInfo *t, TransDataContainer *tc, Object *ob)
{
float flip_mtx[4][4];
unit_m4(flip_mtx);
flip_mtx[0][0] = -1;
bPose *pose = ob->pose;
PoseInitData_Mirror *pid = NULL;
if ((t->mode != TFM_BONESIZE) && (pose->flag & POSE_MIRROR_RELATIVE)) {
pid = tc->custom.type.data;
}
TransData *td = tc->data;
for (int i = tc->data_len; i--; td++) {
bPoseChannel *pchan_orig = td->extra;
BLI_assert(pchan_orig->bone->flag & BONE_TRANSFORM);
/* No layer check, correct mirror is more important. */
bPoseChannel *pchan = BKE_pose_channel_get_mirrored(pose, pchan_orig->name);
if (pchan == NULL) {
continue;
}
/* Also do bbone scaling. */
pchan->bone->xwidth = pchan_orig->bone->xwidth;
pchan->bone->zwidth = pchan_orig->bone->zwidth;
/* We assume X-axis flipping for now. */
pchan->curve_in_x = pchan_orig->curve_in_x * -1;
pchan->curve_out_x = pchan_orig->curve_out_x * -1;
pchan->roll1 = pchan_orig->roll1 * -1; // XXX?
pchan->roll2 = pchan_orig->roll2 * -1; // XXX?
float pchan_mtx_final[4][4];
BKE_pchan_to_mat4(pchan_orig, pchan_mtx_final);
mul_m4_m4m4(pchan_mtx_final, pchan_mtx_final, flip_mtx);
mul_m4_m4m4(pchan_mtx_final, flip_mtx, pchan_mtx_final);
if (pid) {
mul_m4_m4m4(pchan_mtx_final, pid->offset_mtx, pchan_mtx_final);
}
BKE_pchan_apply_mat4(pchan, pchan_mtx_final, false);
/* In this case we can do target-less IK grabbing. */
if (t->mode == TFM_TRANSLATION) {
bKinematicConstraint *data = has_targetless_ik(pchan);
if (data == NULL) {
continue;
}
mul_v3_m4v3(data->grabtarget, flip_mtx, td->loc);
if (pid) {
/* TODO(germano): Realitve Mirror support */
}
data->flag |= CONSTRAINT_IK_AUTO;
}
if (pid) {
pid++;
}
}
}
void restoreMirrorPoseBones(TransDataContainer *tc)
{
bPose *pose = tc->poseobj->pose;
if (!(pose->flag & POSE_MIRROR_EDIT)) {
return;
}
for (PoseInitData_Mirror *pid = tc->custom.type.data; pid->pchan; pid++) {
pose_mirror_info_restore(pid);
}
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Convert Armature
* \{ */
/**
* When objects array is NULL, use 't->data_container' as is.
*/
@ -620,19 +749,6 @@ void createTransPose(TransInfo *t)
t->flag &= ~T_PROP_EDIT_ALL;
}
void restoreMirrorPoseBones(TransDataContainer *tc)
{
bPose *pose = tc->poseobj->pose;
if (!(pose->flag & POSE_MIRROR_EDIT)) {
return;
}
for (PoseInitData_Mirror *pid = tc->custom.type.data; pid->pchan; pid++) {
pose_mirror_info_restore(pid);
}
}
void restoreBones(TransDataContainer *tc)
{
bArmature *arm;
@ -682,7 +798,6 @@ void restoreBones(TransDataContainer *tc)
}
}
/* ********************* armature ************** */
void createTransArmatureVerts(TransInfo *t)
{
t->data_len_all = 0;
@ -936,3 +1051,5 @@ void createTransArmatureVerts(TransInfo *t)
}
}
}
/** \} */

View File

@ -783,69 +783,6 @@ static void recalcData_spaceclip(TransInfo *t)
}
}
/**
* if pose bone (partial) selected, copy data.
* context; posemode armature, with mirror editing enabled.
*
* \param pid: Optional, apply relative transform when set (has no effect on mirrored bones).
*/
static void pose_transform_mirror_update(TransInfo *t,
TransDataContainer *tc,
Object *ob,
PoseInitData_Mirror *pid)
{
float flip_mtx[4][4];
unit_m4(flip_mtx);
flip_mtx[0][0] = -1;
TransData *td = tc->data;
for (int i = tc->data_len; i--; td++) {
bPoseChannel *pchan_orig = td->extra;
BLI_assert(pchan_orig->bone->flag & BONE_TRANSFORM);
/* No layer check, correct mirror is more important. */
bPoseChannel *pchan = BKE_pose_channel_get_mirrored(ob->pose, pchan_orig->name);
if (pchan == NULL) {
continue;
}
/* Also do bbone scaling. */
pchan->bone->xwidth = pchan_orig->bone->xwidth;
pchan->bone->zwidth = pchan_orig->bone->zwidth;
/* We assume X-axis flipping for now. */
pchan->curve_in_x = pchan_orig->curve_in_x * -1;
pchan->curve_out_x = pchan_orig->curve_out_x * -1;
pchan->roll1 = pchan_orig->roll1 * -1; // XXX?
pchan->roll2 = pchan_orig->roll2 * -1; // XXX?
float pchan_mtx_final[4][4];
BKE_pchan_to_mat4(pchan_orig, pchan_mtx_final);
mul_m4_m4m4(pchan_mtx_final, pchan_mtx_final, flip_mtx);
mul_m4_m4m4(pchan_mtx_final, flip_mtx, pchan_mtx_final);
if (pid) {
mul_m4_m4m4(pchan_mtx_final, pid->offset_mtx, pchan_mtx_final);
}
BKE_pchan_apply_mat4(pchan, pchan_mtx_final, false);
/* In this case we can do target-less IK grabbing. */
if (t->mode == TFM_TRANSLATION) {
bKinematicConstraint *data = has_targetless_ik(pchan);
if (data == NULL) {
continue;
}
mul_v3_m4v3(data->grabtarget, flip_mtx, td->loc);
if (pid) {
/* TODO(germano): Realitve Mirror support */
}
data->flag |= CONSTRAINT_IK_AUTO;
}
if (pid) {
pid++;
}
}
}
/* helper for recalcData() - for object transforms, typically in the 3D view */
static void recalcData_objects(TransInfo *t)
{
@ -1058,7 +995,7 @@ static void recalcData_objects(TransInfo *t)
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
bPose *pose = ob->pose;
if (arm->flag & ARM_MIRROR_EDIT || pose->flag & POSE_MIRROR_EDIT) {
pose_transform_mirror_update(t, tc, ob, NULL);
pose_transform_mirror_update(t, tc, ob);
}
}
}
@ -1072,11 +1009,7 @@ static void recalcData_objects(TransInfo *t)
if (pose->flag & POSE_MIRROR_EDIT) {
if (t->state != TRANS_CANCEL) {
PoseInitData_Mirror *pid = NULL;
if (pose->flag & POSE_MIRROR_RELATIVE) {
pid = tc->custom.type.data;
}
pose_transform_mirror_update(t, tc, ob, pid);
pose_transform_mirror_update(t, tc, ob);
}
else {
restoreMirrorPoseBones(tc);

View File

@ -26,10 +26,18 @@
#define __TRANSFORM_MODE_H__
struct AnimData;
struct LinkNode;
struct TransInfo;
struct TransDataContainer;
struct TransData;
/* header of TransDataEdgeSlideVert, TransDataEdgeSlideEdge */
typedef struct TransDataGenericSlideVert {
struct BMVert *v;
struct LinkNode **cd_loop_groups;
float co_orig_3d[3];
} TransDataGenericSlideVert;
/* transform_mode.c */
bool transdata_check_local_center(TransInfo *t, short around);
void protectedTransBits(short protectflag, float vec[3]);

View File

@ -60,6 +60,41 @@
/** \name Transform Edge Slide
* \{ */
typedef struct TransDataEdgeSlideVert {
/** #TransDataGenericSlideVert (header) */
struct BMVert *v;
struct LinkNode **cd_loop_groups;
float v_co_orig[3];
/* end generic */
float edge_len;
struct BMVert *v_side[2];
/* add origvert.co to get the original locations */
float dir_side[2][3];
int loop_nr;
} TransDataEdgeSlideVert;
typedef struct EdgeSlideData {
TransDataEdgeSlideVert *sv;
int totsv;
int mval_start[2], mval_end[2];
int curr_sv_index;
/** when un-clamped - use this index: #TransDataEdgeSlideVert.dir_side */
int curr_side_unclamp;
} EdgeSlideData;
typedef struct EdgeSlideParams {
float perc;
bool use_even;
bool flipped;
} EdgeSlideParams;
/**
* Get the first valid EdgeSlideData.
*

View File

@ -57,6 +57,34 @@
/** \name Transform Vert Slide
* \{ */
typedef struct TransDataVertSlideVert {
/** #TransDataGenericSlideVert (header) */
struct BMVert *v;
struct LinkNode **cd_loop_groups;
float co_orig_3d[3];
/* end generic */
float (*co_link_orig_3d)[3];
int co_link_tot;
int co_link_curr;
} TransDataVertSlideVert;
typedef struct VertSlideData {
TransDataVertSlideVert *sv;
int totsv;
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;
static void calcVertSlideCustomPoints(struct TransInfo *t)
{
VertSlideParams *slp = t->custom.mode.data;