Update from school work.

This commit is contained in:
Martin Poirier
2007-11-07 21:45:35 +00:00
parent 4cae0a0ff9
commit e7c4bad8e9
6 changed files with 97 additions and 13 deletions

View File

@@ -54,6 +54,10 @@ extern "C" {
#define M_SQRT1_2 0.70710678118654752440
#endif
#ifdef WIN32
#define isnan(n) _isnan(n)
#endif
#define MAT4_UNITY {{ 1.0, 0.0, 0.0, 0.0},\
{ 0.0, 1.0, 0.0, 0.0},\
{ 0.0, 0.0, 1.0, 0.0},\

View File

@@ -6585,7 +6585,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
else
wrld->ao_samp_method = WO_AOSAMP_HAMMERSLEY;
wrld->ao_adapt_thresh = 0.005;
wrld->ao_adapt_thresh = 0.005f;
}
for(la=main->lamp.first; la; la= la->id.next) {
@@ -6778,7 +6778,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
sce->toolsettings->skgen_threshold_external = 0.01f;
sce->toolsettings->skgen_threshold_angle = 45.0f;
sce->toolsettings->skgen_threshold_length = 1.3f;
sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_REPOSITION|SKGEN_CUT_LENGTH|SKGEN_CUT_ANGLE;
sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_REPOSITION|SKGEN_SMOOTH|SKGEN_CUT_LENGTH|SKGEN_CUT_ANGLE;
}
}
}

View File

@@ -680,6 +680,7 @@ typedef struct Scene {
#define SKGEN_SYMMETRY 8
#define SKGEN_CUT_LENGTH 16
#define SKGEN_CUT_ANGLE 32
#define SKGEN_SMOOTH 64
#ifdef __cplusplus
}

View File

@@ -4425,19 +4425,20 @@ static void editing_panel_mesh_skgen(Object *ob, Mesh *me)
block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_skgen", UI_EMBOSS, UI_HELV, curarea->win);
if(uiNewPanel(curarea, block, "Skeleton Generation", "Editing", 960, 0, 318, 204)==0) return;
uiDefBut(block, BUT, B_GEN_SKELETON, "Generate Skeleton", 1125,160,150,39, 0, 0, 0, 0, 0, "Generate Skeleton from Mesh");
uiDefBut(block, BUT, B_GEN_SKELETON, "Generate Skeleton", 1075,160,200,39, 0, 0, 0, 0, 0, "Generate Skeleton from Mesh");
uiBlockBeginAlign(block);
uiDefButS(block, NUM, B_DIFF, "Resolution:", 1125,110,150,19, &G.scene->toolsettings->skgen_resolution,10.0,1000.0, 0, 0, "Specifies the resolution of the graph's embedding");
uiDefButBitS(block, TOG, SKGEN_FILTER_INTERNAL, B_DIFF, "Filter In", 1125, 90, 58,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter internal small arcs from graph");
uiDefButF(block, NUM, B_DIFF, "Thresh:", 1186, 90, 89,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", 1125, 70, 58,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter external small arcs from graph");
uiDefButF(block, NUM, B_DIFF, "Thresh:", 1186, 70, 89,19, &G.scene->toolsettings->skgen_threshold_external,0.0, 1.0, 10, 0, "Specify the threshold ratio for filtering external arcs");
uiDefButBitS(block, TOG, SKGEN_CUT_LENGTH, B_DIFF, "Cut Length", 1125, 50, 58,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Subdivide arcs based on length");
uiDefButF(block, NUM, B_DIFF, "Thresh:", 1186, 50, 89,19, &G.scene->toolsettings->skgen_threshold_length,1.0, 2.0, 10, 0, "Specify the threshold ratio for subdivision");
uiDefButBitS(block, TOG, SKGEN_CUT_ANGLE, B_DIFF, "Cut Angle", 1125, 30, 58,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Subdivide arcs based on angle");
uiDefButF(block, NUM, B_DIFF, "Thresh:", 1186, 30, 89,19, &G.scene->toolsettings->skgen_threshold_angle,0.0, 90.0, 10, 0, "Specify the threshold angle in degrees for subdivision");
uiDefButBitS(block, TOG, SKGEN_REPOSITION, B_DIFF, "Reposition", 1125, 10,150,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Reposition nodes based on embedding instead of original vertice positions");
uiDefButS(block, NUM, B_DIFF, "Resolution:", 1075,110,200,19, &G.scene->toolsettings->skgen_resolution,10.0,1000.0, 0, 0, "Specifies the resolution of the graph's embedding");
uiDefButBitS(block, TOG, SKGEN_FILTER_INTERNAL, B_DIFF, "Filter In", 1075, 90, 83,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter internal small arcs from graph");
uiDefButF(block, NUM, B_DIFF, "Thresh:", 1161, 90,114,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", 1075, 70, 83,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter external small arcs from graph");
uiDefButF(block, NUM, B_DIFF, "Thresh:", 1161, 70,114,19, &G.scene->toolsettings->skgen_threshold_external,0.0, 1.0, 10, 0, "Specify the threshold ratio for filtering external arcs");
uiDefButBitS(block, TOG, SKGEN_CUT_LENGTH, B_DIFF, "Cut Length", 1075, 50, 83,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Subdivide arcs based on length");
uiDefButF(block, NUM, B_DIFF, "Thresh:", 1161, 50,114,19, &G.scene->toolsettings->skgen_threshold_length,1.0, 2.0, 10, 0, "Specify the threshold ratio for subdivision");
uiDefButBitS(block, TOG, SKGEN_CUT_ANGLE, B_DIFF, "Cut Angle", 1075, 30, 83,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Subdivide arcs based on angle");
uiDefButF(block, NUM, B_DIFF, "Thresh:", 1161, 30,114,19, &G.scene->toolsettings->skgen_threshold_angle,0.0, 90.0, 10, 0, "Specify the threshold angle in degrees for subdivision");
uiDefButBitS(block, TOG, SKGEN_REPOSITION, B_DIFF, "Reposition", 1075, 10,100,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Reposition nodes based on embedding instead of original vertice positions");
uiDefButBitS(block, TOG, SKGEN_SMOOTH, B_DIFF, "Smooth", 1175, 10,100,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Smooth embeddings");
uiBlockEndAlign(block);
}

View File

@@ -3228,6 +3228,7 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
tail = arc->v1;
}
/************************* CUT LENGTH *****************************/
if ((G.scene->toolsettings->skgen_options & SKGEN_CUT_LENGTH) &&
arcLengthRatio(arc) >= G.scene->toolsettings->skgen_threshold_length)
{
@@ -3331,6 +3332,59 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
added = 1;
}
/************************* CUT ANGLE *****************************/
else if (G.scene->toolsettings->skgen_options & SKGEN_CUT_ANGLE)
{
EditBone *child = NULL;
EditBone *parent = NULL;
float angleLimit = 0.80f;//cosf(M_PI / 4);//cosf(G.scene->toolsettings->skgen_threshold_angle * M_PI / 180.0f);
int same = 0;
int index = 0;
int stride = 1;
// If head is the highest node, invert stride and start index
if (head == arc->v2)
{
stride *= -1;
index = arc->bcount -1;
}
parent = add_editbone("Bone");
VECCOPY(parent->head, head->p);
firstBone = parent; /* set first bone in the chain */
for(index = 1; index < arc->bcount; index++)
{
float vec1[3], vec2[3];
float len1, len2;
VecSubf(vec1, arc->buckets[index - 1].p, parent->head);
VecSubf(vec2, arc->buckets[index].p, arc->buckets[index - 1].p);
len1 = Normalize(vec1);
len2 = Normalize(vec2);
//printf("%f < %f\n", Inpf(vec1, vec2), angleLimit);
if (len1 > 0.0f && len2 > 0.0f && Inpf(vec1, vec2) < angleLimit)
{
VECCOPY(parent->tail, arc->buckets[index - 1].p);
child = add_editbone("Bone");
VECCOPY(child->head, parent->tail);
child->parent = parent;
child->flag |= BONE_CONNECTED;
parent = child; // new child is next parent
}
}
VECCOPY(parent->tail, tail->p);
lastBone = parent; /* set last bone in the chain */
added = 1;
}
if (added == 0)
{

View File

@@ -380,6 +380,25 @@ void buildAdjacencyList(ReebGraph *rg)
addArcToNodeAdjacencyList(arc->v2, arc);
}
}
/****************************************** SMOOTHING **************************************************/
void smoothGraph(ReebGraph *rg)
{
ReebArc *arc;
for(arc = rg->arcs.first; arc; arc = arc->next)
{
EmbedBucket *buckets = arc->buckets;
int bcount = arc->bcount;
int index;
for(index = 1; index < bcount - 1; index++)
{
VecLerpf(buckets[index].p, buckets[index].p, buckets[index - 1].p, 0.5f);
VecLerpf(buckets[index].p, buckets[index].p, buckets[index + 1].p, 1.0f/3.0f);
}
}
}
/****************************************** FILTERING **************************************************/
@@ -1787,6 +1806,11 @@ void generateSkeleton(void)
verifyBuckets(rg);
if (G.scene->toolsettings->skgen_options & SKGEN_SMOOTH)
{
smoothGraph(rg);
}
buildAdjacencyList(rg);
exportGraph(rg, -1);