// Use this for initialization void Start() { Debug.Log(HandActionRecog.getInstance()); if (HandActionRecog.getInstance().BeginMotion("Basic")) { HandActionRecog.getInstance().DefineTransform("palm|pinch|undefined", "palm|pinch|undefined", -Vector3.up, Vector3.up, 1.0f); HandActionRecog.getInstance().DefineTransform("palm|pinch|undefined", "palm|pinch|undefined", Vector3.up, -Vector3.up, 1.0f); HandActionRecog.getInstance().EndMotion(); Debug.Log("defined gesture Basic"); } }
// Use this for initialization void Start() { dataManager = GameObject.Find("gDataManager").GetComponent <DataManager> (); gestureManager = this.GetComponent <GestureControl> (); paintManager = this.GetComponent <PaintManager> (); palm = this.transform.GetChild(5).gameObject; grabHolder = this.transform.GetChild(5).GetChild(0).gameObject; thumbFinger = this.transform.GetChild(0).GetChild(2).gameObject; indexFinger = this.transform.GetChild(1).GetChild(2).gameObject; indexFingerPos = new Vector3[10]; thumbFingerPos = new Vector3[10]; pIndexFingerPos = Vector3.zero; pThumbFingerPos = Vector3.zero; _handThrowingPowerMultiplier = dataManager.handThrowingPowerMultiplier; context_buff = new int[context_buff_len]; context_dict.Add(0, "object"); context_dict.Add(1, "paint"); context_dict.Add(2, "menu"); context_dict.Add(3, "brush"); // Get menus if (GameObject.Find("FurnitureMenu") != null) { m_furnitureMenu = GameObject.Find("FurnitureMenu").GetComponent <VirtualFurnitureMenu>(); m_paintMenu = GameObject.Find("PaintMenu").GetComponent <VirtualPaintMenu>(); m_brushMenu = GameObject.Find("strokeMatMenu").GetComponent <VirtualMenuBrush>(); m_furnitureMenu.close(); m_paintMenu.close(); m_brushMenu.close(); } /*initial all user-defined settings*/ DataManager data_mngr = GameObject.Find("gDataManager").GetComponent <DataManager> (); palm_collider_delay = data_mngr.getPalmColliderDelay(); palm.GetComponent <Rigidbody> ().maxAngularVelocity = 0; //use for disable UI for photo //smallMenu = GameObject.Find("GameControlPanel"); //smallMenu.SetActive (false); // register new motion if (HandActionRecog.getInstance() != null && HandActionRecog.getInstance().BeginMotion("OpenMenu")) { HandActionRecog.getInstance().DefineTransform("palm|pinch|undefined", "palm|pinch|undefined", Vector3.up, -Vector3.up, 1.0f); HandActionRecog.getInstance().DefineTransform("palm|pinch|undefined", "palm|pinch|undefined", -Vector3.up, Vector3.up, 1.0f); HandActionRecog.getInstance().EndMotion(); } }
void Awake() { // Singleton. if (_instance != null) { Debug.LogError("Trying to initialize two or more instances of HandActionRecog"); Destroy(gameObject); } else { _instance = this; DontDestroyOnLoad(gameObject); } }
/// <summary> /// Set hand action enabled /// </summary> /// <param name="e">true for enabled, false for not</param> public void SetActionRecogEnabled(bool e) { HandActionRecog.getInstance().SetEnabled(e); }
// 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(); }
/* update commented session */ //public override void OnARCorePlaneHit(TrackableHit hit) { // if (m_SetInfinitePlane) // return; // // Place a cup // if ((hit.Trackable is DetectedPlane) && // Vector3.Dot(m_FirstPersonCamera.transform.position - hit.Pose.position, // hit.Pose.rotation * Vector3.up) < 0) { // Debug.Log("Hit at back of the current DetectedPlane"); // } // else { // // Choose the Andy model for the Trackable that got hit. // GameObject prefab = CupPrefab; // // Instantiate Andy model at the hit pose. // var andyObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); // // Compensate for the hitPose rotation facing away from the raycast (i.e. camera). // andyObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self); // } //} /* update commented session */ //public override void OnUnityPlaneHit(RaycastHit hit) { // if (m_SetInfinitePlane) { // if (m_InfinitePlane == null) { // m_InfinitePlane = Instantiate<Transform>(m_PlaneColliderPrefab); // m_InfinitePlaneComp = m_InfinitePlane.GetComponent<InfinitePlaneFloor>(); // } // /* update commented session */ // //DetectedPlaneVisualizer visualizer = hit.transform.GetComponent<DetectedPlaneVisualizer>(); // //DetectedPlane dp = visualizer.GetDetectedPlane(); // m_InfinitePlane.position = dp.CenterPose.position; // m_InfinitePlane.localScale = new Vector3(500f, 1f, 500f); // m_InfinitePlane.rotation = dp.CenterPose.rotation; // m_InfinitePlaneComp.BindToPlane(hit.transform); // m_SetInfinitePlane = false; // UpdateButton(); // } //} public void ToggleHandAction() { m_HandActionToggleFlag = !m_HandActionToggleFlag; HandActionRecog.getInstance().SetEnabled(m_HandActionToggleFlag); }
// Update is called once per frame void Update() { Debug.Log("Action Current:" + GameObject.Find("Hand_l").GetComponent <GestureControl> ().bufferedGesture()); Debug.Log("Action Recog:" + HandActionRecog.getInstance().IsMotion("Basic")); }