public static float getGrabHeuristic(Hand hand, GameObject obj) { float grabProbability = 0.0f; //If palm is facing away from the object, no chance of grabbing Vector3 palmNormal = handController.transform.TransformDirection(hand.PalmNormal.ToUnity()); Vector3 palmPos = handController.transform.TransformPoint(hand.PalmPosition.ToUnityScaled()); if (Vector3.Dot(palmNormal, obj.transform.position - palmPos) < 0) { return(0); } float proximityFactor = 0.0f; foreach (Finger finger in hand.Fingers) { Vector3 point = handController.transform.TransformPoint(finger.JointPosition(Leap.Finger.FingerJoint.JOINT_TIP).ToUnityScaled()); Vector3 pointOn = ColliderUtil.closestPointOnSurfaces(obj, point); float distance = Vector3.Distance(point, pointOn); if (ColliderUtil.isInsideColliders(obj, point)) { distance = 0.0f; } //if any finger is <releaseRadius> meters away, negative infinity, no way that hand is close enough float thresh = Mathf.Clamp01(1.0f - distance / 0.15f); proximityFactor += 2.0f - 1.0f / thresh; } proximityFactor /= hand.Fingers.Count; //Debug.Log(proximityFactor); grabProbability += proximityFactor; //The more the hand is opening, the more grabbable grabProbability += getHandClosingSpeed(hand) * 10.0f; //If the hand is mostly open, the probability of a grab goes down grabProbability -= Mathf.Pow(1.0f - getHandClosedPercent(hand), 4.0f); if (hand.PalmVelocity.ToUnityScaled().sqrMagnitude > 0.09f) { grabProbability = 0.7f; } grabProbability = 0.7f + (grabProbability - 0.7f) / (hand.PalmVelocity.ToUnityScaled().sqrMagnitude * 3.0f + 1); grabProbability = 0.7f + (grabProbability - 0.7f) / (getHandRotationAmount(hand) * 1 + 1.0f); if (grabProbability > 0 && grabProbability < 10.0f) { DebugGraph.Log("Grabbing", grabProbability, grabProbability > 0.7f ? Color.green : Color.red); } return(grabProbability); }
public void Update() { if (Input.GetKeyUp(KeyCode.C)) { Debug.Log("test:" + ColliderUtil.CollidePoint(testPosition, mask)); } if (Input.GetKeyUp(KeyCode.T)) { Debug.Log("test:" + (Physics2D.OverlapBox(testCenter, testSize, 0, mask))); } }
private void LoadGltfFile(string file) { ResetForm(true); gltf = Interface.LoadModel(file); colliderManager = new ColliderManager(); for (int i = 0; i < gltf.Nodes.Length; i++) { var node = gltf.Nodes[i]; var name = GetNodeName(node, i); nodeListBox.Items.Add(name); var collider = ColliderUtil.GetNodeCollider(gltf, i); if (collider != null) { colliderManager.AddCollider(i, collider); } } }