[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19095] branches/etch-a-ton/source/blender : Merging volume embedding and transform snapping.

Martin Poirier theeth at yahoo.com
Tue Feb 24 01:45:45 CET 2009


Revision: 19095
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19095
Author:   theeth
Date:     2009-02-24 01:45:40 +0100 (Tue, 24 Feb 2009)

Log Message:
-----------
Merging volume embedding and transform snapping.

- Volume embed is available as a transform snap option (need new icon). Not as "continuous" as stroke embed, will have to be fixed somehow.
- Transform snaps work in armature edit mode (only snap to mesh, not other armatures, for now). Adding to other edit data type should be easy.
- Strokes can use all the transform snap options plus volume embed.

Bug fix: added small threshold to face snap (and volume embed) to prevent slipping in cracks between faces. More tweaking needed but this now takes care of all the worst cases.

Modified Paths:
--------------
    branches/etch-a-ton/source/blender/blenlib/BLI_arithb.h
    branches/etch-a-ton/source/blender/blenlib/intern/arithb.c
    branches/etch-a-ton/source/blender/include/BIF_transform.h
    branches/etch-a-ton/source/blender/makesdna/DNA_scene_types.h
    branches/etch-a-ton/source/blender/src/editarmature_sketch.c
    branches/etch-a-ton/source/blender/src/header_view3d.c
    branches/etch-a-ton/source/blender/src/transform_snap.c

Modified: branches/etch-a-ton/source/blender/blenlib/BLI_arithb.h
===================================================================
--- branches/etch-a-ton/source/blender/blenlib/BLI_arithb.h	2009-02-23 21:00:42 UTC (rev 19094)
+++ branches/etch-a-ton/source/blender/blenlib/BLI_arithb.h	2009-02-24 00:45:40 UTC (rev 19095)
@@ -394,6 +394,7 @@
 int LineIntersectLineStrict(float v1[3], float v2[3], float v3[3], float v4[3], float vi[3], float *lambda);
 int LineIntersectsTriangle(float p1[3], float p2[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv);
 int RayIntersectsTriangle(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv);
+int RayIntersectsTriangleThreshold(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float threshold);
 int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, float v0[3], float v1[3], float v2[3], float *lambda, float *ipoint);
 int AxialLineIntersectsTriangle(int axis, float co1[3], float co2[3], float v0[3], float v1[3], float v2[3], float *lambda);
 int AabbIntersectAabb(float min1[3], float max1[3], float min2[3], float max2[3]);

Modified: branches/etch-a-ton/source/blender/blenlib/intern/arithb.c
===================================================================
--- branches/etch-a-ton/source/blender/blenlib/intern/arithb.c	2009-02-23 21:00:42 UTC (rev 19094)
+++ branches/etch-a-ton/source/blender/blenlib/intern/arithb.c	2009-02-24 00:45:40 UTC (rev 19095)
@@ -3896,6 +3896,57 @@
 	return 1;
 }
 
+int RayIntersectsTriangleThreshold(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float threshold)
+{
+	float p[3], s[3], e1[3], e2[3], q[3];
+	float a, f, u, v;
+	float du = 0, dv = 0;
+	
+	VecSubf(e1, v1, v0);
+	VecSubf(e2, v2, v0);
+	
+	Crossf(p, d, e2);
+	a = Inpf(e1, p);
+	if ((a > -0.000001) && (a < 0.000001)) return 0;
+	f = 1.0f/a;
+	
+	VecSubf(s, p1, v0);
+	
+	Crossf(q, s, e1);
+	*lambda = f * Inpf(e2, q);
+	if ((*lambda < 0.0)) return 0;
+	
+	u = f * Inpf(s, p);
+	v = f * Inpf(d, q);
+	
+	if (u < 0) du = u;
+	if (u > 1) du = u - 1;
+	if (v < 0) dv = v;
+	if (v > 1) dv = v - 1;
+	if (u > 0 && v > 0 && u + v > 1)
+	{
+		float t = u + v - 1;
+		du = u - t/2;
+		dv = v - t/2;
+	}
+
+	VecMulf(e1, du);
+	VecMulf(e2, dv);
+	
+	if (Inpf(e1, e1) + Inpf(e2, e2) > threshold * threshold)
+	{
+		return 0;
+	}
+
+	if(uv) {
+		uv[0]= u;
+		uv[1]= v;
+	}
+	
+	return 1;
+}
+
+
 /* Adapted from the paper by Kasper Fauerby */
 /* "Improved Collision detection and Response" */
 static int getLowestRoot(float a, float b, float c, float maxR, float* root)

Modified: branches/etch-a-ton/source/blender/include/BIF_transform.h
===================================================================
--- branches/etch-a-ton/source/blender/include/BIF_transform.h	2009-02-23 21:00:42 UTC (rev 19094)
+++ branches/etch-a-ton/source/blender/include/BIF_transform.h	2009-02-24 00:45:40 UTC (rev 19095)
@@ -86,6 +86,7 @@
 struct ScrArea;
 struct Base;
 struct Scene;
+struct Object;
 
 struct TransInfo * BIF_GetTransInfo(void);
 void BIF_setSingleAxisConstraint(float vec[3], char *text);
@@ -125,5 +126,30 @@
 int BIF_do_manipulator(struct ScrArea *sa);
 void BIF_draw_manipulator(struct ScrArea *sa);
 
+/* Snapping */
+
+
+typedef struct DepthPeel
+{
+	struct DepthPeel *next, *prev;
+	
+	float depth;
+	float p[3];
+	float no[3];
+	struct Object *ob;
+	int flag;
+} DepthPeel;
+
+struct ListBase;
+
+typedef enum SnapMode
+{
+	NOT_SELECTED = 0,
+	NOT_ACTIVE = 1
+} SnapMode;
+
+int snapObjects(int *dist, float *loc, float *no, SnapMode mode);
+int peelObjects(struct ListBase *depth_peels, short mval[2]);
+
 #endif
 

Modified: branches/etch-a-ton/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/etch-a-ton/source/blender/makesdna/DNA_scene_types.h	2009-02-23 21:00:42 UTC (rev 19094)
+++ branches/etch-a-ton/source/blender/makesdna/DNA_scene_types.h	2009-02-24 00:45:40 UTC (rev 19095)
@@ -752,6 +752,7 @@
 #define SCE_SNAP_MODE_VERTEX	0
 #define SCE_SNAP_MODE_EDGE		1
 #define SCE_SNAP_MODE_FACE		2
+#define SCE_SNAP_MODE_VOLUME	3
 
 /* sce->selectmode */
 #define SCE_SELECT_VERTEX	1 /* for mesh */

Modified: branches/etch-a-ton/source/blender/src/editarmature_sketch.c
===================================================================
--- branches/etch-a-ton/source/blender/src/editarmature_sketch.c	2009-02-23 21:00:42 UTC (rev 19094)
+++ branches/etch-a-ton/source/blender/src/editarmature_sketch.c	2009-02-24 00:45:40 UTC (rev 19095)
@@ -57,6 +57,8 @@
 #include "BIF_generate.h"
 #include "BIF_interface.h"
 
+#include "BIF_transform.h"
+
 #include "blendef.h"
 #include "mydevice.h"
 #include "reeb.h"
@@ -418,224 +420,6 @@
 	}
 }	
 
-/******************** PEELING *********************************/
-
-typedef struct SK_DepthPeel
-{
-	struct SK_DepthPeel *next, *prev;
-	
-	float depth;
-	float p[3];
-	float no[3];
-	Object *ob;
-	int flag;
-} SK_DepthPeel;
-
-int cmpPeel(void *arg1, void *arg2)
-{
-	SK_DepthPeel *p1 = arg1;
-	SK_DepthPeel *p2 = arg2;
-	int val = 0;
-	
-	if (p1->depth < p2->depth)
-	{
-		val = -1;
-	}
-	else if (p1->depth > p2->depth)
-	{
-		val = 1;
-	}
-	
-	return val;
-}
-
-void addDepthPeel(ListBase *depth_peels, float depth, float p[3], float no[3], Object *ob)
-{
-	SK_DepthPeel *peel = MEM_callocN(sizeof(SK_DepthPeel), "DepthPeel");
-	
-	peel->depth = depth;
-	peel->ob = ob;
-	VECCOPY(peel->p, p);
-	VECCOPY(peel->no, no);
-	
-	BLI_addtail(depth_peels, peel);
-	
-	peel->flag = 0;
-}
-
-int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_start[3], float ray_normal[3], short mval[2], ListBase *depth_peels)
-{
-	int retval = 0;
-	int totvert = dm->getNumVerts(dm);
-	int totface = dm->getNumFaces(dm);
-	
-	if (totvert > 0) {
-		float imat[4][4];
-		float timat[3][3]; /* transpose inverse matrix for normals */
-		float ray_start_local[3], ray_normal_local[3];
-		int test = 1;
-
-		Mat4Invert(imat, obmat);
-
-		Mat3CpyMat4(timat, imat);
-		Mat3Transp(timat);
-		
-		VECCOPY(ray_start_local, ray_start);
-		VECCOPY(ray_normal_local, ray_normal);
-		
-		Mat4MulVecfl(imat, ray_start_local);
-		Mat4Mul3Vecfl(imat, ray_normal_local);
-		
-		
-		/* If number of vert is more than an arbitrary limit, 
-		 * test against boundbox first
-		 * */
-		if (totface > 16) {
-			struct BoundBox *bb = object_get_boundbox(ob);
-			test = ray_hit_boundbox(bb, ray_start_local, ray_normal_local);
-		}
-		
-		if (test == 1) {
-			MVert *verts = dm->getVertArray(dm);
-			MFace *faces = dm->getFaceArray(dm);
-			int i;
-			
-			for( i = 0; i < totface; i++) {
-				MFace *f = faces + i;
-				float lambda;
-				int result;
-				
-				
-				result = RayIntersectsTriangle(ray_start_local, ray_normal_local, verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, &lambda, NULL);
-				
-				if (result) {
-					float location[3], normal[3];
-					float intersect[3];
-					float new_depth;
-					
-					VECCOPY(intersect, ray_normal_local);
-					VecMulf(intersect, lambda);
-					VecAddf(intersect, intersect, ray_start_local);
-					
-					VECCOPY(location, intersect);
-					
-					if (f->v4)
-						CalcNormFloat4(verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, verts[f->v4].co, normal);
-					else
-						CalcNormFloat(verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, normal);
-
-					Mat4MulVecfl(obmat, location);
-					
-					new_depth = VecLenf(location, ray_start);					
-					
-					Mat3MulVecfl(timat, normal);
-					Normalize(normal);
-
-					addDepthPeel(depth_peels, new_depth, location, normal, ob);
-				}
-		
-				if (f->v4 && result == 0)
-				{
-					result = RayIntersectsTriangle(ray_start_local, ray_normal_local, verts[f->v3].co, verts[f->v4].co, verts[f->v1].co, &lambda, NULL);
-					
-					if (result) {
-						float location[3], normal[3];
-						float intersect[3];
-						float new_depth;
-						
-						VECCOPY(intersect, ray_normal_local);
-						VecMulf(intersect, lambda);
-						VecAddf(intersect, intersect, ray_start_local);
-						
-						VECCOPY(location, intersect);
-						
-						if (f->v4)
-							CalcNormFloat4(verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, verts[f->v4].co, normal);
-						else
-							CalcNormFloat(verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, normal);
-
-						Mat4MulVecfl(obmat, location);
-						
-						new_depth = VecLenf(location, ray_start);					
-						
-						Mat3MulVecfl(timat, normal);
-						Normalize(normal);
-	
-						addDepthPeel(depth_peels, new_depth, location, normal, ob);
-					} 
-				}
-			}
-		}
-	}
-
-	return retval;
-} 
-
-int peelObjects(ListBase *depth_peels, short mval[2])
-{
-	Base *base;
-	int retval = 0;
-	float ray_start[3], ray_normal[3];
-	
-	viewray(mval, ray_start, ray_normal);
-
-	base= FIRSTBASE;
-	for ( base = FIRSTBASE; base != NULL; base = base->next ) {
-		if ( BASE_SELECTABLE(base) ) {
-			Object *ob = base->object;
-			
-			if (ob->transflag & OB_DUPLI)
-			{
-				DupliObject *dupli_ob;
-				ListBase *lb = object_duplilist(G.scene, ob);
-				
-				for(dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next)
-				{
-					Object *ob = dupli_ob->ob;
-					
-					if (ob->type == OB_MESH) {
-						DerivedMesh *dm = mesh_get_derived_final(ob, CD_MASK_BAREMESH);
-						int val;
-						
-						val = peelDerivedMesh(ob, dm, dupli_ob->mat, ray_start, ray_normal, mval, depth_peels);
-	
-						retval = retval || val;
-	
-						dm->release(dm);
-					}
-				}
-				
-				free_object_duplilist(lb);
-			}
-			
-			if (ob->type == OB_MESH) {
-				DerivedMesh *dm = NULL;
-				int val;
-
-				if (ob != G.obedit)
-				{
-					dm = mesh_get_derived_final(ob, CD_MASK_BAREMESH);
-					
-					val = peelDerivedMesh(ob, dm, ob->obmat, ray_start, ray_normal, mval, depth_peels);
-				}
-				else
-				{
-					dm = editmesh_get_derived_cage(CD_MASK_BAREMESH);
-					
-					val = peelDerivedMesh(ob, dm, ob->obmat, ray_start, ray_normal, mval, depth_peels);
-				}
-					
-				retval = retval || val;
-				
-				dm->release(dm);
-			}
-		}
-	}
-	
-	BLI_sortlist(depth_peels, cmpPeel);
-	
-	return retval;
-}
 /*********************** CONVERSION ***************************/
 
 void sk_autoname(ReebArc *arc)
@@ -1087,6 +871,8 @@
 	int nb_points = stk->nb_points;
 	int i, j;
 	
+	return;
+	
 	if (start == -1)
 	{
 		start = 0;
@@ -1783,99 +1569,120 @@
 
 int sk_getStrokeEmbedPoint(SK_Point *pt, SK_Sketch *sketch, SK_Stroke *stk, SK_DrawData *dd)
 {
-	ListBase depth_peels;
-	SK_DepthPeel *p1, *p2;
-	float *last_p = NULL;
-	float dist = FLT_MAX;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list