public HandRepresentation(int handID, Hand hand, Chirality chirality, ModelType modelType) {
      HandID = handID;
      this.MostRecentHand = hand;
      this.RepChirality = chirality;
      this.RepType = modelType;

    }
Example #2
0
 public HandProxy(HandPool parent, Hand hand, Chirality repChirality, ModelType repType) :
   base(hand.Id, hand, repChirality, repType)
 {
   this.parent = parent;
   this.RepChirality = repChirality;
   this.RepType = repType;
   this.MostRecentHand = hand;
 }
Example #3
0
 /*Looks for suitable IHandModel is the ModelGroup's modelList, if found, it is added to modelsCheckedOut.
  * If not, one can be cloned*/
 public IHandModel TryGetModel(Chirality chirality, ModelType modelType) {
   for (int i = 0; i < modelList.Count; i++) {
     if (modelList[i].HandModelType == modelType && modelList[i].Handedness == chirality) {
       IHandModel model = modelList[i];
       modelList.RemoveAt(i);
       modelsCheckedOut.Add(model);
       return model;
     }
   }
   if (CanDuplicate) {
     for (int i = 0; i < modelsCheckedOut.Count; i++) {
       if (modelsCheckedOut[i].HandModelType == modelType && modelsCheckedOut[i].Handedness == chirality) {
         IHandModel modelToSpawn = modelsCheckedOut[i];
         IHandModel spawnedModel = GameObject.Instantiate(modelToSpawn);
         spawnedModel.transform.parent = _handPool.ModelsParent;
         _handPool.modelGroupMapping.Add(spawnedModel, this);
         modelsCheckedOut.Add(spawnedModel);
         return spawnedModel;
       }
     }
   }
   return null;
 }
 /// <summary>
 /// Gets an add message for the given bodypart.
 /// </summary>
 /// <param name="bodypart">The bodypart.</param>
 /// <param name="chirality">The chirality of the bodypart.</param>
 /// <returns>The addition message.</returns>
 protected abstract Task <string> GetAddMessageAsync(Bodypart bodypart, Chirality chirality);
 /// <summary>
 /// Shifts the given bodypart.
 /// </summary>
 /// <param name="bodypart">The bodypart.</param>
 /// <param name="chirality">The chirality of the bodypart.</param>
 /// <returns>A shifting result which may or may not have succeeded.</returns>
 protected abstract Task <Result <ShiftBodypartResult> > ShiftBodypartAsync(Bodypart bodypart, Chirality chirality);
Example #6
0
 public HandRayHit GetHit(Chirality chirality)
 {
     return(chirality == Chirality.Left ? leftHit : rightHit);
 }
Example #7
0
        /// <summary>
        /// Needed because of Unity's horrendous AssetBundle structure. Scripts are only expected in the main assembly, and since we're not there...
        /// </summary>
        /// <param name="hand"></param>
        private RiggedHand SetUpRiggedHand(GameObject handObj, Chirality handedness)
        {
            var hand = handObj.GetComponent <RiggedHand>();

#if UNITY_4_5
            handObj.transform.localScale *= 0.01f;
#endif
            if (hand)
            {
                hand.gameObject.AddComponent <LeapMenuHandler>();

                return(hand);
            }

            hand = handObj.AddComponent <RiggedHand>();
            hand.gameObject.AddComponent <LeapMenuHandler>();

            handObj.AddComponent <HandEnableDisable>();
            hand.handedness = handedness;

            // Get references
            var thumb_meta  = hand.gameObject.Descendants().First(d => d.name.EndsWith("thumb_meta", StringComparison.InvariantCultureIgnoreCase)).AddComponent <RiggedFinger>();
            var index_meta  = hand.gameObject.Descendants().First(d => d.name.EndsWith("index_meta", StringComparison.InvariantCultureIgnoreCase)).AddComponent <RiggedFinger>();
            var ring_meta   = hand.gameObject.Descendants().First(d => d.name.EndsWith("ring_meta")).AddComponent <RiggedFinger>();
            var middle_meta = hand.gameObject.Descendants().First(d => d.name.EndsWith("middle_meta")).AddComponent <RiggedFinger>();
            var pinky_meta  = hand.gameObject.Descendants().First(d => d.name.EndsWith("pinky_meta")).AddComponent <RiggedFinger>();
            var wrist       = hand.gameObject.Descendants().First(d => d.name.EndsWith("Wrist")).transform;
            var palm        = hand.gameObject.Descendants().First(d => d.name.EndsWith("Palm")).transform;

            // Set up hand
            hand.fingers = new RiggedFinger[]
            {
                thumb_meta, index_meta, middle_meta, ring_meta, pinky_meta
            };

            hand.wristJoint           = wrist;
            hand.palm                 = palm;
            hand.ModelPalmAtLeapWrist = true;
            hand.handModelPalmWidth   = 0.085f;
            hand.UseMetaCarpals       = true;
            var pointDir = Vector3.left * (hand.handedness == Chirality.Left ? 1 : -1);
            var palmDir  = Vector3.up * (hand.handedness == Chirality.Left ? 1 : -1);
            hand.modelFingerPointing = pointDir;
            hand.modelPalmFacing     = palmDir;

            // Set up fingers
            thumb_meta.fingerType  = Leap.Finger.FingerType.TYPE_THUMB;
            index_meta.fingerType  = Leap.Finger.FingerType.TYPE_INDEX;
            ring_meta.fingerType   = Leap.Finger.FingerType.TYPE_RING;
            middle_meta.fingerType = Leap.Finger.FingerType.TYPE_MIDDLE;
            pinky_meta.fingerType  = Leap.Finger.FingerType.TYPE_PINKY;

            thumb_meta.bones  = new Transform[] { null, thumb_meta.transform }.Concat(thumb_meta.gameObject.Descendants().Select(d => d.transform).Take(2)).ToArray();
            index_meta.bones  = new Transform[] { index_meta.transform }.Concat(index_meta.gameObject.Descendants().Select(d => d.transform).Take(3)).ToArray();
            ring_meta.bones   = new Transform[] { ring_meta.transform }.Concat(ring_meta.gameObject.Descendants().Select(d => d.transform).Take(3)).ToArray();
            middle_meta.bones = new Transform[] { middle_meta.transform }.Concat(middle_meta.gameObject.Descendants().Select(d => d.transform).Take(3)).ToArray();
            pinky_meta.bones  = new Transform[] { pinky_meta.transform }.Concat(pinky_meta.gameObject.Descendants().Select(d => d.transform).Take(3)).ToArray();

            foreach (var finger in new RiggedFinger[] { thumb_meta, index_meta, ring_meta, middle_meta, pinky_meta })
            {
                finger.modelFingerPointing = pointDir;
                finger.modelPalmFacing     = palmDir;
                finger.joints = new Transform[] { null, null, null };
            }

            foreach (var obj in handObj.Descendants())
            {
                VRLog.Info("{0}: {1}", obj.transform.name, obj.transform.localScale);
            }
            return(hand);
        }
 public XRButtonDatum GetHeldButton(Chirality chirality)
 {
     return(_heldButtons.Find((b) => b.ParentUserController.ControllerChirality == chirality));
 }
Example #9
0
 public static Hand Get(this Frame frame, Chirality whichHand)
 {
     return(frame.Hands.Query().FirstOrDefault(h => h.IsLeft == (whichHand == Chirality.Left)));
 }
Example #10
0
 public void Initialize(Chirality controllerChirality, BlockingObjects blockingObjects, LayerMask blockingMask)
 {
     _controllerChirality = controllerChirality;
     this.blockingObjects = blockingObjects;
     m_BlockingMask       = blockingMask;
 }
        /// <inheritdoc />
        protected override async Task <ShiftBodypartResult> ShiftBodypartAsync(Bodypart bodypart, Chirality chirality)
        {
            if (!this.Appearance.TryGetAppearanceComponent(bodypart, chirality, out var currentComponent))
            {
                return(ShiftBodypartResult.FromError("The character doesn't have that bodypart."));
            }

            if (currentComponent.Pattern is null)
            {
                return(ShiftBodypartResult.FromError("That bodypart doesn't have a pattern."));
            }

            // ReSharper disable once PossibleNullReferenceException
            // Having a pattern implies having a pattern colour
            if (currentComponent.PatternColour.IsSameColourAs(_colour))
            {
                return(ShiftBodypartResult.FromError("The pattern is already that colour."));
            }

            currentComponent.PatternColour = _colour.Clone();

            var shiftMessage = await GetShiftMessageAsync(bodypart, chirality);

            return(ShiftBodypartResult.FromSuccess(shiftMessage, ShiftBodypartAction.Shift));
        }
 /// <inheritdoc />
 protected override Task <string> GetAddMessageAsync(Bodypart bodypart, Chirality chirality)
 {
     throw new InvalidOperationException("Colours can't be added.");
 }
        /// <inheritdoc />
        protected override async Task <ShiftBodypartResult> ShiftBodypartAsync(Bodypart bodypart, Chirality chirality)
        {
            if (_species is null)
            {
                throw new InvalidOperationException
                      (
                          "The shifter must be constructed with a target species when shifting parts."
                      );
            }

            var character = this.Appearance.Character;

            var getTFResult = await _transformations.GetTransformationsByPartAndSpeciesAsync(bodypart, _species);

            if (!getTFResult.IsSuccess)
            {
                return(ShiftBodypartResult.FromError(getTFResult));
            }

            var transformation = getTFResult.Entity.First();

            var getAppearanceResult = await _transformations.GetOrCreateCurrentAppearanceAsync(character);

            if (!getAppearanceResult.IsSuccess)
            {
                return(ShiftBodypartResult.FromError(getAppearanceResult));
            }

            var appearance = getAppearanceResult.Entity;

            if (appearance.TryGetAppearanceComponent(bodypart, chirality, out var existingComponent))
            {
                if (existingComponent.Transformation.Species.Name.Equals(transformation.Species.Name))
                {
                    var message = await GetNoChangeMessageAsync(bodypart);

                    return(ShiftBodypartResult.FromError
                           (
                               message
                           ));
                }
            }

            string shiftMessage;

            if (!appearance.TryGetAppearanceComponent(bodypart, chirality, out var currentComponent))
            {
                currentComponent = AppearanceComponent.CreateFrom(transformation, chirality);

                appearance.Components.Add(currentComponent);

                shiftMessage = await GetAddMessageAsync(bodypart, chirality);

                return(ShiftBodypartResult.FromSuccess(shiftMessage, ShiftBodypartAction.Add));
            }

            if (currentComponent.Transformation.Species.Name == "template")
            {
                // Apply default settings
                currentComponent.BaseColour = transformation.DefaultBaseColour.Clone();

                currentComponent.Pattern       = transformation.DefaultPattern;
                currentComponent.PatternColour = transformation.DefaultPatternColour?.Clone();
            }

            currentComponent.Transformation = transformation;

            shiftMessage = await GetShiftMessageAsync(bodypart, chirality);

            return(ShiftBodypartResult.FromSuccess(shiftMessage, ShiftBodypartAction.Shift));
        }
 public XRPhysicsInteractor GetHoveringInteractor(Chirality chirality)
 {
     return(_hoveringInteractors.Find((i) => i.ParentUserController.ControllerChirality == chirality));
 }
        public static AppearanceComponent CreateFrom([NotNull] Transformation transformation, Chirality chirality = Center)
        {
            if (transformation.Part.IsChiral() && chirality == Center)
            {
                throw new ArgumentException("A chiral transformation requires you to specify the chirality.", nameof(transformation));
            }

            if (!transformation.Part.IsChiral() && chirality != Center)
            {
                throw new ArgumentException("A nonchiral transformation cannot have chirality.", nameof(transformation));
            }

            return(new AppearanceComponent
            {
                Transformation = transformation,
                Chirality = chirality,
                BaseColour = transformation.DefaultBaseColour,
                Pattern = transformation.DefaultPattern,
                PatternColour = transformation.DefaultPatternColour
            });
        }
        /// <inheritdoc />
        protected override async Task <ShiftBodypartResult> RemoveBodypartAsync(Bodypart bodypart, Chirality chirality)
        {
            var character = this.Appearance.Character;

            var getAppearanceResult = await _transformations.GetOrCreateCurrentAppearanceAsync(character);

            if (!getAppearanceResult.IsSuccess)
            {
                return(ShiftBodypartResult.FromError(getAppearanceResult));
            }

            var appearance = getAppearanceResult.Entity;

            if (!appearance.TryGetAppearanceComponent(bodypart, chirality, out var component))
            {
                return(ShiftBodypartResult.FromError("The character doesn't have that bodypart."));
            }

            appearance.Components.Remove(component);

            var removeMessage = _descriptionBuilder.BuildRemoveMessage(appearance, bodypart);

            return(ShiftBodypartResult.FromSuccess(removeMessage, ShiftBodypartAction.Remove));
        }
        /// <inheritdoc />
        protected override async Task <ShiftBodypartResult> RemoveBodypartAsync(Bodypart bodypart, Chirality chirality)
        {
            if (!this.Appearance.TryGetAppearanceComponent(bodypart, chirality, out var currentComponent))
            {
                return(ShiftBodypartResult.FromError("The character doesn't have that bodypart."));
            }

            if (currentComponent.Pattern is null)
            {
                return(ShiftBodypartResult.FromError("The character doesn't have a pattern on that part."));
            }

            currentComponent.Pattern       = null;
            currentComponent.PatternColour = null;

            var shiftMessage = await GetRemoveMessageAsync(bodypart, chirality);

            return(ShiftBodypartResult.FromSuccess(shiftMessage, ShiftBodypartAction.Remove));
        }
        /// <inheritdoc />
        protected override Task <string> GetRemoveMessageAsync(Bodypart bodypart, Chirality chirality)
        {
            var component = this.Appearance.GetAppearanceComponent(bodypart, chirality);

            return(Task.FromResult(_descriptionBuilder.BuildPatternRemoveMessage(this.Appearance, component)));
        }
Example #19
0
        /// <inheritdoc />
        protected override async Task <ShiftBodypartResult> ShiftBodypartAsync(Bodypart bodypart, Chirality chirality)
        {
            var character = this.Appearance.Character;

            var getAppearanceResult = await _transformations.GetOrCreateCurrentAppearanceAsync(character);

            if (!getAppearanceResult.IsSuccess)
            {
                return(ShiftBodypartResult.FromError(getAppearanceResult));
            }

            var appearance = getAppearanceResult.Entity;

            if (!appearance.TryGetAppearanceComponent(bodypart, chirality, out var currentComponent))
            {
                return(ShiftBodypartResult.FromError("The character doesn't have that bodypart."));
            }

            if (currentComponent.Pattern == _pattern)
            {
                return(ShiftBodypartResult.FromError("The character already has that pattern."));
            }

            var shiftAction = ShiftBodypartAction.Shift;

            if (currentComponent.Pattern is null)
            {
                shiftAction = ShiftBodypartAction.Add;
            }

            currentComponent.Pattern       = _pattern;
            currentComponent.PatternColour = _patternColour.Clone();

            var shiftMessage = await GetShiftMessageAsync(bodypart, chirality);

            return(ShiftBodypartResult.FromSuccess(shiftMessage, shiftAction));
        }