// Update is called once per frame void Update() { // Debug.Log(bIsLeftHand + " Gesture:" + gestureManager.bufferedGesture()); if (HandActionRecog.getInstance() != null && HandActionRecog.getInstance().IsMotion("OpenMenu", bIsLeftHand)) { contextSwitch("menu"); } switch (context) { case "menu": break; case "paint": break; default: GameObject interact_obj = getHandObject(); if (interact_obj != null) { cleanGuidance(); //if hand gesture is grabbing string cur_gesture = gestureManager.bufferedGesture(); if (cur_gesture == "pinch" || cur_gesture == "fist") { //grab objbect if hand is not grabbing if (!is_grabbing) { grabObject(interact_obj); } else { this.updateObjTransform(interact_obj); } //Debug.Log ("obj isTrigger is " + interact_obj.GetComponent<Collider>().isTrigger + "palm isTrigger is " + palm.GetComponent<Collider>().isTrigger + "palm angular v is " + palm.GetComponent<Rigidbody>().angularVelocity); //if hand gesture is not grabbing } else { //but hand is grabbing Transform indextip = transform.Find("index").Find("bone3"); Transform thumbtip = transform.Find("thumb").Find("bone3"); float index_thumb_dis = Vector3.Distance(indextip.position, thumbtip.position); if (is_grabbing && (cur_gesture == "palm" || index_thumb_dis > 0.04f)) { Debug.Log("Grab:Release Grab, current gesture:" + gestureManager.bufferedGesture()); //then tell the object to release itself, Here support two version of interaction objects. InteractionScriptObject iso = interact_obj.GetComponent <InteractionScriptObject> (); if (iso != null && iso.isActiveAndEnabled) { iso.releaseSelf(); } else { GrabCollider gc = interact_obj.GetComponentInChildren <GrabCollider> (); if (gc != null) { gc.OnGrabFinished(); } } //releaseObject (interact_obj); CancelInvoke(); } else if (is_grabbing) { this.updateObjTransform(interact_obj); } } /* nothing in hand (interactable object is null)*/ } else { if (gestureManager.bufferedGesture() == "palm") { hitObject(); } else { cleanGuidance(); } } break; } updateHandSpeed(); }
public override void onHandGrab() { Camera cam = Camera.main; // Add object GameObject fo = Instantiate(m_furniturePrefab, cam.transform.position + cam.transform.forward, Quaternion.LookRotation(cam.transform.forward, new Vector3(0, 1, 0))) as GameObject; Debug.Log("Creating new object"); fo.tag = "InteractableObj"; Debug.Log("Adding collider"); if (fo.GetComponent <Renderer> () != null) { SetDepthMaterial(fo); BoxCollider c = fo.AddComponent <BoxCollider> (); c.isTrigger = false; } else { Bounds combinedBounds = new Bounds(); foreach (Transform child in transform) { SetDepthMaterial(child.gameObject); BoxCollider cc = child.gameObject.AddComponent <BoxCollider> (); cc.isTrigger = false; combinedBounds.Encapsulate(cc.bounds); } BoxCollider c = fo.AddComponent <BoxCollider> (); c.isTrigger = false; c.size = combinedBounds.size; } Debug.Log("Adding interaction script"); InteractionScriptObject iso = fo.AddComponent <InteractionScriptObject> (); iso.secondaryMaterial = new Material(Shader.Find("ModelEffect/VerticsOutline_Always")); iso.secondaryMaterial.SetColor("_OutlineColor", new Color(0, 248.0f / 256.0f, 63.0f / 256.0f, 143.0f / 256.0f)); Debug.Log("Adding rigid body"); Rigidbody r = fo.AddComponent <Rigidbody> (); r.collisionDetectionMode = CollisionDetectionMode.Discrete; r.mass = 20; r.useGravity = true; r.velocity = Vector3.zero; r.angularVelocity = Vector3.zero; // Change context hand_l.GetComponent <HandManager> ().contextSwitch("object"); }