[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17628] branches/etch-a-ton/source/blender : Step 3/3, merging subdivision/bone creation methods using iterators

Martin Poirier theeth at yahoo.com
Sat Nov 29 21:37:10 CET 2008


Revision: 17628
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17628
Author:   theeth
Date:     2008-11-29 21:37:10 +0100 (Sat, 29 Nov 2008)

Log Message:
-----------
Step 3/3, merging subdivision/bone creation methods using iterators

This also adds a special Embedding option called "Peel Objects". This option makes the embedding snap consider objects as whole, taking the first and last hit of each of them to calculate the embedding point (instead of peeling with first/second, third/fourth and so on). This option is useful if you have mecanical pieces with lots of details (as single objects) and want to put bones in the middle (think of adding bones to a mecha, for example).

Modified Paths:
--------------
    branches/etch-a-ton/source/blender/blenlib/BLI_graph.h
    branches/etch-a-ton/source/blender/blenlib/intern/graph.c
    branches/etch-a-ton/source/blender/include/reeb.h
    branches/etch-a-ton/source/blender/makesdna/DNA_scene_types.h
    branches/etch-a-ton/source/blender/src/drawview.c
    branches/etch-a-ton/source/blender/src/editarmature.c
    branches/etch-a-ton/source/blender/src/editarmature_retarget.c
    branches/etch-a-ton/source/blender/src/editarmature_sketch.c
    branches/etch-a-ton/source/blender/src/reeb.c

Added Paths:
-----------
    branches/etch-a-ton/source/blender/include/BIF_generate.h
    branches/etch-a-ton/source/blender/src/editarmature_generate.c

Modified: branches/etch-a-ton/source/blender/blenlib/BLI_graph.h
===================================================================
--- branches/etch-a-ton/source/blender/blenlib/BLI_graph.h	2008-11-29 19:53:49 UTC (rev 17627)
+++ branches/etch-a-ton/source/blender/blenlib/BLI_graph.h	2008-11-29 20:37:10 UTC (rev 17628)
@@ -62,13 +62,25 @@
 
 struct BArcIterator;
 
+void* IT_head(void* iter);
+void* IT_tail(void* iter);
+void* IT_peek(void* iter, int n);
+void* IT_next(void* iter);
+void* IT_nextN(void* iter, int n);
+void* IT_previous(void* iter);
+int   IT_stopped(void* iter);
+
+typedef void* (*HeadFct)(void* iter);
+typedef void* (*TailFct)(void* iter);
 typedef void* (*PeekFct)(void* iter, int n);
 typedef void* (*NextFct)(void* iter);
 typedef void* (*NextNFct)(void* iter, int n);
 typedef void* (*PreviousFct)(void* iter);
-typedef int	(*StoppedFct)(void* iter);
+typedef int   (*StoppedFct)(void* iter);
 
 typedef struct BArcIterator {
+	HeadFct		head;
+	TailFct		tail;
 	PeekFct		peek;
 	NextFct		next;
 	NextNFct	nextN;

Modified: branches/etch-a-ton/source/blender/blenlib/intern/graph.c
===================================================================
--- branches/etch-a-ton/source/blender/blenlib/intern/graph.c	2008-11-29 19:53:49 UTC (rev 17627)
+++ branches/etch-a-ton/source/blender/blenlib/intern/graph.c	2008-11-29 20:37:10 UTC (rev 17628)
@@ -465,8 +465,6 @@
 
 int BLI_subtreeShape(BGraph *graph, BNode *node, BArc *rootArc, int include_root)
 {
-	BNode *test_node;
-	
 	BLI_flagNodes(graph, 0);
 	return subtreeShape(node, rootArc, include_root);
 }
@@ -1090,3 +1088,56 @@
 	}
 }
 
+void* IT_head(void* arg)
+{
+	BArcIterator *iter = (BArcIterator*)arg; 
+	return iter->head(iter);
+}
+
+void* IT_tail(void* arg)
+{
+	BArcIterator *iter = (BArcIterator*)arg; 
+	return iter->tail(iter); 
+}
+
+void* IT_peek(void* arg, int n)
+{
+	BArcIterator *iter = (BArcIterator*)arg;
+	
+	if (iter->index + n < 0)
+	{
+		return iter->head(iter);
+	}
+	else if (iter->index + n >= iter->length)
+	{
+		return iter->tail(iter);
+	}
+	else
+	{
+		return iter->peek(iter, n);
+	}
+}
+
+void* IT_next(void* arg)
+{
+	BArcIterator *iter = (BArcIterator*)arg; 
+	return iter->next(iter);
+}
+
+void* IT_nextN(void* arg, int n)
+{
+	BArcIterator *iter = (BArcIterator*)arg; 
+	return iter->nextN(iter, n);
+}
+
+void* IT_previous(void* arg)
+{
+	BArcIterator *iter = (BArcIterator*)arg; 
+	return iter->previous(iter);
+}
+
+int   IT_stopped(void* arg)
+{
+	BArcIterator *iter = (BArcIterator*)arg; 
+	return iter->stopped(iter);
+}

Added: branches/etch-a-ton/source/blender/include/BIF_generate.h
===================================================================
--- branches/etch-a-ton/source/blender/include/BIF_generate.h	                        (rev 0)
+++ branches/etch-a-ton/source/blender/include/BIF_generate.h	2008-11-29 20:37:10 UTC (rev 17628)
@@ -0,0 +1,44 @@
+/**
+ * $Id:  $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+ 
+#ifndef BIF_GENERATE_H
+#define BIF_GENERATE_H
+
+struct EditBone;
+struct BArcIterator;
+struct bArmature;
+struct ListBase;
+
+typedef int(NextSubdivisionFunc)(struct BArcIterator*, int, int, float[3], float[3]);
+ 
+float calcArcCorrelation(struct BArcIterator *iter, int start, int end, float v0[3], float n[3]);
+
+int nextFixedSubdivision(struct BArcIterator *iter, int start, int end, float head[3], float p[3]);
+int nextLengthSubdivision(struct BArcIterator *iter, int start, int end, float head[3], float p[3]);
+int nextCorrelationSubdivision(struct BArcIterator *iter, int start, int end, float head[3], float p[3]);
+
+struct EditBone * subdivideArcBy(struct bArmature *arm, ListBase *editbones, struct BArcIterator *iter, float invmat[][4], float tmat[][3], NextSubdivisionFunc next_subdividion);
+
+void setBoneRollFromNormal(struct EditBone *bone, float *no, float invmat[][4], float tmat[][3]);
+ 
+
+#endif /* BIF_GENERATE_H */

Modified: branches/etch-a-ton/source/blender/include/reeb.h
===================================================================
--- branches/etch-a-ton/source/blender/include/reeb.h	2008-11-29 19:53:49 UTC (rev 17627)
+++ branches/etch-a-ton/source/blender/include/reeb.h	2008-11-29 20:37:10 UTC (rev 17628)
@@ -28,7 +28,7 @@
 #ifndef REEB_H_
 #define REEB_H_
 
-#define WITH_BF_REEB
+//#define WITH_BF_REEB
 
 #include "DNA_listBase.h"
 
@@ -120,6 +120,8 @@
 } ReebArc;
 
 typedef struct ReebArcIterator {
+	HeadFct		head;
+	TailFct		tail;
 	PeekFct		peek;
 	NextFct		next;
 	NextNFct	nextN;
@@ -151,9 +153,9 @@
 ReebGraph * generateReebGraph(struct EditMesh *me, int subdivisions);
 ReebGraph * newReebGraph();
 
-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);
+void initArcIterator(BArcIterator *iter, struct ReebArc *arc, struct ReebNode *head);
+void initArcIterator2(BArcIterator *iter, struct ReebArc *arc, int start, int end);
+void initArcIteratorStart(BArcIterator *iter, struct ReebArc *arc, struct ReebNode *head, int start);
 
 /* Filtering */
 void filterNullReebGraph(ReebGraph *rg);

Modified: branches/etch-a-ton/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/etch-a-ton/source/blender/makesdna/DNA_scene_types.h	2008-11-29 19:53:49 UTC (rev 17627)
+++ branches/etch-a-ton/source/blender/makesdna/DNA_scene_types.h	2008-11-29 20:37:10 UTC (rev 17628)
@@ -728,6 +728,7 @@
 /* scene->snap_flag */
 #define SCE_SNAP				1
 #define SCE_SNAP_ROTATE			2
+#define SCE_SNAP_PEEL_OBJECT	4
 /* scene->snap_target */
 #define SCE_SNAP_TARGET_CLOSEST	0
 #define SCE_SNAP_TARGET_CENTER	1

Modified: branches/etch-a-ton/source/blender/src/drawview.c
===================================================================
--- branches/etch-a-ton/source/blender/src/drawview.c	2008-11-29 19:53:49 UTC (rev 17627)
+++ branches/etch-a-ton/source/blender/src/drawview.c	2008-11-29 20:37:10 UTC (rev 17628)
@@ -2294,7 +2294,7 @@
 	static char joint_label[32];
 	uiBlock *block;
 	uiBut *but;
-	int yco = 70, height = 140;
+	int yco = 130, height = 140;
 	int nb_joints;
 
 	/* replace with check call to sketching lib */
@@ -2382,7 +2382,9 @@
 		BLI_snprintf(joint_label, 32, "%i joints", nb_joints);
 		
 		uiDefBut(block, LABEL, 1, joint_label,					10, yco, 200, 20, NULL, 0.0, 0.0, 0, 0, "");
+		yco -= 20;
 		
+		uiDefButBitS(block, TOG, SCE_SNAP_PEEL_OBJECT, B_DIFF, "Peel Objects", 10, yco, 200, 20, &G.scene->snap_flag, 0, 0, 0, 0, "Peel whole objects as one");
 
 		if(yco < 0) uiNewPanelHeight(block, height-yco);
 	}

Modified: branches/etch-a-ton/source/blender/src/editarmature.c
===================================================================
--- branches/etch-a-ton/source/blender/src/editarmature.c	2008-11-29 19:53:49 UTC (rev 17627)
+++ branches/etch-a-ton/source/blender/src/editarmature.c	2008-11-29 20:37:10 UTC (rev 17628)
@@ -93,6 +93,7 @@
 #include "BIF_space.h"
 #include "BIF_toolbox.h"
 #include "BIF_transform.h"
+#include "BIF_generate.h"
 
 #include "BDR_editobject.h"
 #include "BDR_drawobject.h"
@@ -4655,7 +4656,8 @@
 	EditBone *lastBone = NULL;
 	if (G.scene->toolsettings->skgen_options & SKGEN_CUT_ANGLE)
 	{
-		ReebArcIterator iter;
+		ReebArcIterator arc_iter;
+		BArcIterator *iter = (BArcIterator*)&arc_iter;
 		float *previous = NULL, *current = NULL;
 		EditBone *child = NULL;
 		EditBone *parent = NULL;
@@ -4668,18 +4670,18 @@
 		
 		root = parent;
 		
-		initArcIterator(&iter, arc, head);
-		iter.next(&iter);
-		previous = iter.p;
+		initArcIterator(iter, arc, head);
+		IT_next(iter);
+		previous = iter->p;
 		
-		for (iter.next(&iter);
-			iter.stopped(&iter) == 0;
-			previous = iter.p, iter.next(&iter))
+		for (IT_next(iter);
+			IT_stopped(iter) == 0;
+			previous = iter->p, IT_next(iter))
 		{
 			float vec1[3], vec2[3];
 			float len1, len2;
 			
-			current = iter.p;
+			current = iter->p;
 
 			VecSubf(vec1, previous, parent->head);
 			VecSubf(vec2, current, previous);
@@ -4716,173 +4718,26 @@
 	return lastBone;
 }
 
-float calcVariance(ReebArc *arc, int start, int end, float v0[3], float n[3])
+EditBone * test_subdivideByCorrelation(ReebArc *arc, ReebNode *head, ReebNode *tail)
 {
-	int len = 2 + abs(end - start);
-	
-	if (len > 2)
-	{
-		ReebArcIterator iter;
-		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), iter.next(&iter);
-			iter.stopped(&iter) == 0;
-			iter.next(&iter))
-		{
-			float v[3];
-			
-			VecSubf(v, iter.p, v0);
-			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), iter.next(&iter);
-			iter.stopped(&iter) == 0;
-			iter.next(&iter))
-		{
-			float v[3], d[3];
-			float dt;
-			
-			VecSubf(v, iter.p, v0);
-			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 s_xyz / s_t; 
-	}
-	else
-	{
-		return 0;
-	}
-}
-
-float calcDistance(ReebArc *arc, int start, int end, float head[3], float tail[3])
-{
-	ReebArcIterator iter;
-	float max_dist = 0;
-	
-	/* calculate maximum distance */
-	for (initArcIterator2(&iter, arc, start, end), iter.next(&iter);
-		iter.stopped(&iter) == 0;
-		iter.next(&iter))
-	{
-		float v1[3], v2[3], c[3];
-		float dist;
-		
-		VecSubf(v1, head, tail);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list