Skeleton retargetting - Preliminary commit. Results are encouraging but nothing *that* useful yet
Smarter heuristic noise arc filtering for Reeb graph
This commit is contained in:
parent
1345417f27
commit
db44a4a1a7
|
@ -68,6 +68,8 @@ typedef struct EditBone
|
|||
|
||||
} EditBone;
|
||||
|
||||
void make_boneList(struct ListBase *list, struct ListBase *bones, EditBone *parent);
|
||||
void editbones_to_armature (struct ListBase *list, struct Object *ob);
|
||||
|
||||
void adduplicate_armature(void);
|
||||
void addvert_armature(void);
|
||||
|
@ -142,6 +144,9 @@ void show_all_armature_bones(void);
|
|||
|
||||
#define BONESEL_NOSEL 0x80000000 /* Indicates a negative number */
|
||||
|
||||
/* from autoarmature */
|
||||
void BIF_retargetArmature();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -444,7 +444,8 @@ void curvemap_buttons(struct uiBlock *block, struct CurveMapping *cumap, char la
|
|||
#define B_SETMCOL_RND 2083
|
||||
#define B_DRAWBWEIGHTS 2084
|
||||
|
||||
#define B_GEN_SKELETON 2090
|
||||
#define B_GEN_SKELETON 2085
|
||||
#define B_RETARGET_SKELETON 2086
|
||||
|
||||
/* *********************** */
|
||||
#define B_VGROUPBUTS 2100
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "DNA_listBase.h"
|
||||
|
||||
struct GHash;
|
||||
struct EdgeHash;
|
||||
struct ReebArc;
|
||||
struct ReebEdge;
|
||||
|
@ -55,7 +56,11 @@ typedef struct ReebNode {
|
|||
int degree;
|
||||
float weight;
|
||||
float p[3];
|
||||
int flags;
|
||||
int flag;
|
||||
|
||||
int symmetry_level;
|
||||
int symmetry_flag;
|
||||
float symmetry_axis[3];
|
||||
} ReebNode;
|
||||
|
||||
typedef struct ReebEdge {
|
||||
|
@ -63,6 +68,7 @@ typedef struct ReebEdge {
|
|||
struct ReebArc *arc;
|
||||
struct ReebNode *v1, *v2;
|
||||
struct ReebEdge *nextEdge;
|
||||
int flag;
|
||||
} ReebEdge;
|
||||
|
||||
typedef struct ReebArc {
|
||||
|
@ -71,7 +77,13 @@ typedef struct ReebArc {
|
|||
struct ReebNode *v1, *v2;
|
||||
struct EmbedBucket *buckets;
|
||||
int bcount;
|
||||
int flags;
|
||||
int flag;
|
||||
|
||||
int symmetry_level;
|
||||
int symmetry_flag;
|
||||
|
||||
struct GHash *faces;
|
||||
float angle;
|
||||
} ReebArc;
|
||||
|
||||
typedef struct ReebArcIterator {
|
||||
|
@ -87,21 +99,28 @@ struct EditMesh;
|
|||
int weightToHarmonic(struct EditMesh *em);
|
||||
int weightFromDistance(struct EditMesh *em);
|
||||
int weightFromLoc(struct EditMesh *me, int axis);
|
||||
void weightToVCol(struct EditMesh *em);
|
||||
void weightToVCol(struct EditMesh *em, int index);
|
||||
void arcToVCol(struct ReebGraph *rg, struct EditMesh *em, int index);
|
||||
void angleToVCol(EditMesh *em, int index);
|
||||
void renormalizeWeight(struct EditMesh *em, float newmax);
|
||||
|
||||
ReebGraph * generateReebGraph(struct EditMesh *me, int subdivisions);
|
||||
void freeGraph(ReebGraph *rg);
|
||||
void exportGraph(ReebGraph *rg, int count);
|
||||
ReebGraph * newReebGraph();
|
||||
|
||||
#define OTHER_NODE(arc, node) ((arc->v1 == node) ? arc->v2 : arc->v1)
|
||||
|
||||
void initArcIterator(struct ReebArcIterator *iter, struct ReebArc *arc, struct ReebNode *head);
|
||||
void initArcIterator2(struct ReebArcIterator *iter, struct ReebArc *arc, int start, int end);
|
||||
void initArcIteratorStart(struct ReebArcIterator *iter, struct ReebArc *arc, struct ReebNode *head, int start);
|
||||
struct EmbedBucket * nextBucket(struct ReebArcIterator *iter);
|
||||
struct EmbedBucket * nextNBucket(ReebArcIterator *iter, int n);
|
||||
struct EmbedBucket * currentBucket(struct ReebArcIterator *iter);
|
||||
struct EmbedBucket * previousBucket(struct ReebArcIterator *iter);
|
||||
int iteratorStopped(struct ReebArcIterator *iter);
|
||||
|
||||
/* Filtering */
|
||||
void filterNullReebGraph(ReebGraph *rg);
|
||||
int filterSmartReebGraph(ReebGraph *rg, float threshold);
|
||||
int filterExternalReebGraph(ReebGraph *rg, float threshold);
|
||||
int filterInternalReebGraph(ReebGraph *rg, float threshold);
|
||||
|
||||
|
@ -121,7 +140,32 @@ int countConnectedArcs(ReebGraph *rg, ReebNode *node);
|
|||
int hasAdjacencyList(ReebGraph *rg);
|
||||
int isGraphCyclic(ReebGraph *rg);
|
||||
|
||||
/* Sanity check */
|
||||
/*------------ Symmetry handling ------------*/
|
||||
void markdownSymmetry(ReebGraph *rg);
|
||||
|
||||
/* ReebNode symmetry flags */
|
||||
#define SYM_TOPOLOGICAL 1
|
||||
#define SYM_PHYSICAL 2
|
||||
|
||||
/* the following two are exclusive */
|
||||
#define SYM_AXIAL 4
|
||||
#define SYM_RADIAL 8
|
||||
|
||||
/* ReebArc symmetry flags
|
||||
*
|
||||
* axial symetry sides */
|
||||
#define SYM_SIDE_POSITIVE 1
|
||||
#define SYM_SIDE_NEGATIVE 2
|
||||
|
||||
|
||||
|
||||
/*------------ Sanity check ------------*/
|
||||
void verifyBuckets(ReebGraph *rg);
|
||||
void verifyFaces(ReebGraph *rg);
|
||||
|
||||
/*********************** PUBLIC *********************************/
|
||||
ReebGraph *BIF_ReebGraphFromEditMesh(void);
|
||||
void REEB_freeGraph(ReebGraph *rg);
|
||||
void REEB_exportGraph(ReebGraph *rg, int count);
|
||||
|
||||
#endif /*REEB_H_*/
|
||||
|
|
|
@ -433,6 +433,8 @@ typedef struct ToolSettings {
|
|||
float skgen_angle_limit;
|
||||
float skgen_correlation_limit;
|
||||
float skgen_symmetry_limit;
|
||||
float skgen_retarget_angle_weight;
|
||||
float skgen_retarget_length_weight;
|
||||
short skgen_options;
|
||||
char skgen_postpro;
|
||||
char skgen_postpro_passes;
|
||||
|
@ -831,6 +833,7 @@ typedef struct Scene {
|
|||
#define SKGEN_CUT_LENGTH 8
|
||||
#define SKGEN_CUT_ANGLE 16
|
||||
#define SKGEN_CUT_CORRELATION 32
|
||||
#define SKGEN_HARMONIC 64
|
||||
|
||||
#define SKGEN_SUB_LENGTH 0
|
||||
#define SKGEN_SUB_ANGLE 1
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4891,6 +4891,9 @@ void do_meshbuts(unsigned short event)
|
|||
case B_GEN_SKELETON:
|
||||
generateSkeleton();
|
||||
break;
|
||||
case B_RETARGET_SKELETON:
|
||||
BIF_retargetArmature();
|
||||
break;
|
||||
}
|
||||
|
||||
/* WATCH IT: previous events only in editmode! */
|
||||
|
@ -4989,6 +4992,38 @@ static void skgen_reorder(void *option, void *arg2)
|
|||
}
|
||||
}
|
||||
|
||||
static void editing_panel_mesh_skgen_retarget(Object *ob, Mesh *me)
|
||||
{
|
||||
uiBlock *block;
|
||||
|
||||
block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_skgen_retarget", UI_EMBOSS, UI_HELV, curarea->win);
|
||||
uiNewPanelTabbed("Mesh Tools More", "Editing");
|
||||
if(uiNewPanel(curarea, block, "Skeleton Retargetting", "Editing", 960, 0, 318, 204)==0) return;
|
||||
|
||||
uiDefBut(block, BUT, B_RETARGET_SKELETON, "Retarget Skeleton", 1025,170,250,19, 0, 0, 0, 0, 0, "Retarget Selected Armature to this Mesh");
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButS(block, NUM, B_DIFF, "Resolution:", 1025,150,225,19, &G.scene->toolsettings->skgen_resolution,10.0,1000.0, 0, 0, "Specifies the resolution of the graph's embedding");
|
||||
uiDefButBitS(block, TOG, SKGEN_HARMONIC, B_DIFF, "H", 1250,150, 25,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Apply harmonic smoothing to the weighting");
|
||||
uiDefButBitS(block, TOG, SKGEN_FILTER_INTERNAL, B_DIFF, "Filter In", 1025,130, 83,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter internal small arcs from graph");
|
||||
uiDefButF(block, NUM, B_DIFF, "T:", 1111,130,164,19, &G.scene->toolsettings->skgen_threshold_internal,0.0, 1.0, 10, 0, "Specify the threshold ratio for filtering internal arcs");
|
||||
uiDefButBitS(block, TOG, SKGEN_FILTER_EXTERNAL, B_DIFF, "Filter Ex", 1025,110, 83,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter external small arcs from graph");
|
||||
uiDefButF(block, NUM, B_DIFF, "T:", 1111,110,164,19, &G.scene->toolsettings->skgen_threshold_external,0.0, 1.0, 10, 0, "Specify the threshold ratio for filtering external arcs");
|
||||
uiBlockEndAlign(block);
|
||||
|
||||
uiDefButF(block, NUM, B_DIFF, "Angle:", 1025, 60, 125,19, &G.scene->toolsettings->skgen_retarget_angle_weight, 0, 10, 1, 0, "Angle Weight");
|
||||
uiDefButF(block, NUM, B_DIFF, "Length:", 1150, 60, 125,19, &G.scene->toolsettings->skgen_retarget_length_weight, 0, 10, 1, 0, "Length Weight");
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButBitS(block, TOG, SKGEN_SYMMETRY, B_DIFF, "Symmetry", 1025, 30,125,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Restore symmetries based on topology");
|
||||
uiDefButF(block, NUM, B_DIFF, "T:", 1150, 30,125,19, &G.scene->toolsettings->skgen_symmetry_limit,0.0, 1.0, 10, 0, "Specify the threshold distance for considering potential symmetric arcs");
|
||||
uiDefButC(block, NUM, B_DIFF, "P:", 1025, 10, 62,19, &G.scene->toolsettings->skgen_postpro_passes, 0, 10, 10, 0, "Specify the number of processing passes on the embeddings");
|
||||
uiDefButC(block, ROW, B_DIFF, "Smooth", 1087, 10, 63,19, &G.scene->toolsettings->skgen_postpro, 5.0, (float)SKGEN_SMOOTH, 0, 0, "Smooth embeddings");
|
||||
uiDefButC(block, ROW, B_DIFF, "Average", 1150, 10, 62,19, &G.scene->toolsettings->skgen_postpro, 5.0, (float)SKGEN_AVERAGE, 0, 0, "Average embeddings");
|
||||
uiDefButC(block, ROW, B_DIFF, "Sharpen", 1212, 10, 63,19, &G.scene->toolsettings->skgen_postpro, 5.0, (float)SKGEN_SHARPEN, 0, 0, "Sharpen embeddings");
|
||||
uiBlockEndAlign(block);
|
||||
}
|
||||
|
||||
static void editing_panel_mesh_skgen(Object *ob, Mesh *me)
|
||||
{
|
||||
uiBlock *block;
|
||||
|
@ -4996,12 +5031,14 @@ static void editing_panel_mesh_skgen(Object *ob, Mesh *me)
|
|||
int i;
|
||||
|
||||
block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_skgen", UI_EMBOSS, UI_HELV, curarea->win);
|
||||
uiNewPanelTabbed("Mesh Tools More", "Editing");
|
||||
if(uiNewPanel(curarea, block, "Skeleton Generator", "Editing", 960, 0, 318, 204)==0) return;
|
||||
|
||||
uiDefBut(block, BUT, B_GEN_SKELETON, "Generate Skeleton", 1025,170,250,19, 0, 0, 0, 0, 0, "Generate Skeleton from Mesh");
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButS(block, NUM, B_DIFF, "Resolution:", 1025,150,250,19, &G.scene->toolsettings->skgen_resolution,10.0,1000.0, 0, 0, "Specifies the resolution of the graph's embedding");
|
||||
uiDefButS(block, NUM, B_DIFF, "Resolution:", 1025,150,225,19, &G.scene->toolsettings->skgen_resolution,10.0,1000.0, 0, 0, "Specifies the resolution of the graph's embedding");
|
||||
uiDefButBitS(block, TOG, SKGEN_HARMONIC, B_DIFF, "H", 1250,150, 25,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Apply harmonic smoothing to the weighting");
|
||||
uiDefButBitS(block, TOG, SKGEN_FILTER_INTERNAL, B_DIFF, "Filter In", 1025,130, 83,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter internal small arcs from graph");
|
||||
uiDefButF(block, NUM, B_DIFF, "T:", 1111,130,164,19, &G.scene->toolsettings->skgen_threshold_internal,0.0, 1.0, 10, 0, "Specify the threshold ratio for filtering internal arcs");
|
||||
uiDefButBitS(block, TOG, SKGEN_FILTER_EXTERNAL, B_DIFF, "Filter Ex", 1025,110, 83,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter external small arcs from graph");
|
||||
|
@ -6511,8 +6548,8 @@ void editing_panels()
|
|||
editing_panel_mesh_tools1(ob, ob->data);
|
||||
uiNewPanelTabbed("Mesh Tools 1", "Editing");
|
||||
|
||||
if (G.rt == 42) /* hidden for now, no time for docs */
|
||||
editing_panel_mesh_skgen(ob, ob->data);
|
||||
editing_panel_mesh_skgen(ob, ob->data);
|
||||
editing_panel_mesh_skgen_retarget(ob, ob->data);
|
||||
|
||||
editing_panel_mesh_uvautocalculation();
|
||||
if (EM_texFaceCheck())
|
||||
|
|
|
@ -4142,542 +4142,7 @@ void transform_armature_mirror_update(void)
|
|||
/*************************************** SKELETON GENERATOR ******************************************/
|
||||
/*****************************************************************************************************/
|
||||
|
||||
/**************************************** SYMMETRY HANDLING ******************************************/
|
||||
|
||||
void markdownSymmetryArc(ReebArc *arc, ReebNode *node, int level);
|
||||
|
||||
void mirrorAlongAxis(float v[3], float center[3], float axis[3])
|
||||
{
|
||||
float dv[3], pv[3];
|
||||
|
||||
VecSubf(dv, v, center);
|
||||
Projf(pv, dv, axis);
|
||||
VecMulf(pv, -2);
|
||||
VecAddf(v, v, pv);
|
||||
}
|
||||
|
||||
/* Helper structure for radial symmetry */
|
||||
typedef struct RadialArc
|
||||
{
|
||||
ReebArc *arc;
|
||||
float n[3]; /* normalized vector joining the nodes of the arc */
|
||||
} RadialArc;
|
||||
|
||||
void reestablishRadialSymmetry(ReebNode *node, int depth, float axis[3])
|
||||
{
|
||||
RadialArc *ring = NULL;
|
||||
RadialArc *unit;
|
||||
float limit = G.scene->toolsettings->skgen_symmetry_limit;
|
||||
int symmetric = 1;
|
||||
int count = 0;
|
||||
int i;
|
||||
|
||||
/* count the number of arcs in the symmetry ring */
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* depth is store as a negative in flag. symmetry level is positive */
|
||||
if (connectedArc->flags == -depth)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
ring = MEM_callocN(sizeof(RadialArc) * count, "radial symmetry ring");
|
||||
unit = ring;
|
||||
|
||||
/* fill in the ring */
|
||||
for (unit = ring, i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* depth is store as a negative in flag. symmetry level is positive */
|
||||
if (connectedArc->flags == -depth)
|
||||
{
|
||||
ReebNode *otherNode = OTHER_NODE(connectedArc, node);
|
||||
float vec[3];
|
||||
|
||||
unit->arc = connectedArc;
|
||||
|
||||
/* project the node to node vector on the symmetry plane */
|
||||
VecSubf(unit->n, otherNode->p, node->p);
|
||||
Projf(vec, unit->n, axis);
|
||||
VecSubf(unit->n, unit->n, vec);
|
||||
|
||||
Normalize(unit->n);
|
||||
|
||||
unit++;
|
||||
}
|
||||
}
|
||||
|
||||
/* sort ring */
|
||||
for (i = 0; i < count - 1; i++)
|
||||
{
|
||||
float minAngle = 3; /* arbitrary high value, higher than 2, at least */
|
||||
int minIndex = -1;
|
||||
int j;
|
||||
|
||||
for (j = i + 1; j < count; j++)
|
||||
{
|
||||
float angle = Inpf(ring[i].n, ring[j].n);
|
||||
|
||||
/* map negative values to 1..2 */
|
||||
if (angle < 0)
|
||||
{
|
||||
angle = 1 - angle;
|
||||
}
|
||||
|
||||
if (angle < minAngle)
|
||||
{
|
||||
minIndex = j;
|
||||
minAngle = angle;
|
||||
}
|
||||
}
|
||||
|
||||
/* swap if needed */
|
||||
if (minIndex != i + 1)
|
||||
{
|
||||
RadialArc tmp;
|
||||
tmp = ring[i + 1];
|
||||
ring[i + 1] = ring[minIndex];
|
||||
ring[minIndex] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < count && symmetric; i++)
|
||||
{
|
||||
ReebNode *node1, *node2;
|
||||
float tangent[3];
|
||||
float normal[3];
|
||||
float p[3];
|
||||
int j = (i + 1) % count; /* next arc in the circular list */
|
||||
|
||||
VecAddf(tangent, ring[i].n, ring[j].n);
|
||||
Crossf(normal, tangent, axis);
|
||||
|
||||
node1 = OTHER_NODE(ring[i].arc, node);
|
||||
node2 = OTHER_NODE(ring[j].arc, node);
|
||||
|
||||
VECCOPY(p, node2->p);
|
||||
mirrorAlongAxis(p, node->p, normal);
|
||||
|
||||
/* check if it's within limit before continuing */
|
||||
if (VecLenf(node1->p, p) > limit)
|
||||
{
|
||||
symmetric = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (symmetric)
|
||||
{
|
||||
/* first pass, merge incrementally */
|
||||
for (i = 0; i < count - 1; i++)
|
||||
{
|
||||
ReebNode *node1, *node2;
|
||||
float tangent[3];
|
||||
float normal[3];
|
||||
int j = i + 1;
|
||||
|
||||
VecAddf(tangent, ring[i].n, ring[j].n);
|
||||
Crossf(normal, tangent, axis);
|
||||
|
||||
node1 = OTHER_NODE(ring[i].arc, node);
|
||||
node2 = OTHER_NODE(ring[j].arc, node);
|
||||
|
||||
/* mirror first node and mix with the second */
|
||||
mirrorAlongAxis(node1->p, node->p, normal);
|
||||
VecLerpf(node2->p, node2->p, node1->p, 1.0f / (j + 1));
|
||||
|
||||
/* Merge buckets
|
||||
* there shouldn't be any null arcs here, but just to be safe
|
||||
* */
|
||||
if (ring[i].arc->bcount > 0 && ring[j].arc->bcount > 0)
|
||||
{
|
||||
ReebArcIterator iter1, iter2;
|
||||
EmbedBucket *bucket1 = NULL, *bucket2 = NULL;
|
||||
|
||||
initArcIterator(&iter1, ring[i].arc, node);
|
||||
initArcIterator(&iter2, ring[j].arc, node);
|
||||
|
||||
bucket1 = nextBucket(&iter1);
|
||||
bucket2 = nextBucket(&iter2);
|
||||
|
||||
/* Make sure they both start at the same value */
|
||||
while(bucket1 && bucket1->val < bucket2->val)
|
||||
{
|
||||
bucket1 = nextBucket(&iter1);
|
||||
}
|
||||
|
||||
while(bucket2 && bucket2->val < bucket1->val)
|
||||
{
|
||||
bucket2 = nextBucket(&iter2);
|
||||
}
|
||||
|
||||
|
||||
for ( ;bucket1 && bucket2; bucket1 = nextBucket(&iter1), bucket2 = nextBucket(&iter2))
|
||||
{
|
||||
bucket2->nv += bucket1->nv; /* add counts */
|
||||
|
||||
/* mirror on axis */
|
||||
mirrorAlongAxis(bucket1->p, node->p, normal);
|
||||
/* add bucket2 in bucket1 */
|
||||
VecLerpf(bucket2->p, bucket2->p, bucket1->p, (float)bucket1->nv / (float)(bucket2->nv));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* second pass, mirror back on previous arcs */
|
||||
for (i = count - 1; i > 0; i--)
|
||||
{
|
||||
ReebNode *node1, *node2;
|
||||
float tangent[3];
|
||||
float normal[3];
|
||||
int j = i - 1;
|
||||
|
||||
VecAddf(tangent, ring[i].n, ring[j].n);
|
||||
Crossf(normal, tangent, axis);
|
||||
|
||||
node1 = OTHER_NODE(ring[i].arc, node);
|
||||
node2 = OTHER_NODE(ring[j].arc, node);
|
||||
|
||||
/* copy first node than mirror */
|
||||
VECCOPY(node2->p, node1->p);
|
||||
mirrorAlongAxis(node2->p, node->p, normal);
|
||||
|
||||
/* Copy buckets
|
||||
* there shouldn't be any null arcs here, but just to be safe
|
||||
* */
|
||||
if (ring[i].arc->bcount > 0 && ring[j].arc->bcount > 0)
|
||||
{
|
||||
ReebArcIterator iter1, iter2;
|
||||
EmbedBucket *bucket1 = NULL, *bucket2 = NULL;
|
||||
|
||||
initArcIterator(&iter1, ring[i].arc, node);
|
||||
initArcIterator(&iter2, ring[j].arc, node);
|
||||
|
||||
bucket1 = nextBucket(&iter1);
|
||||
bucket2 = nextBucket(&iter2);
|
||||
|
||||
/* Make sure they both start at the same value */
|
||||
while(bucket1 && bucket1->val < bucket2->val)
|
||||
{
|
||||
bucket1 = nextBucket(&iter1);
|
||||
}
|
||||
|
||||
while(bucket2 && bucket2->val < bucket1->val)
|
||||
{
|
||||
bucket2 = nextBucket(&iter2);
|
||||
}
|
||||
|
||||
|
||||
for ( ;bucket1 && bucket2; bucket1 = nextBucket(&iter1), bucket2 = nextBucket(&iter2))
|
||||
{
|
||||
/* copy and mirror back to bucket2 */
|
||||
bucket2->nv = bucket1->nv;
|
||||
VECCOPY(bucket2->p, bucket1->p);
|
||||
mirrorAlongAxis(bucket2->p, node->p, normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MEM_freeN(ring);
|
||||
}
|
||||
|
||||
void reestablishAxialSymmetry(ReebNode *node, int depth, float axis[3])
|
||||
{
|
||||
ReebArc *arc1 = NULL;
|
||||
ReebArc *arc2 = NULL;
|
||||
ReebNode *node1 = NULL, *node2 = NULL;
|
||||
float limit = G.scene->toolsettings->skgen_symmetry_limit;
|
||||
float nor[3], vec[3], p[3];
|
||||
int i;
|
||||
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* depth is store as a negative in flag. symmetry level is positive */
|
||||
if (connectedArc->flags == -depth)
|
||||
{
|
||||
if (arc1 == NULL)
|
||||
{
|
||||
arc1 = connectedArc;
|
||||
node1 = OTHER_NODE(arc1, node);
|
||||
}
|
||||
else
|
||||
{
|
||||
arc2 = connectedArc;
|
||||
node2 = OTHER_NODE(arc2, node);
|
||||
break; /* Can stop now, the two arcs have been found */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* shouldn't happen, but just to be sure */
|
||||
if (node1 == NULL || node2 == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
VecSubf(p, node1->p, node->p);
|
||||
Crossf(vec, p, axis);
|
||||
Crossf(nor, vec, axis);
|
||||
|
||||
/* mirror node2 along axis */
|
||||
VECCOPY(p, node2->p);
|
||||
mirrorAlongAxis(p, node->p, nor);
|
||||
|
||||
/* check if it's within limit before continuing */
|
||||
if (VecLenf(node1->p, p) <= limit)
|
||||
{
|
||||
|
||||
/* average with node1 */
|
||||
VecAddf(node1->p, node1->p, p);
|
||||
VecMulf(node1->p, 0.5f);
|
||||
|
||||
/* mirror back on node2 */
|
||||
VECCOPY(node2->p, node1->p);
|
||||
mirrorAlongAxis(node2->p, node->p, nor);
|
||||
|
||||
/* Merge buckets
|
||||
* there shouldn't be any null arcs here, but just to be safe
|
||||
* */
|
||||
if (arc1->bcount > 0 && arc2->bcount > 0)
|
||||
{
|
||||
ReebArcIterator iter1, iter2;
|
||||
EmbedBucket *bucket1 = NULL, *bucket2 = NULL;
|
||||
|
||||
initArcIterator(&iter1, arc1, node);
|
||||
initArcIterator(&iter2, arc2, node);
|
||||
|
||||
bucket1 = nextBucket(&iter1);
|
||||
bucket2 = nextBucket(&iter2);
|
||||
|
||||
/* Make sure they both start at the same value */
|
||||
while(bucket1 && bucket1->val < bucket2->val)
|
||||
{
|
||||
bucket1 = nextBucket(&iter1);
|
||||
}
|
||||
|
||||
while(bucket2 && bucket2->val < bucket1->val)
|
||||
{
|
||||
bucket2 = nextBucket(&iter2);
|
||||
}
|
||||
|
||||
|
||||
for ( ;bucket1 && bucket2; bucket1 = nextBucket(&iter1), bucket2 = nextBucket(&iter2))
|
||||
{
|
||||
bucket1->nv += bucket2->nv; /* add counts */
|
||||
|
||||
/* mirror on axis */
|
||||
mirrorAlongAxis(bucket2->p, node->p, nor);
|
||||
/* add bucket2 in bucket1 */
|
||||
VecLerpf(bucket1->p, bucket1->p, bucket2->p, (float)bucket2->nv / (float)(bucket1->nv));
|
||||
|
||||
/* copy and mirror back to bucket2 */
|
||||
bucket2->nv = bucket1->nv;
|
||||
VECCOPY(bucket2->p, bucket1->p);
|
||||
mirrorAlongAxis(bucket2->p, node->p, nor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void markdownSecondarySymmetry(ReebNode *node, int depth, int level)
|
||||
{
|
||||
float axis[3] = {0, 0, 0};
|
||||
int count = 0;
|
||||
int i;
|
||||
|
||||
/* Only reestablish spatial symmetry if needed */
|
||||
if (G.scene->toolsettings->skgen_options & SKGEN_SYMMETRY)
|
||||
{
|
||||
/* count the number of branches in this symmetry group
|
||||
* and determinte the axis of symmetry
|
||||
* */
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* depth is store as a negative in flag. symmetry level is positive */
|
||||
if (connectedArc->flags == -depth)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
/* If arc is on the axis */
|
||||
else if (connectedArc->flags == level)
|
||||
{
|
||||
VecAddf(axis, axis, connectedArc->v1->p);
|
||||
VecSubf(axis, axis, connectedArc->v2->p);
|
||||
}
|
||||
}
|
||||
|
||||
Normalize(axis);
|
||||
|
||||
/* Split between axial and radial symmetry */
|
||||
if (count == 2)
|
||||
{
|
||||
reestablishAxialSymmetry(node, depth, axis);
|
||||
}
|
||||
else
|
||||
{
|
||||
reestablishRadialSymmetry(node, depth, axis);
|
||||
}
|
||||
}
|
||||
|
||||
/* markdown secondary symetries */
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
if (connectedArc->flags == -depth)
|
||||
{
|
||||
/* markdown symmetry for branches corresponding to the depth */
|
||||
markdownSymmetryArc(connectedArc, node, level + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void markdownSymmetryArc(ReebArc *arc, ReebNode *node, int level)
|
||||
{
|
||||
int i;
|
||||
arc->flags = level;
|
||||
|
||||
node = OTHER_NODE(arc, node);
|
||||
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
if (connectedArc != arc)
|
||||
{
|
||||
ReebNode *connectedNode = OTHER_NODE(connectedArc, node);
|
||||
|
||||
/* symmetry level is positive value, negative values is subtree depth */
|
||||
connectedArc->flags = -subtreeDepth(connectedNode, connectedArc);
|
||||
}
|
||||
}
|
||||
|
||||
arc = NULL;
|
||||
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
int issymmetryAxis = 0;
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* only arcs not already marked as symetric */
|
||||
if (connectedArc->flags < 0)
|
||||
{
|
||||
int j;
|
||||
|
||||
/* true by default */
|
||||
issymmetryAxis = 1;
|
||||
|
||||
for (j = 0; node->arcs[j] != NULL && issymmetryAxis == 1; j++)
|
||||
{
|
||||
ReebArc *otherArc = node->arcs[j];
|
||||
|
||||
/* different arc, same depth */
|
||||
if (otherArc != connectedArc && otherArc->flags == connectedArc->flags)
|
||||
{
|
||||
/* not on the symmetry axis */
|
||||
issymmetryAxis = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* arc could be on the symmetry axis */
|
||||
if (issymmetryAxis == 1)
|
||||
{
|
||||
/* no arc as been marked previously, keep this one */
|
||||
if (arc == NULL)
|
||||
{
|
||||
arc = connectedArc;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* there can't be more than one symmetry arc */
|
||||
arc = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* go down the arc continuing the symmetry axis */
|
||||
if (arc)
|
||||
{
|
||||
markdownSymmetryArc(arc, node, level);
|
||||
}
|
||||
|
||||
|
||||
/* secondary symmetry */
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* only arcs not already marked as symetric and is not the next arc on the symmetry axis */
|
||||
if (connectedArc->flags < 0)
|
||||
{
|
||||
/* subtree depth is store as a negative value in the flag */
|
||||
markdownSecondarySymmetry(node, -connectedArc->flags, level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void markdownSymmetry(ReebGraph *rg)
|
||||
{
|
||||
ReebNode *node;
|
||||
ReebArc *arc;
|
||||
/* only for Acyclic graphs */
|
||||
int cyclic = isGraphCyclic(rg);
|
||||
|
||||
/* mark down all arcs as non-symetric */
|
||||
for (arc = rg->arcs.first; arc; arc = arc->next)
|
||||
{
|
||||
arc->flags = 0;
|
||||
}
|
||||
|
||||
/* mark down all nodes as not on the symmetry axis */
|
||||
for (node = rg->nodes.first; node; node = node->next)
|
||||
{
|
||||
node->flags = 0;
|
||||
}
|
||||
|
||||
/* node list is sorted, so lowest node is always the head (by design) */
|
||||
node = rg->nodes.first;
|
||||
|
||||
/* only work on acyclic graphs and if only one arc is incident on the first node */
|
||||
if (cyclic == 0 && countConnectedArcs(rg, node) == 1)
|
||||
{
|
||||
arc = node->arcs[0];
|
||||
|
||||
markdownSymmetryArc(arc, node, 1);
|
||||
|
||||
/* mark down non-symetric arcs */
|
||||
for (arc = rg->arcs.first; arc; arc = arc->next)
|
||||
{
|
||||
if (arc->flags < 0)
|
||||
{
|
||||
arc->flags = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* mark down nodes with the lowest level symmetry axis */
|
||||
if (arc->v1->flags == 0 || arc->v1->flags > arc->flags)
|
||||
{
|
||||
arc->v1->flags = arc->flags;
|
||||
}
|
||||
if (arc->v2->flags == 0 || arc->v2->flags > arc->flags)
|
||||
{
|
||||
arc->v2->flags = arc->flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************** SUBDIVISION ALGOS ******************************************/
|
||||
|
||||
|
@ -5002,8 +4467,6 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
|||
{
|
||||
exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); // freedata, and undo
|
||||
}
|
||||
|
||||
setcursor_space(SPACE_VIEW3D, CURSOR_WAIT);
|
||||
|
||||
dst = add_object(OB_ARMATURE);
|
||||
base_init_from_view3d(BASACT, G.vd);
|
||||
|
@ -5030,35 +4493,35 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
|||
|
||||
/* Find out the direction of the arc through simple heuristics (in order of priority) :
|
||||
*
|
||||
* 1- Arcs on primary symmetry axis (flags == 1) point up (head: high weight -> tail: low weight)
|
||||
* 1- Arcs on primary symmetry axis (symmetry == 1) point up (head: high weight -> tail: low weight)
|
||||
* 2- Arcs starting on a primary axis point away from it (head: node on primary axis)
|
||||
* 3- Arcs point down (head: low weight -> tail: high weight)
|
||||
*
|
||||
* Finally, the arc direction is stored in its flags: 1 (low -> high), -1 (high -> low)
|
||||
* Finally, the arc direction is stored in its flag: 1 (low -> high), -1 (high -> low)
|
||||
*/
|
||||
|
||||
/* if arc is a symmetry axis, internal bones go up the tree */
|
||||
if (arc->flags == 1 && arc->v2->degree != 1)
|
||||
if (arc->symmetry_level == 1 && arc->v2->degree != 1)
|
||||
{
|
||||
head = arc->v2;
|
||||
tail = arc->v1;
|
||||
|
||||
arc->flags = -1; /* mark arc direction */
|
||||
arc->flag = -1; /* mark arc direction */
|
||||
}
|
||||
/* Bones point AWAY from the symmetry axis */
|
||||
else if (arc->v1->flags == 1)
|
||||
else if (arc->v1->symmetry_level == 1)
|
||||
{
|
||||
head = arc->v1;
|
||||
tail = arc->v2;
|
||||
|
||||
arc->flags = 1; /* mark arc direction */
|
||||
arc->flag = 1; /* mark arc direction */
|
||||
}
|
||||
else if (arc->v2->flags == 1)
|
||||
else if (arc->v2->symmetry_level == 1)
|
||||
{
|
||||
head = arc->v2;
|
||||
tail = arc->v1;
|
||||
|
||||
arc->flags = -1; /* mark arc direction */
|
||||
arc->flag = -1; /* mark arc direction */
|
||||
}
|
||||
/* otherwise, always go from low weight to high weight */
|
||||
else
|
||||
|
@ -5066,7 +4529,7 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
|||
head = arc->v1;
|
||||
tail = arc->v2;
|
||||
|
||||
arc->flags = 1; /* mark arc direction */
|
||||
arc->flag = 1; /* mark arc direction */
|
||||
}
|
||||
|
||||
/* Loop over subdivision methods */
|
||||
|
@ -5113,7 +4576,7 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
|||
arc = node->arcs[i];
|
||||
|
||||
/* if arc is incoming into the node */
|
||||
if ((arc->v1 == node && arc->flags == -1) || (arc->v2 == node && arc->flags == 1))
|
||||
if ((arc->v1 == node && arc->flag == -1) || (arc->v2 == node && arc->flag == 1))
|
||||
{
|
||||
if (incomingArc == NULL)
|
||||
{
|
||||
|
@ -5139,7 +4602,7 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
|||
arc = node->arcs[i];
|
||||
|
||||
/* if arc is outgoing from the node */
|
||||
if ((arc->v1 == node && arc->flags == 1) || (arc->v2 == node && arc->flags == -1))
|
||||
if ((arc->v1 == node && arc->flag == 1) || (arc->v2 == node && arc->flag == -1))
|
||||
{
|
||||
EditBone *childBone = BLI_ghash_lookup(arcBoneMap, arc);
|
||||
|
||||
|
@ -5157,89 +4620,21 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
|||
}
|
||||
|
||||
BLI_ghash_free(arcBoneMap, NULL, NULL);
|
||||
|
||||
setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
|
||||
|
||||
BIF_undo_push("Generate Skeleton");
|
||||
}
|
||||
|
||||
void generateSkeleton(void)
|
||||
{
|
||||
EditMesh *em = G.editMesh;
|
||||
ReebGraph *rg = NULL;
|
||||
int i;
|
||||
ReebGraph *reebg;
|
||||
|
||||
if (em == NULL)
|
||||
return;
|
||||
|
||||
setcursor_space(SPACE_VIEW3D, CURSOR_WAIT);
|
||||
|
||||
if (weightFromDistance(em) == 0)
|
||||
{
|
||||
error("No selected vertex\n");
|
||||
return;
|
||||
}
|
||||
|
||||
renormalizeWeight(em, 1.0f);
|
||||
|
||||
weightToHarmonic(em);
|
||||
|
||||
#ifdef DEBUG_REEB
|
||||
weightToVCol(em);
|
||||
#endif
|
||||
|
||||
rg = generateReebGraph(em, G.scene->toolsettings->skgen_resolution);
|
||||
reebg = BIF_ReebGraphFromEditMesh();
|
||||
|
||||
verifyBuckets(rg);
|
||||
|
||||
/* Remove arcs without embedding */
|
||||
filterNullReebGraph(rg);
|
||||
generateSkeletonFromReebGraph(reebg);
|
||||
|
||||
verifyBuckets(rg);
|
||||
REEB_freeGraph(reebg);
|
||||
|
||||
|
||||
i = 1;
|
||||
/* filter until there's nothing more to do */
|
||||
while (i == 1)
|
||||
{
|
||||
i = 0; /* no work done yet */
|
||||
|
||||
if (G.scene->toolsettings->skgen_options & SKGEN_FILTER_EXTERNAL)
|
||||
{
|
||||
i |= filterExternalReebGraph(rg, G.scene->toolsettings->skgen_threshold_external * G.scene->toolsettings->skgen_resolution);
|
||||
}
|
||||
|
||||
verifyBuckets(rg);
|
||||
|
||||
if (G.scene->toolsettings->skgen_options & SKGEN_FILTER_INTERNAL)
|
||||
{
|
||||
i |= filterInternalReebGraph(rg, G.scene->toolsettings->skgen_threshold_internal * G.scene->toolsettings->skgen_resolution);
|
||||
}
|
||||
}
|
||||
|
||||
verifyBuckets(rg);
|
||||
|
||||
repositionNodes(rg);
|
||||
|
||||
verifyBuckets(rg);
|
||||
|
||||
/* Filtering might have created degree 2 nodes, so remove them */
|
||||
removeNormalNodes(rg);
|
||||
|
||||
verifyBuckets(rg);
|
||||
|
||||
for(i = 0; i < G.scene->toolsettings->skgen_postpro_passes; i++)
|
||||
{
|
||||
postprocessGraph(rg, G.scene->toolsettings->skgen_postpro);
|
||||
}
|
||||
|
||||
buildAdjacencyList(rg);
|
||||
|
||||
sortNodes(rg);
|
||||
|
||||
sortArcs(rg);
|
||||
|
||||
generateSkeletonFromReebGraph(rg);
|
||||
|
||||
freeGraph(rg);
|
||||
setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue