Generalized unique_editbone_name to be useable if a name change after the bone has been added to the list (this could probably simplify some code in editarmature, I haven't done that yet).
First pass for retargetting template's renaming magic. For now, in new retargetted bone's name: %S (side) and %N (number) will be replaced by user defined strings. Will need to experiment on how useful that is and how it could be better.
This commit is contained in:
@@ -133,7 +133,7 @@ void selectconnected_posearmature(void);
|
|||||||
void armature_select_hierarchy(short direction, short add_to_sel);
|
void armature_select_hierarchy(short direction, short add_to_sel);
|
||||||
|
|
||||||
void setflag_armature(short mode);
|
void setflag_armature(short mode);
|
||||||
void unique_editbone_name (struct ListBase *ebones, char *name);
|
void unique_editbone_name (struct ListBase *ebones, char *name, EditBone *bone); /* if bone is already in list, pass it as param to ignore it */
|
||||||
|
|
||||||
void auto_align_armature(short mode);
|
void auto_align_armature(short mode);
|
||||||
void switch_direction_armature(void);
|
void switch_direction_armature(void);
|
||||||
|
|||||||
@@ -113,16 +113,21 @@ typedef struct RigEdge {
|
|||||||
} RigEdge;
|
} RigEdge;
|
||||||
|
|
||||||
/* Control flags */
|
/* Control flags */
|
||||||
#define RIG_CTRL_DONE 1
|
#define RIG_CTRL_HEAD_DONE 1
|
||||||
#define RIG_CTRL_PARENT_DEFORM 2
|
#define RIG_CTRL_TAIL_DONE 2
|
||||||
#define RIG_CTRL_FIT_ROOT 4
|
#define RIG_CTRL_PARENT_DEFORM 4
|
||||||
#define RIG_CTRL_FIT_BONE 8
|
#define RIG_CTRL_FIT_ROOT 8
|
||||||
|
#define RIG_CTRL_FIT_BONE 16
|
||||||
|
|
||||||
|
#define RIG_CTRL_DONE (RIG_CTRL_HEAD_DONE|RIG_CTRL_TAIL_DONE)
|
||||||
|
|
||||||
|
|
||||||
typedef struct RigControl {
|
typedef struct RigControl {
|
||||||
struct RigControl *next, *prev;
|
struct RigControl *next, *prev;
|
||||||
float head[3], tail[3];
|
float head[3], tail[3];
|
||||||
EditBone *bone;
|
EditBone *bone;
|
||||||
EditBone *link;
|
EditBone *link;
|
||||||
|
EditBone *link_tail;
|
||||||
float up_axis[3];
|
float up_axis[3];
|
||||||
float offset[3];
|
float offset[3];
|
||||||
int flag;
|
int flag;
|
||||||
|
|||||||
@@ -448,6 +448,8 @@ typedef struct ToolSettings {
|
|||||||
char bone_sketching_convert;
|
char bone_sketching_convert;
|
||||||
char skgen_subdivision_number;
|
char skgen_subdivision_number;
|
||||||
char skgen_retarget_options;
|
char skgen_retarget_options;
|
||||||
|
char skgen_side_string[8];
|
||||||
|
char skgen_num_string[8];
|
||||||
|
|
||||||
/* Alt+RMB option */
|
/* Alt+RMB option */
|
||||||
char edge_mode;
|
char edge_mode;
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ static int BonesDict_SetItem(BPy_BonesDict *self, PyObject *key, PyObject *value
|
|||||||
//create a new editbone
|
//create a new editbone
|
||||||
editbone = MEM_callocN(sizeof(EditBone), "eBone");
|
editbone = MEM_callocN(sizeof(EditBone), "eBone");
|
||||||
BLI_strncpy(editbone->name, key_str, 32);
|
BLI_strncpy(editbone->name, key_str, 32);
|
||||||
unique_editbone_name(NULL, editbone->name);
|
unique_editbone_name(NULL, editbone->name, NULL);
|
||||||
editbone->dist = ((BPy_EditBone*)value)->dist;
|
editbone->dist = ((BPy_EditBone*)value)->dist;
|
||||||
editbone->ease1 = ((BPy_EditBone*)value)->ease1;
|
editbone->ease1 = ((BPy_EditBone*)value)->ease1;
|
||||||
editbone->ease2 = ((BPy_EditBone*)value)->ease2;
|
editbone->ease2 = ((BPy_EditBone*)value)->ease2;
|
||||||
|
|||||||
@@ -832,7 +832,7 @@ static PyObject *EditBone_new(PyTypeObject *type, PyObject *args, PyObject *kwds
|
|||||||
//otherwise this will act as a py_object
|
//otherwise this will act as a py_object
|
||||||
py_editBone->editbone = NULL;
|
py_editBone->editbone = NULL;
|
||||||
|
|
||||||
unique_editbone_name(NULL, name);
|
unique_editbone_name(NULL, name, NULL);
|
||||||
BLI_strncpy(py_editBone->name, name, 32);
|
BLI_strncpy(py_editBone->name, name, 32);
|
||||||
py_editBone->parent = NULL;
|
py_editBone->parent = NULL;
|
||||||
py_editBone->weight= 1.0f;
|
py_editBone->weight= 1.0f;
|
||||||
|
|||||||
@@ -2361,6 +2361,9 @@ static void view3d_panel_bonesketch_spaces(short cntrl)
|
|||||||
uiDefButF(block, NUM, B_DIFF, "Len:", 60, yco, 50,19, &G.scene->toolsettings->skgen_retarget_length_weight, 0, 10, 1, 0, "Length Weight");
|
uiDefButF(block, NUM, B_DIFF, "Len:", 60, yco, 50,19, &G.scene->toolsettings->skgen_retarget_length_weight, 0, 10, 1, 0, "Length Weight");
|
||||||
uiDefButF(block, NUM, B_DIFF, "Dist:", 110,yco, 50,19, &G.scene->toolsettings->skgen_retarget_distance_weight, 0, 10, 1, 0, "Distance Weight");
|
uiDefButF(block, NUM, B_DIFF, "Dist:", 110,yco, 50,19, &G.scene->toolsettings->skgen_retarget_distance_weight, 0, 10, 1, 0, "Distance Weight");
|
||||||
yco -= 20;
|
yco -= 20;
|
||||||
|
|
||||||
|
uiDefBut(block, TEX,0,"S:", 10, yco, 75, 20, G.scene->toolsettings->skgen_side_string, 0.0, 8.0, 0, 0, "Text to replace %S with");
|
||||||
|
uiDefBut(block, TEX,0,"N:", 85, yco, 75, 20, G.scene->toolsettings->skgen_num_string, 0.0, 8.0, 0, 0, "Text to replace %N with");
|
||||||
|
|
||||||
uiBlockEndAlign(block);
|
uiBlockEndAlign(block);
|
||||||
|
|
||||||
|
|||||||
@@ -699,7 +699,7 @@ int join_armature(void)
|
|||||||
curbone= editbone_name_exists(&eblist, pchan->name);
|
curbone= editbone_name_exists(&eblist, pchan->name);
|
||||||
|
|
||||||
/* Get new name */
|
/* Get new name */
|
||||||
unique_editbone_name(&ebbase, curbone->name);
|
unique_editbone_name(&ebbase, curbone->name, NULL);
|
||||||
|
|
||||||
/* Transform the bone */
|
/* Transform the bone */
|
||||||
{
|
{
|
||||||
@@ -1999,7 +1999,7 @@ EditBone *addEditBone(char *name, ListBase *ebones, bArmature *arm)
|
|||||||
EditBone *bone= MEM_callocN(sizeof(EditBone), "eBone");
|
EditBone *bone= MEM_callocN(sizeof(EditBone), "eBone");
|
||||||
|
|
||||||
BLI_strncpy(bone->name, name, 32);
|
BLI_strncpy(bone->name, name, 32);
|
||||||
unique_editbone_name(ebones, bone->name);
|
unique_editbone_name(ebones, bone->name, NULL);
|
||||||
|
|
||||||
BLI_addtail(ebones, bone);
|
BLI_addtail(ebones, bone);
|
||||||
|
|
||||||
@@ -2298,7 +2298,7 @@ EditBone *duplicateEditBoneObjects(EditBone *curBone, ListBase *editbones, Objec
|
|||||||
curBone->temp = eBone;
|
curBone->temp = eBone;
|
||||||
eBone->temp = curBone;
|
eBone->temp = curBone;
|
||||||
|
|
||||||
unique_editbone_name(editbones, eBone->name);
|
unique_editbone_name(editbones, eBone->name, NULL);
|
||||||
BLI_addtail(editbones, eBone);
|
BLI_addtail(editbones, eBone);
|
||||||
|
|
||||||
/* Lets duplicate the list of constraints that the
|
/* Lets duplicate the list of constraints that the
|
||||||
@@ -2388,7 +2388,7 @@ void adduplicate_armature(void)
|
|||||||
curBone->temp = eBone;
|
curBone->temp = eBone;
|
||||||
eBone->temp = curBone;
|
eBone->temp = curBone;
|
||||||
|
|
||||||
unique_editbone_name(&G.edbo, eBone->name);
|
unique_editbone_name(&G.edbo, eBone->name, NULL);
|
||||||
BLI_addtail(&G.edbo, eBone);
|
BLI_addtail(&G.edbo, eBone);
|
||||||
if (!firstDup)
|
if (!firstDup)
|
||||||
firstDup=eBone;
|
firstDup=eBone;
|
||||||
@@ -3152,13 +3152,16 @@ static EditBone *editbone_name_exists (ListBase *ebones, char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* note: there's a unique_bone_name() too! */
|
/* note: there's a unique_bone_name() too! */
|
||||||
void unique_editbone_name (ListBase *ebones, char *name)
|
void unique_editbone_name (ListBase *ebones, char *name, EditBone *bone)
|
||||||
{
|
{
|
||||||
|
EditBone *dupli;
|
||||||
char tempname[64];
|
char tempname[64];
|
||||||
int number;
|
int number;
|
||||||
char *dot;
|
char *dot;
|
||||||
|
|
||||||
if (editbone_name_exists(ebones, name)) {
|
dupli = editbone_name_exists(ebones, name);
|
||||||
|
|
||||||
|
if (dupli && bone != dupli) {
|
||||||
/* Strip off the suffix, if it's a number */
|
/* Strip off the suffix, if it's a number */
|
||||||
number= strlen(name);
|
number= strlen(name);
|
||||||
if (number && isdigit(name[number-1])) {
|
if (number && isdigit(name[number-1])) {
|
||||||
@@ -3279,7 +3282,7 @@ void extrude_armature(int forked)
|
|||||||
else strcat(newbone->name, "_R");
|
else strcat(newbone->name, "_R");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unique_editbone_name(&G.edbo, newbone->name);
|
unique_editbone_name(&G.edbo, newbone->name, NULL);
|
||||||
|
|
||||||
/* Add the new bone to the list */
|
/* Add the new bone to the list */
|
||||||
BLI_addtail(&G.edbo, newbone);
|
BLI_addtail(&G.edbo, newbone);
|
||||||
@@ -3366,7 +3369,7 @@ void subdivide_armature(int numcuts)
|
|||||||
|
|
||||||
newbone->flag |= BONE_CONNECTED;
|
newbone->flag |= BONE_CONNECTED;
|
||||||
|
|
||||||
unique_editbone_name (&G.edbo, newbone->name);
|
unique_editbone_name (&G.edbo, newbone->name, NULL);
|
||||||
|
|
||||||
/* correct parent bones */
|
/* correct parent bones */
|
||||||
for (tbone = G.edbo.first; tbone; tbone=tbone->next) {
|
for (tbone = G.edbo.first; tbone; tbone=tbone->next) {
|
||||||
@@ -4400,7 +4403,7 @@ void armature_bone_rename(bArmature *arm, char *oldnamep, char *newnamep)
|
|||||||
|
|
||||||
eBone= editbone_name_exists(&G.edbo, oldname);
|
eBone= editbone_name_exists(&G.edbo, oldname);
|
||||||
if (eBone) {
|
if (eBone) {
|
||||||
unique_editbone_name(&G.edbo, newname);
|
unique_editbone_name(&G.edbo, newname, NULL);
|
||||||
BLI_strncpy(eBone->name, newname, MAXBONENAME);
|
BLI_strncpy(eBone->name, newname, MAXBONENAME);
|
||||||
}
|
}
|
||||||
else return;
|
else return;
|
||||||
|
|||||||
@@ -400,6 +400,44 @@ static void RIG_addEdgeToArc(RigArc *arc, float tail[3], EditBone *bone)
|
|||||||
}
|
}
|
||||||
/************************************** CLONING TEMPLATES **********************************************/
|
/************************************** CLONING TEMPLATES **********************************************/
|
||||||
|
|
||||||
|
static void renameTemplateBone(EditBone *bone, char *template_name, ListBase *editbones)
|
||||||
|
{
|
||||||
|
char *side_string = G.scene->toolsettings->skgen_side_string;
|
||||||
|
char *num_string = G.scene->toolsettings->skgen_num_string;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
for (i = 0, j = 0; template_name[i] != '\0' && i < 31 && j < 31; i++)
|
||||||
|
{
|
||||||
|
if (template_name[i] == '%')
|
||||||
|
{
|
||||||
|
if (template_name[i+1] == 'S')
|
||||||
|
{
|
||||||
|
j += sprintf(bone->name + j, side_string);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else if (template_name[i+1] == 'N')
|
||||||
|
{
|
||||||
|
j += sprintf(bone->name + j, num_string);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bone->name[j] = template_name[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bone->name[j] = template_name[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bone->name[j] = '\0';
|
||||||
|
|
||||||
|
unique_editbone_name(editbones, bone->name, bone);
|
||||||
|
}
|
||||||
|
|
||||||
static RigControl *cloneControl(RigGraph *rg, RigGraph *src_rg, RigControl *src_ctrl, GHash *ptr_hash)
|
static RigControl *cloneControl(RigGraph *rg, RigGraph *src_rg, RigControl *src_ctrl, GHash *ptr_hash)
|
||||||
{
|
{
|
||||||
RigControl *ctrl;
|
RigControl *ctrl;
|
||||||
@@ -414,6 +452,7 @@ static RigControl *cloneControl(RigGraph *rg, RigGraph *src_rg, RigControl *src_
|
|||||||
ctrl->flag = src_ctrl->flag;
|
ctrl->flag = src_ctrl->flag;
|
||||||
|
|
||||||
ctrl->bone = duplicateEditBoneObjects(src_ctrl->bone, rg->editbones, src_rg->ob, rg->ob);
|
ctrl->bone = duplicateEditBoneObjects(src_ctrl->bone, rg->editbones, src_rg->ob, rg->ob);
|
||||||
|
renameTemplateBone(ctrl->bone, src_ctrl->bone->name, rg->editbones);
|
||||||
ctrl->bone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE);
|
ctrl->bone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE);
|
||||||
BLI_ghash_insert(ptr_hash, src_ctrl->bone, ctrl->bone);
|
BLI_ghash_insert(ptr_hash, src_ctrl->bone, ctrl->bone);
|
||||||
|
|
||||||
@@ -455,6 +494,7 @@ static RigArc *cloneArc(RigGraph *rg, RigGraph *src_rg, RigArc *src_arc, GHash *
|
|||||||
if (src_edge->bone != NULL)
|
if (src_edge->bone != NULL)
|
||||||
{
|
{
|
||||||
edge->bone = duplicateEditBoneObjects(src_edge->bone, rg->editbones, src_rg->ob, rg->ob);
|
edge->bone = duplicateEditBoneObjects(src_edge->bone, rg->editbones, src_rg->ob, rg->ob);
|
||||||
|
renameTemplateBone(edge->bone, src_edge->bone->name, rg->editbones);
|
||||||
edge->bone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE);
|
edge->bone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE);
|
||||||
BLI_ghash_insert(ptr_hash, src_edge->bone, edge->bone);
|
BLI_ghash_insert(ptr_hash, src_edge->bone, edge->bone);
|
||||||
}
|
}
|
||||||
@@ -1456,7 +1496,7 @@ static EditBone *add_editbonetolist(char *name, ListBase *list)
|
|||||||
EditBone *bone= MEM_callocN(sizeof(EditBone), "eBone");
|
EditBone *bone= MEM_callocN(sizeof(EditBone), "eBone");
|
||||||
|
|
||||||
BLI_strncpy(bone->name, name, 32);
|
BLI_strncpy(bone->name, name, 32);
|
||||||
unique_editbone_name(list, bone->name);
|
unique_editbone_name(list, bone->name, NULL);
|
||||||
|
|
||||||
BLI_addtail(list, bone);
|
BLI_addtail(list, bone);
|
||||||
|
|
||||||
@@ -1624,35 +1664,53 @@ void generateMissingArcs(RigGraph *rigg)
|
|||||||
|
|
||||||
/************************************ RETARGETTING *****************************************************/
|
/************************************ RETARGETTING *****************************************************/
|
||||||
|
|
||||||
|
static void repositionControl(RigGraph *rigg, RigControl *ctrl, float head[3], float tail[3], float qrot[4], float resize);
|
||||||
|
|
||||||
|
|
||||||
|
static void finalizeControl(RigGraph *rigg, RigControl *ctrl, float qrot[4], float resize)
|
||||||
|
{
|
||||||
|
if ((ctrl->flag & RIG_CTRL_DONE) == RIG_CTRL_DONE)
|
||||||
|
{
|
||||||
|
RigControl *ctrl_child;
|
||||||
|
|
||||||
|
ctrl->bone->roll = rollBoneByQuat(ctrl->bone, ctrl->up_axis, qrot);
|
||||||
|
|
||||||
|
/* Cascade to connected control bones */
|
||||||
|
for (ctrl_child = rigg->controls.first; ctrl_child; ctrl_child = ctrl_child->next)
|
||||||
|
{
|
||||||
|
if (ctrl_child->link == ctrl->bone)
|
||||||
|
{
|
||||||
|
repositionControl(rigg, ctrl_child, ctrl->bone->head, ctrl->bone->tail, qrot, resize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void repositionControl(RigGraph *rigg, RigControl *ctrl, float head[3], float tail[3], float qrot[4], float resize)
|
static void repositionControl(RigGraph *rigg, RigControl *ctrl, float head[3], float tail[3], float qrot[4], float resize)
|
||||||
{
|
{
|
||||||
RigControl *ctrl_child;
|
|
||||||
float parent_offset[3], tail_offset[3];
|
float parent_offset[3], tail_offset[3];
|
||||||
|
|
||||||
VecSubf(tail_offset, ctrl->tail, ctrl->head);
|
|
||||||
VecMulf(tail_offset, resize);
|
|
||||||
|
|
||||||
VECCOPY(parent_offset, ctrl->offset);
|
VECCOPY(parent_offset, ctrl->offset);
|
||||||
VecMulf(parent_offset, resize);
|
VecMulf(parent_offset, resize);
|
||||||
|
|
||||||
QuatMulVecf(qrot, parent_offset);
|
QuatMulVecf(qrot, parent_offset);
|
||||||
QuatMulVecf(qrot, tail_offset);
|
|
||||||
|
|
||||||
VecAddf(ctrl->bone->head, head, parent_offset);
|
VecAddf(ctrl->bone->head, head, parent_offset);
|
||||||
VecAddf(ctrl->bone->tail, ctrl->bone->head, tail_offset);
|
|
||||||
ctrl->bone->roll = rollBoneByQuat(ctrl->bone, ctrl->up_axis, qrot);
|
|
||||||
|
|
||||||
ctrl->flag |= RIG_CTRL_DONE;
|
|
||||||
|
|
||||||
/* Cascade to connected control bones */
|
ctrl->flag |= RIG_CTRL_HEAD_DONE;
|
||||||
for (ctrl_child = rigg->controls.first; ctrl_child; ctrl_child = ctrl_child->next)
|
|
||||||
|
if (ctrl->link_tail == NULL)
|
||||||
{
|
{
|
||||||
if (ctrl_child->link == ctrl->bone)
|
VecSubf(tail_offset, ctrl->tail, ctrl->head);
|
||||||
{
|
VecMulf(tail_offset, resize);
|
||||||
repositionControl(rigg, ctrl_child, ctrl->bone->head, ctrl->bone->tail, qrot, resize);
|
QuatMulVecf(qrot, tail_offset);
|
||||||
}
|
|
||||||
|
VecAddf(ctrl->bone->tail, ctrl->bone->head, tail_offset);
|
||||||
|
|
||||||
|
ctrl->flag |= RIG_CTRL_TAIL_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finalizeControl(rigg, ctrl, qrot, resize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void repositionBone(RigGraph *rigg, RigEdge *edge, float vec0[3], float vec1[3], float up_axis[3])
|
static void repositionBone(RigGraph *rigg, RigEdge *edge, float vec0[3], float vec1[3], float up_axis[3])
|
||||||
|
|||||||
@@ -933,7 +933,7 @@ static void gp_stroke_to_bonechain (bGPDlayer *gpl, bGPDstroke *gps, bArmature *
|
|||||||
/* add new bone - note: sync with editarmature.c::add_editbone() */
|
/* add new bone - note: sync with editarmature.c::add_editbone() */
|
||||||
{
|
{
|
||||||
BLI_strncpy(ebo->name, "Stroke", 32);
|
BLI_strncpy(ebo->name, "Stroke", 32);
|
||||||
unique_editbone_name(bones, ebo->name);
|
unique_editbone_name(bones, ebo->name, NULL);
|
||||||
|
|
||||||
BLI_addtail(bones, ebo);
|
BLI_addtail(bones, ebo);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user