/* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * Licensed under the Oculus SDK License Agreement (the "License"); * you may not use the Oculus SDK except in compliance with the License, * which is provided at the time of installation or download, or which * otherwise accompanies this software in either electronic or hard copy form. * * You may obtain a copy of the License at * * https://developer.oculus.com/licenses/oculussdk/ * * Unless required by applicable law or agreed to in writing, the Oculus SDK * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using Oculus.Interaction.Input; using System.Collections.Generic; using UnityEngine; namespace Oculus.Interaction.HandGrab.Visuals { /// /// Stores the translation between hand tracked data and the represented joint. /// [System.Serializable] public class HandJointMap { /// /// The unique identifier for the joint. /// public HandJointId id; /// /// The transform that this joint drives. /// public Transform transform; /// /// The rotation offset between the hand-tracked joint, and the represented joint. /// public Vector3 rotationOffset; /// /// Get the rotationOffset as a Quaternion. /// public Quaternion RotationOffset { get { return Quaternion.Euler(rotationOffset); } } /// /// Get the raw rotation of the joint, taken from the tracking data /// public Quaternion TrackedRotation { get { return Quaternion.Inverse(RotationOffset) * transform.localRotation; } } } /// /// A collection of joint maps to quick access the joints that are actually available in the hand rig. /// Stores an internal array of indices so it can transform from positions in the HandPose.HAND_JOINTIDS collection /// to the JointMap List without having to search for the (maybe unavailable) index every time. /// [System.Serializable] public class JointCollection { /// /// List of indices of the joints in the actual rig for quick access /// [SerializeField] [HideInInspector] private int[] _jointIndices = new int[FingersMetadata.HAND_JOINT_IDS.Length]; /// /// List of joints in the actual rig /// [SerializeField] [HideInInspector] private List _jointMaps; public JointCollection(List joints) { _jointMaps = joints; for (int i = 0; i < FingersMetadata.HAND_JOINT_IDS.Length; i++) { HandJointId boneId = FingersMetadata.HAND_JOINT_IDS[i]; _jointIndices[i] = joints.FindIndex(bone => bone.id == boneId); } } public HandJointMap this[int jointIndex] { get { int joint = _jointIndices[jointIndex]; if (joint >= 0) { return _jointMaps[joint]; } return null; } } } }