[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49335] branches/soc-2012-sushi/source/ blender: SnapSystem work, and parallel snapping implemented.

luke frisken l.frisken at gmail.com
Sat Jul 28 20:51:17 CEST 2012


Revision: 49335
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49335
Author:   lfrisken
Date:     2012-07-28 18:51:17 +0000 (Sat, 28 Jul 2012)
Log Message:
-----------
SnapSystem work, and parallel snapping implemented.

Modified Paths:
--------------
    branches/soc-2012-sushi/source/blender/blenkernel/BKE_snap.h
    branches/soc-2012-sushi/source/blender/blenkernel/CMakeLists.txt
    branches/soc-2012-sushi/source/blender/blenkernel/SConscript
    branches/soc-2012-sushi/source/blender/blenkernel/intern/snap.c
    branches/soc-2012-sushi/source/blender/editors/transform/transform.c
    branches/soc-2012-sushi/source/blender/editors/transform/transform.h
    branches/soc-2012-sushi/source/blender/editors/transform/transform_generics.c
    branches/soc-2012-sushi/source/blender/editors/transform/transform_snap.c
    branches/soc-2012-sushi/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2012-sushi/source/blender/makesrna/intern/rna_scene.c

Modified: branches/soc-2012-sushi/source/blender/blenkernel/BKE_snap.h
===================================================================
--- branches/soc-2012-sushi/source/blender/blenkernel/BKE_snap.h	2012-07-28 18:42:54 UTC (rev 49334)
+++ branches/soc-2012-sushi/source/blender/blenkernel/BKE_snap.h	2012-07-28 18:51:17 UTC (rev 49335)
@@ -7,6 +7,8 @@
 #include "DNA_screen_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_mesh_types.h"
+#include "BKE_context.h"
+#include "WM_types.h"
 
 typedef struct{
 	//perhaps more info later I might guess
@@ -16,9 +18,49 @@
 	float r_depth;
 }SnapPoint;
 
+typedef struct SnapSystem SnapSystem;
+
+typedef enum{
+	SNAPSYSTEM_MODE_SELECT_ALL = 0,
+	SNAPSYSTEM_MODE_SELECT_NOT_SELECTED = 1,
+	SNAPSYSTEM_MODE_SELECT_NOT_OBEDIT = 2
+}SnapSystem_mode_select;
+
+SnapSystem* SnapSystem_create( Scene* scene, View3D* v3d, ARegion* ar, Object* obedit, bContext* C,
+								void* callback_data,
+								void (*update_callback)(void* callback_data, SnapPoint sp),
+								void (*finish_callback)(void* callback_data, SnapPoint sp),
+							   void (*cancel_callback)(void* callback_data));
+
+void SnapSystem_test_run(SnapSystem* ssystem);
+void SnapSystem_reset_ob_list(SnapSystem* ssystem);
+void SnapSystem_evaluate_stack(SnapSystem* ssystem);
+void SnapSystem_find_snap(SnapSystem* ssystem);
+void SnapSystem_pick_snap(SnapSystem* ssystem);
+void SnapSystem_add_ob(SnapSystem* ssystem, Object* ob);
+Object* SnapSystem_get_ob(SnapSystem* ssystem, int index);
+void SnapSystem_set_mode_select(SnapSystem* ssystem, SnapSystem_mode_select mode_select);
+int SnapSystem_get_retval(SnapSystem* ssystem);
+int SnapSystem_Event(SnapSystem* ssystem, wmEvent* event);
+void SnapSystem_reset_snappoint(SnapSystem* ssystem);
+void SnapSystem_clear_pick(SnapSystem* ssystem);
+void SnapSystem_reset(SnapSystem* ssystem);
+void SnapSystem_free(SnapSystem* ssystem);
+
+/*default callbacks*/
+void SnapSystem_default_object_iterator(SnapSystem* ssystem, void* callback_data);
+void SnapSystem_default_object_handler(SnapSystem* ssystem, void* callback_data, Object* ob);
+
 typedef struct Snap Snap;
 
 typedef enum{
+	SNAP_TYPE_MESH,
+	SNAP_TYPE_CURVE,
+	SNAP_TYPE_BONE,
+	SNAP_TYPE_AXIS
+}Snap_type;
+
+typedef enum{
 	SNAPMESH_DATA_TYPE_DerivedMesh,
 	SNAPMESH_DATA_TYPE_BMEditMesh
 }SnapMesh_data_type;
@@ -44,11 +86,13 @@
 int Snap_getretval(Snap* s);
 SnapPoint* Snap_getSnapPoint(Snap* s);
 void Snap_setClosestPoint(Snap* s, SnapPoint* sp);
+void Snap_setpick(Snap* s, Snap* pick);
 
 Snap* SnapMesh_create(	void* mesh_data,
 						SnapMesh_data_type data_type,
+					   int free_mesh_data,
 						SnapMesh_type sm_type,
-						Scene *scene, Object *ob, View3D *v3d, ARegion *ar, int mval[2]);
+						Scene *scene, Object *ob, View3D *v3d, ARegion *ar, bContext *C, int mval[2]);
 
 
 

Modified: branches/soc-2012-sushi/source/blender/blenkernel/CMakeLists.txt
===================================================================
--- branches/soc-2012-sushi/source/blender/blenkernel/CMakeLists.txt	2012-07-28 18:42:54 UTC (rev 49334)
+++ branches/soc-2012-sushi/source/blender/blenkernel/CMakeLists.txt	2012-07-28 18:51:17 UTC (rev 49335)
@@ -45,6 +45,7 @@
 	../../../intern/mikktspace
 	../../../intern/opennl/extern
 	../../../intern/raskter
+	../editors/transform
 	
 
 	# XXX - BAD LEVEL CALL WM_api.h

Modified: branches/soc-2012-sushi/source/blender/blenkernel/SConscript
===================================================================
--- branches/soc-2012-sushi/source/blender/blenkernel/SConscript	2012-07-28 18:42:54 UTC (rev 49334)
+++ branches/soc-2012-sushi/source/blender/blenkernel/SConscript	2012-07-28 18:51:17 UTC (rev 49335)
@@ -18,6 +18,7 @@
 incs += ' #/intern/audaspace/intern'
 incs += ' #/intern/ffmpeg'
 incs += ' #/intern/raskter'
+incs += ' ../editors/include ../editors/transform'
 
 incs += ' ' + env['BF_OPENGL_INC']
 incs += ' ' + env['BF_ZLIB_INC']

Modified: branches/soc-2012-sushi/source/blender/blenkernel/intern/snap.c
===================================================================
--- branches/soc-2012-sushi/source/blender/blenkernel/intern/snap.c	2012-07-28 18:42:54 UTC (rev 49334)
+++ branches/soc-2012-sushi/source/blender/blenkernel/intern/snap.c	2012-07-28 18:51:17 UTC (rev 49335)
@@ -1,8 +1,9 @@
 #include "BKE_snap.h"
-
 #include "BKE_mesh.h"
 #include "BKE_tessmesh.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_context.h"
+#include "BKE_anim.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -12,30 +13,654 @@
 #include "DNA_screen_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_mesh_types.h"
+#include "DNA_listBase.h"
 
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
 #include "ED_view3d.h"
-
+#include "ED_screen.h"
 #include "ED_mesh.h"
 
 #include "BLI_math_vector.h"
+#include "BLI_listbase.h"
+#include "BLI_utildefines.h"
 
+#include "UI_resources.h"
+
+#include "transform.h"
+
 #include <stdio.h>
-
 #include <stdlib.h>
 #include <math.h>
 #include <float.h>
+#include <assert.h>
 
+//#define DEBUG_SNAP
 /* -- PROTOTYPES -- */
 typedef struct MeshData MeshData;
+typedef struct SnapStack SnapStack;
+typedef struct SnapIsect SnapIsect;
+
+void SnapSystem_reset_snappoint(SnapSystem* ssystem);
+void SnapSystem_parallel_hack_ob_handler(SnapSystem* ssystem, void* callback_data, Object* ob); //TODO: get rid of this
+
+SnapStack* SnapStack_create(void);
+int SnapStack_getN_Snaps(SnapStack* sstack);
+void SnapStack_pushSnap(SnapStack* sstack, Snap* s);
+Snap* SnapStack_popSnap(SnapStack* sstack);
+Snap* SnapStack_getSnap(SnapStack* sstack, int index);
+void SnapStack_reset(SnapStack* sstack);
+void SnapStack_free(SnapStack*);
 void Snap_draw_default(Snap *s);
 void SnapMesh_run(Snap *sm);
 void SnapMesh_free(Snap* sm);
+Snap_type Snap_getType(Snap* s);
 
+void SnapPoint_deepcopy(SnapPoint* out, SnapPoint* in){
+	copy_v3_v3(out->location, in->location);
+	copy_v3_v3(out->normal, in->normal);
+	out->r_depth = in->r_depth;
+	out->r_dist = in->r_dist;
+}
 
+typedef struct SnapObRef SnapObRef;
+struct SnapObRef{
+	SnapObRef *next, *prev;
+	Object* ob;
+};
+
+typedef enum{
+	SNAPSYSTEM_STATE_SNAPPING,
+	SNAPSYSTEM_STATE_INIT_SNAP,
+	SNAPSYSTEM_STATE_IDLE
+}SnapSystem_state;
+
+/* -- SnapSystem Class -- */
+struct SnapSystem{
+	SnapStack* sstack;
+
+	/*events and state machine variables*/
+	/*most are hacks to get this working for now*/
+	SnapSystem_state state;
+	Snap* pick; //used for parallel snap, perpendicular and planar snap
+
+	bContext* C;
+	Scene* scene;
+	View3D* v3d;
+	ARegion* ar;
+	Object* obedit;
+
+	SnapPoint snap_point;
+	int min_distance;
+	int retval;
+
+	ListBase ob_list;
+	int n_obs;
+
+	SnapSystem_mode_select mode_select;
+
+	void* callback_data;
+	void (*update_callback)(void* callback_data, SnapPoint sp);
+	void (*finish_callback)(void* callback_data, SnapPoint sp);
+	void (*cancel_callback)(void* callback_data);
+
+	void* (*object_iterator)(SnapSystem* ssystem, void* callback_data);
+	void* (*object_handler)(SnapSystem* ssystem, void* callback_data, Object* ob);
+
+	MeshData* (*meshdata_selector)(SnapStack* stack, void* callback_data);
+	void (*bonedata_selector)(SnapStack* stack, void* callback_data);
+};
+
+SnapSystem* SnapSystem_create( Scene* scene, View3D* v3d, ARegion* ar, Object* obedit, bContext* C,
+								void* callback_data,
+								void (*update_callback)(void* callback_data, SnapPoint sp),
+								void (*finish_callback)(void* callback_data, SnapPoint sp),
+							   void (*cancel_callback)(void* callback_data))
+{
+	SnapSystem* ssystem = (SnapSystem*)MEM_mallocN(sizeof(SnapSystem), "snapsystem");
+	ssystem->sstack = SnapStack_create();
+	ssystem->C = C;
+	ssystem->scene = scene;
+	ssystem->v3d = v3d;
+	ssystem->ar = ar;
+	ssystem->obedit = obedit;
+	ssystem->callback_data = callback_data;
+	ssystem->update_callback = update_callback;
+	ssystem->finish_callback = finish_callback;
+	ssystem->cancel_callback = cancel_callback;
+	ssystem->object_iterator = SnapSystem_default_object_iterator;
+	/*I'm thinking of having an object_handler struct full of functions for handling each type
+	  of object. So the other sections of code can override the handling of a certain type of object, say
+	  for a certain tool which uses curves or a certain tool which uses meshes but wants the snapping to work in
+	  a particular manner*/
+	ssystem->object_handler = SnapSystem_default_object_handler;
+	ssystem->min_distance = 30; //TODO: make this settable in user settings.
+	SnapSystem_reset_snappoint(ssystem);
+	ssystem->n_obs = 0;
+	ssystem->ob_list.first = NULL;
+	ssystem->ob_list.last = NULL;
+
+	/*TODO: clean up state stuff with proper design*/
+	ssystem->retval = 0;
+	ssystem->state = SNAPSYSTEM_STATE_IDLE;
+	ssystem->pick = NULL;
+	return ssystem;
+}
+
+void SnapSystem_test_run(SnapSystem* ssystem){
+	SnapSystem_evaluate_stack(ssystem);
+}
+
+void SnapSystem_reset_snappoint(SnapSystem* ssystem){
+	ssystem->snap_point.r_dist = ssystem->min_distance;
+	ssystem->snap_point.r_depth = FLT_MAX;
+	//ssystem->retval = 0;
+}
+
+SnapPoint* SnapSystem_getSnapPoint(SnapSystem* ssystem){
+	return &(ssystem->snap_point);
+}
+
+void SnapSystem_state_logic(SnapSystem* ssystem){
+	ToolSettings *ts= ssystem->scene->toolsettings;
+	switch(ssystem->state){
+	case SNAPSYSTEM_STATE_INIT_SNAP:
+		SnapSystem_pick_snap(ssystem);
+		break;
+	case SNAPSYSTEM_STATE_SNAPPING:
+		SnapSystem_find_snap(ssystem);
+		break;
+	}
+}
+
+void SnapSystem_find_snap(SnapSystem* ssystem){
+	Object* ob;
+	int i;
+	for(i=0;i<ssystem->n_obs;i++){
+		ob = SnapSystem_get_ob(ssystem, i);
+		ssystem->object_handler(ssystem, ssystem->callback_data, ob);
+	}
+}
+
+void SnapSystem_pick_snap(SnapSystem* ssystem){
+	//use the parallel snap hack object handler
+	Object* ob;
+	int i;
+	for(i=0;i<ssystem->n_obs;i++){
+		ob = SnapSystem_get_ob(ssystem, i);
+		SnapSystem_parallel_hack_ob_handler(ssystem, ssystem->callback_data, ob);
+	}
+	SnapSystem_reset_snappoint(ssystem); //reset snap point generated by picking
+}
+
+//TODO: change this when I refactor the way object handlers work
+Snap* snapmesh_edit_create(SnapSystem* ssystem, void* callback_data, SnapMesh_type sm_type, Object* ob, BMEditMesh *em, DerivedMesh *dm){
+	TransInfo* t = (TransInfo*)callback_data; //hack to test using existing option system
+	Scene* scene = ssystem->scene;
+	bContext *C = ssystem->C;
+	if(em == NULL){
+		return SnapMesh_create(dm, SNAPMESH_DATA_TYPE_DerivedMesh, 1, sm_type, scene, ob, t->view, t->ar, C, t->mval);
+	}else{
+		dm->release(dm);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list