@@ -90,7 +90,7 @@ public interface IDeformationData
9090 /// <summary>
9191 /// The OVR Skeleton component for the character.
9292 /// </summary>
93- public OVRCustomSkeleton ConstraintSkeleton { get ; }
93+ public OVRSkeleton ConstraintSkeleton { get ; }
9494
9595 /// <summary>
9696 /// The array of transforms from the hips to the head bones.
@@ -152,7 +152,7 @@ public enum SpineTranslationCorrectionType
152152
153153 // Interface implementation
154154 /// <inheritdoc />
155- OVRCustomSkeleton IDeformationData . ConstraintSkeleton => _skeleton ;
155+ OVRSkeleton IDeformationData . ConstraintSkeleton => _skeleton ;
156156
157157 /// <inheritdoc />
158158 SpineTranslationCorrectionType IDeformationData . SpineCorrectionType => _spineTranslationCorrectionType ;
@@ -178,7 +178,7 @@ public enum SpineTranslationCorrectionType
178178 /// <inheritdoc cref="IDeformationData.ConstraintSkeleton"/>
179179 [ NotKeyable , SerializeField ]
180180 [ Tooltip ( DeformationDataTooltips . Skeleton ) ]
181- private OVRCustomSkeleton _skeleton ;
181+ private OVRSkeleton _skeleton ;
182182
183183 /// <inheritdoc cref="IDeformationData.SpineCorrectionType"/>
184184 [ NotKeyable , SerializeField ]
@@ -245,57 +245,107 @@ public enum SpineTranslationCorrectionType
245245 /// <summary>
246246 /// Setup the deformation data struct for the deformation job.
247247 /// </summary>
248- public void Setup ( )
248+ /// <param name="dummyOne">Dummy transform if skeleton is not ready.</param>
249+ /// <param name="dummyTwo">Dummy transform if skeleton is not ready.</param>
250+ public void Setup ( Transform dummyOne , Transform dummyTwo )
249251 {
250- SetupHipsHeadData ( ) ;
251- SetupArmData ( ) ;
252- SetupBonePairs ( ) ;
252+ SetupHipsHeadData ( dummyOne , dummyTwo ) ;
253+ SetupArmData ( dummyOne , dummyTwo ) ;
254+ SetupBonePairs ( dummyOne ) ;
253255 }
254256
255257 /// <summary>
256258 /// Assign the OVR Skeleton.
257259 /// </summary>
258260 /// <param name="skeleton">The OVRSkeleton</param>
259- public void AssignOVRSkeleton ( OVRCustomSkeleton skeleton )
261+ public void AssignOVRSkeleton ( OVRSkeleton skeleton )
260262 {
261263 _skeleton = skeleton ;
262264 }
263265
264- private void SetupHipsHeadData ( )
266+ private void SetupHipsHeadData ( Transform dummyOne , Transform dummyTwo )
265267 {
266268 // Setup hips to head
267269 var hipToHeadBones = new List < Transform > ( ) ;
268- for ( int i = ( int ) OVRSkeleton . BoneId . Body_Hips ; i <= ( int ) OVRSkeleton . BoneId . Body_Head ; i ++ )
270+
271+ if ( _skeleton . IsInitialized )
272+ {
273+ for ( int boneId = ( int ) OVRSkeleton . BoneId . Body_Hips ; boneId <= ( int ) OVRSkeleton . BoneId . Body_Head ; boneId ++ )
274+ {
275+ var bones = _skeleton . Bones ;
276+ for ( int boneIndex = 0 ; boneIndex < bones . Count ; boneIndex ++ )
277+ {
278+ if ( bones [ boneIndex ] . Id == ( OVRSkeleton . BoneId ) boneId )
279+ {
280+ hipToHeadBones . Add ( _skeleton . Bones [ boneIndex ] . Transform ) ;
281+ }
282+ }
283+ }
284+ }
285+ else
269286 {
270- hipToHeadBones . Add ( _skeleton . CustomBones [ i ] . transform ) ;
287+ hipToHeadBones . Add ( dummyOne ) ;
288+ hipToHeadBones . Add ( dummyTwo ) ;
271289 }
290+
272291 _hipsToHeadDistance =
273292 Vector3 . Distance ( hipToHeadBones [ 0 ] . position , hipToHeadBones [ ^ 1 ] . position ) ;
274293 _hipsToHeadBones = hipToHeadBones . ToArray ( ) ;
275294 }
276295
277- private void SetupArmData ( )
296+ private Transform FindBoneTransform ( OVRSkeleton . BoneId boneId )
297+ {
298+ if ( ! _skeleton . IsInitialized )
299+ {
300+ return null ;
301+ }
302+ var bones = _skeleton . Bones ;
303+ for ( int boneIndex = 0 ; boneIndex < bones . Count ; boneIndex ++ )
304+ {
305+ if ( bones [ boneIndex ] . Id == boneId )
306+ {
307+ return bones [ boneIndex ] . Transform ;
308+ }
309+ }
310+
311+ return null ;
312+ }
313+
314+ private void SetupArmData ( Transform dummyOne , Transform dummyTwo )
278315 {
316+ bool skeletonInitialized = _skeleton . IsInitialized ;
279317 // Setup arm data
280318 _leftArmData = new ArmPosData ( )
281319 {
282320 Weight = _armWeight ,
283321 MoveSpeed = _armMoveSpeed ,
284- ShoulderBone = _skeleton . CustomBones [ ( int ) OVRSkeleton . BoneId . Body_LeftShoulder ] ,
285- UpperArmBone = _skeleton . CustomBones [ ( int ) OVRSkeleton . BoneId . Body_LeftArmUpper ] ,
286- LowerArmBone = _skeleton . CustomBones [ ( int ) OVRSkeleton . BoneId . Body_LeftArmLower ] ,
322+ ShoulderBone = skeletonInitialized ?
323+ FindBoneTransform ( OVRSkeleton . BoneId . Body_LeftShoulder ) :
324+ dummyOne ,
325+ UpperArmBone = skeletonInitialized ?
326+ FindBoneTransform ( OVRSkeleton . BoneId . Body_LeftArmUpper ) :
327+ dummyTwo ,
328+ LowerArmBone = skeletonInitialized ?
329+ FindBoneTransform ( OVRSkeleton . BoneId . Body_LeftArmLower ) :
330+ dummyTwo ,
287331 } ;
288332 _rightArmData = new ArmPosData ( )
289333 {
290334 Weight = _armWeight ,
291335 MoveSpeed = _armMoveSpeed ,
292- ShoulderBone = _skeleton . CustomBones [ ( int ) OVRSkeleton . BoneId . Body_RightShoulder ] ,
293- UpperArmBone = _skeleton . CustomBones [ ( int ) OVRSkeleton . BoneId . Body_RightArmUpper ] ,
294- LowerArmBone = _skeleton . CustomBones [ ( int ) OVRSkeleton . BoneId . Body_RightArmLower ] ,
336+ ShoulderBone = skeletonInitialized ?
337+ FindBoneTransform ( OVRSkeleton . BoneId . Body_RightShoulder ) :
338+ dummyOne ,
339+ UpperArmBone = skeletonInitialized ?
340+ FindBoneTransform ( OVRSkeleton . BoneId . Body_RightArmUpper ) :
341+ dummyTwo ,
342+ LowerArmBone = skeletonInitialized ?
343+ FindBoneTransform ( OVRSkeleton . BoneId . Body_RightArmLower ) :
344+ dummyTwo ,
295345 } ;
296346 }
297347
298- private void SetupBonePairs ( )
348+ private void SetupBonePairs ( Transform dummyTransform )
299349 {
300350 // Setup bone pairs
301351 var bonePairs = new List < BonePairData > ( ) ;
@@ -317,7 +367,9 @@ private void SetupBonePairs()
317367
318368 if ( _applyToArms )
319369 {
320- var chestBone = _skeleton . CustomBones [ ( int ) OVRSkeleton . BoneId . Body_Chest ] . transform ;
370+ var chestBone = _skeleton . IsInitialized ?
371+ FindBoneTransform ( OVRSkeleton . BoneId . Body_Chest ) :
372+ dummyTransform ;
321373 var chestBonePos = chestBone . position ;
322374 var leftShoulderBonePos = _leftArmData . ShoulderBone . position ;
323375 var rightShoulderBonePos = _rightArmData . ShoulderBone . position ;
@@ -416,14 +468,25 @@ public class DeformationConstraint : RigConstraint<
416468 DeformationJobBinder < DeformationData > > ,
417469 IOVRSkeletonConstraint
418470 {
471+ private GameObject _dummyOne , _dummyTwo ;
472+
473+ private void Awake ( )
474+ {
475+ _dummyOne = new GameObject ( "Deformation Constraint Dummy 1" ) ;
476+ _dummyOne . transform . SetParent ( this . transform ) ;
477+ _dummyTwo = new GameObject ( "Deformation Constraint Dummy 2" ) ;
478+ _dummyTwo . transform . SetParent ( this . transform ) ;
479+ }
480+
419481 private void Start ( )
420482 {
421- data . Setup ( ) ;
483+ data . Setup ( _dummyOne . transform , _dummyTwo . transform ) ;
422484 }
423485
424486 /// <inheritdoc />
425487 public void RegenerateData ( )
426488 {
489+ data . Setup ( _dummyOne . transform , _dummyTwo . transform ) ;
427490 }
428491 }
429492}
0 commit comments