Skip to content

Commit

Permalink
[Automated] Merged dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Sep 4, 2024
2 parents c396ef0 + 2df44ee commit 2485947
Show file tree
Hide file tree
Showing 524 changed files with 140,553 additions and 21 deletions.
47 changes: 47 additions & 0 deletions Editor/Utils/ScriptableObjectMenus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ internal static class ScriptableObjectMenus
private const string _SAVE_HUMANOID_REFERENCE_POSE =
"Save Humanoid Reference Pose";

private const string _SAVE_CUSTOM_HUMANOID_REFERENCE_POSE =
"Save Custom Humanoid Reference Pose";

private const string _MOVEMENT_SCRIPTABLE_OBJECTS_DIRECTORY =
"MovementSDKSampleScriptableObjects";

private const string _HUMANOID_REFERENCE_POSE_ASSET_NAME_SUFFIX =
"_HumanoidReferencePose.asset";

private const string _CUSTOM_HUMANOID_REFERENCE_POSE_ASSET_NAME_SUFFIX =
"_CustomBindPose.asset";

[MenuItem(_MOVEMENT_SAMPLES_MENU + _SCRIPTABLE_OBJECTS_MENU + _SAVE_HUMANOID_REFERENCE_POSE)]
private static void SaveHumanoidReferencePose()
{
Expand Down Expand Up @@ -64,5 +70,46 @@ private static void SaveHumanoidReferencePose()
Debug.LogError($"Failed to save humanoid reference pose, reason: {exception}.");
}
}

[MenuItem(_MOVEMENT_SAMPLES_MENU + _SCRIPTABLE_OBJECTS_MENU + _SAVE_CUSTOM_HUMANOID_REFERENCE_POSE)]
private static void SaveCustomHumanoidReferencePose()
{
try
{
var activeGameObject = Selection.activeGameObject;
var activeObjectAnimator = activeGameObject.GetComponent<Animator>();
if (activeObjectAnimator == null)
{
throw new Exception($"Cannot create custom humanoid reference pose if {activeGameObject} " +
"does not have an animator");
}

var poseDataAsset = ScriptableObject.CreateInstance<BindPoseObjectSkeleton>();

string parentDirectory = Path.Combine("Assets", _MOVEMENT_SCRIPTABLE_OBJECTS_DIRECTORY);
if (!Directory.Exists(parentDirectory))
{
Directory.CreateDirectory(parentDirectory);
}

string selectedObjectName = activeGameObject.name;
var assetPath = Path.Combine(parentDirectory,
$"{selectedObjectName}{_CUSTOM_HUMANOID_REFERENCE_POSE_ASSET_NAME_SUFFIX}");

if (File.Exists(assetPath))
{
Debug.LogWarning($"{assetPath} already exists. Will overwrite it.");
}

AssetDatabase.CreateAsset(poseDataAsset, assetPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Debug.Log($"Saved reference pose as {assetPath}.");
}
catch (Exception exception)
{
Debug.LogError($"Failed to save custom humanoid reference pose, reason: {exception}.");
}
}
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ The Unity-Movement package is released under the [Oculus License](https://github
- 2021.3.26f1 (2021 LTS or newer)
- 2022.3.11f2 (2022 LTS or newer)
- 2023.2.7f1 or newer
- 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).
- A project set up with these [configuration settings](https://developer.oculus.com/documentation/unity/unity-conf-settings/)
- 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).
- A project set up with these [steps](https://developer.oculus.com/documentation/unity/move-overview/#unity-project-setup).

## Getting Started
First, ensure that all of the [requirements](#requirements) are met.
Expand Down
77 changes: 76 additions & 1 deletion Runtime/Scripts/AnimationRigging/RetargetingLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Oculus.Interaction;
using Oculus.Movement.AnimationRigging.Utils;
using Oculus.Movement.Utils;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -192,6 +193,19 @@ public RetargetedBoneMappings RetargetedBoneMappingsInst
set => _retargetedBoneMappings = value;
}

/// <summary>
/// The custom bind pose that can be used to modify the current bind pose.
/// </summary>
[SerializeField]
[Tooltip(RetargetingLayerTooltips.CustomBindPose)]
protected BindPoseObjectSkeleton _customBindPose;
/// <inheritdoc cref="_customBindPose"/>
public BindPoseObjectSkeleton CustomBindPose
{
get => _customBindPose;
set => _customBindPose = value;
}

/// <summary>
/// Exposes a button used to update bone pair mappings based on the humanoid.
/// </summary>
Expand Down Expand Up @@ -309,6 +323,67 @@ protected override void Start()
}
}

/// <summary>
/// Initializes the custom bind pose if set.
/// </summary>
protected override void InitializeBindPose()
{
base.InitializeBindPose();

if (_customBindPose == null)
{
return;
}

BoneId[] boneIds =
{
BoneId.FullBody_SpineLower,
BoneId.FullBody_SpineMiddle,
BoneId.FullBody_SpineUpper,
BoneId.FullBody_Chest,
BoneId.FullBody_Neck,
BoneId.FullBody_Head,
BoneId.FullBody_LeftShoulder,
BoneId.FullBody_RightShoulder,
BoneId.FullBody_LeftArmUpper,
BoneId.FullBody_RightArmUpper,
};
BoneId[] parentBoneIds = {
BoneId.FullBody_Hips,
BoneId.FullBody_SpineLower,
BoneId.FullBody_SpineMiddle,
BoneId.FullBody_SpineUpper,
BoneId.FullBody_Chest,
BoneId.FullBody_Neck,
BoneId.FullBody_Chest,
BoneId.FullBody_Chest,
BoneId.FullBody_LeftShoulder,
BoneId.FullBody_RightShoulder,
};
for (var i = 0; i < boneIds.Length; i++)
{
var targetBoneId = boneIds[i];
var parentBoneId = parentBoneIds[i];
var targetPose =
_customBindPose.GetBonePoseData((OVRHumanBodyBonesMappings.FullBodyTrackingBoneId)targetBoneId);
if (targetPose == null)
{
continue;
}

var targetBone = BindPoses[(int)targetBoneId].Transform;
var parentBone = BindPoses[(int)parentBoneId].Transform;
var direction = BindPoses[(int)targetBoneId].Transform.localPosition -
BindPoses[(int)parentBoneId].Transform.localPosition;
targetBone.localPosition = parentBone.localPosition + targetPose.DeltaRot * direction;
if (targetPose.AdjustmentRot.eulerAngles.sqrMagnitude > float.Epsilon)
{
parentBone.localRotation *= targetPose.AdjustmentRot;
}
}
ComputeOffsetsUsingSkeletonComponent();
}

private void CaptureTransformInformationHipsUpwards(Transform currentTransform)
{
// Avoid going to topmost transform (the character). We want to ignore any rotations
Expand Down Expand Up @@ -584,7 +659,7 @@ private void ResetBoneTransformationsHipsUpwards(Transform currentTransform)
/// <summary>
/// Empty fixed update to avoid updating OVRSkeleton during fixed update.
/// </summary>
private void FixedUpdate()
private new void FixedUpdate()
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void Awake()
_instantiatedMaterials = _skinnedMeshRenderer.materials;
foreach (var recalculateMaterialIndex in _recalculateMaterialIndices)
{
Assert.IsTrue(recalculateMaterialIndex < _recalculateMaterialIndices.Length);
Assert.IsTrue(recalculateMaterialIndex < _instantiatedMaterials.Length);
_recalculateMaterials.Add(_instantiatedMaterials[recalculateMaterialIndex]);
}

Expand Down
3 changes: 3 additions & 0 deletions Runtime/Scripts/Tooltips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,9 @@ public static class RetargetingLayerTooltips
public const string RetargetedBoneMappings =
"Retargeted bone mappings to be updated based on valid bones in the humanoid.";

public const string CustomBindPose =
"The custom bind pose that can be used to modify the current bind pose.";

public const string FingerPositionCorrectionWeight =
"Finger position correction weight.";

Expand Down
18 changes: 1 addition & 17 deletions Runtime/Scripts/Tracking/FaceTrackingData/ARKitFace.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

using UnityEngine;

namespace Oculus.Movement.Tracking
{
/// <summary>
/// Version of Correctives mapped to ARKit blend shapes,
/// via "custom" mapping.
/// </summary>
public class ARKitFace : CorrectivesFace, ISerializationCallbackReceiver
public class ARKitFace : CorrectivesFace
{
private static (string, OVRFaceExpressions.FaceExpression)[] ARKitBlendshapesSorted =
{
Expand Down Expand Up @@ -82,19 +80,5 @@ protected override (string[], OVRFaceExpressions.FaceExpression[]) GetCustomBlen
}
return (arKitBlendShapeNames, arKitFaceExpressions);
}

public void OnBeforeSerialize()
{
if (RetargetingValue != RetargetingType.Custom)
{
Debug.LogError($"Please use {nameof(RetargetingType.Custom)} with ARKitFace; " +
$"other values will not work. Reverting change.");
RetargetingValue = RetargetingType.Custom;
}
}

public void OnAfterDeserialize()
{
}
}
}
104 changes: 104 additions & 0 deletions Runtime/Scripts/Utils/Tracking/BindPoseObjectSkeleton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

using System;
using System.Collections.Generic;
using UnityEngine;
using static OVRUnityHumanoidSkeletonRetargeter.OVRHumanBodyBonesMappings;

namespace Oculus.Movement.Utils
{
/// <summary>
/// Scriptable object that contains custom bind pose information that can be applied
/// onto a bind pose to configure a custom bind pose. This can be used to fix artifacts
/// that are a result of retargeting and deformation.
/// </summary>
public class BindPoseObjectSkeleton : ScriptableObject
{
/// <summary>
/// Holds delta pose information for each bone.
/// </summary>
[Serializable]
public class BonePoseData
{
/// <summary>
/// Constructor for BonePoseData, taking in a bone transform and comparing it against
/// the target transform to store delta information.
/// </summary>
/// <param name="boneTransform"></param>
/// <param name="targetTransform"></param>
/// <param name="boneId"></param>
public BonePoseData(
Transform boneTransform,
Transform targetTransform,
FullBodyTrackingBoneId boneId)
{
var jointAxisOther = boneTransform.parent.position - boneTransform.position;
var jointAxisReference = targetTransform.parent.position - targetTransform.position;
DeltaRot = Quaternion.FromToRotation(jointAxisReference, jointAxisOther);
WorldPose = new Pose(boneTransform.position, boneTransform.rotation);
BoneId = boneId;
}

/// <summary>
/// The bone id corresponding to the delta pose information.
/// </summary>
public FullBodyTrackingBoneId BoneId;

/// <summary>
/// The world pose of this bone at rest.
/// </summary>
public Pose WorldPose;

/// <summary>
/// The delta rotation between the two bone transforms that were compared.
/// </summary>
public Quaternion DeltaRot = Quaternion.identity;

/// <summary>
/// The adjustment rotation to be applied to the bone transform.
/// </summary>
public Quaternion AdjustmentRot = Quaternion.identity;
}

/// <inheritdoc cref="_bonePoses"/>>
public BonePoseData[] BonePoses
{
get => _bonePoses;
set => _bonePoses = value;
}

/// <summary>
/// Array containing all the stored bone pose information.
/// </summary>
[SerializeField]
protected BonePoseData[] _bonePoses;

/// <summary>
/// Initializes the bind pose data from two skeletons, capturing the deltas between
/// the source skeleton and the target skeleton.
/// </summary>
/// <param name="source">The source skeleton.</param>
/// <param name="target">The target skeleton.</param>
public void InitializeBindPoseDataFromSkeletons(OVRSkeleton source, OVRSkeleton target)
{
var bonePoses = new List<BonePoseData>();
for (var i = FullBodyTrackingBoneId.FullBody_Root; i < FullBodyTrackingBoneId.FullBody_End; i++)
{
bonePoses.Add(new BonePoseData(
source.Bones[(int)i].Transform,
target.Bones[(int)i].Transform, i));
}

_bonePoses = bonePoses.ToArray();
}

/// <summary>
/// Returns bone pose data for the given bone.
/// </summary>
/// <returns>Bone pose data, if bone is found in the map.</returns>
public BonePoseData GetBonePoseData(FullBodyTrackingBoneId boneId)
{
return (int)boneId >= _bonePoses.Length ? null : _bonePoses[(int)boneId];
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/Utils/Tracking/BindPoseObjectSkeleton.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Samples.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Samples/AdvancedSamples.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Samples/AdvancedSamples/BodyTrackingForFitness.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Samples/AdvancedSamples/BodyTrackingForFitness/Models.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2485947

Please sign in to comment.