private IEnumerator enableGroup(string groupName) { yield return(new WaitForEndOfFrame()); ModelGroup group = null; for (int i = 0; i < ModelPool.Count; i++) { if (ModelPool[i].GroupName == groupName) { group = ModelPool[i]; for (int hp = 0; hp < activeHandReps.Count; hp++) { HandRepresentation handRep = activeHandReps[hp]; HandModelBase model = group.TryGetModel(handRep.RepChirality, handRep.RepType); if (model != null) { handRep.AddModel(model); modelToHandRepMapping.Add(model, handRep); } } group.IsEnabled = true; } } if (group == null) { Debug.LogWarning("A group matching that name does not exisit in the modelPool"); } }
/** * MakeHandRepresentation receives a Hand and combines that with a HandModelBase to create a HandRepresentation * @param hand The Leap Hand data to be drive a HandModelBase * @param modelType Filters for a type of hand model, for example, physics or graphics hands. */ public HandRepresentation MakeHandRepresentation(Hand hand, ModelType modelType) { Chirality handChirality = hand.IsRight ? Chirality.Right : Chirality.Left; HandRepresentation handRep = new HandRepresentation(this, hand, handChirality, modelType); for (int i = 0; i < ModelPool.Count; i++) { ModelGroup group = ModelPool[i]; if (group.IsEnabled) { HandModelBase model = group.TryGetModel(handChirality, modelType); if (model != null) { handRep.AddModel(model); if (!modelToHandRepMapping.ContainsKey(model)) { model.group = group; modelToHandRepMapping.Add(model, handRep); } } } } activeHandReps.Add(handRep); return(handRep); }
/** * EnableGroup finds suitable HandRepresentations and adds IHandModels from the ModelGroup, returns them to their ModelGroup and sets the groups IsEnabled to true. * @param groupName Takes a string that matches the ModelGroup's groupName serialized in the Inspector */ public void EnableGroup(string groupName) { ModelGroup group = null; for (int i = 0; i < ModelPool.Count; i++) { if (ModelPool[i].GroupName == groupName) { group = ModelPool[i]; for (int hp = 0; hp < activeHandReps.Count; hp++) { HandRepresentation handRep = activeHandReps[hp]; IHandModel model = group.TryGetModel(handRep.RepChirality, handRep.RepType); if (model != null) { handRep.AddModel(model); modelToHandRepMapping.Add(model, handRep); } } group.IsEnabled = true; } } if (group == null) { Debug.LogWarning("A group matching that name does not exisit in the modelPool"); } }
/** * MakeHandRepresentation receives a Hand and combines that with an IHandModel to create a HandRepresentation * @param hand The Leap Hand data to be drive an IHandModel * @param modelType Filters for a type of hand model, for example, physics or graphics hands. */ public override HandRepresentation MakeHandRepresentation(Hand hand, ModelType modelType) { HandRepresentation handRep = null; for (int i = 0; i < ModelPool.Count; i++) { IHandModel model = ModelPool[i]; bool isCorrectHandedness; Chirality handChirality = hand.IsRight ? Chirality.Right : Chirality.Left; isCorrectHandedness = model.Handedness == handChirality; if (!EnforceHandedness || model.Handedness == Chirality.Either) { isCorrectHandedness = true; } bool isCorrectModelType; isCorrectModelType = model.HandModelType == modelType; if (isCorrectModelType && isCorrectHandedness) { ModelPool.RemoveAt(i); handRep = new HandProxy(this, model, hand); break; } } return(handRep); }
/** * Updates HandRepresentations based in the specified HandRepresentation Dictionary. * Active HandRepresentation instances are updated if the hand they represent is still * present in the Provider's CurrentFrame; otherwise, the HandRepresentation is removed. If new * Leap Hand objects are present in the Leap HandRepresentation Dictionary, new HandRepresentations are * created and added to the dictionary. * @param all_hand_reps = A dictionary of Leap Hand ID's with a paired HandRepresentation * @param modelType Filters for a type of hand model, for example, physics or graphics hands. * @param frame The Leap Frame containing Leap Hand data for each currently tracked hand */ void UpdateHandRepresentations(Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType, Frame frame) { foreach (Leap.Hand curHand in frame.Hands) { // Skip disabled hands if (curHand.IsLeft && !enableLeft) { continue; } if (curHand.IsRight && !enableRight) { continue; } HandRepresentation rep; if (!all_hand_reps.TryGetValue(curHand.Id, out rep)) { rep = Factory.MakeHandRepresentation(curHand, modelType); if (rep != null) { all_hand_reps.Add(curHand.Id, rep); } } if (rep != null) { rep.IsMarked = true; rep.UpdateRepresentation(curHand, modelType); rep.LastUpdatedTime = (int)frame.Timestamp; } } /** Mark-and-sweep to finish unused HandRepresentations */ HandRepresentation toBeDeleted = null; foreach (KeyValuePair <int, HandRepresentation> r in all_hand_reps) { if (r.Value != null) { if (r.Value.IsMarked) { r.Value.IsMarked = false; } else { /** Initialize toBeDeleted with a value to be deleted */ //Debug.Log("Finishing"); toBeDeleted = r.Value; } } } /**Inform the representation that we will no longer be giving it any hand updates * because the corresponding hand has gone away */ if (toBeDeleted != null) { all_hand_reps.Remove(toBeDeleted.HandID); toBeDeleted.Finish(); } }
//Felix void UpdateHandRepresentations(List <Hand> list, Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType) { foreach (Leap.Hand curHand in list) { HandRepresentation rep; if (!all_hand_reps.TryGetValue(curHand.Id, out rep)) { rep = factory.MakeHandRepresentation(curHand, modelType); if (rep != null) { all_hand_reps.Add(curHand.Id, rep); //float hand_scale = curHand.PalmWidth / rep.handModel.handModelPalmWidth; //rep.handModel.transform.localScale = hand_scale * Vector3.one; } } if (rep != null) { rep.IsMarked = true; //float hand_scale = curHand.PalmWidth / rep.handModel.handModelPalmWidth; //rep.handModel.transform.localScale = hand_scale * Vector3.one; rep.UpdateRepresentation(curHand); rep.LastUpdatedTime = (int)provider.CurrentFrame.Timestamp; } } //Mark-and-sweep or set difference implementation HandRepresentation toBeDeleted = null; foreach (KeyValuePair <int, HandRepresentation> r in all_hand_reps) { if (r.Value != null) { if (r.Value.IsMarked) { //Debug.Log("LeapHandController Marking False"); r.Value.IsMarked = false; } else { //Initialize toBeDeleted with a value to be deleted //Debug.Log("Finishing"); toBeDeleted = r.Value; } } } //Inform the representation that we will no longer be giving it any hand updates //because the corresponding hand has gone away if (toBeDeleted != null) { all_hand_reps.Remove(toBeDeleted.HandID); toBeDeleted.Finish(); } }
/** * Updates HandRepresentations based in the specified HandRepresentation Dictionary. * Active HandRepresentation instances are updated if the hand they represent is still * present in the Provider's CurrentFrame; otherwise, the HandRepresentation is removed. If new * Leap Hand objects are present in the Leap HandRepresentation Dictionary, new HandRepresentations are * created and added to the dictionary. * @param all_hand_reps = A dictionary of Leap Hand ID's with a paired HandRepresentation * @param modelType Filters for a type of hand model, for example, physics or graphics hands. * @param frame The Leap Frame containing Leap Hand data for each currently tracked hand */ protected virtual void UpdateHandRepresentations(Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType, Frame frame) { for (int i = 0; i < frame.Hands.Count; i++) { var curHand = frame.Hands[i]; HandRepresentation rep; if (!all_hand_reps.TryGetValue(curHand.Id, out rep)) { rep = pool.MakeHandRepresentation(curHand, modelType); if (rep != null) { all_hand_reps.Add(curHand.Id, rep); } } if (rep != null) { rep.IsMarked = true; rep.UpdateRepresentation(curHand); rep.LastUpdatedTime = (int)frame.Timestamp; } } /** Mark-and-sweep to finish unused HandRepresentations */ HandRepresentation toBeDeleted = null; for (var it = all_hand_reps.GetEnumerator(); it.MoveNext();) { var r = it.Current; if (r.Value != null) { if (r.Value.IsMarked) { r.Value.IsMarked = false; } else { /** Initialize toBeDeleted with a value to be deleted */ //Debug.Log("Finishing"); toBeDeleted = r.Value; } } } /**Inform the representation that we will no longer be giving it any hand updates * because the corresponding hand has gone away */ if (toBeDeleted != null) { all_hand_reps.Remove(toBeDeleted.HandID); toBeDeleted.Finish(); } }
//Felix void UpdateHandRepresentations(List <Hand> list, Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType) { foreach (Leap.Hand curHand in list) { HandRepresentation rep; if (!all_hand_reps.TryGetValue(curHand.Id, out rep)) { rep = Factory.MakeHandRepresentation(curHand, modelType); if (rep != null) { all_hand_reps.Add(curHand.Id, rep); } } if (rep != null) { rep.IsMarked = true; rep.UpdateRepresentation(curHand); rep.LastUpdatedTime = (int)Provider.CurrentFrame.Timestamp; } } //Mark-and-sweep or set difference implementation HandRepresentation toBeDeleted = null; foreach (KeyValuePair <int, HandRepresentation> r in all_hand_reps) { if (r.Value != null) { if (r.Value.IsMarked) { r.Value.IsMarked = false; } else { toBeDeleted = r.Value; } } } //Inform the representation that we will no longer be giving it any hand updates //because the corresponding hand has gone away if (toBeDeleted != null) { all_hand_reps.Remove(toBeDeleted.HandID); toBeDeleted.Finish(); } }
public void EnableGroup(string groupName) { for (int i = 0; i < ModelPool.Count; i++) { if (ModelPool[i].GroupName == groupName) { ModelGroup group = ModelPool[i]; for (int hp = 0; hp < activeHandReps.Count; hp++) { HandRepresentation handRep = activeHandReps[hp]; IHandModel model = group.TryGetModel(handRep.RepChirality, handRep.RepType); if (model != null) { handRep.AddModel(model); modelToHandRepMapping.Add(model, handRep); } } group.IsEnabled = true; } } }
public void ReturnToPool(HandModelBase model) { ModelGroup modelGroup; bool groupFound = modelGroupMapping.TryGetValue(model, out modelGroup); Assert.IsTrue(groupFound); //First see if there is another active Representation that can use this model for (int i = 0; i < activeHandReps.Count; i++) { HandRepresentation rep = activeHandReps[i]; if (rep.RepChirality == model.Handedness && rep.RepType == model.HandModelType) { bool modelFromGroupFound = false; if (rep.handModels != null) { //And that Represention does not contain a model from this model's modelGroup for (int j = 0; j < modelGroup.modelsCheckedOut.Count; j++) { HandModelBase modelToCompare = modelGroup.modelsCheckedOut[j]; for (int k = 0; k < rep.handModels.Count; k++) { if (rep.handModels[k] == modelToCompare) { modelFromGroupFound = true; } } } } if (!modelFromGroupFound) { rep.AddModel(model); modelToHandRepMapping[model] = rep; return; } } } //Otherwise return to pool modelGroup.ReturnToGroup(model); }
public void RemoveHandRepresentation(HandRepresentation handRepresentation) { activeHandReps.Remove(handRepresentation); }
/** * Updates HandRepresentations based in the specified HandRepresentation Dictionary. * Active HandRepresentation instances are updated if the hand they represent is still * present in the Provider's CurrentFrame; otherwise, the HandRepresentation is removed. If new * Leap Hand objects are present in the Leap HandRepresentation Dictionary, new HandRepresentations are * created and added to the dictionary. * @param all_hand_reps = A dictionary of Leap Hand ID's with a paired HandRepresentation * @param modelType Filters for a type of hand model, for example, physics or graphics hands. * @param frame The Leap Frame containing Leap Hand data for each currently tracked hand */ protected virtual void UpdateHandRepresentations(Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType, Frame frame) { //------------------------------------------------------------------------------ //Local Hands -- Unremote if (!IsRemoteServer) { foreach (Leap.Hand curHand in frame.Hands) { HandRepresentation rep; if (!all_hand_reps.TryGetValue(curHand.Id, out rep)) { rep = factory.MakeHandRepresentation(curHand, modelType, false); if (rep != null) { all_hand_reps.Add(curHand.Id, rep); } } if (rep != null) { rep.IsMarked = true; rep.UpdateRepresentation(curHand); rep.LastUpdatedTime = (int)frame.Timestamp; } } } //------------------------------------------------------------------------------ // Remote Hands -- remote else { foreach (Leap.Hand curHand in remoteHandServer.RemoteFrame.Hands) { HandRepresentation rep; if (!all_hand_reps.TryGetValue(curHand.Id, out rep)) { rep = factory.MakeHandRepresentation(curHand, modelType, true); if (rep != null) { all_hand_reps.Add(curHand.Id, rep); } } if (rep != null) { rep.IsMarked = true; rep.UpdateRepresentation(curHand); rep.LastUpdatedTime = (int)frame.Timestamp; } } } //------------------------------------------------------------------------------ /** Mark-and-sweep to finish unused HandRepresentations */ HandRepresentation toBeDeleted = null; foreach (KeyValuePair <int, HandRepresentation> r in all_hand_reps) { if (r.Value != null) { if (r.Value.IsMarked) { r.Value.IsMarked = false; } else { /** Initialize toBeDeleted with a value to be deleted */ //Debug.Log("Finishing"); toBeDeleted = r.Value; } } } /**Inform the representation that we will no longer be giving it any hand updates * because the corresponding hand has gone away */ if (toBeDeleted != null) { all_hand_reps.Remove(toBeDeleted.HandID); toBeDeleted.Finish(); } // Fixe ModelPool }