@@ -53,12 +53,6 @@ public class JointPositionAdjustment
5353 public Vector3 GetPositionOffset ( )
5454 {
5555 var targetPositionOffset = FinalPosition - OriginalPosition ;
56- // The recorded positions will not be finite when we regenerate data for the rig.
57- if ( ! RiggingUtilities . IsFiniteVector3 ( FinalPosition ) ||
58- ! RiggingUtilities . IsFiniteVector3 ( OriginalPosition ) )
59- {
60- return Vector3 . zero ;
61- }
6256 return targetPositionOffset ;
6357 }
6458 }
@@ -214,6 +208,11 @@ public RetargetedBoneMappings RetargetedBoneMappingsInst
214208 private ProxyTransformLogic _proxyTransformLogic = new ProxyTransformLogic ( ) ;
215209 private bool _isFocusedWhileInBuild = true ;
216210
211+ // Cached array versions of dictionaries used in OVRUnityHumanoidSkeletonRetargeter
212+ private HumanBodyBones [ ] _customBoneIdToHumanBodyBoneArray ;
213+ private OVRSkeletonMetadata . BoneData [ ] _targetSkeletonDataBodyToBoneDataArray ;
214+ private OVRHumanBodyBonesMappings . BodySection [ ] _boneToBodySectionArray ;
215+
217216 /// <summary>
218217 /// Check for required components.
219218 /// </summary>
@@ -263,6 +262,7 @@ protected override void Start()
263262 ConstructDefaultPoseInformation ( ) ;
264263 ConstructBoneAdjustmentInformation ( ) ;
265264 CacheJointConstraints ( ) ;
265+ CacheBoneMapping ( ) ;
266266 ValidateHumanoid ( ) ;
267267
268268 _retargetingAnimationRig . ValidateRig ( this ) ;
@@ -325,6 +325,26 @@ private void CacheJointConstraints()
325325 _jointConstraints = jointConstraints . ToArray ( ) ;
326326 }
327327
328+ private void CacheBoneMapping ( )
329+ {
330+ _targetSkeletonDataBodyToBoneDataArray = new OVRSkeletonMetadata . BoneData [ ( int ) HumanBodyBones . LastBone ] ;
331+ _customBoneIdToHumanBodyBoneArray = new HumanBodyBones [ ( int ) BoneId . Max ] ;
332+ for ( int i = 0 ; i < _customBoneIdToHumanBodyBoneArray . Length ; i ++ )
333+ {
334+ _customBoneIdToHumanBodyBoneArray [ i ] = BodyBoneMappingsInterface . GetFullBodyBoneIdToHumanBodyBone .
335+ GetValueOrDefault ( ( BoneId ) i , HumanBodyBones . LastBone ) ;
336+ }
337+
338+ _boneToBodySectionArray =
339+ new OVRHumanBodyBonesMappings . BodySection [ OVRHumanBodyBonesMappings . BoneToBodySection . Count ] ;
340+ for ( int i = 0 ; i < _boneToBodySectionArray . Length ; i ++ )
341+ {
342+ _boneToBodySectionArray [ i ] =
343+ OVRHumanBodyBonesMappings . BoneToBodySection . GetValueOrDefault ( ( HumanBodyBones ) i ,
344+ OVRHumanBodyBonesMappings . BodySection . Head ) ;
345+ }
346+ }
347+
328348 private void ValidateHumanoid ( )
329349 {
330350 bool validHumanoid = true ;
@@ -386,6 +406,13 @@ protected override void Update()
386406 _retargetingAnimationRig . UpdateRig ( this ) ;
387407 }
388408
409+ /// <summary>
410+ /// Empty fixed update to avoid updating OVRSkeleton during fixed update.
411+ /// </summary>
412+ private void FixedUpdate ( )
413+ {
414+ }
415+
389416 /// <summary>
390417 /// Allows fixing joints via the retargeting processors. The avatar does not allow
391418 /// precise finger positions even with translate DoF checked.
@@ -397,6 +424,7 @@ protected virtual void LateUpdate()
397424 return ;
398425 }
399426
427+ UpdateBoneDataToArray ( ) ;
400428 foreach ( var retargetingProcessor in _retargetingProcessors )
401429 {
402430 retargetingProcessor . PrepareRetargetingProcessor ( this , Bones ) ;
@@ -419,10 +447,18 @@ protected virtual void OnDrawGizmos()
419447 }
420448 }
421449
450+ protected virtual void UpdateBoneDataToArray ( )
451+ {
452+ for ( int i = 0 ; i < TargetSkeletonData . BodyToBoneData . Count ; i ++ )
453+ {
454+ _targetSkeletonDataBodyToBoneDataArray [ i ] =
455+ TargetSkeletonData . BodyToBoneData . GetValueOrDefault ( ( HumanBodyBones ) i , null ) ;
456+ }
457+ }
458+
422459 protected virtual bool ShouldUpdatePositionOfBone ( HumanBodyBones humanBodyBone )
423460 {
424- var bodySectionOfJoint =
425- OVRHumanBodyBonesMappings . BoneToBodySection [ humanBodyBone ] ;
461+ var bodySectionOfJoint = _boneToBodySectionArray [ ( int ) humanBodyBone ] ;
426462 return IsBodySectionInArray ( bodySectionOfJoint ,
427463 _skeletonType == SkeletonType . FullBody ? FullBodySectionToPosition : BodySectionToPosition ) ;
428464 }
@@ -547,7 +583,7 @@ public void UpdateAdjustments(Quaternion[] rotationOffsets,
547583 if ( avatarMask != null )
548584 {
549585 jointFailsMask = ! avatarMask . GetHumanoidBodyPartActive (
550- BoneMappingsExtension . HumanBoneToAvatarBodyPart [ targetHumanBodyBone ] ) ;
586+ BoneMappingsExtension . HumanBoneToAvatarBodyPartArray [ ( int ) targetHumanBodyBone ] ) ;
551587 }
552588
553589 if ( adjustment == null )
@@ -672,25 +708,33 @@ public int GetNumberOfTransformsRetargeted()
672708 /// <returns>The human body bone for a custom bone id. Returns null if it doesn't exist.</returns>
673709 public HumanBodyBones ? GetCustomBoneIdToHumanBodyBone ( BoneId boneId )
674710 {
675- if ( CustomBoneIdToHumanBodyBone == null )
676- {
677- return null ;
678- }
679- if ( ! CustomBoneIdToHumanBodyBone . TryGetValue ( boneId , out var humanBodyBone ) )
711+ var humanBodyBone = _customBoneIdToHumanBodyBoneArray [ ( int ) boneId ] ;
712+ if ( humanBodyBone == HumanBodyBones . LastBone )
680713 {
681714 return null ;
682715 }
683716 return humanBodyBone ;
684717 }
685718
719+ /// <summary>
720+ /// Returns the human body bone to body section pairing.
721+ /// </summary>
722+ /// <param name="humanBodyBone">The human body bone to check for.</param>
723+ /// <returns>The body section for a human body bone.</returns>
724+ public OVRHumanBodyBonesMappings . BodySection GetHumanBodyBoneToBodySection ( HumanBodyBones humanBodyBone )
725+ {
726+ return _boneToBodySectionArray [ ( int ) humanBodyBone ] ;
727+ }
728+
686729 /// <summary>
687730 /// Returns the correction quaternion for a human body bone, if it exists.
688731 /// </summary>
689732 /// <param name="humanBodyBone">The human body bone to check for.</param>
690733 /// <returns>The correction quaternion for a human body bone. Returns null if it doesn't exist.</returns>
691734 public Quaternion ? GetCorrectionQuaternion ( HumanBodyBones humanBodyBone )
692735 {
693- if ( ! TargetSkeletonData . BodyToBoneData . TryGetValue ( humanBodyBone , out var targetData ) )
736+ var targetData = _targetSkeletonDataBodyToBoneDataArray [ ( int ) humanBodyBone ] ;
737+ if ( targetData == null )
694738 {
695739 return null ;
696740 }
@@ -708,7 +752,8 @@ public int GetNumberOfTransformsRetargeted()
708752 /// <returns>The original joint for a human body bone.</returns>
709753 public Transform GetOriginalJoint ( HumanBodyBones humanBodyBone )
710754 {
711- if ( ! TargetSkeletonData . BodyToBoneData . TryGetValue ( humanBodyBone , out var targetData ) )
755+ var targetData = _targetSkeletonDataBodyToBoneDataArray [ ( int ) humanBodyBone ] ;
756+ if ( targetData == null )
712757 {
713758 return null ;
714759 }
0 commit comments