[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15071] branches/harmonic-skeleton/source/ blender/src/editarmature.c: Alternative method for correletation based skeleton subdivision ( where bone end points can deviate from embedding).
Martin Poirier
theeth at yahoo.com
Sat May 31 20:52:23 CEST 2008
Revision: 15071
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15071
Author: theeth
Date: 2008-05-31 20:52:23 +0200 (Sat, 31 May 2008)
Log Message:
-----------
Alternative method for correletation based skeleton subdivision (where bone end points can deviate from embedding).
Disabled because too unstable
Modified Paths:
--------------
branches/harmonic-skeleton/source/blender/src/editarmature.c
Modified: branches/harmonic-skeleton/source/blender/src/editarmature.c
===================================================================
--- branches/harmonic-skeleton/source/blender/src/editarmature.c 2008-05-31 16:22:07 UTC (rev 15070)
+++ branches/harmonic-skeleton/source/blender/src/editarmature.c 2008-05-31 18:52:23 UTC (rev 15071)
@@ -4207,6 +4207,8 @@
return lastBone;
}
+#if 1
+
float calcCorrelation(ReebArc *arc, int start, int end, float v0[3], float n[3])
{
int len = 2 + abs(end - start);
@@ -4318,6 +4320,137 @@
return lastBone;
}
+#else
+
+float calcCorrelation(ReebArc *arc, int start, int end, float v0[3], float n[3])
+{
+ int len = 2 + abs(end - start);
+
+ if (len > 2)
+ {
+ ReebArcIterator iter;
+ EmbedBucket *bucket = NULL;
+ float avg_t = 0.0f;
+ float s_t = 0.0f;
+ float s_xyz = 0.0f;
+
+ /* First pass, calculate average */
+ for (initArcIterator2(&iter, arc, start, end), bucket = nextBucket(&iter);
+ bucket;
+ bucket = nextBucket(&iter))
+ {
+ float v[3];
+
+ VecSubf(v, bucket->p, v0);
+ Normalize(v);
+ avg_t += Inpf(v, n);
+ }
+
+ avg_t /= Inpf(n, n);
+ avg_t += 1.0f; /* adding start (0) and end (1) values */
+ avg_t /= len;
+
+ /* Second pass, calculate s_xyz and s_t */
+ for (initArcIterator2(&iter, arc, start, end), bucket = nextBucket(&iter);
+ bucket;
+ bucket = nextBucket(&iter))
+ {
+ float v[3], d[3];
+ float dt;
+
+ VecSubf(v, bucket->p, v0);
+ Normalize(v);
+ Projf(d, v, n);
+ VecSubf(v, v, d);
+
+ dt = VecLength(d) - avg_t;
+
+ s_t += dt * dt;
+ s_xyz += Inpf(v, v);
+ }
+
+ /* adding start(0) and end(1) values to s_t */
+ s_t += (avg_t * avg_t) + (1 - avg_t) * (1 - avg_t);
+
+ return 1.0f - s_xyz / s_t;
+ }
+ else
+ {
+ return 1.0f;
+ }
+}
+
+EditBone * subdivideByCorrelation(ReebArc *arc, ReebNode *head, ReebNode *tail)
+{
+ ReebArcIterator iter;
+ float n[3];
+ float CORRELATION_THRESHOLD = G.scene->toolsettings->skgen_correlation_limit;
+ EditBone *lastBone = NULL;
+
+ /* init iterator to get start and end from head */
+ initArcIterator(&iter, arc, head);
+
+ /* Calculate overall */
+ VecSubf(n, arc->buckets[iter.end].p, head->p);
+
+ if (G.scene->toolsettings->skgen_options & SKGEN_CUT_CORRELATION)
+ {
+ EmbedBucket *bucket = NULL;
+ EmbedBucket *previous = NULL;
+ EditBone *child = NULL;
+ EditBone *parent = NULL;
+ float normal[3] = {0, 0, 0};
+ float avg_normal[3];
+ int total = 0;
+ int boneStart = iter.start;
+
+ parent = add_editbone("Bone");
+ parent->flag = BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL;
+ VECCOPY(parent->head, head->p);
+
+ for (previous = nextBucket(&iter), bucket = nextBucket(&iter);
+ bucket;
+ previous = bucket, bucket = nextBucket(&iter))
+ {
+ float length;
+
+ /* Calculate normal */
+ VecSubf(n, bucket->p, parent->head);
+ length = Normalize(n);
+
+ total += 1;
+ VecAddf(normal, normal, n);
+ VECCOPY(avg_normal, normal);
+ VecMulf(avg_normal, 1.0f / total);
+
+ if (calcCorrelation(arc, boneStart, iter.index, parent->head, avg_normal) < CORRELATION_THRESHOLD)
+ {
+ VECCOPY(parent->tail, avg_normal);
+ VecMulf(parent->tail, length);
+ VecAddf(parent->tail, parent->tail, parent->head);
+
+ child = add_editbone("Bone");
+ VECCOPY(child->head, parent->tail);
+ child->parent = parent;
+ child->flag |= BONE_CONNECTED|BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL;
+
+ parent = child; // new child is next parent
+ boneStart = iter.index; // start from end
+
+ normal[0] = normal[1] = normal[2] = 0;
+ total = 0;
+ }
+ }
+
+ VECCOPY(parent->tail, tail->p);
+
+ lastBone = parent; /* set last bone in the chain */
+ }
+
+ return lastBone;
+}
+#endif
+
float arcLengthRatio(ReebArc *arc)
{
float arcLength = 0.0f;
More information about the Bf-blender-cvs
mailing list