[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48392] branches/soc-2012-sushi/source/ blender: Edge Snapping now re-implemented using new snapping system, and working
luke frisken
l.frisken at gmail.com
Fri Jun 29 08:47:57 CEST 2012
Revision: 48392
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48392
Author: lfrisken
Date: 2012-06-29 06:47:43 +0000 (Fri, 29 Jun 2012)
Log Message:
-----------
Edge Snapping now re-implemented using new snapping system, and working
correctly!
Modified Paths:
--------------
branches/soc-2012-sushi/source/blender/blenkernel/intern/snap.c
branches/soc-2012-sushi/source/blender/editors/transform/transform_snap.c
Modified: branches/soc-2012-sushi/source/blender/blenkernel/intern/snap.c
===================================================================
--- branches/soc-2012-sushi/source/blender/blenkernel/intern/snap.c 2012-06-29 00:24:28 UTC (rev 48391)
+++ branches/soc-2012-sushi/source/blender/blenkernel/intern/snap.c 2012-06-29 06:47:43 UTC (rev 48392)
@@ -120,7 +120,10 @@
}
void Snap_calc_rays(Snap* s){
- ED_view3d_win_to_ray(s->ar, s->v3d, s->mval, s->ray_start, s->ray_normal);
+ float mval_f[2];
+ mval_f[0] = (float)(s->mval[0]);
+ mval_f[1] = (float)(s->mval[1]);
+ ED_view3d_win_to_ray(s->ar, s->v3d, mval_f, s->ray_start, s->ray_normal);
}
void Snap_calc_matrix(Snap* s){
@@ -369,8 +372,10 @@
}
int MeshData_DerivedMesh_checkEdge(MeshData *md, int index){
+ //TODO: optimise this code a bit, and remove debug variables.
MEdge* edges;
MVert* verts;
+ MVert *v1, *v2;
DerivedMesh* dm = (DerivedMesh*)md->data;
char hidden, v1_selected, v2_selected;
edges = dm->getEdgeArray(dm);
@@ -379,9 +384,11 @@
When they are selected their flag will be 0? (if indeed it works similar to bmesh)*/
/* in this case v1 and v2 are integer indexes for the vertex array*/
+ v1 = &(verts[edges[index].v1]);
+ v2 = &(verts[edges[index].v2]);
if(md->edit_mode){
- v1_selected = verts[edges[index].v1].flag & 1;
- v2_selected = verts[edges[index].v2].flag & 1;
+ v1_selected = v1->flag & 1;
+ v2_selected = v2->flag & 1;
}
else{
v1_selected = 0;
@@ -527,7 +534,7 @@
copy_v3_v3(sm->snap_point.location, location);
- printf("SnapPointInternal: %f, %f, %f\n", location[0], location[1], location[2]);
+ //printf("SnapPointInternal: %f, %f, %f\n", location[0], location[1], location[2]);
normal_short_to_float_v3(sm->snap_point.normal, mv.no);
mul_m3_v3(sm->timat, sm->snap_point.normal);
@@ -546,13 +553,13 @@
}
void SnapMesh_snap_edge(Snap* sm){
- int i, totedge, result, new_dist, r_dist;
+ int i, totedge, result, new_dist;
int screen_loc[2];
float intersect[3] = {0, 0, 0}, ray_end[3], dvec[3];
float edge_loc[3], vec[3], location[3];
float n1[3], n2[3];
- float mul, new_depth, r_depth;
+ float mul, new_depth;
SnapMesh_data* sm_data = (SnapMesh_data*)sm->snap_data;
MeshData* md = sm_data->mesh_data;
@@ -563,8 +570,6 @@
add_v3_v3v3(ray_end, sm->ray_start_local, ray_end);
sm->retval = 0;
- r_depth = FLT_MAX;
- r_dist = sm->min_distance;
md->index_init(md, SNAPMESH_DAT_edge); //should perhaps only be called once per mesh...
@@ -630,7 +635,7 @@
* this takes care of series of connected edges a bit slanted w.r.t the viewport
* otherwise, it would stick to the verts of the closest edge and not slide along merrily
* */
- if (new_dist > r_dist || new_depth > r_depth){
+ if (new_dist > sm->snap_point.r_dist || new_depth >= sm->snap_point.r_depth * 1.001f){
continue;
}
@@ -652,8 +657,10 @@
copy_v3_v3(sm->snap_point.normal, location);
- r_dist = new_dist;
+ copy_v3_v3(sm->snap_point.location, location);
+ sm->snap_point.r_dist = new_dist;
+ sm->snap_point.r_depth = new_depth;
}
}
Modified: branches/soc-2012-sushi/source/blender/editors/transform/transform_snap.c
===================================================================
--- branches/soc-2012-sushi/source/blender/editors/transform/transform_snap.c 2012-06-29 00:24:28 UTC (rev 48391)
+++ branches/soc-2012-sushi/source/blender/editors/transform/transform_snap.c 2012-06-29 06:47:43 UTC (rev 48392)
@@ -1673,7 +1673,6 @@
Snap_setClosestPoint(sm, &sp_prev);
}
-
Snap_run(sm);
retval = Snap_getretval(sm);
if(retval){
@@ -1686,22 +1685,36 @@
}
Snap_free(sm);
-// }else if(ts->snap_mode == SCE_SNAP_MODE_EDGE){
-// int mval_i[2] = {mval[0], mval[1]};
-// Snap* sm;
-// SnapPoint* sp;
-// if(em == NULL){
-// sm = SnapMesh_create(dm, SNAPMESH_DATA_TYPE_DerivedMesh, SNAPMESH_TYPE_EDGE, scene, ob, v3d, ar, mval_i);
-// }else{
-// sm = SnapMesh_create(em, SNAPMESH_DATA_TYPE_BMEditMesh, SNAPMESH_TYPE_EDGE, scene, ob, v3d, ar, mval_i);
-// }
-// Snap_run(sm);
-// retval = Snap_getretval(sm);
-// sp = Snap_getSnapPoint(sm);
-// printf("SnapPoint: %f, %f, %f\n", sp->location[0], sp->location[1], sp->location[2]);
-// copy_v3_v3(r_loc, sp->location);
-// copy_v3_v3(r_no, sp->normal);
-// Snap_free(sm); //TODO: there is some memory not getting freed around here.
+ }else if(ts->snap_mode == SCE_SNAP_MODE_EDGE){
+ int mval_i[2] = {mval[0], mval[1]};
+ Snap* sm;
+ SnapPoint* sp;
+ SnapPoint sp_prev;
+
+ if(em == NULL){
+ sm = SnapMesh_create(dm, SNAPMESH_DATA_TYPE_DerivedMesh, SNAPMESH_TYPE_EDGE, scene, ob, v3d, ar, mval_i);
+ }else{
+ sm = SnapMesh_create(em, SNAPMESH_DATA_TYPE_BMEditMesh, SNAPMESH_TYPE_EDGE, scene, ob, v3d, ar, mval_i);
+ }
+
+ //if this is not the first run through.
+ if(*r_depth < FLT_MAX - 10){
+ sp_prev.r_depth = *r_depth;
+ sp_prev.r_dist = *r_dist;
+ Snap_setClosestPoint(sm, &sp_prev);
+ }
+
+ Snap_run(sm);
+ retval = Snap_getretval(sm);
+ if(retval){
+ sp = Snap_getSnapPoint(sm);
+ //printf("SnapPointExternal: %f, %f, %f\n", sp->location[0], sp->location[1], sp->location[2]);
+ copy_v3_v3(r_loc, sp->location);
+ copy_v3_v3(r_no, sp->normal);
+ *r_depth = sp->r_depth;
+ *r_dist = sp->r_dist;
+ }
+ Snap_free(sm); //TODO: there is some memory not getting freed around here.
}else {
retval = snapDerivedMesh(ts->snap_mode, ar, ob, dm, em, obmat, ray_start, ray_normal, mval, r_loc, r_no, r_dist, r_depth);
}
More information about the Bf-blender-cvs
mailing list