From BlenderWiki

Jump to: navigation, search
Note: This is an archived version of the Blender Developer Wiki. The current and active wiki is available on wiki.blender.org.

Precision Modelling Tools Dev Docs

note: many sections of the SnapSystem class are still under heavy developement still and subject to change in internal design.

Internal Structs and Functions Overview

Internal Structs Overview


SnapPoint

variables

r_dist
is the distance from mouse to snap point.
r_depth
is the depth of the snap point from the screen.

SnapSystem

variables

retval
is a boolean indicating whether or not a valid snap point has been found.
callback_data
is the data assigned from parent code using snapsystem to be used when the function pointers update, finish or cancel_callback are called.
update_callback
gets called when the snapping system has not yet recieved confirmation from the user of the chosen snap point, but there is a temporary snap_point available for providing realtime feedback to the user of their actions when moving the mouse. In the case of transform, this means the geometry moves towards the snap point without permenantly being applied.
finish_callback
same as update_callback, but the snap_point is to be applied this time.
cancel_callback
tells the code using the snapsystem that the current snapsystem snap search has been cancelled.

functions

SnapSystem_create(...)
used to setup and create an instance of SnapSystem. Remember to call SnapSystem_free() when finished with it.
SnapSystem_evaluate_stack()
evaluate the SnapStack contained within SnapSystem to allow final snappoint to be aquired and for draw functions to work.
SnapSystem_Event(wmEvent*)
This function drives the snapping system by passing it events. It indicates whether the events have been consumed by its return value, so external code can act accordingly.
SnapSystem_add_ob()
SnapSystem operates on a specific list of objects. This function is used to add objects to that list. There are other internal functions which use this function to add objects automatically by a filter.
SnapSystem_draw()
calles draw for each of the active snaps in the stack
SnapSystem_reset()
reset snap system back to default state

Snap

Snap is not designed to be used externally, but rather as a parent for the various snap types (SnapMesh, SnapBone, SnapCurve).

variables

snap_data
this variable stores the data for Snap's subclasses (e.g. SnapMesh_data)
s_type
is the type of snap (Mesh, Curve, Bone, Axis...)
snap_point
is the storage point for the calculated snap point
closest_point
is a pointer, that when set is used during calculations to ignore potential snaps which are not as close to the screen (depth) or the mouse.
pick
is a previously calculated snap to be used for mosed such as planar and parallel snapping, as the user picked face/line/vert.
min_distance
is the minimum distance from the mouse to the snap point required for the snap point to be valid during calculations
run
This variable stores the function pointer which calculates the snap.
draw
This variable stores the function pointer which draws the snap. By default this is set to Snap_draw_default()
intersect
free
This variable stores the function pointer to the subclass's free function.

functions

Snap_create(...)
used to setup and create an instance of Snap. Remember to call Snap_free() when finished with it.
Snap_run()
calls interal s->run()
Snap_draw()
Calls internal s->draw()
Snap_draw_default()
Default drawing function to be assigned to s->draw. It draws the snap_point as a circle at its location.
Snap_free()
Snap_free function calls it's internal s->free()
Snap_free_f()
Snap_free_f() frees Snap struct's internal data. This is useful to call after Snap's subclasses have finished their own free, and need to free parent data.

SnapMesh

SnapMesh isn't a struct, but rather a collection of functions designed to operate on one type (Mesh) of instance of Snap defined by its s_type variable

functions

SnapMesh_create(...)
SnapMesh_snap_face(), SnapMesh_snap_planar(), SnapMesh_snap_vertex(), SnapMesh_snap_edge(), SnapMesh_snap_edge_midpoint(), SnapMesh_snap_parallel()
The various snap function calculate a snap point given the mouse position and various other inputs, and then assign the retval variable of Snap according to whether a valid snap was found or not. All, but planar and parallel have a return value indicating the geometry which the user has picked during their snap, for use in combination with other snap modes (planar, parallel etc..).
SnapMesh_draw_planar(), SnapMesh_draw_parallel()
These functions are used instead of Snap_draw_default as the value of Snap->draw when SnapMesh->sm_type is set to planar or parallel snap.


SnapMesh_data

variables

sm_type
Stores the type of meshsnap (planar, face, vertex, etc..)
ret_data_type
Sets the type of the return data. I'm planning on implementing a better, and more consistent scheme for input and output data for Snaps.
ret_data_index
index of return data if it is a vertex or an edge.
ret_data_pface
pface is a struct storing all the details of a face, with its own internal vert array.
check
check is a variable which stores the various check types that a snap needs to make on the mesh during its calculations to avoid snapping on them. (selected or hidden geometry)
dm_index_array
not in use

MeshData

The purpose of meshdata is to provide a consistent interface to the mesh system for use in mesh based snapping modes without the requirement to convert between them, and thus suffer a performance loss. At the moment it supports two backends: BMEditmesh and DerivedMesh. It does this using a struct with function pointers that are assigned according to the type of mesh system that is getting used.

variables

data_type
Indicates the type of data stored in MeshData->data pointer.
edit_mode
whether the mesh is from an object in edit mode
index_init
Accessing mesh often requires an initialization phase. I'll probably be able to make this invisible to users of MeshData in the future by cache-calling this from the other functions which access the mesh-data.
getVert
get vertex from MeshData using index.
getEdgeVerts
get an edge's two verts using the edge index.
bvh_from_faces
create a bvh from faces contained within MeshData
free_bvh_tree
free the bvh tree which was created using above function
checkVert, checkEdge
Conduct checks on vert or edge to determine whether they have various qualities (hidden, selected) which might make them unsuitable for snapping.
free_data
this variable determines whether the data given the the MeshData struct during creation should be free'd along with the MeshData struct when the MeshData->free() function is called. This is useful if a temporary mesh has been passed to MeshData.

functions

BMEditMesh and DerivedMesh functions
for each type of data which can be accessed using MeshData there are corresponding functions implemented to assign to each of the function pointers in MeshData struct.

Operation and Integration with transform

Snapping System State Diagram
Internal Structs Overview