# Process

## The snapping process

If PosePoint has a SnapPoint reference, Snapper will make PosableHand to pose ghost hand and ghost hand will be used to preview pose and to transfer the pose to the slave hand during the snapping process.&#x20;

The whole process of snapping is described as follows.

### 1. Search candidates

If the mean between ProxyHandModel.fistLerp and ProxyHandModel.graspLerp is greater than SnapperModel.minSelectionGestureLerp, SnapperController will search for closest candidates according to certain restrictions like SnapperModel.availability or SnapPointModel.availability.

If the candidate SnapPoint has a PosePoint connected to it, ghost hand will be shown as a pose preview.

### 2. Start attraction

If ProxyHandModel.graspLerp is greater that SnapPointModel.graspLerp for the current best candidate. Then:

#### 2.1. Attraction joint

A new ConfigurableJoint will be attached to the rigidbody (SnapperModel.currentSnapJoint). If SnapPointModel. useTheseAttractionDirves is enabled, this joint will be configured according to SnapPointModel.attractionMotionDrive and SnapPointModel.attractionRotationDrive. If not, joint will be configured according to SnapperModel.configuration.attractionMotionDrive and SnapperModel.configuration.attractionRotationDrive.

#### 2.2. Lock bones

PosableHandController will copy ghost hand pose into slave and SlaveBoneModel.minLocalRot will be updated with copied local rotation so HandPhysicsController will not be able to control that slave bone, locking every bone in the hand.

#### 2.3. Ignore collisions

Snap point of snapped object will have to reach hand palm, but hand pose is locked so, if hand is closed and locked, attracted object would never be able to reach its destination. To solve this, snapped object (and its connected rigidbodies) will ignore collisions with every slave bone.

### 3. Snap

If distance between SnapperModel.currentSnapJoint anchor and connectedAnchor is lower than a theresold (SnapperModel.configuration.minDistancetoCompleteSnap) during some time (SnapperModel.configuration.timeInMinDistanceToSnap), then:

#### 3.1.   Snap joint

SnapperModel.currentSnapJoint drives will be updated. If SnapPointModel. useTheseSnapDirves is enabled, this joint will be configured according to SnapPointModel.snap MotionDrive and SnapPointModel.snapRotationDrive. If not, joint will be configured according to SnapperModel.configuration.snapMotionDrive and SnapperModel.configuration.snapRotationDrive.

#### 3.2. Lock certain bones

PosableHandController will reset SlaveBoneModel.minLocalRot to Quaternion.identity for some slave bones so HandPhysicsController will be able to control these slave bones again. The slave bones to keep locked are the ones lower that the bone level specified for each finger in PosePointModel.limit{Finger}. If these values are set to Distal, lower than distal bones (including distal) will be locked, so every finger bone will keep locked. If these values are set to None, every finger bone will be unlocked.

#### 3.3. Ignore certain collisions

SnapperController will make bone collisions to be detected again for certain bones according to SnapPointModel.ignore{Finger}. Assuming SnapPointModel.ignoreInnerBones is enabled and SnapPointModel.ignoreOuterBones is disabled, if these values are set to Distal, then lower than distal bones (including distal) will ignore collisions and every finger bone will ignore collisions with the snapped object. If these values are set to None, every finger bone will collide with the snapped object.

### 4. Unsnap

If ProxyHandHandler.onUngrasp is invoked, SnapperModel.currentSnapJoint will  be destroyed and SnapperModel.currentSnapPoint will be reset.
