void FindHandData(Side side) { // Camera OVRCameraRig cameraRig = GameObject.FindObjectOfType <OVRCameraRig>(); if (!cameraRig) { return; } if (!HPTK.core.trackingSpace) { HPTK.core.trackingSpace = cameraRig.trackingSpace; } if (!HPTK.core.trackedCamera) { HPTK.core.trackedCamera = cameraRig.trackingSpace.Find("CenterEyeAnchor").transform; } // Hands OVRHand[] ovrHands = cameraRig.GetComponentsInChildren <OVRHand>(); foreach (var ovrHand in ovrHands) { OVRSkeleton.IOVRSkeletonDataProvider skeltonDataProvider = ovrHand as OVRSkeleton.IOVRSkeletonDataProvider; OVRSkeleton.SkeletonType skeletonType = skeltonDataProvider.GetSkeletonType(); OVRSkeleton ovrSkelton = ovrHand.GetComponent <OVRSkeleton>(); if (ovrSkelton == null) { continue; } if ((skeletonType == OVRSkeleton.SkeletonType.HandLeft && side == Side.Left) || (skeletonType == OVRSkeleton.SkeletonType.HandRight && side == Side.Right)) { handData = ovrHand; boneData = ovrSkelton; } else { continue; } } }
void Find() { // Camera OVRCameraRig cameraRig = GameObject.FindObjectOfType <OVRCameraRig>(); HPTKCore.core.model.trackedCamera = cameraRig.trackingSpace.Find("CenterEyeAnchor").transform; // Reparenting if (!rootHPTK) { rootHPTK = transform; } if (trackingSpaceIsParent) { rootHPTK.parent = cameraRig.trackingSpace; } // Hands OVRHand[] ovrHands = cameraRig.GetComponentsInChildren <OVRHand>(); foreach (var ovrHand in ovrHands) { OVRSkeleton.IOVRSkeletonDataProvider skeltonDataProvider = ovrHand as OVRSkeleton.IOVRSkeletonDataProvider; OVRSkeleton.SkeletonType skeltonType = skeltonDataProvider.GetSkeletonType(); // SMR SkinnedMeshRenderer smr = ovrHand.GetComponent <SkinnedMeshRenderer>(); if (disableDefaultSMR) { smr.enabled = false; } if (applyMatToDefaultSMR) { smr.material = matToApply; } OVRSkeleton ovrSkelton = ovrHand.GetComponent <OVRSkeleton>(); if (ovrSkelton == null) { continue; } // Fix for static hands in Unity Editor #if UNITY_EDITOR ovrSkelton.ShouldUpdateBonePoses = true; #endif // IDPs if (findOVRHandsForIdps) { switch (skeltonType) { case OVRSkeleton.SkeletonType.HandLeft: if (!ovrSkeletonTrackerL.handData || !ovrSkeletonTrackerL.boneData) { ovrSkeletonTrackerL.handData = ovrHand; ovrSkeletonTrackerL.boneData = ovrSkelton; } break; case OVRSkeleton.SkeletonType.HandRight: if (!ovrSkeletonTrackerR.handData || !ovrSkeletonTrackerR.boneData) { ovrSkeletonTrackerR.handData = ovrHand; ovrSkeletonTrackerR.boneData = ovrSkelton; } break; } } } }
void Apply() { // Camera HPTKCore.core.model.trackedCamera = cameraRig.trackingSpace.Find("CenterEyeAnchor").transform; // Reparenting if (!rootHPTK) { rootHPTK = transform; } if (trackingSpaceIsParent) { rootHPTK.parent = cameraRig.trackingSpace; } // Hands OVRHand[] ovrHands = cameraRig.GetComponentsInChildren <OVRHand>(); foreach (var ovrHand in ovrHands) { OVRSkeleton.IOVRSkeletonDataProvider skeltonDataProvider = ovrHand as OVRSkeleton.IOVRSkeletonDataProvider; OVRSkeleton.SkeletonType skeltonType = skeltonDataProvider.GetSkeletonType(); // SMR SkinnedMeshRenderer smr = ovrHand.GetComponent <SkinnedMeshRenderer>(); if (disableDefaultSMR) { smr.enabled = false; } OVRSkeleton ovrSkelton = ovrHand.GetComponent <OVRSkeleton>(); if (ovrSkelton == null) { continue; } // IDPs if (findOVRHandsForIdps) { switch (skeltonType) { case OVRSkeleton.SkeletonType.HandLeft: if (!ovrSkeletonTrackerL.handData || !ovrSkeletonTrackerL.boneData) { ovrSkeletonTrackerL.handData = ovrHand; ovrSkeletonTrackerL.boneData = ovrSkelton; } defaultSMR_L = smr; // Copy materials from origin if (copyDefaultSMRMaterial) { Debug.Log("-------------"); Debug.Log(smr.name); Debug.Log(avatar.viewModel.leftHand.name); Debug.Log(avatar.viewModel.leftHand.viewModel.slave.skinnedMR.name); Debug.Log("-------------"); avatar.viewModel.leftHand.viewModel.slave.skinnedMR.material = defaultSMR_L.material; } break; case OVRSkeleton.SkeletonType.HandRight: if (!ovrSkeletonTrackerR.handData || !ovrSkeletonTrackerR.boneData) { ovrSkeletonTrackerR.handData = ovrHand; ovrSkeletonTrackerR.boneData = ovrSkelton; } defaultSMR_R = smr; // Copy materials from origin if (copyDefaultSMRMaterial) { avatar.viewModel.rightHand.viewModel.slave.skinnedMR.material = defaultSMR_R.material; } break; } } // Apply materials to origin if (applyMatToDefaultSMR) { smr.material = matToApply; } } ready = true; onReady.Invoke(); }