Initialer Upload neues Unity-Projekt

This commit is contained in:
Daniel Ocks
2025-07-21 09:11:14 +02:00
commit eeca72985b
14558 changed files with 1508140 additions and 0 deletions

View File

@ -0,0 +1,137 @@
/*
* 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 Oculus.Interaction.Body.Input;
using UnityEngine.Assertions;
namespace Oculus.Interaction.Body
{
public class BodyDebugGizmos : SkeletonDebugGizmos
{
public enum CoordSpace
{
World,
Local,
}
[SerializeField, Interface(typeof(IBody))]
private UnityEngine.Object _body;
private IBody Body;
[Tooltip("The coordinate space in which to draw the skeleton. " +
"World space draws the skeleton at the world Body location. " +
"Local draws the skeleton relative to this transform.")]
[SerializeField]
private CoordSpace _space = CoordSpace.World;
public CoordSpace Space
{
get => _space;
set => _space = value;
}
protected bool _started = false;
protected virtual void Awake()
{
Body = _body as IBody;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
Assert.IsNotNull(Body);
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Body.WhenBodyUpdated += HandleBodyUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Body.WhenBodyUpdated -= HandleBodyUpdated;
}
}
protected override bool TryGetWorldJointPose(BodyJointId jointId, out Pose pose)
{
bool result;
switch (_space)
{
default:
case CoordSpace.World:
result = Body.GetJointPose(jointId, out pose);
break;
case CoordSpace.Local:
result = Body.GetJointPoseFromRoot(jointId, out pose);
pose.position = transform.TransformPoint(pose.position);
pose.rotation = transform.rotation * pose.rotation;
break;
}
return result;
}
protected override bool TryGetParentJointId(BodyJointId jointId, out BodyJointId parent)
{
return Body.SkeletonMapping.TryGetParentJointId(jointId, out parent);
}
private VisibilityFlags GetModifiedDrawFlags()
{
VisibilityFlags modifiedFlags = Visibility;
if (HasNegativeScale && Space == CoordSpace.Local)
{
modifiedFlags &= ~VisibilityFlags.Axes;
}
return modifiedFlags;
}
private void HandleBodyUpdated()
{
foreach (BodyJointId joint in Body.SkeletonMapping.Joints)
{
Draw(joint, GetModifiedDrawFlags());
}
}
#region Inject
public void InjectAllBodyJointDebugGizmos(IBody body)
{
InjectBody(body);
}
public void InjectBody(IBody body)
{
_body = body as UnityEngine.Object;
Body = body;
}
#endregion
}
}

View File

@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 3f90df98d80579a4eb0b25852e0f6758
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- _body: {instanceID: 0}
- _debugPrefab: {fileID: 1332877395996002986, guid: d1ed0fc8d54eb1e4283a76baf1e42b1d,
type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 080ee45c4ae29f847a3919f73fbc0df6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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();
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 55afe974697276a46949c30d6d15f347
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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];
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3341c364a9e73724bbd5f1f56e1f2bbc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f3c3dce4531a44741a6120d58ae02113
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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];
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a9ade89b75ac75740827400fcb618e09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c0163dd25f6c25141bbe3c5b18171c50
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f35e83192bb091044bae08a796e8858d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 65f8c7ef36409cb40a43b76f21309db3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 458a8f64bd4fde84a85ac79b6cb254eb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,199 @@
/*
* 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.Generic;
using UnityEngine;
using Oculus.Interaction.Body.Input;
namespace Oculus.Interaction.Body.PoseDetection
{
/// <summary>
/// Compares a user-provided set of joints between two Body Poses.
/// </summary>
public class BodyPoseComparerActiveState :
MonoBehaviour, IActiveState
{
public struct BodyPoseComparerFeatureState
{
public readonly float Delta;
public readonly float MaxDelta;
public BodyPoseComparerFeatureState(float delta, float maxDelta)
{
Delta = delta;
MaxDelta = maxDelta;
}
}
[Serializable]
public class JointComparerConfig
{
[Tooltip("The joint to compare from each Body Pose")]
public BodyJointId Joint = BodyJointId.Body_Head;
[Min(0)]
[Tooltip("The maximum angle that two joint rotations " +
"can be from each other to be considered equal.")]
public float MaxDelta = 30f;
[Tooltip("The width of the threshold when transitioning " +
"states. " + nameof(Width) + " / 2 is added to " +
nameof(MaxDelta) + " when leaving Active state, and " +
"subtracted when entering.")]
[Min(0)]
public float Width = 4f;
}
[Tooltip("The first body pose to compare.")]
[SerializeField, Interface(typeof(IBodyPose))]
private UnityEngine.Object _poseA;
private IBodyPose PoseA;
[Tooltip("The second body pose to compare.")]
[SerializeField, Interface(typeof(IBodyPose))]
private UnityEngine.Object _poseB;
private IBodyPose PoseB;
[SerializeField]
private List<JointComparerConfig> _configs =
new List<JointComparerConfig>()
{
new JointComparerConfig()
};
[Tooltip("A new state must be maintaned for at least this " +
"many seconds before the Active property changes.")]
[SerializeField]
private float _minTimeInState = 0.05f;
public float MinTimeInState
{
get => _minTimeInState;
set => _minTimeInState = value;
}
public IReadOnlyDictionary<JointComparerConfig, BodyPoseComparerFeatureState> FeatureStates =>
_featureStates;
private Dictionary<JointComparerConfig, BodyPoseComparerFeatureState> _featureStates =
new Dictionary<JointComparerConfig, BodyPoseComparerFeatureState>();
private Func<float> _timeProvider;
private bool _isActive;
private bool _internalActive;
private float _lastStateChangeTime;
protected virtual void Awake()
{
PoseA = _poseA as IBodyPose;
PoseB = _poseB as IBodyPose;
_timeProvider = () => Time.time;
}
protected virtual void Start()
{
this.AssertField(PoseA, nameof(PoseA));
this.AssertField(PoseB, nameof(PoseB));
}
public bool Active
{
get
{
if (!isActiveAndEnabled)
{
return false;
}
bool wasActive = _internalActive;
_internalActive = true;
foreach (var config in _configs)
{
float maxDelta = wasActive ?
config.MaxDelta + config.Width / 2f :
config.MaxDelta - config.Width / 2f;
bool withinDelta = GetJointDelta(config.Joint, out float delta) &&
Mathf.Abs(delta) <= maxDelta;
_featureStates[config] = new BodyPoseComparerFeatureState(delta, maxDelta);
_internalActive &= withinDelta;
}
float time = _timeProvider();
if (wasActive != _internalActive)
{
_lastStateChangeTime = time;
}
if (time - _lastStateChangeTime >= _minTimeInState)
{
_isActive = _internalActive;
}
return _isActive;
}
}
private bool GetJointDelta(BodyJointId joint, out float delta)
{
if (!PoseA.GetJointPoseLocal(joint, out Pose localA) ||
!PoseB.GetJointPoseLocal(joint, out Pose localB))
{
delta = 0;
return false;
}
delta = Quaternion.Angle(localA.rotation, localB.rotation);
return true;
}
#region Inject
public void InjectAllBodyPoseComparerActiveState(
IBodyPose poseA, IBodyPose poseB,
IEnumerable<JointComparerConfig> configs)
{
InjectPoseA(poseA);
InjectPoseB(poseB);
InjectJoints(configs);
}
public void InjectPoseA(IBodyPose poseA)
{
_poseA = poseA as UnityEngine.Object;
PoseA = poseA;
}
public void InjectPoseB(IBodyPose poseB)
{
_poseB = poseB as UnityEngine.Object;
PoseB = poseB;
}
public void InjectJoints(IEnumerable<JointComparerConfig> configs)
{
_configs = new List<JointComparerConfig>(configs);
}
public void InjectOptionalTimeProvider(Func<float> timeProvider)
{
_timeProvider = timeProvider;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ebf7b9e4cfb7d2e4aa5a2dccb5ee7d0f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,131 @@
/*
* 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.Body.Input;
using UnityEngine;
namespace Oculus.Interaction.Body.PoseDetection
{
public class BodyPoseComparerActiveStateDebugVisual : MonoBehaviour
{
[Tooltip("The PoseComparer to debug.")]
[SerializeField]
private BodyPoseComparerActiveState _bodyPoseComparer;
[Tooltip("Gizmos will be drawn at joint positions of this body pose.")]
[SerializeField, Interface(typeof(IBodyPose))]
private UnityEngine.Object _bodyPose;
private IBodyPose BodyPose;
[Tooltip("The root transform of the body skeleton. Debug " +
"gizmos will be drawn in the local space of this transform.")]
[SerializeField]
private Transform _root;
[Tooltip("The radius of the debug spheres.")]
[SerializeField, Delayed]
private float _radius = 0.1f;
public float Radius
{
get => _radius;
set => _radius = value;
}
protected virtual void Awake()
{
BodyPose = _bodyPose as IBodyPose;
}
protected virtual void Start()
{
this.AssertField(_bodyPoseComparer, nameof(_bodyPoseComparer));
this.AssertField(BodyPose, nameof(BodyPose));
this.AssertField(_root, nameof(BodyPose));
}
protected virtual void Update()
{
DrawJointSpheres();
}
private void DrawJointSpheres()
{
var featureStates = _bodyPoseComparer.FeatureStates;
foreach (var kvp in featureStates)
{
BodyJointId joint = kvp.Key.Joint;
var state = kvp.Value;
if (BodyPose.GetJointPoseFromRoot(joint, out Pose pose))
{
Vector3 jointPos = _root.TransformPoint(pose.position);
Color color;
if (state.Delta <= state.MaxDelta)
{
color = Color.green;
}
else if (state.MaxDelta > 0)
{
float amt = (state.Delta / state.MaxDelta) / 2f;
color = Color.Lerp(Color.yellow, Color.red, amt);
}
else
{
color = Color.red;
}
DebugGizmos.LineWidth = _radius / 2f;
DebugGizmos.Color = color;
DebugGizmos.DrawPoint(jointPos);
}
}
}
#region Inject
public void InjectAllBodyPoseComparerActiveStateDebugVisual(
BodyPoseComparerActiveState bodyPoseComparer,
IBodyPose bodyPose, Transform root)
{
InjectBodyPoseComparer(bodyPoseComparer);
InjectBodyPose(bodyPose);
InjectRootTransform(root);
}
public void InjectRootTransform(Transform root)
{
_root = root;
}
public void InjectBodyPoseComparer(BodyPoseComparerActiveState bodyPoseComparer)
{
_bodyPoseComparer = bodyPoseComparer;
}
public void InjectBodyPose(IBodyPose bodyPose)
{
_bodyPose = bodyPose as UnityEngine.Object;
BodyPose = bodyPose;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9faf130193937b348be91e09c530a810
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,128 @@
/*
* 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 UnityEngine;
using Oculus.Interaction.Body.Input;
using System;
using Oculus.Interaction.Collections;
namespace Oculus.Interaction.Body.PoseDetection
{
[CreateAssetMenu(menuName = "Oculus/Interaction/SDK/Pose Detection/Body Pose")]
public class BodyPoseData : ScriptableObject,
IBodyPose, ISerializationCallbackReceiver
{
[System.Serializable]
private struct JointData
{
public BodyJointId JointId;
public BodyJointId ParentId;
public Pose PoseFromRoot;
public Pose LocalPose;
}
private class Mapping : ISkeletonMapping
{
public EnumerableHashSet<BodyJointId> Joints =
new EnumerableHashSet<BodyJointId>();
public Dictionary<BodyJointId, BodyJointId> JointToParent =
new Dictionary<BodyJointId, BodyJointId>();
IEnumerableHashSet<BodyJointId> ISkeletonMapping.Joints => Joints;
bool ISkeletonMapping.TryGetParentJointId(BodyJointId jointId, out BodyJointId parent) =>
JointToParent.TryGetValue(jointId, out parent);
}
public event Action WhenBodyPoseUpdated = delegate { };
[SerializeField, HideInInspector]
private List<JointData> _jointData = new List<JointData>();
private Dictionary<BodyJointId, Pose> _posesFromRoot =
new Dictionary<BodyJointId, Pose>();
private Dictionary<BodyJointId, Pose> _localPoses =
new Dictionary<BodyJointId, Pose>();
private Mapping _mapping = new Mapping();
public bool GetJointPoseFromRoot(BodyJointId bodyJointId, out Pose pose) =>
_posesFromRoot.TryGetValue(bodyJointId, out pose);
public bool GetJointPoseLocal(BodyJointId bodyJointId, out Pose pose) =>
_localPoses.TryGetValue(bodyJointId, out pose);
public ISkeletonMapping SkeletonMapping => _mapping;
public void SetBodyPose(IBody body)
{
_jointData.Clear();
foreach (var joint in body.SkeletonMapping.Joints)
{
if (body.GetJointPoseLocal(joint, out Pose local) &&
body.GetJointPoseFromRoot(joint, out Pose fromRoot) &&
body.SkeletonMapping.TryGetParentJointId(joint, out BodyJointId parent))
{
_jointData.Add(new JointData()
{
JointId = joint,
ParentId = parent,
PoseFromRoot = fromRoot,
LocalPose = local,
});
}
}
Rebuild();
WhenBodyPoseUpdated.Invoke();
}
public void OnBeforeSerialize()
{
}
public void OnAfterDeserialize()
{
Rebuild();
}
private void Rebuild()
{
_localPoses.Clear();
_posesFromRoot.Clear();
_mapping.Joints.Clear();
_mapping.JointToParent.Clear();
for (int i = 0; i < _jointData.Count; ++i)
{
_localPoses[_jointData[i].JointId] =
_jointData[i].LocalPose;
_posesFromRoot[_jointData[i].JointId] =
_jointData[i].PoseFromRoot;
_mapping.Joints.Add(
_jointData[i].JointId);
_mapping.JointToParent.Add(
_jointData[i].JointId, _jointData[i].ParentId);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 55ca4a17febb5bb4084ecb9e8cd230cc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,92 @@
/*
* 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 Oculus.Interaction.Body.Input;
using UnityEngine.Assertions;
namespace Oculus.Interaction.Body.PoseDetection
{
public class BodyPoseDebugGizmos : SkeletonDebugGizmos
{
[SerializeField, Interface(typeof(IBodyPose))]
private UnityEngine.Object _bodyPose;
private IBodyPose BodyPose;
protected virtual void Awake()
{
BodyPose = _bodyPose as IBodyPose;
}
protected virtual void Start()
{
Assert.IsNotNull(BodyPose);
}
protected virtual void Update()
{
foreach (BodyJointId joint in BodyPose.SkeletonMapping.Joints)
{
Draw(joint, GetVisibilityFlags());
}
}
private VisibilityFlags GetVisibilityFlags()
{
VisibilityFlags modifiedFlags = Visibility;
if (HasNegativeScale)
{
modifiedFlags &= ~VisibilityFlags.Axes;
}
return modifiedFlags;
}
protected override bool TryGetWorldJointPose(BodyJointId jointId, out Pose pose)
{
if (BodyPose.GetJointPoseFromRoot(jointId, out pose))
{
pose.position = transform.TransformPoint(pose.position);
pose.rotation = transform.rotation * pose.rotation;
return true;
}
return false;
}
protected override bool TryGetParentJointId(BodyJointId jointId, out BodyJointId parent)
{
return BodyPose.SkeletonMapping.TryGetParentJointId(jointId, out parent);
}
#region Inject
public void InjectAllBodyJointDebugGizmos(IBodyPose bodyPose)
{
InjectBodyPose(bodyPose);
}
public void InjectBodyPose(IBodyPose bodyPose)
{
_bodyPose = bodyPose as UnityEngine.Object;
BodyPose = bodyPose;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: feb0f50b1a0593647b5de2d2b20029a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,51 @@
/*
* 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 UnityEngine;
using Oculus.Interaction.Body.Input;
namespace Oculus.Interaction.Body.PoseDetection
{
public interface IBodyPose
{
/// <summary>
/// Called each time the body pose is updated with new data
/// </summary>
event Action WhenBodyPoseUpdated;
/// <summary>
/// The mapping of the skeleton
/// </summary>
ISkeletonMapping SkeletonMapping { get; }
/// <summary>
/// Attempts to return the pose of the requested body joint,
/// in local space relative to its parent joint.
/// </summary>
bool GetJointPoseLocal(BodyJointId bodyJointId, out Pose pose);
/// <summary>
/// Attempts to return the pose of the requested body joint relative
/// to the root joint <see cref="BodyJointId.Body_Root"/>.
/// </summary>
bool GetJointPoseFromRoot(BodyJointId bodyJointId, out Pose pose);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d2eac04d5eb0c554bbbdcdcb2df831c2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,145 @@
/*
* 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 UnityEngine;
using Oculus.Interaction.Body.Input;
using System.Collections.Generic;
namespace Oculus.Interaction.Body.PoseDetection
{
/// <summary>
/// Exposes an <see cref="IBodyPose"/> from an <see cref="IBody"/>
/// </summary>
public class PoseFromBody : MonoBehaviour, IBodyPose
{
public event Action WhenBodyPoseUpdated = delegate { };
[Tooltip("The IBodyPose will be derived from this IBody.")]
[SerializeField, Interface(typeof(IBody))]
private UnityEngine.Object _body;
private IBody Body;
[Tooltip("If true, this component will track the provided IBody as " +
"its data is updated. If false, you must call " +
nameof(UpdatePose) + " to update joint data.")]
[SerializeField]
private bool _autoUpdate = true;
/// <summary>
/// If true, this component will track the provided IBody as
/// its data is updated. If false, you must call
/// <see cref="UpdatePose"/> to update joint data.
/// </summary>
public bool AutoUpdate
{
get => _autoUpdate;
set => _autoUpdate = value;
}
protected bool _started = false;
private Dictionary<BodyJointId, Pose> _jointPosesLocal;
private Dictionary<BodyJointId, Pose> _jointPosesFromRoot;
public ISkeletonMapping SkeletonMapping => Body.SkeletonMapping;
public bool GetJointPoseLocal(BodyJointId bodyJointId, out Pose pose) =>
_jointPosesLocal.TryGetValue(bodyJointId, out pose);
public bool GetJointPoseFromRoot(BodyJointId bodyJointId, out Pose pose) =>
_jointPosesFromRoot.TryGetValue(bodyJointId, out pose);
protected virtual void Awake()
{
_jointPosesLocal = new Dictionary<BodyJointId, Pose>();
_jointPosesFromRoot = new Dictionary<BodyJointId, Pose>();
Body = _body as IBody;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Body, nameof(Body));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Body.WhenBodyUpdated += Body_WhenBodyUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Body.WhenBodyUpdated -= Body_WhenBodyUpdated;
}
}
private void Body_WhenBodyUpdated()
{
if (_autoUpdate)
{
UpdatePose();
}
}
public void UpdatePose()
{
_jointPosesLocal.Clear();
_jointPosesFromRoot.Clear();
foreach (var joint in Body.SkeletonMapping.Joints)
{
if (Body.GetJointPoseLocal(joint,
out Pose localPose))
{
_jointPosesLocal[joint] = localPose;
}
if (Body.GetJointPoseFromRoot(joint,
out Pose poseFromRoot))
{
_jointPosesFromRoot[joint] = poseFromRoot;
}
}
WhenBodyPoseUpdated.Invoke();
}
#region Inject
public void InjectAllPoseFromBody(IBody body)
{
InjectBody(body);
}
public void InjectBody(IBody body)
{
_body = body as UnityEngine.Object;
Body = body;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f2be7e1a3256ca942865ee433ce9e3e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,114 @@
/*
* 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 Oculus.Interaction.Body.Input;
namespace Oculus.Interaction.Body
{
public abstract class SkeletonDebugGizmos : MonoBehaviour
{
[System.Flags]
public enum VisibilityFlags
{
Joints = 1 << 0,
Axes = 1 << 1,
Bones = 1 << 2,
}
[Tooltip("Which components of the skeleton will be visualized.")]
[SerializeField]
private VisibilityFlags _visibility =
VisibilityFlags.Axes | VisibilityFlags.Joints;
[Tooltip("The joint debug spheres will be drawn with this color.")]
[SerializeField]
private Color _jointColor = Color.white;
[Tooltip("The bone connecting lines will be drawn with this color.")]
[SerializeField]
private Color _boneColor = Color.gray;
[Tooltip("The radius of the joint spheres and the thickness " +
"of the bone and axis lines.")]
[SerializeField]
private float _radius = 0.02f;
public float Radius
{
get => _radius;
set => _radius = value;
}
public VisibilityFlags Visibility
{
get => _visibility;
set => _visibility = value;
}
public Color JointColor
{
get => _jointColor;
set => _jointColor = value;
}
public Color BoneColor
{
get => _boneColor;
set => _boneColor = value;
}
private float LineWidth => _radius / 2f;
protected abstract bool TryGetWorldJointPose(BodyJointId jointId, out Pose pose);
protected abstract bool TryGetParentJointId(BodyJointId jointId, out BodyJointId parent);
protected bool HasNegativeScale => transform.lossyScale.x < 0 ||
transform.lossyScale.y < 0 ||
transform.lossyScale.z < 0;
protected void Draw(BodyJointId joint, VisibilityFlags visibility)
{
if (TryGetWorldJointPose(joint, out Pose pose))
{
if (visibility.HasFlag(VisibilityFlags.Axes))
{
DebugGizmos.LineWidth = LineWidth;
DebugGizmos.DrawAxis(pose, _radius);
}
if (visibility.HasFlag(VisibilityFlags.Joints))
{
DebugGizmos.Color = _jointColor;
DebugGizmos.LineWidth = _radius;
DebugGizmos.DrawPoint(pose.position);
}
if (visibility.HasFlag(VisibilityFlags.Bones) &&
TryGetParentJointId(joint, out BodyJointId parent) &&
TryGetWorldJointPose(parent, out Pose parentPose))
{
DebugGizmos.Color = _boneColor;
DebugGizmos.LineWidth = LineWidth;
DebugGizmos.DrawLine(pose.position, parentPose.position);
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 179ced13df8b20443aaf9b57fdee24ee
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: