Skip to content

Commit

Permalink
Merge pull request #44 from oculus-samples/fixup-T172927076-dev
Browse files Browse the repository at this point in the history
Re-sync with internal repository
  • Loading branch information
sohailshafiiWk authored Dec 16, 2023
2 parents 7562245 + d0b233c commit a0341bd
Show file tree
Hide file tree
Showing 135 changed files with 19,128 additions and 4,114 deletions.
7 changes: 5 additions & 2 deletions Editor/AnimationRigging/GroundingConstraintEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@ private void FindHips(GroundingConstraint constraint)
{
IGroundingData groundingData = constraint.data;
Transform hipsTransform = null;
bool isFullSkeleton = groundingData.ConstraintSkeleton.GetSkeletonType() == OVRSkeleton.SkeletonType.FullBody;

if (groundingData.ConstraintSkeleton != null)
{
hipsTransform = RiggingUtilities.FindBoneTransformFromCustomSkeleton(
groundingData.ConstraintSkeleton,
OVRSkeleton.BoneId.Body_Hips);
isFullSkeleton ? OVRSkeleton.BoneId.FullBody_Hips : OVRSkeleton.BoneId.Body_Hips);
}
else
{
hipsTransform = RiggingUtilities.FindBoneTransformAnimator(
groundingData.ConstraintAnimator,
OVRSkeleton.BoneId.Body_Hips);
isFullSkeleton ? OVRSkeleton.BoneId.FullBody_Hips : OVRSkeleton.BoneId.Body_Hips,
groundingData.ConstraintAnimator.GetComponent<OVRSkeleton>().GetSkeletonType() == OVRSkeleton.SkeletonType.FullBody);
}
if (hipsTransform == null)
{
Expand Down
17 changes: 15 additions & 2 deletions Editor/Tracking/CorrectivesFaceEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ public class CorrectivesFaceEditor : OVRCustomFaceEditor
{
private SerializedProperty _blendshapeModifier;
private SerializedProperty _combinationShapesTextAsset;
private SerializedProperty _forceJawDropForTongue;
private SerializedProperty _tongueOutThreshold;
private SerializedProperty _minJawDrop;

protected override void OnEnable()
{
base.OnEnable();
_blendshapeModifier = serializedObject.FindProperty("_blendshapeModifier");
_combinationShapesTextAsset = serializedObject.FindProperty("_combinationShapesTextAsset");
_forceJawDropForTongue = serializedObject.FindProperty("_forceJawDropForTongue");
_tongueOutThreshold = serializedObject.FindProperty("_tongueOutThreshold");
_minJawDrop = serializedObject.FindProperty("_minJawDrop");
}

/// <inheritdoc />
Expand All @@ -29,9 +35,16 @@ public override void OnInspectorGUI()
serializedObject.Update();

EditorGUILayout.ObjectField(_blendshapeModifier,
new GUIContent("Blend shape modifiers (optional)"));
new GUIContent("Blendshape Modifiers (Optional)"));
EditorGUILayout.ObjectField(_combinationShapesTextAsset,
new GUIContent("Combination shapes text (Optional)"));
new GUIContent("Combination Shapes Text (Optional)"));

EditorGUILayout.PropertyField(_forceJawDropForTongue);
if (_forceJawDropForTongue.boolValue)
{
EditorGUILayout.PropertyField(_tongueOutThreshold);
EditorGUILayout.PropertyField(_minJawDrop);
}

serializedObject.ApplyModifiedProperties();
}
Expand Down
562 changes: 562 additions & 0 deletions Editor/Utils/FullBodyHelperMenus.cs

Large diffs are not rendered by default.

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

26 changes: 17 additions & 9 deletions Editor/Utils/HelperMenus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using UnityEngine;
using UnityEngine.Animations.Rigging;
using static Oculus.Movement.AnimationRigging.RetargetedBoneTargets;
using static OVRUnityHumanoidSkeletonRetargeter;

namespace Oculus.Movement.Utils
{
Expand Down Expand Up @@ -87,12 +88,12 @@ private static void SetupCharacterForAnimationRiggingRetargetingConstraints()

AddRetargetedBoneTargetComponent(activeGameObject, spineBoneTargets);

AddHandBlendConstraint(activeGameObject, null,
retargetingLayer, CustomMappings.BodyTrackingBoneId.Body_LeftHandWrist,
AddHandBlendConstraint(activeGameObject,
retargetingLayer, OVRHumanBodyBonesMappings.BodyTrackingBoneId.Body_LeftHandWrist,
animatorComp.GetBoneTransform(HumanBodyBones.Head));

AddHandBlendConstraint(activeGameObject, null,
retargetingLayer, CustomMappings.BodyTrackingBoneId.Body_RightHandWrist,
AddHandBlendConstraint(activeGameObject,
retargetingLayer, OVRHumanBodyBonesMappings.BodyTrackingBoneId.Body_RightHandWrist,
animatorComp.GetBoneTransform(HumanBodyBones.Head));

// Add final components to tie everything together.
Expand Down Expand Up @@ -189,6 +190,7 @@ private static RetargetingLayer AddMainRetargetingComponents(GameObject mainPare
retargetingLayer = mainParent.AddComponent<RetargetingLayer>();
Undo.RegisterCreatedObjectUndo(retargetingLayer, "Add Retargeting Layer");
}
retargetingLayer.EnableTrackingByProxy = true;

var bodySectionToPosition =
typeof(OVRUnityHumanoidSkeletonRetargeter).GetField(
Expand Down Expand Up @@ -235,7 +237,7 @@ private static (RigBuilder, GameObject) AddBasicAnimationRiggingComponents(GameO
if (!rigBuilder)
{
rigBuilder = mainParent.AddComponent<RigBuilder>();
rigBuilder.layers = new System.Collections.Generic.List<RigLayer>
rigBuilder.layers = new List<RigLayer>
{
new RigLayer(rigComponent, true)
};
Expand Down Expand Up @@ -288,9 +290,9 @@ private static void AddAnimationRiggingLayer(GameObject mainParent,
{
return;
}
var animatorComponent = mainParent.GetComponent<Animator>();
rigSetup = mainParent.AddComponent<AnimationRigSetup>();
rigSetup.Skeleton = skeletalComponent;
var animatorComponent = mainParent.GetComponent<Animator>();
rigSetup.AnimatorComp = animatorComponent;
rigSetup.RigbuilderComp = rigBuilder;
if (constraintComponents != null)
Expand All @@ -303,6 +305,7 @@ private static void AddAnimationRiggingLayer(GameObject mainParent,
rigSetup.RebindAnimator = true;
rigSetup.ReEnableRig = true;
rigSetup.RetargetingLayerComp = retargetingLayer;
rigSetup.CheckSkeletalUpdatesByProxy = true;
Undo.RegisterCreatedObjectUndo(rigSetup, "Create Anim Rig Setup");
}

Expand Down Expand Up @@ -387,7 +390,7 @@ private static RetargetedBoneTarget[] AddSpineBoneTargets(GameObject rigObject,
RetargetedBoneTarget boneRTTarget = new RetargetedBoneTarget();
boneRTTarget.BoneId = boneToRetarget.Item1;
boneRTTarget.Target = boneToRetarget.Item2;
boneRTTarget.HumanBodyBone = CustomMappings.BoneIdToHumanBodyBone[boneRTTarget.BoneId];
boneRTTarget.HumanBodyBone = OVRHumanBodyBonesMappings.BoneIdToHumanBodyBone[boneRTTarget.BoneId];
boneTargets.Add(boneRTTarget);
}
return boneTargets.ToArray();
Expand Down Expand Up @@ -522,8 +525,8 @@ private static bool DestroyTwoBoneIKConstraint(GameObject rigObject, string name
}

private static BlendHandConstraints AddHandBlendConstraint(
GameObject mainParent, MonoBehaviour[] constraints, RetargetingLayer retargetingLayer,
CustomMappings.BodyTrackingBoneId boneIdToTest, Transform headTransform)
GameObject mainParent, RetargetingLayer retargetingLayer,
OVRHumanBodyBonesMappings.BodyTrackingBoneId boneIdToTest, Transform headTransform)
{
var blendHandConstraints = mainParent.GetComponentsInChildren<BlendHandConstraints>();
foreach (var blendHandConstraint in blendHandConstraints)
Expand Down Expand Up @@ -567,6 +570,11 @@ private static void ValidGameObjectForAnimationRigging(GameObject go)
}
}

/// <summary>
/// Validates GameObject for face mapping.
/// </summary>
/// <param name="go">GameObject to check.</param>
/// <exception cref="InvalidOperationException">Exception thrown if GameObject fails check.</exception>
public static void ValidateGameObjectForFaceMapping(GameObject go)
{
var renderer = go.GetComponent<SkinnedMeshRenderer>();
Expand Down
133 changes: 133 additions & 0 deletions Editor/Utils/OVRProjectSetupMovementSDKSamples.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

using UnityEditor;
using UnityEngine;

namespace Oculus.Movement.Utils
{
/// <summary>
/// Add project setup validation tasks for MovementSDK Samples.
/// </summary>
[InitializeOnLoad]
internal static class OVRProjectSetupMovementSDKSamplesTasks
{
/// <summary>
/// All character and mirrored character layers should exist based on their indices.
/// That is because the scene assets are assigned based on layer index.
/// </summary>
private static readonly int[] _expectedLayersIndices =
{
10, 11
};

/// <summary>
/// The HiddenMesh layer is required for RecalculateNormals to function correctly.
/// </summary>
private static readonly string _hiddenMeshLayerName = "HiddenMesh";

private const OVRProjectSetup.TaskGroup _group = OVRProjectSetup.TaskGroup.Features;

static OVRProjectSetupMovementSDKSamplesTasks()
{
// Body tracking settings.
OVRProjectSetup.AddTask(
level: OVRProjectSetup.TaskLevel.Required,
group: _group,
platform: BuildTargetGroup.Android,
isDone: group => OVRRuntimeSettings.GetRuntimeSettings().BodyTrackingFidelity == OVRPlugin.BodyTrackingFidelity2.High,
message: "Body Tracking Fidelity should be set to High.",
fix: group => OVRRuntimeSettings.GetRuntimeSettings().BodyTrackingFidelity = OVRPlugin.BodyTrackingFidelity2.High,
fixMessage: "Set OVRRuntimeSettings.BodyTrackingFidelity = High"
);

OVRProjectSetup.AddTask(
level: OVRProjectSetup.TaskLevel.Required,
group: _group,
platform: BuildTargetGroup.Android,
isDone: group => OVRRuntimeSettings.GetRuntimeSettings().BodyTrackingJointSet == OVRPlugin.BodyJointSet.FullBody,
message: "Body Tracking Joint Set should be set to Full Body.",
fix: group => OVRRuntimeSettings.GetRuntimeSettings().BodyTrackingJointSet = OVRPlugin.BodyJointSet.FullBody,
fixMessage: "Set OVRRuntimeSettings.BodyTrackingJointSet = FullBody"
);

// Test layers.
OVRProjectSetup.AddTask(
level: OVRProjectSetup.TaskLevel.Recommended,
group: _group,
platform: BuildTargetGroup.Android,
isDone: group => LayerMask.NameToLayer(_hiddenMeshLayerName) != -1,
message: $"The layer '{_hiddenMeshLayerName}' needs to exist for Recalculate Normals to function properly.",
fix: group =>
{
int unusedLayer = -1;
for (int i = 0; i < 32; i++)
{
if (string.IsNullOrEmpty(LayerMask.LayerToName(i)))
{
unusedLayer = i;
break;
}
}
if (LayerMask.NameToLayer(_hiddenMeshLayerName) == -1)
{
if (unusedLayer == -1)
{
Debug.LogError("All Layers are Used!");
}
else
{
SetLayerName(unusedLayer, "HiddenMesh");
}
}
},
fixMessage: $"Set an unused layer to '{_hiddenMeshLayerName}'."
);
OVRProjectSetup.AddTask(
level: OVRProjectSetup.TaskLevel.Recommended,
group: _group,
platform: BuildTargetGroup.Android,
isDone: group =>
{
foreach (var layerIndex in _expectedLayersIndices)
{
if (string.IsNullOrEmpty(LayerMask.LayerToName(layerIndex)))
{
return false;
}
}
return true;
},
message: "Layers 10 and 11 must be indexed for the samples to display correctly.",
fix: group =>
{
foreach (var expectedLayerIndex in _expectedLayersIndices)
{
if (string.IsNullOrEmpty(LayerMask.LayerToName(expectedLayerIndex)))
{
// Default layer names.
string newLayerName = expectedLayerIndex == 10 ? "Character" : "MirroredCharacter";
SetLayerName(expectedLayerIndex, newLayerName);
}
}
},
fixMessage: "Set layers 10 and 11 to be valid layers."
);
}

private static void SetLayerName(int layer, string name)
{
SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAssetAtPath<Object>("ProjectSettings/TagManager.asset"));

SerializedProperty it = tagManager.GetIterator();
while (it.NextVisible(true))
{
if (it.name == "layers")
{
it.GetArrayElementAtIndex(layer).stringValue = name;
break;
}
}
tagManager.ApplyModifiedProperties();
}
}
}
11 changes: 11 additions & 0 deletions Editor/Utils/OVRProjectSetupMovementSDKSamples.cs.meta

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

49 changes: 1 addition & 48 deletions Editor/Utils/ProjectValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Oculus.Movement.Utils
{
Expand All @@ -11,54 +12,6 @@ namespace Oculus.Movement.Utils
[InitializeOnLoad]
public class ProjectValidation
{
/// <summary>
/// All character and mirrored character layers should exist based on their indices.
/// That is because the scene assets are assigned based on layer index.
/// </summary>
private static readonly int[] _expectedLayersIndices =
{ 10, 11 };
private static readonly string[] _expectedLayersNotIndexed = { "HiddenMesh" };

static ProjectValidation()
{
if (!ShouldShowWindow())
{
return;
}

ProjectValidationWindow.ShowProjectValidationWindow();
}

/// <summary>
/// If all expected layers are in the project, returns true.
/// </summary>
/// <returns>True if all expected layers are in the project.</returns>
public static bool TestLayers()
{
foreach (var expectedLayer in _expectedLayersNotIndexed)
{
if (LayerMask.NameToLayer(expectedLayer) == -1)
{
return false;
}
}

foreach (var layerIndex in _expectedLayersIndices)
{
if (LayerMask.LayerToName(layerIndex) == null)
{
return false;
}
}

return true;
}

private static bool ShouldShowWindow()
{
return !TestLayers();
}

[MenuItem("Movement/Check Project Settings", priority = 100)]
public static void BuildProjectAndroid64()
{
Expand Down
Loading

0 comments on commit a0341bd

Please sign in to comment.