Skip to content

Commit 2485947

Browse files
committed
[Automated] Merged dev into main
2 parents c396ef0 + 2df44ee commit 2485947

File tree

524 files changed

+140553
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

524 files changed

+140553
-21
lines changed

Editor/Utils/ScriptableObjectMenus.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ internal static class ScriptableObjectMenus
1717
private const string _SAVE_HUMANOID_REFERENCE_POSE =
1818
"Save Humanoid Reference Pose";
1919

20+
private const string _SAVE_CUSTOM_HUMANOID_REFERENCE_POSE =
21+
"Save Custom Humanoid Reference Pose";
22+
2023
private const string _MOVEMENT_SCRIPTABLE_OBJECTS_DIRECTORY =
2124
"MovementSDKSampleScriptableObjects";
2225

2326
private const string _HUMANOID_REFERENCE_POSE_ASSET_NAME_SUFFIX =
2427
"_HumanoidReferencePose.asset";
2528

29+
private const string _CUSTOM_HUMANOID_REFERENCE_POSE_ASSET_NAME_SUFFIX =
30+
"_CustomBindPose.asset";
31+
2632
[MenuItem(_MOVEMENT_SAMPLES_MENU + _SCRIPTABLE_OBJECTS_MENU + _SAVE_HUMANOID_REFERENCE_POSE)]
2733
private static void SaveHumanoidReferencePose()
2834
{
@@ -64,5 +70,46 @@ private static void SaveHumanoidReferencePose()
6470
Debug.LogError($"Failed to save humanoid reference pose, reason: {exception}.");
6571
}
6672
}
73+
74+
[MenuItem(_MOVEMENT_SAMPLES_MENU + _SCRIPTABLE_OBJECTS_MENU + _SAVE_CUSTOM_HUMANOID_REFERENCE_POSE)]
75+
private static void SaveCustomHumanoidReferencePose()
76+
{
77+
try
78+
{
79+
var activeGameObject = Selection.activeGameObject;
80+
var activeObjectAnimator = activeGameObject.GetComponent<Animator>();
81+
if (activeObjectAnimator == null)
82+
{
83+
throw new Exception($"Cannot create custom humanoid reference pose if {activeGameObject} " +
84+
"does not have an animator");
85+
}
86+
87+
var poseDataAsset = ScriptableObject.CreateInstance<BindPoseObjectSkeleton>();
88+
89+
string parentDirectory = Path.Combine("Assets", _MOVEMENT_SCRIPTABLE_OBJECTS_DIRECTORY);
90+
if (!Directory.Exists(parentDirectory))
91+
{
92+
Directory.CreateDirectory(parentDirectory);
93+
}
94+
95+
string selectedObjectName = activeGameObject.name;
96+
var assetPath = Path.Combine(parentDirectory,
97+
$"{selectedObjectName}{_CUSTOM_HUMANOID_REFERENCE_POSE_ASSET_NAME_SUFFIX}");
98+
99+
if (File.Exists(assetPath))
100+
{
101+
Debug.LogWarning($"{assetPath} already exists. Will overwrite it.");
102+
}
103+
104+
AssetDatabase.CreateAsset(poseDataAsset, assetPath);
105+
AssetDatabase.SaveAssets();
106+
AssetDatabase.Refresh();
107+
Debug.Log($"Saved reference pose as {assetPath}.");
108+
}
109+
catch (Exception exception)
110+
{
111+
Debug.LogError($"Failed to save custom humanoid reference pose, reason: {exception}.");
112+
}
113+
}
67114
}
68115
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ The Unity-Movement package is released under the [Oculus License](https://github
99
- 2021.3.26f1 (2021 LTS or newer)
1010
- 2022.3.11f2 (2022 LTS or newer)
1111
- 2023.2.7f1 or newer
12-
- v63.0 or newer of the Meta XR SDK. You will need the Meta XR Core SDK and the [Meta XR Interaction SDK OVR Integration](https://assetstore.unity.com/packages/tools/integration/meta-xr-interaction-sdk-ovr-integration-265014) packages found [on this page](https://assetstore.unity.com/publishers/25353).
13-
- A project set up with these [configuration settings](https://developer.oculus.com/documentation/unity/unity-conf-settings/)
12+
- v67.0 or newer of the Meta XR SDK. You will need the [Meta XR Core SDK](https://assetstore.unity.com/packages/tools/integration/meta-xr-core-sdk-269169) and the [Meta XR Interaction SDK](https://assetstore.unity.com/packages/tools/integration/meta-xr-interaction-sdk-265014) packages found [on this page](https://assetstore.unity.com/publishers/25353).
13+
- A project set up with these [steps](https://developer.oculus.com/documentation/unity/move-overview/#unity-project-setup).
1414

1515
## Getting Started
1616
First, ensure that all of the [requirements](#requirements) are met.

Runtime/Scripts/AnimationRigging/RetargetingLayer.cs

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using Oculus.Interaction;
44
using Oculus.Movement.AnimationRigging.Utils;
5+
using Oculus.Movement.Utils;
56
using System;
67
using System.Collections.Generic;
78
using System.IO;
@@ -192,6 +193,19 @@ public RetargetedBoneMappings RetargetedBoneMappingsInst
192193
set => _retargetedBoneMappings = value;
193194
}
194195

196+
/// <summary>
197+
/// The custom bind pose that can be used to modify the current bind pose.
198+
/// </summary>
199+
[SerializeField]
200+
[Tooltip(RetargetingLayerTooltips.CustomBindPose)]
201+
protected BindPoseObjectSkeleton _customBindPose;
202+
/// <inheritdoc cref="_customBindPose"/>
203+
public BindPoseObjectSkeleton CustomBindPose
204+
{
205+
get => _customBindPose;
206+
set => _customBindPose = value;
207+
}
208+
195209
/// <summary>
196210
/// Exposes a button used to update bone pair mappings based on the humanoid.
197211
/// </summary>
@@ -309,6 +323,67 @@ protected override void Start()
309323
}
310324
}
311325

326+
/// <summary>
327+
/// Initializes the custom bind pose if set.
328+
/// </summary>
329+
protected override void InitializeBindPose()
330+
{
331+
base.InitializeBindPose();
332+
333+
if (_customBindPose == null)
334+
{
335+
return;
336+
}
337+
338+
BoneId[] boneIds =
339+
{
340+
BoneId.FullBody_SpineLower,
341+
BoneId.FullBody_SpineMiddle,
342+
BoneId.FullBody_SpineUpper,
343+
BoneId.FullBody_Chest,
344+
BoneId.FullBody_Neck,
345+
BoneId.FullBody_Head,
346+
BoneId.FullBody_LeftShoulder,
347+
BoneId.FullBody_RightShoulder,
348+
BoneId.FullBody_LeftArmUpper,
349+
BoneId.FullBody_RightArmUpper,
350+
};
351+
BoneId[] parentBoneIds = {
352+
BoneId.FullBody_Hips,
353+
BoneId.FullBody_SpineLower,
354+
BoneId.FullBody_SpineMiddle,
355+
BoneId.FullBody_SpineUpper,
356+
BoneId.FullBody_Chest,
357+
BoneId.FullBody_Neck,
358+
BoneId.FullBody_Chest,
359+
BoneId.FullBody_Chest,
360+
BoneId.FullBody_LeftShoulder,
361+
BoneId.FullBody_RightShoulder,
362+
};
363+
for (var i = 0; i < boneIds.Length; i++)
364+
{
365+
var targetBoneId = boneIds[i];
366+
var parentBoneId = parentBoneIds[i];
367+
var targetPose =
368+
_customBindPose.GetBonePoseData((OVRHumanBodyBonesMappings.FullBodyTrackingBoneId)targetBoneId);
369+
if (targetPose == null)
370+
{
371+
continue;
372+
}
373+
374+
var targetBone = BindPoses[(int)targetBoneId].Transform;
375+
var parentBone = BindPoses[(int)parentBoneId].Transform;
376+
var direction = BindPoses[(int)targetBoneId].Transform.localPosition -
377+
BindPoses[(int)parentBoneId].Transform.localPosition;
378+
targetBone.localPosition = parentBone.localPosition + targetPose.DeltaRot * direction;
379+
if (targetPose.AdjustmentRot.eulerAngles.sqrMagnitude > float.Epsilon)
380+
{
381+
parentBone.localRotation *= targetPose.AdjustmentRot;
382+
}
383+
}
384+
ComputeOffsetsUsingSkeletonComponent();
385+
}
386+
312387
private void CaptureTransformInformationHipsUpwards(Transform currentTransform)
313388
{
314389
// Avoid going to topmost transform (the character). We want to ignore any rotations
@@ -584,7 +659,7 @@ private void ResetBoneTransformationsHipsUpwards(Transform currentTransform)
584659
/// <summary>
585660
/// Empty fixed update to avoid updating OVRSkeleton during fixed update.
586661
/// </summary>
587-
private void FixedUpdate()
662+
private new void FixedUpdate()
588663
{
589664
}
590665

Runtime/Scripts/Effects/NormalRecalculation/RecalculateNormals.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void Awake()
126126
_instantiatedMaterials = _skinnedMeshRenderer.materials;
127127
foreach (var recalculateMaterialIndex in _recalculateMaterialIndices)
128128
{
129-
Assert.IsTrue(recalculateMaterialIndex < _recalculateMaterialIndices.Length);
129+
Assert.IsTrue(recalculateMaterialIndex < _instantiatedMaterials.Length);
130130
_recalculateMaterials.Add(_instantiatedMaterials[recalculateMaterialIndex]);
131131
}
132132

Runtime/Scripts/Tooltips.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,9 @@ public static class RetargetingLayerTooltips
14211421
public const string RetargetedBoneMappings =
14221422
"Retargeted bone mappings to be updated based on valid bones in the humanoid.";
14231423

1424+
public const string CustomBindPose =
1425+
"The custom bind pose that can be used to modify the current bind pose.";
1426+
14241427
public const string FingerPositionCorrectionWeight =
14251428
"Finger position correction weight.";
14261429

Runtime/Scripts/Tracking/FaceTrackingData/ARKitFace.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// Copyright (c) Meta Platforms, Inc. and affiliates.
22

3-
using UnityEngine;
4-
53
namespace Oculus.Movement.Tracking
64
{
75
/// <summary>
86
/// Version of Correctives mapped to ARKit blend shapes,
97
/// via "custom" mapping.
108
/// </summary>
11-
public class ARKitFace : CorrectivesFace, ISerializationCallbackReceiver
9+
public class ARKitFace : CorrectivesFace
1210
{
1311
private static (string, OVRFaceExpressions.FaceExpression)[] ARKitBlendshapesSorted =
1412
{
@@ -82,19 +80,5 @@ protected override (string[], OVRFaceExpressions.FaceExpression[]) GetCustomBlen
8280
}
8381
return (arKitBlendShapeNames, arKitFaceExpressions);
8482
}
85-
86-
public void OnBeforeSerialize()
87-
{
88-
if (RetargetingValue != RetargetingType.Custom)
89-
{
90-
Debug.LogError($"Please use {nameof(RetargetingType.Custom)} with ARKitFace; " +
91-
$"other values will not work. Reverting change.");
92-
RetargetingValue = RetargetingType.Custom;
93-
}
94-
}
95-
96-
public void OnAfterDeserialize()
97-
{
98-
}
9983
}
10084
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using UnityEngine;
6+
using static OVRUnityHumanoidSkeletonRetargeter.OVRHumanBodyBonesMappings;
7+
8+
namespace Oculus.Movement.Utils
9+
{
10+
/// <summary>
11+
/// Scriptable object that contains custom bind pose information that can be applied
12+
/// onto a bind pose to configure a custom bind pose. This can be used to fix artifacts
13+
/// that are a result of retargeting and deformation.
14+
/// </summary>
15+
public class BindPoseObjectSkeleton : ScriptableObject
16+
{
17+
/// <summary>
18+
/// Holds delta pose information for each bone.
19+
/// </summary>
20+
[Serializable]
21+
public class BonePoseData
22+
{
23+
/// <summary>
24+
/// Constructor for BonePoseData, taking in a bone transform and comparing it against
25+
/// the target transform to store delta information.
26+
/// </summary>
27+
/// <param name="boneTransform"></param>
28+
/// <param name="targetTransform"></param>
29+
/// <param name="boneId"></param>
30+
public BonePoseData(
31+
Transform boneTransform,
32+
Transform targetTransform,
33+
FullBodyTrackingBoneId boneId)
34+
{
35+
var jointAxisOther = boneTransform.parent.position - boneTransform.position;
36+
var jointAxisReference = targetTransform.parent.position - targetTransform.position;
37+
DeltaRot = Quaternion.FromToRotation(jointAxisReference, jointAxisOther);
38+
WorldPose = new Pose(boneTransform.position, boneTransform.rotation);
39+
BoneId = boneId;
40+
}
41+
42+
/// <summary>
43+
/// The bone id corresponding to the delta pose information.
44+
/// </summary>
45+
public FullBodyTrackingBoneId BoneId;
46+
47+
/// <summary>
48+
/// The world pose of this bone at rest.
49+
/// </summary>
50+
public Pose WorldPose;
51+
52+
/// <summary>
53+
/// The delta rotation between the two bone transforms that were compared.
54+
/// </summary>
55+
public Quaternion DeltaRot = Quaternion.identity;
56+
57+
/// <summary>
58+
/// The adjustment rotation to be applied to the bone transform.
59+
/// </summary>
60+
public Quaternion AdjustmentRot = Quaternion.identity;
61+
}
62+
63+
/// <inheritdoc cref="_bonePoses"/>>
64+
public BonePoseData[] BonePoses
65+
{
66+
get => _bonePoses;
67+
set => _bonePoses = value;
68+
}
69+
70+
/// <summary>
71+
/// Array containing all the stored bone pose information.
72+
/// </summary>
73+
[SerializeField]
74+
protected BonePoseData[] _bonePoses;
75+
76+
/// <summary>
77+
/// Initializes the bind pose data from two skeletons, capturing the deltas between
78+
/// the source skeleton and the target skeleton.
79+
/// </summary>
80+
/// <param name="source">The source skeleton.</param>
81+
/// <param name="target">The target skeleton.</param>
82+
public void InitializeBindPoseDataFromSkeletons(OVRSkeleton source, OVRSkeleton target)
83+
{
84+
var bonePoses = new List<BonePoseData>();
85+
for (var i = FullBodyTrackingBoneId.FullBody_Root; i < FullBodyTrackingBoneId.FullBody_End; i++)
86+
{
87+
bonePoses.Add(new BonePoseData(
88+
source.Bones[(int)i].Transform,
89+
target.Bones[(int)i].Transform, i));
90+
}
91+
92+
_bonePoses = bonePoses.ToArray();
93+
}
94+
95+
/// <summary>
96+
/// Returns bone pose data for the given bone.
97+
/// </summary>
98+
/// <returns>Bone pose data, if bone is found in the map.</returns>
99+
public BonePoseData GetBonePoseData(FullBodyTrackingBoneId boneId)
100+
{
101+
return (int)boneId >= _bonePoses.Length ? null : _bonePoses[(int)boneId];
102+
}
103+
}
104+
}

Runtime/Scripts/Utils/Tracking/BindPoseObjectSkeleton.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Samples.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Samples/AdvancedSamples.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Samples/AdvancedSamples/BodyTrackingForFitness.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Samples/AdvancedSamples/BodyTrackingForFitness/Models.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)