Initialer Upload neues Unity-Projekt
This commit is contained in:
133
Assets/Oculus/Interaction/Runtime/Scripts/Body/Input/Body.cs
Normal file
133
Assets/Oculus/Interaction/Runtime/Scripts/Body/Input/Body.cs
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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 UnityEngine;
|
||||
using System;
|
||||
using Oculus.Interaction.Input;
|
||||
|
||||
namespace Oculus.Interaction.Body.Input
|
||||
{
|
||||
public class Body : DataModifier<BodyDataAsset>, IBody
|
||||
{
|
||||
[Tooltip("If assigned, joint pose translations into world " +
|
||||
"space will be performed via this transform. If unassigned, " +
|
||||
"world joint poses will be returned in tracking space.")]
|
||||
[SerializeField, Optional]
|
||||
private Transform _trackingSpace;
|
||||
|
||||
public bool IsConnected => GetData().IsDataValid;
|
||||
|
||||
public bool IsHighConfidence => GetData().IsDataHighConfidence;
|
||||
|
||||
public float Scale => GetData().RootScale;
|
||||
|
||||
public ISkeletonMapping SkeletonMapping => GetData().SkeletonMapping;
|
||||
|
||||
public bool IsTrackedDataValid => GetData().IsDataValid;
|
||||
|
||||
public event Action WhenBodyUpdated = delegate { };
|
||||
|
||||
private BodyJointsCache _jointPosesCache;
|
||||
|
||||
public bool GetJointPose(BodyJointId bodyJointId, out Pose pose)
|
||||
{
|
||||
pose = Pose.identity;
|
||||
if (!IsTrackedDataValid || !SkeletonMapping.Joints.Contains(bodyJointId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CheckJointPosesCacheUpdate();
|
||||
pose = _jointPosesCache.GetWorldJointPose(bodyJointId);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool GetJointPoseLocal(BodyJointId bodyJointId, out Pose pose)
|
||||
{
|
||||
pose = Pose.identity;
|
||||
if (!IsTrackedDataValid || !SkeletonMapping.Joints.Contains(bodyJointId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CheckJointPosesCacheUpdate();
|
||||
pose = _jointPosesCache.GetLocalJointPose(bodyJointId);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool GetJointPoseFromRoot(BodyJointId bodyJointId, out Pose pose)
|
||||
{
|
||||
pose = Pose.identity;
|
||||
if (!IsTrackedDataValid || !SkeletonMapping.Joints.Contains(bodyJointId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CheckJointPosesCacheUpdate();
|
||||
pose = _jointPosesCache.GetJointPoseFromRoot(bodyJointId);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool GetRootPose(out Pose pose)
|
||||
{
|
||||
pose = Pose.identity;
|
||||
if (!IsTrackedDataValid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CheckJointPosesCacheUpdate();
|
||||
pose = _jointPosesCache.GetWorldRootPose();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void InitializeJointPosesCache()
|
||||
{
|
||||
if (_jointPosesCache == null)
|
||||
{
|
||||
_jointPosesCache = new BodyJointsCache();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckJointPosesCacheUpdate()
|
||||
{
|
||||
if (_jointPosesCache != null
|
||||
&& CurrentDataVersion != _jointPosesCache.LocalDataVersion)
|
||||
{
|
||||
_jointPosesCache.Update(GetData(), CurrentDataVersion, _trackingSpace);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Apply(BodyDataAsset data)
|
||||
{
|
||||
// Default implementation does nothing, to allow instantiation of this modifier directly
|
||||
}
|
||||
|
||||
public override void MarkInputDataRequiresUpdate()
|
||||
{
|
||||
base.MarkInputDataRequiresUpdate();
|
||||
if (Started)
|
||||
{
|
||||
InitializeJointPosesCache();
|
||||
WhenBodyUpdated.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55afe974697276a46949c30d6d15f347
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 UnityEngine;
|
||||
using System;
|
||||
using Oculus.Interaction.Input;
|
||||
|
||||
namespace Oculus.Interaction.Body.Input
|
||||
{
|
||||
public class BodyDataAsset : ICopyFrom<BodyDataAsset>
|
||||
{
|
||||
public ISkeletonMapping SkeletonMapping { get; set; }
|
||||
public Pose Root { get; set; } = Pose.identity;
|
||||
public float RootScale { get; set; } = 1f;
|
||||
public bool IsDataValid { get; set; } = false;
|
||||
public bool IsDataHighConfidence { get; set; } = false;
|
||||
public Pose[] JointPoses { get; set; } = new Pose[Constants.NUM_BODY_JOINTS];
|
||||
public int SkeletonChangedCount { get; set; } = 0;
|
||||
|
||||
public void CopyFrom(BodyDataAsset source)
|
||||
{
|
||||
SkeletonMapping = source.SkeletonMapping;
|
||||
Root = source.Root;
|
||||
RootScale = source.RootScale;
|
||||
IsDataValid = source.IsDataValid;
|
||||
IsDataHighConfidence = source.IsDataHighConfidence;
|
||||
SkeletonChangedCount = source.SkeletonChangedCount;
|
||||
|
||||
for (int i = 0; i < source.JointPoses.Length; ++i)
|
||||
{
|
||||
JointPoses[i] = source.JointPoses[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3341c364a9e73724bbd5f1f56e1f2bbc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,236 @@
|
||||
/*
|
||||
* 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 UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.Body.Input
|
||||
{
|
||||
public class BodyJointsCache
|
||||
{
|
||||
private const int DIRTY_ARRAY_SIZE = 1 + (Constants.NUM_BODY_JOINTS / 64);
|
||||
|
||||
public int LocalDataVersion { get; private set; } = -1;
|
||||
|
||||
private Pose[] _originalPoses = new Pose[Constants.NUM_BODY_JOINTS];
|
||||
private Pose[] _posesFromRoot = new Pose[Constants.NUM_BODY_JOINTS];
|
||||
private Pose[] _localPoses = new Pose[Constants.NUM_BODY_JOINTS];
|
||||
private Pose[] _worldPoses = new Pose[Constants.NUM_BODY_JOINTS];
|
||||
|
||||
private ReadOnlyBodyJointPoses _posesFromRootCollection;
|
||||
private ReadOnlyBodyJointPoses _worldPosesCollection;
|
||||
private ReadOnlyBodyJointPoses _localPosesCollection;
|
||||
|
||||
private ulong[] _dirtyJointsFromRoot;
|
||||
private ulong[] _dirtyLocalJoints;
|
||||
private ulong[] _dirtyWorldJoints;
|
||||
|
||||
private Matrix4x4 _scale;
|
||||
private Pose _rootPose;
|
||||
private Pose _worldRoot;
|
||||
|
||||
private ISkeletonMapping _mapping;
|
||||
|
||||
public BodyJointsCache()
|
||||
{
|
||||
LocalDataVersion = -1;
|
||||
|
||||
_dirtyJointsFromRoot = new ulong[DIRTY_ARRAY_SIZE];
|
||||
_dirtyLocalJoints = new ulong[DIRTY_ARRAY_SIZE];
|
||||
_dirtyWorldJoints = new ulong[DIRTY_ARRAY_SIZE];
|
||||
|
||||
_localPosesCollection = new ReadOnlyBodyJointPoses(_localPoses);
|
||||
_worldPosesCollection = new ReadOnlyBodyJointPoses(_worldPoses);
|
||||
_posesFromRootCollection = new ReadOnlyBodyJointPoses(_posesFromRoot);
|
||||
}
|
||||
|
||||
public void Update(BodyDataAsset data, int dataVersion,
|
||||
Transform trackingSpace = null)
|
||||
{
|
||||
LocalDataVersion = dataVersion;
|
||||
_mapping = data.SkeletonMapping;
|
||||
|
||||
for (int i = 0; i < DIRTY_ARRAY_SIZE; ++i)
|
||||
{
|
||||
_dirtyJointsFromRoot[i] = ulong.MaxValue;
|
||||
_dirtyLocalJoints[i] = ulong.MaxValue;
|
||||
_dirtyWorldJoints[i] = ulong.MaxValue;
|
||||
}
|
||||
if (!data.IsDataValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_scale = Matrix4x4.Scale(Vector3.one * data.RootScale);
|
||||
_rootPose = data.Root;
|
||||
_worldRoot = _rootPose;
|
||||
|
||||
if (trackingSpace != null)
|
||||
{
|
||||
_scale *= Matrix4x4.Scale(trackingSpace.lossyScale);
|
||||
_worldRoot.position = trackingSpace.TransformPoint(_rootPose.position);
|
||||
_worldRoot.rotation = trackingSpace.rotation * _rootPose.rotation;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Constants.NUM_BODY_JOINTS; ++i)
|
||||
{
|
||||
_originalPoses[i] = data.JointPoses[i];
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetAllLocalPoses(out ReadOnlyBodyJointPoses localJointPoses)
|
||||
{
|
||||
UpdateAllLocalPoses();
|
||||
localJointPoses = _localPosesCollection;
|
||||
return _localPosesCollection.Count > 0;
|
||||
}
|
||||
|
||||
public bool GetAllPosesFromRoot(out ReadOnlyBodyJointPoses posesFromRoot)
|
||||
{
|
||||
UpdateAllPosesFromRoot();
|
||||
posesFromRoot = _posesFromRootCollection;
|
||||
return _posesFromRootCollection.Count > 0;
|
||||
}
|
||||
|
||||
public bool GetAllWorldPoses(out ReadOnlyBodyJointPoses worldJointPoses)
|
||||
{
|
||||
UpdateAllWorldPoses();
|
||||
worldJointPoses = _worldPosesCollection;
|
||||
return _worldPosesCollection.Count > 0;
|
||||
}
|
||||
|
||||
public Pose GetLocalJointPose(BodyJointId jointId)
|
||||
{
|
||||
UpdateLocalJointPose(jointId);
|
||||
return _localPoses[(int)jointId];
|
||||
}
|
||||
|
||||
public Pose GetJointPoseFromRoot(BodyJointId jointId)
|
||||
{
|
||||
UpdateJointPoseFromRoot(jointId);
|
||||
return _posesFromRoot[(int)jointId];
|
||||
}
|
||||
|
||||
public Pose GetWorldJointPose(BodyJointId jointId)
|
||||
{
|
||||
UpdateWorldJointPose(jointId);
|
||||
return _worldPoses[(int)jointId];
|
||||
}
|
||||
|
||||
public Pose GetWorldRootPose()
|
||||
{
|
||||
return _worldRoot;
|
||||
}
|
||||
|
||||
private void UpdateJointPoseFromRoot(BodyJointId jointId)
|
||||
{
|
||||
if (!CheckJointDirty(jointId, _dirtyJointsFromRoot))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pose originalPose = _originalPoses[(int)jointId];
|
||||
Vector3 posFromRoot = Quaternion.Inverse(_rootPose.rotation) *
|
||||
(originalPose.position - _rootPose.position);
|
||||
Quaternion rotFromRoot = Quaternion.Inverse(_rootPose.rotation) *
|
||||
originalPose.rotation;
|
||||
_posesFromRoot[(int)jointId] = new Pose(posFromRoot, rotFromRoot);
|
||||
|
||||
SetJointClean(jointId, _dirtyJointsFromRoot);
|
||||
}
|
||||
|
||||
private void UpdateLocalJointPose(BodyJointId jointId)
|
||||
{
|
||||
if (!CheckJointDirty(jointId, _dirtyLocalJoints))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_mapping.TryGetParentJointId(jointId, out BodyJointId parentId) &&
|
||||
parentId >= BodyJointId.Body_Root)
|
||||
{
|
||||
Pose originalPose = _originalPoses[(int)jointId];
|
||||
Pose parentPose = _originalPoses[(int)parentId];
|
||||
|
||||
Vector3 localPos = Quaternion.Inverse(parentPose.rotation) *
|
||||
(originalPose.position - parentPose.position);
|
||||
Quaternion localRot = Quaternion.Inverse(parentPose.rotation) *
|
||||
originalPose.rotation;
|
||||
_localPoses[(int)jointId] = new Pose(localPos, localRot);
|
||||
}
|
||||
else
|
||||
{
|
||||
_localPoses[(int)jointId] = Pose.identity;
|
||||
}
|
||||
SetJointClean(jointId, _dirtyLocalJoints);
|
||||
}
|
||||
|
||||
private void UpdateWorldJointPose(BodyJointId jointId)
|
||||
{
|
||||
if (!CheckJointDirty(jointId, _dirtyWorldJoints))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pose fromRoot = GetJointPoseFromRoot(jointId);
|
||||
fromRoot.position = _scale * fromRoot.position;
|
||||
fromRoot.Postmultiply(GetWorldRootPose());
|
||||
_worldPoses[(int)jointId] = fromRoot;
|
||||
SetJointClean(jointId, _dirtyWorldJoints);
|
||||
}
|
||||
|
||||
private void UpdateAllWorldPoses()
|
||||
{
|
||||
foreach (BodyJointId joint in _mapping.Joints)
|
||||
{
|
||||
UpdateWorldJointPose(joint);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAllLocalPoses()
|
||||
{
|
||||
foreach (BodyJointId joint in _mapping.Joints)
|
||||
{
|
||||
UpdateLocalJointPose(joint);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAllPosesFromRoot()
|
||||
{
|
||||
foreach (BodyJointId joint in _mapping.Joints)
|
||||
{
|
||||
UpdateJointPoseFromRoot(joint);
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckJointDirty(BodyJointId jointId, ulong[] dirtyFlags)
|
||||
{
|
||||
int outerIdx = (int)jointId / 64;
|
||||
int innerIdx = (int)jointId % 64;
|
||||
return (dirtyFlags[outerIdx] & (1UL << innerIdx)) != 0;
|
||||
}
|
||||
|
||||
private void SetJointClean(BodyJointId jointId, ulong[] dirtyFlags)
|
||||
{
|
||||
int outerIdx = (int)jointId / 64;
|
||||
int innerIdx = (int)jointId % 64;
|
||||
dirtyFlags[outerIdx] = dirtyFlags[outerIdx] & ~(1UL << innerIdx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3c3dce4531a44741a6120d58ae02113
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,218 @@
|
||||
/*
|
||||
* 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 System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Primitive type serialization
|
||||
/// </summary>
|
||||
namespace Oculus.Interaction.Body.Input
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const int NUM_BODY_JOINTS = (int)BodyJointId.Body_End;
|
||||
}
|
||||
|
||||
public enum BodyJointId
|
||||
{
|
||||
Invalid = -1,
|
||||
|
||||
[InspectorName("Body Start")]
|
||||
Body_Start = 0,
|
||||
[InspectorName("Root")]
|
||||
Body_Root = Body_Start + 0,
|
||||
[InspectorName("Hips")]
|
||||
Body_Hips = Body_Start + 1,
|
||||
[InspectorName("Spine Lower")]
|
||||
Body_SpineLower = Body_Start + 2,
|
||||
[InspectorName("Spine Middle")]
|
||||
Body_SpineMiddle = Body_Start + 3,
|
||||
[InspectorName("Spine Upper")]
|
||||
Body_SpineUpper = Body_Start + 4,
|
||||
[InspectorName("Chest")]
|
||||
Body_Chest = Body_Start + 5,
|
||||
[InspectorName("Neck")]
|
||||
Body_Neck = Body_Start + 6,
|
||||
[InspectorName("Head")]
|
||||
Body_Head = Body_Start + 7,
|
||||
[InspectorName("Left Arm/Left Shoulder")]
|
||||
Body_LeftShoulder = Body_Start + 8,
|
||||
[InspectorName("Left Arm/Left Scapula")]
|
||||
Body_LeftScapula = Body_Start + 9,
|
||||
[InspectorName("Left Arm/Left Arm Upper")]
|
||||
Body_LeftArmUpper = Body_Start + 10,
|
||||
[InspectorName("Left Arm/Left Arm Lower")]
|
||||
Body_LeftArmLower = Body_Start + 11,
|
||||
[InspectorName("Left Arm/Left Hand Wrist Twist")]
|
||||
Body_LeftHandWristTwist = Body_Start + 12,
|
||||
[InspectorName("Right Arm/Right Shoulder")]
|
||||
Body_RightShoulder = Body_Start + 13,
|
||||
[InspectorName("Right Arm/Right Scapula")]
|
||||
Body_RightScapula = Body_Start + 14,
|
||||
[InspectorName("Right Arm/Right Arm Upper")]
|
||||
Body_RightArmUpper = Body_Start + 15,
|
||||
[InspectorName("Right Arm/Right Arm Lower")]
|
||||
Body_RightArmLower = Body_Start + 16,
|
||||
[InspectorName("Right Arm/Right Hand Wrist Twist")]
|
||||
Body_RightHandWristTwist = Body_Start + 17,
|
||||
|
||||
[InspectorName("Left Hand/Left Hand Wrist")]
|
||||
Body_LeftHandWrist = Body_Start + 18,
|
||||
[InspectorName("Left Hand/Left Hand Palm")]
|
||||
Body_LeftHandPalm = Body_Start + 19,
|
||||
[InspectorName("Left Hand/Left Hand Thumb Metacarpal")]
|
||||
Body_LeftHandThumbMetacarpal = Body_Start + 20,
|
||||
[InspectorName("Left Hand/Left Hand Thumb Proximal")]
|
||||
Body_LeftHandThumbProximal = Body_Start + 21,
|
||||
[InspectorName("Left Hand/Left Hand Thumb Distal")]
|
||||
Body_LeftHandThumbDistal = Body_Start + 22,
|
||||
[InspectorName("Left Hand/Left Hand Thumb Tip")]
|
||||
Body_LeftHandThumbTip = Body_Start + 23,
|
||||
[InspectorName("Left Hand/Left Hand Index Metacarpal")]
|
||||
Body_LeftHandIndexMetacarpal = Body_Start + 24,
|
||||
[InspectorName("Left Hand/Left Hand Index Proximal")]
|
||||
Body_LeftHandIndexProximal = Body_Start + 25,
|
||||
[InspectorName("Left Hand/Left Hand Index Intermediate")]
|
||||
Body_LeftHandIndexIntermediate = Body_Start + 26,
|
||||
[InspectorName("Left Hand/Left Hand Index Distal")]
|
||||
Body_LeftHandIndexDistal = Body_Start + 27,
|
||||
[InspectorName("Left Hand/Left Hand Index Tip")]
|
||||
Body_LeftHandIndexTip = Body_Start + 28,
|
||||
[InspectorName("Left Hand/Left Hand Middle Metacarpal")]
|
||||
Body_LeftHandMiddleMetacarpal = Body_Start + 29,
|
||||
[InspectorName("Left Hand/Left Hand Middle Proximal")]
|
||||
Body_LeftHandMiddleProximal = Body_Start + 30,
|
||||
[InspectorName("Left Hand/Left Hand Middle Intermediate")]
|
||||
Body_LeftHandMiddleIntermediate = Body_Start + 31,
|
||||
[InspectorName("Left Hand/Left Hand Middle Distal")]
|
||||
Body_LeftHandMiddleDistal = Body_Start + 32,
|
||||
[InspectorName("Left Hand/Left Hand Middle Tip")]
|
||||
Body_LeftHandMiddleTip = Body_Start + 33,
|
||||
[InspectorName("Left Hand/Left Hand Ring Metacarpal")]
|
||||
Body_LeftHandRingMetacarpal = Body_Start + 34,
|
||||
[InspectorName("Left Hand/Left Hand Ring Proximal")]
|
||||
Body_LeftHandRingProximal = Body_Start + 35,
|
||||
[InspectorName("Left Hand/Left Hand Ring Intermediate")]
|
||||
Body_LeftHandRingIntermediate = Body_Start + 36,
|
||||
[InspectorName("Left Hand/Left Hand Ring Distal")]
|
||||
Body_LeftHandRingDistal = Body_Start + 37,
|
||||
[InspectorName("Left Hand/Left Hand Ring Tip")]
|
||||
Body_LeftHandRingTip = Body_Start + 38,
|
||||
[InspectorName("Left Hand/Left Hand Little Metacarpal")]
|
||||
Body_LeftHandLittleMetacarpal = Body_Start + 39,
|
||||
[InspectorName("Left Hand/Left Hand Little Proximal")]
|
||||
Body_LeftHandLittleProximal = Body_Start + 40,
|
||||
[InspectorName("Left Hand/Left Hand Little Intermediate")]
|
||||
Body_LeftHandLittleIntermediate = Body_Start + 41,
|
||||
[InspectorName("Left Hand/Left Hand Little Distal")]
|
||||
Body_LeftHandLittleDistal = Body_Start + 42,
|
||||
[InspectorName("Left Hand/Left Hand Little Tip")]
|
||||
Body_LeftHandLittleTip = Body_Start + 43,
|
||||
|
||||
[InspectorName("Right Hand/Right Hand Wrist")]
|
||||
Body_RightHandWrist = Body_Start + 44,
|
||||
[InspectorName("Right Hand/Right Hand Palm")]
|
||||
Body_RightHandPalm = Body_Start + 45,
|
||||
[InspectorName("Right Hand/Right Hand Thumb Metacarpal")]
|
||||
Body_RightHandThumbMetacarpal = Body_Start + 46,
|
||||
[InspectorName("Right Hand/Right Hand Thumb Proximal")]
|
||||
Body_RightHandThumbProximal = Body_Start + 47,
|
||||
[InspectorName("Right Hand/Right Hand Thumb Distal")]
|
||||
Body_RightHandThumbDistal = Body_Start + 48,
|
||||
[InspectorName("Right Hand/Right Hand Thumb Tip")]
|
||||
Body_RightHandThumbTip = Body_Start + 49,
|
||||
[InspectorName("Right Hand/Right Hand Index Metacarpal")]
|
||||
Body_RightHandIndexMetacarpal = Body_Start + 50,
|
||||
[InspectorName("Right Hand/Right Hand Index Proximal")]
|
||||
Body_RightHandIndexProximal = Body_Start + 51,
|
||||
[InspectorName("Right Hand/Right Hand Index Intermediate")]
|
||||
Body_RightHandIndexIntermediate = Body_Start + 52,
|
||||
[InspectorName("Right Hand/Right Hand Index Distal")]
|
||||
Body_RightHandIndexDistal = Body_Start + 53,
|
||||
[InspectorName("Right Hand/Right Hand Index Tip")]
|
||||
Body_RightHandIndexTip = Body_Start + 54,
|
||||
[InspectorName("Right Hand/Right Hand Middle Metacarpal")]
|
||||
Body_RightHandMiddleMetacarpal = Body_Start + 55,
|
||||
[InspectorName("Right Hand/Right Hand Middle Proximal")]
|
||||
Body_RightHandMiddleProximal = Body_Start + 56,
|
||||
[InspectorName("Right Hand/Right Hand Middle Intermediate")]
|
||||
Body_RightHandMiddleIntermediate = Body_Start + 57,
|
||||
[InspectorName("Right Hand/Right Hand Middle Distal")]
|
||||
Body_RightHandMiddleDistal = Body_Start + 58,
|
||||
[InspectorName("Right Hand/Right Hand Middle Tip")]
|
||||
Body_RightHandMiddleTip = Body_Start + 59,
|
||||
[InspectorName("Right Hand/Right Hand Ring Metacarpal")]
|
||||
Body_RightHandRingMetacarpal = Body_Start + 60,
|
||||
[InspectorName("Right Hand/Right Hand Ring Proximal")]
|
||||
Body_RightHandRingProximal = Body_Start + 61,
|
||||
[InspectorName("Right Hand/Right Hand Ring Intermediate")]
|
||||
Body_RightHandRingIntermediate = Body_Start + 62,
|
||||
[InspectorName("Right Hand/Right Hand Ring Distal")]
|
||||
Body_RightHandRingDistal = Body_Start + 63,
|
||||
[InspectorName("Right Hand/Right Hand Ring Tip")]
|
||||
Body_RightHandRingTip = Body_Start + 64,
|
||||
[InspectorName("Right Hand/Right Hand Little Metacarpal")]
|
||||
Body_RightHandLittleMetacarpal = Body_Start + 65,
|
||||
[InspectorName("Right Hand/Right Hand Little Proximal")]
|
||||
Body_RightHandLittleProximal = Body_Start + 66,
|
||||
[InspectorName("Right Hand/Right Hand Little Intermediate")]
|
||||
Body_RightHandLittleIntermediate = Body_Start + 67,
|
||||
[InspectorName("Right Hand/Right Hand Little Distal")]
|
||||
Body_RightHandLittleDistal = Body_Start + 68,
|
||||
[InspectorName("Right Hand/Right Hand Little Tip")]
|
||||
Body_RightHandLittleTip = Body_Start + 69,
|
||||
[InspectorName("Body End")]
|
||||
Body_End = Body_Start + 70,
|
||||
}
|
||||
|
||||
public class ReadOnlyBodyJointPoses : IReadOnlyList<Pose>
|
||||
{
|
||||
private Pose[] _poses;
|
||||
|
||||
public ReadOnlyBodyJointPoses(Pose[] poses)
|
||||
{
|
||||
_poses = poses;
|
||||
}
|
||||
|
||||
public IEnumerator<Pose> GetEnumerator()
|
||||
{
|
||||
foreach (var pose in _poses)
|
||||
{
|
||||
yield return pose;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public static ReadOnlyBodyJointPoses Empty { get; } = new ReadOnlyBodyJointPoses(Array.Empty<Pose>());
|
||||
|
||||
public int Count => _poses.Length;
|
||||
|
||||
public Pose this[int index] => _poses[index];
|
||||
|
||||
public ref readonly Pose this[BodyJointId index] => ref _poses[(int)index];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a9ade89b75ac75740827400fcb618e09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine.Assertions;
|
||||
using Oculus.Interaction.Collections;
|
||||
|
||||
namespace Oculus.Interaction.Body.Input
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps a skeleton with joint id <see cref="TSourceJointId"/> to BodyJointId,
|
||||
/// and exposes parent/child relationships within the skeleton.
|
||||
/// </summary>
|
||||
/// <typeparam name="TSourceJointId">The enum joint type of the source skeleton</typeparam>
|
||||
public abstract class BodySkeletonMapping<TSourceJointId> : ISkeletonMapping
|
||||
where TSourceJointId : System.Enum
|
||||
{
|
||||
public IEnumerableHashSet<BodyJointId> Joints => _joints;
|
||||
|
||||
public bool TryGetParentJointId(BodyJointId jointId, out BodyJointId parentJointId)
|
||||
{
|
||||
return _jointToParent.TryGetValue(jointId, out parentJointId);
|
||||
}
|
||||
|
||||
public bool TryGetSourceJointId(BodyJointId jointId, out TSourceJointId sourceJointId)
|
||||
{
|
||||
return _reverseMap.TryGetValue(jointId, out sourceJointId);
|
||||
}
|
||||
|
||||
public bool TryGetBodyJointId(TSourceJointId jointId, out BodyJointId bodyJointId)
|
||||
{
|
||||
return _forwardMap.TryGetValue(jointId, out bodyJointId);
|
||||
}
|
||||
|
||||
protected TSourceJointId GetSourceJointFromBodyJoint(BodyJointId jointId)
|
||||
{
|
||||
return _reverseMap[jointId];
|
||||
}
|
||||
|
||||
protected BodyJointId GetBodyJointFromSourceJoint(TSourceJointId sourceJointId)
|
||||
{
|
||||
return _forwardMap[sourceJointId];
|
||||
}
|
||||
|
||||
protected abstract TSourceJointId GetRoot();
|
||||
protected abstract IReadOnlyDictionary<BodyJointId, JointInfo> GetJointMapping();
|
||||
|
||||
public BodySkeletonMapping()
|
||||
{
|
||||
_tree = new SkeletonTree(GetRoot(), GetJointMapping());
|
||||
_joints = new EnumerableHashSet<BodyJointId>(_tree.Nodes.Select(n => n.BodyJointId));
|
||||
_forwardMap = _tree.Nodes.ToDictionary((n) => n.SourceJointId, (n) => n.BodyJointId);
|
||||
_reverseMap = _tree.Nodes.ToDictionary((n) => n.BodyJointId, (n) => n.SourceJointId);
|
||||
_jointToParent = _tree.Nodes.ToDictionary((n) => n.BodyJointId, (n) => n.Parent.BodyJointId);
|
||||
}
|
||||
|
||||
private readonly SkeletonTree _tree;
|
||||
private readonly IEnumerableHashSet<BodyJointId> _joints;
|
||||
private readonly IReadOnlyDictionary<TSourceJointId, BodyJointId> _forwardMap;
|
||||
private readonly IReadOnlyDictionary<BodyJointId, TSourceJointId> _reverseMap;
|
||||
private readonly IReadOnlyDictionary<BodyJointId, BodyJointId> _jointToParent;
|
||||
|
||||
private class SkeletonTree
|
||||
{
|
||||
public readonly Node Root;
|
||||
public readonly IReadOnlyList<Node> Nodes;
|
||||
|
||||
public SkeletonTree(TSourceJointId root,
|
||||
IReadOnlyDictionary<BodyJointId, JointInfo> mapping)
|
||||
{
|
||||
Dictionary<TSourceJointId, Node> nodes = new Dictionary<TSourceJointId, Node>();
|
||||
foreach (var map in mapping)
|
||||
{
|
||||
BodyJointId jointId = map.Key;
|
||||
JointInfo jointInfo = map.Value;
|
||||
Assert.IsFalse(nodes.ContainsKey(jointInfo.SourceJointId),
|
||||
"Duplicate Joint ID in Mapping");
|
||||
nodes[jointInfo.SourceJointId] =
|
||||
new Node(jointInfo.SourceJointId, jointId);
|
||||
}
|
||||
foreach (var jointInfo in mapping.Values)
|
||||
{
|
||||
Node thisNode = nodes[jointInfo.SourceJointId];
|
||||
thisNode.Parent = nodes[jointInfo.ParentJointId];
|
||||
thisNode.Parent.Children.Add(thisNode);
|
||||
}
|
||||
Nodes = new List<Node>(nodes.Values);
|
||||
Root = nodes[root];
|
||||
}
|
||||
|
||||
public class Node
|
||||
{
|
||||
public readonly TSourceJointId SourceJointId;
|
||||
public readonly BodyJointId BodyJointId;
|
||||
|
||||
public Node Parent;
|
||||
public List<Node> Children = new List<Node>();
|
||||
|
||||
public Node(TSourceJointId sourceJointId, BodyJointId bodyJointId)
|
||||
{
|
||||
SourceJointId = sourceJointId;
|
||||
BodyJointId = bodyJointId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected readonly struct JointInfo
|
||||
{
|
||||
public readonly TSourceJointId SourceJointId;
|
||||
public readonly TSourceJointId ParentJointId;
|
||||
|
||||
public JointInfo(
|
||||
TSourceJointId sourceJointId,
|
||||
TSourceJointId parentJointId)
|
||||
{
|
||||
SourceJointId = sourceJointId;
|
||||
ParentJointId = parentJointId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0163dd25f6c25141bbe3c5b18171c50
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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 UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Oculus.Interaction.Body.Input
|
||||
{
|
||||
public interface IBody
|
||||
{
|
||||
/// <summary>
|
||||
/// The mapping for this body, which allows querying of the supported joint set
|
||||
/// of the skeleton as well as joint parent/child relationship.
|
||||
/// </summary>
|
||||
ISkeletonMapping SkeletonMapping { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the body connected and tracked
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The body is connected and tracked, and the root pose's tracking data is marked as
|
||||
/// high confidence.
|
||||
/// If this is true, then it implies that <see cref="IsConnected"/> is also true,
|
||||
/// so they don't need to be checked in addition to this.
|
||||
/// </summary>
|
||||
bool IsHighConfidence { get; }
|
||||
|
||||
/// <summary>
|
||||
/// True if the body is currently tracked, thus tracking poses are available for the body
|
||||
/// root and joints.
|
||||
/// </summary>
|
||||
bool IsTrackedDataValid { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The scale of the body skeleton applied to world joint poses.
|
||||
/// </summary>
|
||||
float Scale { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the root pose of the body, in world space.
|
||||
/// Will return true if a pose was available; false otherwise.
|
||||
/// Confidence level of the pose is exposed via <see cref="IsHighConfidence"/>.
|
||||
/// </summary>
|
||||
bool GetRootPose(out Pose pose);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to calculate the pose of the requested body joint, in world space.
|
||||
/// Returns false if the skeleton is not yet initialized, or there is no valid
|
||||
/// tracking data. Scale is applied to this joint position.
|
||||
/// </summary>
|
||||
bool GetJointPose(BodyJointId bodyJointId, out Pose pose);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to calculate the pose of the requested body joint, in local space
|
||||
/// to its parent joint. Returns false if the skeleton is not yet initialized,
|
||||
/// or there is no valid tracking data. Scale is not applied.
|
||||
/// </summary>
|
||||
bool GetJointPoseLocal(BodyJointId bodyJointId, out Pose pose);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to calculate the pose of the requested hand joint relative to the root.
|
||||
/// Returns false if the skeleton is not yet initialized, or there is no valid
|
||||
/// tracking data. Scale is not applied.
|
||||
/// </summary>
|
||||
bool GetJointPoseFromRoot(BodyJointId bodyJointId, out Pose pose);
|
||||
|
||||
/// <summary>
|
||||
/// Incremented every time the source tracking or state data changes.
|
||||
/// </summary>
|
||||
int CurrentDataVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Called each time the body is updated with new data
|
||||
/// </summary>
|
||||
event Action WhenBodyUpdated;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f35e83192bb091044bae08a796e8858d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.Collections;
|
||||
|
||||
namespace Oculus.Interaction.Body.Input
|
||||
{
|
||||
public interface ISkeletonMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// The set of <see cref="BodyJointId"/>s supported by this skeleton
|
||||
/// </summary>
|
||||
IEnumerableHashSet<BodyJointId> Joints { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the parent joint for a given body joint
|
||||
/// </summary>
|
||||
/// <param name="jointId">The joint to fetch the parent for</param>
|
||||
/// <param name="parent">The parent joint</param>
|
||||
/// <returns>True if parent could be retrieved</returns>
|
||||
bool TryGetParentJointId(BodyJointId jointId, out BodyJointId parent);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65f8c7ef36409cb40a43b76f21309db3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user