Skip to content

Commit 34e0282

Browse files
committed
Version 2.2 - Minor fixes for release to asset store
1 parent 3b51e17 commit 34e0282

16 files changed

+202
-116
lines changed

Assets/SteamVR/Input/SteamVR_Behaviour_Pose.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public class SteamVR_Behaviour_Pose : MonoBehaviour
6767
protected int deviceIndex = -1;
6868

6969
protected SteamVR_HistoryBuffer historyBuffer = new SteamVR_HistoryBuffer(30);
70-
70+
71+
private bool debugVelocity = true;
72+
7173

7274
protected virtual void Start()
7375
{
@@ -134,6 +136,20 @@ protected virtual void UpdateTransform()
134136
transform.localPosition = poseAction[inputSource].localPosition;
135137
transform.localRotation = poseAction[inputSource].localRotation;
136138
}
139+
140+
if (debugVelocity && isActive)
141+
{
142+
/*
143+
Vector3 positionAtTime, velocityAtTime, angularVelocityAtTime;
144+
Quaternion rotationAtTime;
145+
146+
poseAction[inputSource].GetPoseAtTimeOffset(1 * -0.011f, out positionAtTime, out rotationAtTime, out velocityAtTime, out angularVelocityAtTime);
147+
148+
SteamVR_Utils.DrawVelocity(-Time.frameCount, positionAtTime, velocityAtTime, Color.green);
149+
150+
SteamVR_Utils.DrawVelocity(Time.frameCount, transform.position, poseAction[inputSource].velocity, Color.red);
151+
*/
152+
}
137153
}
138154

139155
private void SteamVR_Behaviour_Pose_OnChange(SteamVR_Action_Pose fromAction, SteamVR_Input_Sources fromSource)
@@ -223,6 +239,34 @@ public void GetEstimatedPeakVelocities(out Vector3 velocity, out Vector3 angular
223239
historyBuffer.GetAverageVelocities(out velocity, out angularVelocity, 2, top);
224240
}
225241

242+
/// <summary>Rewrite the history buffer using SteamVR's actual recorded poses and get velocities based on those.</summary>
243+
public void GetRealPeakVelocities(out Vector3 velocity, out Vector3 angularVelocity)
244+
{
245+
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
246+
stopwatch.Start();
247+
248+
historyBuffer.Clear();
249+
250+
for (int framesBack = 1; framesBack < 15; framesBack++)
251+
{
252+
Vector3 positionAtTime, velocityAtTime, angularVelocityAtTime;
253+
Quaternion rotationAtTime;
254+
255+
poseAction[inputSource].GetPoseAtTimeOffset(framesBack * -0.011f, out positionAtTime, out rotationAtTime, out velocityAtTime, out angularVelocityAtTime);
256+
257+
historyBuffer.Update(positionAtTime, rotationAtTime, velocityAtTime, angularVelocityAtTime);
258+
}
259+
260+
int top = historyBuffer.GetTopVelocity(10, 1);
261+
262+
var step = historyBuffer.GetAtIndex(top);
263+
velocity = step.velocity;
264+
angularVelocity = step.angularVelocity;
265+
266+
stopwatch.Stop();
267+
Debug.Log("ms: " + stopwatch.Elapsed.TotalMilliseconds);
268+
}
269+
226270
protected int lastFrameUpdated;
227271
protected void UpdateHistoryBuffer()
228272
{

Assets/SteamVR/Input/SteamVR_Behaviour_Skeleton.cs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,6 @@ public class SteamVR_Behaviour_Skeleton : MonoBehaviour
4747
[Tooltip("Modify this to blend between animations setup on the hand")]
4848
public float skeletonBlend = 1f;
4949

50-
/// <summary>
51-
/// How much of a blend to apply to the transform positions and rotations between the normal position/rotation and the transform's
52-
/// Set to 0 for the transform orientation to be set to the skeleton position/rotation
53-
/// Set to 1 for the transform orientation to be set by the attached transform's position/rotation
54-
/// </summary>
55-
[Range(0, 1)]
56-
[Tooltip("Modify this to blend between skeleton root orientation and attached transform root orientation")]
57-
public float attachedTransformBlend = 0f;
58-
59-
public Transform attachedToTransform;
60-
6150
/// <summary>This Unity event will fire whenever the position or rotation of the bones are updated.</summary>
6251
public SteamVR_Behaviour_SkeletonEvent onBoneTransformsUpdated;
6352

@@ -178,6 +167,17 @@ public class SteamVR_Behaviour_Skeleton : MonoBehaviour
178167
/// <summary>The range of motion that is set temporarily (call ResetTemporaryRangeOfMotion to reset to rangeOfMotion)</summary>
179168
protected EVRSkeletalMotionRange? temporaryRangeOfMotion = null;
180169

170+
/// <summary>
171+
/// Get the accuracy level of the skeletal tracking data.
172+
/// <para/>* Estimated: Body part location can’t be directly determined by the device. Any skeletal pose provided by the device is estimated based on the active buttons, triggers, joysticks, or other input sensors. Examples include the Vive Controller and gamepads.
173+
/// <para/>* Partial: Body part location can be measured directly but with fewer degrees of freedom than the actual body part.Certain body part positions may be unmeasured by the device and estimated from other input data.Examples include Knuckles or gloves that only measure finger curl
174+
/// <para/>* Full: Body part location can be measured directly throughout the entire range of motion of the body part.Examples include hi-end mocap systems, or gloves that measure the rotation of each finger segment.
175+
/// </summary>
176+
public EVRSkeletalTrackingLevel skeletalTrackingLevel
177+
{
178+
get { return skeletonAction.skeletalTrackingLevel; }
179+
}
180+
181181
/// <summary>Returns true if we are in the process of blending the skeletonBlend field (between animation and bone data)</summary>
182182
public bool isBlending
183183
{
@@ -352,7 +352,7 @@ public void SetRangeOfMotion(EVRSkeletalMotionRange newRangeOfMotion, float blen
352352
/// Blend from the current skeletonBlend amount to full bone data. (skeletonBlend = 1)
353353
/// </summary>
354354
/// <param name="overTime">How long you want the blend to take (in seconds)</param>
355-
public void BlendToSkeleton(float overTime = 0.1f, bool detachTransform = false)
355+
public void BlendToSkeleton(float overTime = 0.1f)
356356
{
357357
BlendTo(1, overTime);
358358
}
@@ -364,20 +364,9 @@ public void BlendToSkeleton(float overTime = 0.1f, bool detachTransform = false)
364364
/// <param name="overTime">How long you want the blend to take (in seconds)</param>
365365
public void BlendToPoser(SteamVR_Skeleton_Poser poser, float overTime = 0.1f)
366366
{
367-
if (poser == null) return;
368-
blendPoser = poser;
369-
BlendTo(0, overTime);
370-
}
367+
if (poser == null)
368+
return;
371369

372-
/// <summary>
373-
/// Blend from the current skeletonBlend amount to pose animation. (skeletonBlend = 0)
374-
/// Note: This will ignore the root position and rotation of the pose.
375-
/// </summary>
376-
/// <param name="overTime">How long you want the blend to take (in seconds)</param>
377-
/// <param name="attachToTransform">If you have a positiona and rotation offset for your pose you can attach it to a particular transform</param>
378-
public void BlendToPoser(SteamVR_Skeleton_Poser poser, Transform attachToTransform, float overTime = 0.1f)
379-
{
380-
if (poser == null) return;
381370
blendPoser = poser;
382371
BlendTo(0, overTime);
383372
}

Assets/SteamVR/InteractionSystem/Core/Scripts/Hand.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ public void HideSkeleton(bool permanent = false)
275275
hoverhighlightRenderModel.SetHandVisibility(false, permanent);
276276
}
277277

278+
public bool HasSkeleton()
279+
{
280+
return mainRenderModel != null && mainRenderModel.GetSkeleton() != null;
281+
}
282+
278283
public void Show()
279284
{
280285
SetVisibility(true);
@@ -454,7 +459,7 @@ public void AttachObject(GameObject objectToAttach, GrabTypes grabbedWithType, A
454459

455460
if (attachedObject.HasAttachFlag(AttachmentFlags.SnapOnAttach))
456461
{
457-
if (attachedObject.interactable != null && attachedObject.interactable.skeletonPoser != null)
462+
if (attachedObject.interactable != null && attachedObject.interactable.skeletonPoser != null && HasSkeleton())
458463
{
459464
SteamVR_Skeleton_PoseSnapshot pose = attachedObject.interactable.skeletonPoser.GetBlendedPose(skeleton);
460465

@@ -491,7 +496,7 @@ public void AttachObject(GameObject objectToAttach, GrabTypes grabbedWithType, A
491496
}
492497
else
493498
{
494-
if (attachedObject.interactable != null && attachedObject.interactable.skeletonPoser != null)
499+
if (attachedObject.interactable != null && attachedObject.interactable.skeletonPoser != null && HasSkeleton())
495500
{
496501
attachedObject.initialPositionalOffset = attachedObject.handAttachmentPointTransform.InverseTransformPoint(objectToAttach.transform.position);
497502
attachedObject.initialRotationalOffset = Quaternion.Inverse(attachedObject.handAttachmentPointTransform.rotation) * objectToAttach.transform.rotation;
@@ -637,7 +642,7 @@ public void DetachObject(GameObject objectToDetach, bool restoreOriginalParent =
637642
}
638643
}
639644

640-
if (attachedObjects[index].interactable != null && attachedObjects[index].interactable.handFollowTransform)
645+
if (attachedObjects[index].interactable != null && attachedObjects[index].interactable.handFollowTransform && HasSkeleton())
641646
{
642647
skeleton.transform.localPosition = Vector3.zero;
643648
skeleton.transform.localRotation = Quaternion.identity;
@@ -743,6 +748,13 @@ public void GetEstimatedPeakVelocities(out Vector3 velocity, out Vector3 angular
743748
angularVelocity = Player.instance.trackingOriginTransform.TransformDirection(angularVelocity);
744749
}
745750

751+
public void GetRealPeakVelocities(out Vector3 velocity, out Vector3 angularVelocity)
752+
{
753+
trackedObject.GetRealPeakVelocities(out velocity, out angularVelocity);
754+
velocity = Player.instance.trackingOriginTransform.TransformVector(velocity);
755+
angularVelocity = Player.instance.trackingOriginTransform.TransformDirection(angularVelocity);
756+
}
757+
746758

747759
//-------------------------------------------------
748760
private void CleanUpAttachedObjectStack()
@@ -1101,7 +1113,7 @@ protected virtual void HandFollowUpdate()
11011113
{
11021114
SteamVR_Skeleton_PoseSnapshot pose = null;
11031115

1104-
if (currentAttachedObjectInfo.Value.interactable.skeletonPoser != null)
1116+
if (currentAttachedObjectInfo.Value.interactable.skeletonPoser != null && HasSkeleton())
11051117
{
11061118
pose = currentAttachedObjectInfo.Value.interactable.skeletonPoser.GetBlendedPose(skeleton);
11071119
}
@@ -1224,7 +1236,7 @@ protected void UpdateAttachedVelocity(AttachedObject attachedObjectInfo)
12241236

12251237
protected Vector3 TargetItemPosition(AttachedObject attachedObject)
12261238
{
1227-
if (attachedObject.interactable != null && attachedObject.interactable.skeletonPoser != null)
1239+
if (attachedObject.interactable != null && attachedObject.interactable.skeletonPoser != null && HasSkeleton())
12281240
{
12291241
Vector3 tp = attachedObject.handAttachmentPointTransform.InverseTransformPoint(transform.TransformPoint(attachedObject.interactable.skeletonPoser.GetBlendedPose(skeleton).position));
12301242
//tp.x *= -1;
@@ -1238,7 +1250,7 @@ protected Vector3 TargetItemPosition(AttachedObject attachedObject)
12381250

12391251
protected Quaternion TargetItemRotation(AttachedObject attachedObject)
12401252
{
1241-
if (attachedObject.interactable != null && attachedObject.interactable.skeletonPoser != null)
1253+
if (attachedObject.interactable != null && attachedObject.interactable.skeletonPoser != null && HasSkeleton())
12421254
{
12431255
Quaternion tr = Quaternion.Inverse(attachedObject.handAttachmentPointTransform.rotation) * (transform.rotation * attachedObject.interactable.skeletonPoser.GetBlendedPose(skeleton).rotation);
12441256
return currentAttachedObjectInfo.Value.handAttachmentPointTransform.rotation * tr;

Assets/SteamVR/InteractionSystem/Core/Scripts/Interactable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ protected virtual void OnAttachedToHand(Hand hand)
283283

284284
if (skeletonPoser != null && hand.skeleton != null)
285285
{
286-
hand.skeleton.BlendToPoser(skeletonPoser, this.transform, blendToPoseTime);
286+
hand.skeleton.BlendToPoser(skeletonPoser, blendToPoseTime);
287287
}
288288

289289
attachedToHand = hand;
@@ -310,7 +310,7 @@ protected virtual void OnDetachedFromHand(Hand hand)
310310
if (skeletonPoser != null)
311311
{
312312
if (hand.skeleton != null)
313-
hand.skeleton.BlendToSkeleton(releasePoseBlendTime, true);
313+
hand.skeleton.BlendToSkeleton(releasePoseBlendTime);
314314
}
315315

316316
attachedToHand = null;

Assets/SteamVR/InteractionSystem/Core/Scripts/RenderModel.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ protected void InitializeHand()
6161
SetHandVisibility(false);
6262

6363
handAnimator = handInstance.GetComponentInChildren<Animator>();
64+
65+
if (handSkeleton.skeletonAction.activeBinding == false)
66+
{
67+
Debug.LogWarning("Skeleton action: " + handSkeleton.skeletonAction.GetPath() + " is not bound. Your controller may not support SteamVR Skeleton Input.");
68+
DestroyHand();
69+
}
6470
}
6571
}
6672

@@ -352,7 +358,10 @@ public EVRSkeletalMotionRange GetSkeletonRangeOfMotion
352358
{
353359
get
354360
{
355-
return handSkeleton.rangeOfMotion;
361+
if (handSkeleton != null)
362+
return handSkeleton.rangeOfMotion;
363+
else
364+
return EVRSkeletalMotionRange.WithController;
356365
}
357366
}
358367

Assets/SteamVR/InteractionSystem/Core/Scripts/Throwable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public virtual void GetReleaseVelocities(Hand hand, out Vector3 velocity, out Ve
187187
angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
188188
break;
189189
case ReleaseStyle.AdvancedEstimation:
190-
hand.GetEstimatedPeakVelocities(out velocity, out angularVelocity);
190+
hand.GetRealPeakVelocities(out velocity, out angularVelocity);
191191
break;
192192
case ReleaseStyle.GetFromHand:
193193
velocity = hand.GetTrackedObjectVelocity(releaseVelocityTimeOffset);
-377 KB
Binary file not shown.

Assets/SteamVR/InteractionSystem/InteractionSystem.pdf.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

Assets/SteamVR/InteractionSystem/Readme_InteractionSystem.txt

Lines changed: 0 additions & 22 deletions
This file was deleted.

Assets/SteamVR/InteractionSystem/Readme_InteractionSystem.txt.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)