void StartListening(BoneModel bone) { PuppetReprModel slave = bone.reprs[PuppetModel.key] as PuppetReprModel; // Listen to trigger and collision notifiers for each bone.pheasy (when possible) if (slave.pheasy) { if (slave.pheasy.collisionNotifier) { slave.pheasy.collisionNotifier.invokeStayEvents = true; slave.pheasy.collisionNotifier.onRbEnter.AddListener(col => OnRbTouchStart(col, bone)); slave.pheasy.collisionNotifier.onRbStay.AddListener(col => OnRbTouchStay(col, bone)); slave.pheasy.collisionNotifier.onRbExit.AddListener(col => OnRbTouchEnd(col, bone)); } if (model.hoverDetectionSystem == HoverDetectionSystem.Triggers) { for (int tn = 0; tn < slave.pheasy.triggerNotifiers.Length; tn++) { slave.pheasy.triggerNotifiers[tn].onRbEnter.AddListener(col => OnRbEnter(col, bone)); slave.pheasy.triggerNotifiers[tn].onRbExit.AddListener(col => OnRbExit(col, bone)); } } } }
void OnAvatarReady() { if (!model.part.root.reprs.ContainsKey(PuppetModel.key) || !(model.part.root.reprs[PuppetModel.key] is PuppetReprModel)) { Debug.LogError("Root of part " + model.part.name + ", " + model.part.root.name + ", does not have a valid " + PuppetModel.key + " representation. ContactDetection cannot start for this part"); return; } PuppetReprModel rootSlave = model.part.root.reprs[PuppetModel.key] as PuppetReprModel; if (rootSlave.specificView.ready) { OnPhysicsReady(); } else { rootSlave.specificView.onPhysicsReady.AddListener(OnPhysicsReady); } }
void OnRbExit(Rigidbody exitedRb, BoneModel bone) { ContactableView contactable = exitedRb.GetComponent <ContactableView>(); if (contactable) { Contact contact = model.contacts.Find(c => c.contactable == contactable); if (contact != null) { // Existing contact if (contact.bonesEntered.Contains(bone)) { bool stillEntered = false; /* * PuppetReprModel slave = bone.reprs.FirstOrDefault(r => r.Value is PuppetReprModel).Value as PuppetReprModel; * PuppetReprModel slave = BasicHelpers.Get<ReprModel, PuppetReprModel>(bone.reprs); */ PuppetReprModel slave = bone.reprs[PuppetModel.key] as PuppetReprModel; // Remove bone only if exitedRb is not in any bone.pheasy.triggerNotifiers for (int tn = 0; tn < slave.pheasy.triggerNotifiers.Length; tn++) { if (slave.pheasy.triggerNotifiers[tn].enteredRbs.Contains(exitedRb)) { stillEntered = true; break; } } if (!stillEntered) { contact.bonesEntered.Remove(bone); } } } } }
void OverlapSphere(BoneModel bone, float radius, List <Rigidbody> foundRbs) { foundRbs.Clear(); if (!bone.reprs.ContainsKey(PuppetModel.key)) { return; } PuppetReprModel slave = bone.reprs[PuppetModel.key] as PuppetReprModel; Collider[] colliders = UnityEngine.Physics.OverlapSphere(slave.transformRef.position, radius); for (int c = 0; c < colliders.Length; c++) { if (!colliders[c].attachedRigidbody) { continue; } foundRbs.Add(colliders[c].attachedRigidbody); } }
void GenerateReprModel(Point point, bool isLeaf) { if (point.original == null) { return; } if (point.repr == null) { switch (representation) { case Representation.Slave: // Avoid generating multiple ReprModels for the same point point.repr = point.tsf.GetComponent <PuppetReprModel>(); point.repr = point.tsf.gameObject.AddComponent <PuppetReprModel>(); PuppetReprModel puppetRepr = point.repr as PuppetReprModel; if (isLeaf) { puppetRepr.usePhysics = false; } else { puppetRepr.usePhysics = true; } if (source is BodySearchEngine) { Body body = (source as BodySearchEngine).body; puppetRepr.isSpecial = (point == body.hipsPoint || point == body.spinePoint || point == body.chestPoint || point == body.neckPoint); } else if (source is HandSearchEngine) { Hand hand = (source as HandSearchEngine).hand; puppetRepr.isSpecial = (point == hand.thumb0Point || point == hand.thumb1Point || point == hand.thumb2Point || point == hand.thumb3Point); } break; case Representation.Master: default: // Avoid generating multiple ReprModels for the same point point.repr = point.tsf.GetComponent <ReprModel>(); point.repr = point.tsf.gameObject.AddComponent <ReprModel>(); break; } point.repr.originalTsfRef = point.original; } if (!reprModels.Contains(point.repr)) { reprModels.Add(point.repr); } }