protected override void OnLateUpdate() { base.OnUpdate(); if (checkGrabTarget) { // See OnFistStart() checkGrabTarget = false; testGrabTarget(); } // After our OnUpdate, someone resets the position in their OnUpdate. // Using OnLateUpdate works, but only while grabbing. // After assigning HAnimation to the girl, it works in OnUpdate without any foreign resets. if (grabbing && currentEffector != null) { var effector = currentEffector.Effector; effector.positionWeight = 1f; // XXX weight 1 too strong? deformation possible. experiment with RotationLimit. var handPos = IKHelper.GetHandPosition(hand); var handRot = IKHelper.GetHandRotation(hand); effector.position = handPos; var newRot = Quaternion.Inverse(handRot) * startingRotation; effector.rotation = newRot; } else if (fisting && Time.time - fistStart > FIST_START_THRESHOLD) { Logger.Info("now grabbing {0}", currentEffector == null ? "nothing" : "something"); grabbing = true; } }
//protected StudioFemale FindClosestStudioFemale() { // return Singleton<Studio>.Instance.FemaleList // .Select(entry => entry.Value) // .OrderBy(studioF => Vector3.Distance(CurrentHandPosition(), studioF.female.gameObject.transform.position)) // .FirstOrDefault(); //} //protected SexyActor FindClosestActor() { // return VR.Interpreter.Actors // .Cast<SexyActor>() // .OrderBy(actor => Vector3.Distance(CurrentHandPosition(), actor.Actor.gameObject.transform.position)) // .FirstOrDefault(); //} //protected IKEffector FindClosestIkEffectorInRange(SexyActor actor) { // if (actor.Actor.getIK() == null) { // Logger.Info("No IK present"); // return null; // } // // Initially the EKEffector.position is at a weird position. We have to check the bone. // var effectorCandidate = actor.Actor.getIK().solver.effectors // .OrderBy(ef => Vector3.Distance(CurrentHandPosition(), ef.bone.position)) // .FirstOrDefault(); // if (Vector3.Distance(CurrentHandPosition(), effectorCandidate.bone.position) < grabRange) { // return effectorCandidate; // } // return null; //} //protected EffectorTarget FindClosestEffectorTarget(StudioFemale female) { // return female.ikCtrl.drivingRig.effectorTargets // .OrderBy(et => Vector3.Distance(CurrentHandPosition(), et.target.position)) // .FirstOrDefault(); //} //protected IKEffector FindClosestIkEffectorInRange() { // var handPosition = CurrentHandPosition(); // var effector = VR.Interpreter.Actors // .Cast<SexyActor>() // .SelectMany(actor => actor.Actor.getIK().solver.effectors) // // Initially the EKEffector.position is at a weird position. We have to check the bone. // .OrderBy(ef => Vector3.Distance(handPosition, ef.bone.position)) // .FirstOrDefault(); // return effector != null && Vector3.Distance(handPosition, effector.bone.position) < grabRange // ? effector // : null; //} protected EffectorAndActor FindIkEffectorAndActorInRange() { var handPosition = IKHelper.GetHandPosition(hand); var effectorToActor = IKHelper.GetEffectorsToActors() .OrderBy(pair => IKHelper.GetDistance(pair.Effector, handPosition)) .FirstOrDefault(); return(effectorToActor == null ? null : effectorToActor); }
protected void testGrabTarget() { fistStart = Time.time; var closest = FindIkEffectorAndActorInRange(); if (closest != null) { fisting = true; currentEffector = closest; startingRotation = IKHelper.GetHandRotation(hand); } else { Logger.Info("No effector in range"); } }
protected override void OnUpdate() { base.OnUpdate(); transform.position = IKHelper.GetEffectorPosition(reference); transform.rotation = IKHelper.GetEffectorRotation(reference); }
private void OnGUI() { if (!SexyStudioVR.menuVisible) { return; } GUIStyle guiStyleLabel = new GUIStyle(GUI.skin.label); guiStyleLabel.fontSize = 16; GUIStyle guiStyleLabelInRange = new GUIStyle(guiStyleLabel); guiStyleLabelInRange.normal.textColor = Color.green; GUIStyle guiStyleLabelOutOfRange = new GUIStyle(guiStyleLabel); guiStyleLabelOutOfRange.normal.textColor = Color.red; GUIStyle guiStyleButton = new GUIStyle(GUI.skin.button); guiStyleButton.fontSize = 16; GUILayout.BeginArea(new Rect((float)Screen.width / 5f, 70f, (float)Screen.width / 1.5f, (float)Screen.height / 1.5f)); GUILayout.BeginVertical(new GUIStyle(GUI.skin.box)); var leftHandPosition = IKHelper.GetHandPosition(true); var rightHandPosition = IKHelper.GetHandPosition(false); GUILayout.Label(string.Format("Left Hand: {0}", format(leftHandPosition)), guiStyleLabel); GUILayout.Label(string.Format("Right Hand: {0}", format(rightHandPosition)), guiStyleLabel); if (GUILayout.Button("Visible", guiStyleButton)) { foreach (var actor in VR.Interpreter.Actors) { IKHelper.MakeVisible((actor as SexyActor).Actor); } } var girlEffectorsText = showGirlEffectors ? "Hide girl effectors" : "Show girl effectors"; if (GUILayout.Button(girlEffectorsText, guiStyleButton)) { showGirlEffectors = !showGirlEffectors; } if (showGirlEffectors) { if ((VR.Interpreter as SexyStudioInterpreter).IsStudio) { // sucks, can't use this in the main game... //IKHelper.UpdateAllIKPosition(); } foreach (var actor in VR.Interpreter.Actors) { GUILayout.Label(string.Format("Actor {0}", (actor as SexyActor).Actor.SaveFileName), guiStyleLabel); Dictionary <FullBodyBipedEffector, IKEffector> dict = IKHelper.GetEffectors(actor as SexyActor); // left bool inRange = IKHelper.IsInRange(dict[FullBodyBipedEffector.LeftHand], leftHandPosition) || IKHelper.IsInRange(dict[FullBodyBipedEffector.LeftHand], rightHandPosition); GUILayout.Label(string.Format("L Hand: {0}", format(IKHelper.GetEffectorPosition(dict[FullBodyBipedEffector.LeftHand]))), inRange ? guiStyleLabelInRange : guiStyleLabelOutOfRange); inRange = IKHelper.IsInRange(dict[FullBodyBipedEffector.LeftShoulder], leftHandPosition) || IKHelper.IsInRange(dict[FullBodyBipedEffector.LeftShoulder], rightHandPosition); GUILayout.Label(string.Format("L Shoulder: {0}", format(IKHelper.GetEffectorPosition(dict[FullBodyBipedEffector.LeftShoulder]))), inRange ? guiStyleLabelInRange : guiStyleLabelOutOfRange); inRange = IKHelper.IsInRange(dict[FullBodyBipedEffector.LeftThigh], leftHandPosition) || IKHelper.IsInRange(dict[FullBodyBipedEffector.LeftThigh], rightHandPosition); GUILayout.Label(string.Format("L Thigh: {0}", format(IKHelper.GetEffectorPosition(dict[FullBodyBipedEffector.LeftThigh]))), inRange ? guiStyleLabelInRange : guiStyleLabelOutOfRange); inRange = IKHelper.IsInRange(dict[FullBodyBipedEffector.LeftFoot], leftHandPosition) || IKHelper.IsInRange(dict[FullBodyBipedEffector.LeftFoot], rightHandPosition); GUILayout.Label(string.Format("L Foot: {0}", format(IKHelper.GetEffectorPosition(dict[FullBodyBipedEffector.LeftFoot]))), inRange ? guiStyleLabelInRange : guiStyleLabelOutOfRange); // right inRange = IKHelper.IsInRange(dict[FullBodyBipedEffector.RightHand], leftHandPosition) || IKHelper.IsInRange(dict[FullBodyBipedEffector.RightHand], rightHandPosition); GUILayout.Label(string.Format("R Hand: {0}", format(IKHelper.GetEffectorPosition(dict[FullBodyBipedEffector.RightHand]))), inRange ? guiStyleLabelInRange : guiStyleLabelOutOfRange); inRange = IKHelper.IsInRange(dict[FullBodyBipedEffector.RightShoulder], leftHandPosition) || IKHelper.IsInRange(dict[FullBodyBipedEffector.RightShoulder], rightHandPosition); GUILayout.Label(string.Format("R Shoulder: {0}", format(IKHelper.GetEffectorPosition(dict[FullBodyBipedEffector.RightShoulder]))), inRange ? guiStyleLabelInRange : guiStyleLabelOutOfRange); inRange = IKHelper.IsInRange(dict[FullBodyBipedEffector.RightThigh], leftHandPosition) || IKHelper.IsInRange(dict[FullBodyBipedEffector.RightThigh], rightHandPosition); GUILayout.Label(string.Format("R Thigh: {0}", format(IKHelper.GetEffectorPosition(dict[FullBodyBipedEffector.RightThigh]))), inRange ? guiStyleLabelInRange : guiStyleLabelOutOfRange); inRange = IKHelper.IsInRange(dict[FullBodyBipedEffector.RightFoot], leftHandPosition) || IKHelper.IsInRange(dict[FullBodyBipedEffector.RightFoot], rightHandPosition); GUILayout.Label(string.Format("R Foot: {0}", format(IKHelper.GetEffectorPosition(dict[FullBodyBipedEffector.RightFoot]))), inRange ? guiStyleLabelInRange : guiStyleLabelOutOfRange); } } GUILayout.EndVertical(); GUILayout.EndArea(); }