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 May 17, 2024
2 parents 21a73bd + db7a615 commit e3dabab
Show file tree
Hide file tree
Showing 714 changed files with 162,515 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
run: |
git checkout HEAD~1 CHANGELOG.md
git checkout HEAD~1 package.json
git rm Samples.meta
git mv Samples Samples~
git commit --amend --no-edit --allow-empty
- name: Push
run: |
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Close inactive issues

on:
schedule:
- cron: "30 1 * * *"

jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v5
with:
days-before-issue-stale: -1
days-before-issue-close: 14
stale-issue-label: "stale"
stale-issue-message: "This issue is stale because it has been open for 14 days with no activity."
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
days-before-pr-stale: -1
days-before-pr-close: -1
repo-token: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private static class Content
private SerializedProperty _originalSpinePositionsWeight;
private SerializedProperty _originalSpineBoneCount;
private SerializedProperty _originalSpineUseHipsToHeadToScale;
private SerializedProperty _originalSpineFixRotations;

private SerializedProperty _hipsToHeadBonesProperty;
private SerializedProperty _hipsToHeadBoneTargetsProperty;
Expand Down Expand Up @@ -167,6 +168,7 @@ private void OnEnable()
_originalSpinePositionsWeight = data.FindPropertyRelative("_originalSpinePositionsWeight");
_originalSpineBoneCount = data.FindPropertyRelative("_originalSpineBoneCount");
_originalSpineUseHipsToHeadToScale = data.FindPropertyRelative("_originalSpineUseHipsToHeadToScale");
_originalSpineFixRotations = data.FindPropertyRelative("_originalSpineFixRotations");

_hipsToHeadBonesProperty = data.FindPropertyRelative("_hipsToHeadBones");
_hipsToHeadBoneTargetsProperty = data.FindPropertyRelative("_hipsToHeadBoneTargets");
Expand Down Expand Up @@ -368,6 +370,7 @@ private void DisplayAdvancedSettingsFoldoutContent()
EditorGUILayout.PropertyField(_stretchProperty);
EditorGUILayout.PropertyField(_originalSpineBoneCount);
EditorGUILayout.PropertyField(_originalSpineUseHipsToHeadToScale);
EditorGUILayout.PropertyField(_originalSpineFixRotations);

EditorGUILayout.Space();
GUILayout.BeginHorizontal();
Expand Down
1 change: 1 addition & 0 deletions Editor/AnimationRigging/HipPinningConstraintEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public override void OnInspectorGUI()
{
Undo.RecordObject(constraint, "Set up data");
constraint.data.SetUpBoneReferences();
constraint.data.SetInitialHipRotation();
EditorUtility.SetDirty(target);
}
}
Expand Down
14 changes: 14 additions & 0 deletions Editor/Utils/OVRProjectSetupMovementSDKSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ internal static class OVRProjectSetupMovementSDKSamplesTasks

static OVRProjectSetupMovementSDKSamplesTasks()
{
// Skin weights settings.
OVRProjectSetup.AddTask(
level: OVRProjectSetup.TaskLevel.Recommended,
group: _group,
platform: BuildTargetGroup.Android,
isDone: group => QualitySettings.skinWeights == SkinWeights.FourBones,
message: "You should use four skin weights to avoid skinning problems",
fix: group =>
{
QualitySettings.skinWeights = SkinWeights.FourBones;
},
fixMessage: "Set quality settings skin weights to four bones."
);

// Body tracking settings.
OVRProjectSetup.AddTask(
level: OVRProjectSetup.TaskLevel.Required,
Expand Down
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ Unity-Movement is a package that uses OpenXR’s tracking layer APIs to expose M
The Unity-Movement package is released under the [Oculus License](https://github.com/oculus-samples/Unity-Movement/blob/main/LICENSE). The MIT License applies to only certain, clearly marked documents. If an individual file does not indicate which license it is subject to, then the Oculus License applies.

### Requirements
- Unity 2021.3.26f1 (2021 LTS) or newer installed. For Unity 2022, use 2022.3.11f1 (2022 LTS) or newer. For Unity 2023, use 2023.1.17f1 or newer (Unity 2023.1.x). Unity 2023.2+ however will not currently work due to the fact TMPro has been deprecated.
- A version of Unity supported for Movement SDK installed:
- 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/)

Expand Down Expand Up @@ -54,20 +57,24 @@ The following settings are recommended:
nearby without experiencing poor quality.
5. At least one pixel light.

## Player Settings
## Samples

Make sure that the color space is set to Linear.
The project contains several sample scenes. To test the samples, they must be imported into the project's Assets folder:
- Select the "Meta Movement" package in the package manager. Once selected, expand the Samples section and import the desired sample scenes.
<br>

## Build Settings

In order for the SceneSelectMenu buttons to work, add the scenes located in **Packages/Meta Movement/Samples/Scenes** folder.
For more information about body tracking, please refer to [this page](https://developer.oculus.com/documentation/unity/move-body-tracking/).

## Samples
The project contains several sample scenes. To test the samples, add the scenes located in the **Packages/com.meta.movement/Samples/Scenes** folder to the project's Assets folder. To view those scenes in the editor or make edits, you may need to make copies of those scenes in the **Assets** folder.
For more information about the samples, please refer to [this page](https://developer.oculus.com/documentation/unity/move-samples/).

For more information about body tracking, please refer to [this page](https://developer.oculus.com/documentation/unity/move-body-tracking/).
## Player Settings

Make sure that the color space is set to Linear.

## Build Settings

For more information about the samples, read [Aura Sample](https://developer.oculus.com/documentation/unity/move-samples/#face-and-eye-tracking-with-aura), [Blendshape Mapping Example Sample](https://developer.oculus.com/documentation/unity/move-samples/#arkit-mapping-with-blendshape-mapping-example), [Hip Pinning Sample](https://developer.oculus.com/documentation/unity/move-samples/#high-fidelity-with-hip-pinning), [High Fidelity Sample](https://developer.oculus.com/documentation/unity/move-samples/#high-fidelity-sample), and [Retargeting Sample](https://developer.oculus.com/documentation/unity/move-samples/#retargeting-with-blue-robot).
In order for the SceneSelectMenu buttons to work, add imported scenes in the [Samples](#samples) step to the Build Settings.

## Documentation
The documentation for this package can be found [here](https://developer.oculus.com/documentation/unity/move-overview/).
Expand Down
24 changes: 24 additions & 0 deletions Runtime/Scripts/AnimationRigging/FullBodyDeformationConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ public interface IFullBodyDeformationData
/// </summary>
public string OriginalSpineUseHipsToHeadScaleBoolProperty { get; }

/// <summary>
/// Allows correcting the rotations of the spine too when using
/// original spine positions.
/// WARNING! EXPERIMENTAL!
/// </summary>
public string OriginalSpineFixRotationsBoolProperty { get; }

/// <summary>
/// Sets up hips and head bones.
/// </summary>
Expand Down Expand Up @@ -548,6 +555,9 @@ bool IFullBodyDeformationData.ShouldUpdate
string IFullBodyDeformationData.OriginalSpineUseHipsToHeadScaleBoolProperty =>
ConstraintsUtils.ConstructConstraintDataPropertyName(nameof(_originalSpineUseHipsToHeadToScale));

string IFullBodyDeformationData.OriginalSpineFixRotationsBoolProperty =>
ConstraintsUtils.ConstructConstraintDataPropertyName(nameof(_originalSpineFixRotations));

/// <inheritdoc cref="IFullBodyDeformationData.BodyType"/>
[SyncSceneToStream, SerializeField, IntAsEnumAttribute(typeof(DeformationBodyType))]
[Tooltip(DeformationDataTooltips.DeformationBodyType)]
Expand Down Expand Up @@ -845,6 +855,19 @@ public bool OriginalSpineUseHipsToHeadToScale
set => _originalSpineUseHipsToHeadToScale = value;
}

/// <summary>
/// Allows rotation correction when using the original spine bone
/// positions.
/// </summary>
[SyncSceneToStream, SerializeField]
[Tooltip(DeformationDataTooltips.OriginalSpineFixRotations)]
private bool _originalSpineFixRotations;
public bool OriginalSpineFixRotations
{
get => _originalSpineFixRotations;
set => _originalSpineFixRotations = value;
}

/// <inheritdoc cref="IFullBodyDeformationData.SpineCorrectionType"/>
[SyncSceneToStream, SerializeField, IntAsEnumAttribute(typeof(SpineTranslationCorrectionType))]
[Tooltip(DeformationDataTooltips.SpineTranslationCorrectionType)]
Expand Down Expand Up @@ -1462,6 +1485,7 @@ void IAnimationJobData.SetDefaultValues()
_originalSpinePositionsWeight = 0.0f;
_originalSpineBoneCount = 0;
_originalSpineUseHipsToHeadToScale = false;
_originalSpineFixRotations = false;

_startingScale = Vector3.one;
_bonePairData = null;
Expand Down
105 changes: 105 additions & 0 deletions Runtime/Scripts/AnimationRigging/FullBodyDeformationJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ public struct BoneDeformationAdjustmentData
/// </summary>
public BoolProperty OriginalSpineUseHipsToHeadToScale;

/// <summary>
/// Allows correcting the rotations of the spine too when using
/// original spine positions.
/// </summary>
public BoolProperty OriginalSpineFixRotations;

/// <summary>
/// True if the arms should be affected by spine correction.
/// </summary>
Expand Down Expand Up @@ -432,6 +438,10 @@ public struct BoneDeformationAdjustmentData
/// </summary>
public float OriginalHipsToHeadDistance;

public NativeArray<Vector3> OriginalHipsToPositions;
public NativeArray<Quaternion> CachedFixedHipsToHeadRotations;
public NativeArray<Vector3> CachedFixedHipsToHeadPositions;

private Vector3 _targetHipsPos;
private Vector3 _targetHeadPos;
private Vector3 _preDeformationLeftUpperArmLocalPos;
Expand Down Expand Up @@ -757,6 +767,13 @@ private void ApplyOriginalSpineOffsets(AnimationStream stream, float weight)
HeadIndex - 1 : requestedBoneCount;
float currentToOriginalSpineScale = ComputeCurrentToOriginalSpineScale(stream);

// cache original positions first, this is used for rotation correction
for (int i = HipsIndex; i <= numBonesToCorrect; i++)
{
OriginalHipsToPositions[i] = HipsToHeadBones[i].GetPosition(stream);
}

// perform position correction
for (int i = HipsIndex; i < numBonesToCorrect; i++)
{
var boneToAffect = EndBones[i];
Expand All @@ -777,6 +794,47 @@ private void ApplyOriginalSpineOffsets(AnimationStream stream, float weight)

EndBones[i] = boneToAffect;
}

// cache final results
for (int i = HipsIndex; i <= numBonesToCorrect; i++)
{
CachedFixedHipsToHeadPositions[i] = HipsToHeadBones[i].GetPosition(stream);
CachedFixedHipsToHeadRotations[i] = HipsToHeadBones[i].GetRotation(stream);
}

// after the positions are set, adjust the rotations if the user requests
if (OriginalSpineFixRotations.Get(stream))
{
// correct rotations of each spine position to respond the fixes to positions.
// that's because rotations should match the new positions set.
// do not correct hips, because that might cause the legs to to rotate out
// of position.
for (int i = HipsIndex + 1; i < numBonesToCorrect; i++)
{
var oldJointPosition = OriginalHipsToPositions[i];
var oldJointTargetPosition = OriginalHipsToPositions[i + 1];

var newJointPosition = HipsToHeadBones[i].GetPosition(stream);
var newJointTargetPosition = HipsToHeadBones[i + 1].GetPosition(stream);

RotateJointBasedOnNewPosition(stream,
oldJointPosition, oldJointTargetPosition,
newJointPosition, newJointTargetPosition,
i, originalSpinePositionsWeight);

// restore bone transforms after the current one to make sure they are not
// affected by the current bone's rotation.
for (int j = i + 1; j <= numBonesToCorrect; j++)
{
var boneToAffect = HipsToHeadBones[j];

boneToAffect.SetPosition(stream, CachedFixedHipsToHeadPositions[j]);
boneToAffect.SetRotation(stream, CachedFixedHipsToHeadRotations[j]);

HipsToHeadBones[j] = boneToAffect;
}
}
}
}

private float ComputeCurrentToOriginalSpineScale(AnimationStream stream)
Expand Down Expand Up @@ -809,6 +867,35 @@ private void AffectBoneByFixedLocalPosition(
boneToAffect.SetLocalPosition(stream, lerpPosition);
}

private void RotateJointBasedOnNewPosition(AnimationStream stream,
Vector3 oldJointPosition, Vector3 oldJointTargetPosition,
Vector3 newJointPosition, Vector3 newJointTargetPosition,
int boneIndex, float interpolationValue)
{
// rotate the joint so that it points toward its target
var rotationChange = GetRotationChange(
oldJointPosition, oldJointTargetPosition,
newJointPosition, newJointTargetPosition);

var bone = HipsToHeadBones[boneIndex];
var currentRotation = bone.GetRotation(stream);
var newRotation = rotationChange * currentRotation;
var interpolatedRotation =
Quaternion.Slerp(currentRotation, newRotation, interpolationValue);
bone.SetRotation(stream, interpolatedRotation);

HipsToHeadBones[boneIndex] = bone;
}

private Quaternion GetRotationChange(
Vector3 oldJointPosition, Vector3 oldJointTargetPosition,
Vector3 newJointPosition, Vector3 newTargetPosition)
{
Vector3 boneToOldTarget = oldJointTargetPosition - oldJointPosition;
Vector3 boneToNewTarget = newTargetPosition - newJointPosition;
return Quaternion.FromToRotation(boneToOldTarget, boneToNewTarget);
}

/// <summary>
/// Optionally interpolate from the current position to the original local position of the shoulders,
/// as the tracked positions may be mismatched.
Expand Down Expand Up @@ -1552,13 +1639,26 @@ public override FullBodyDeformationJob Create(Animator animator, ref T data, Com
NativeArrayOptions.UninitializedMemory);
job.OriginalHipsToHeadDistance = data.HipsToHeadDistance;

job.OriginalHipsToPositions = new NativeArray<Vector3>(data.HipsToHeadBones.Length,
Allocator.Persistent,
NativeArrayOptions.UninitializedMemory);
job.CachedFixedHipsToHeadRotations = new NativeArray<Quaternion>(data.HipsToHeadBones.Length,
Allocator.Persistent,
NativeArrayOptions.UninitializedMemory);
job.CachedFixedHipsToHeadPositions = new NativeArray<Vector3>(data.HipsToHeadBones.Length,
Allocator.Persistent,
NativeArrayOptions.UninitializedMemory);

var upperBodyProportion = 0.0f;
for (int i = 0; i < data.HipsToHeadBones.Length; i++)
{
job.HipsToHeadBones[i] = ReadWriteTransformHandle.Bind(animator, data.HipsToHeadBones[i]);
job.UpperBodyOffsets[i] = Vector3.zero;
job.UpperBodyTargetPositions[i] = Vector3.zero;
upperBodyProportion += data.BonePairs[i].HeightProportion;
job.OriginalHipsToPositions[i] = Vector3.zero;
job.CachedFixedHipsToHeadRotations[i] = Quaternion.identity;
job.CachedFixedHipsToHeadPositions[i] = Vector3.zero;
}
job.LowerBodyProportion = 1.0f - upperBodyProportion;

Expand Down Expand Up @@ -1647,6 +1747,8 @@ public override FullBodyDeformationJob Create(Animator animator, ref T data, Com
IntProperty.Bind(animator, component, data.OriginalSpineBoneCountIntProperty);
job.OriginalSpineUseHipsToHeadToScale =
BoolProperty.Bind(animator, component, data.OriginalSpineUseHipsToHeadScaleBoolProperty);
job.OriginalSpineFixRotations =
BoolProperty.Bind(animator, component, data.OriginalSpineFixRotationsBoolProperty);
job.LeftArmOffsetWeight = FloatProperty.Bind(animator, component, data.LeftArmWeightFloatProperty);
job.RightArmOffsetWeight = FloatProperty.Bind(animator, component, data.RightArmWeightFloatProperty);
job.LeftHandOffsetWeight = FloatProperty.Bind(animator, component, data.LeftHandWeightFloatProperty);
Expand Down Expand Up @@ -1728,6 +1830,9 @@ public override void Destroy(FullBodyDeformationJob job)
job.BoneDirections.Dispose();
job.EndBoneOffsetsLocal.Dispose();
job.ScaleFactor.Dispose();
job.OriginalHipsToPositions.Dispose();
job.CachedFixedHipsToHeadPositions.Dispose();
job.CachedFixedHipsToHeadRotations.Dispose();
}
}
}
17 changes: 15 additions & 2 deletions Runtime/Scripts/AnimationRigging/HipPinningConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public interface IHipPinningData
/// </summary>
/// <returns>Index of bone above hips.</returns>
public int GetIndexOfFirstBoneAboveHips();

/// <summary>
/// Allows storing the initial hip rotation.
/// </summary>
public void SetInitialHipRotation();
}

/// <summary>
Expand Down Expand Up @@ -242,6 +247,10 @@ public bool IsFirstFrame
[NotKeyable, SerializeField, HideInInspector]
private bool _obtainedProperReferences;

/// <summary>
/// Initial hip rotation, used to calculate how much a person has rotated.
/// </summary>
[NotKeyable, SerializeField, HideInInspector]
private Quaternion _initialHipLocalRotation;

private Vector3 _calibratedHipTranslation;
Expand Down Expand Up @@ -269,8 +278,6 @@ public void SetUp()
return;
}
_hasSetUp = true;

_initialHipLocalRotation = GetHipTransform().localRotation;
_bones = new Transform[_skeleton.CustomBones.Count];
for (int i = 0; i < _bones.Length; i++)
{
Expand Down Expand Up @@ -402,6 +409,12 @@ public void CalibrateInitialHipHeight(Vector3 position)
}
}

/// <inheritdoc />
public void SetInitialHipRotation()
{
_initialHipLocalRotation = GetHipTransform().localRotation;
}

/// <summary>
/// Event when the user enters a hip pinning area.
/// </summary>
Expand Down
Loading

0 comments on commit e3dabab

Please sign in to comment.