[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13422] trunk/blender/source/blender/src/ edit.c: === Snap Menu ===

Martin Poirier theeth at yahoo.com
Sun Jan 27 17:43:51 CET 2008


Revision: 13422
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13422
Author:   theeth
Date:     2008-01-27 17:43:51 +0100 (Sun, 27 Jan 2008)

Log Message:
-----------
=== Snap Menu ===

New Cursor-> Active option

Useful on Edit Mesh too!

Modified Paths:
--------------
    trunk/blender/source/blender/src/edit.c

Modified: trunk/blender/source/blender/src/edit.c
===================================================================
--- trunk/blender/source/blender/src/edit.c	2008-01-27 10:34:35 UTC (rev 13421)
+++ trunk/blender/source/blender/src/edit.c	2008-01-27 16:43:51 UTC (rev 13422)
@@ -1518,6 +1518,57 @@
 	allqueue(REDRAWVIEW3D, 0);
 }
 
+void snap_curs_to_active()
+{
+	float *curs;
+	curs = give_cursor();
+
+	if (G.obedit)
+	{
+		if (G.obedit->type == OB_MESH)
+		{
+			/* check active */
+			if (G.editMesh->selected.last) {
+				EditSelection *ese = G.editMesh->selected.last;
+				if ( ese->type == EDITVERT ) {
+					EditVert *eve = (EditVert *)ese->data;
+					VECCOPY(curs, eve->co);
+				}
+				else if ( ese->type == EDITEDGE ) {
+					EditEdge *eed = (EditEdge *)ese->data;
+					VecAddf(curs, eed->v1->co, eed->v2->co);
+					VecMulf(curs, 0.5f);
+				}
+				else if ( ese->type == EDITFACE ) {
+					EditFace *efa = (EditFace *)ese->data;
+					
+					if (efa->v4)
+					{
+						VecAddf(curs, efa->v1->co, efa->v2->co);
+						VecAddf(curs, curs, efa->v3->co);
+						VecAddf(curs, curs, efa->v4->co);
+						VecMulf(curs, 0.25f);
+					}
+					else
+					{
+						VecAddf(curs, efa->v1->co, efa->v2->co);
+						VecAddf(curs, curs, efa->v3->co);
+						VecMulf(curs, 1/3.0f);
+					}
+				}
+			}
+			Mat4MulVecfl(G.obedit->obmat, curs);
+		}
+	}
+	else
+	{
+		if (BASACT)
+		{
+			VECCOPY(curs, BASACT->object->obmat[3]);
+		}
+	}
+}
+
 void snap_curs_to_firstsel()
 {
 	TransVert *tv;
@@ -1776,7 +1827,7 @@
 {
 	short event;
 
-	event = pupmenu("Snap %t|Selection -> Grid%x1|Selection -> Cursor%x2|Cursor-> Grid%x3|Cursor-> Selection%x4|Selection-> Center%x5");
+	event = pupmenu("Snap %t|Selection -> Grid%x1|Selection -> Cursor%x2|Cursor-> Grid%x3|Cursor-> Selection%x4|Selection-> Center%x5|Cursor-> Active%x6");
 
 	switch (event) {
 		case 1: /*Selection to grid*/
@@ -1797,6 +1848,10 @@
 		    snap_to_center();
 			BIF_undo_push("Snap selection to center");
 		    break;
+		case 6: /*Cursor to Active*/
+		    snap_curs_to_active();
+			BIF_undo_push("Snap selection to center");
+		    break;
 	}
 }
 





More information about the Bf-blender-cvs mailing list