-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
98 changed files
with
53,182 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
using System; | ||
using Oculus.Movement.Utils; | ||
using UnityEditor; | ||
|
||
namespace Oculus.Movement.BodyTrackingForFitness | ||
{ | ||
/// <summary> | ||
/// Adds button features in the inspector: | ||
/// * Connect to <see cref="BodyPoseBoneTransforms"/> | ||
/// * Generate a default bone prefab | ||
/// * Generate and/or refresh positions of bone visuals childed to bone transforms | ||
/// * Delete all bone visuals | ||
/// </summary> | ||
[CustomEditor(typeof(BodyPoseBoneVisuals))] | ||
public class BodyBoneVisualsEditor : Editor | ||
{ | ||
private InspectorGuiHelper[] helpers; | ||
private InspectorGuiHelper[] Helpers => helpers != null ? helpers : helpers = new InspectorGuiHelper[] | ||
{ | ||
new InspectorGuiHelper(IsSkeletonInvalid, PopulateSkeleton, "Missing target skeleton", | ||
"Find Target Skeleton", InspectorGuiHelper.OptionalIcon.Warning), | ||
new InspectorGuiHelper(IsBoneVisualEmpty, GenerateBoneVisualPrefab, "Needs bone prefab", | ||
"Generate Bone Prefab", InspectorGuiHelper.OptionalIcon.Warning), | ||
new InspectorGuiHelper(IsShowingRefreshButton, Refresh, null, | ||
"Refresh Bone Visuals", InspectorGuiHelper.OptionalIcon.None), | ||
new InspectorGuiHelper(IsPopulatedWithBones, Clear, null, | ||
"Clear Bone Visuals", InspectorGuiHelper.OptionalIcon.None), | ||
}; | ||
|
||
private BodyPoseBoneVisuals Target => (BodyPoseBoneVisuals)target; | ||
|
||
/// <inheritdoc/> | ||
public override void OnInspectorGUI() | ||
{ | ||
Array.ForEach(Helpers, helper => helper.DrawInInspector()); | ||
DrawDefaultInspector(); | ||
} | ||
|
||
private bool IsShowingRefreshButton() => !IsSkeletonInvalid(); | ||
|
||
private bool IsBoneVisualEmpty() => Target.BoneVisualPrefab == null; | ||
|
||
private bool IsSkeletonInvalid() => Target.Skeleton == null; | ||
|
||
private bool IsPopulatedWithBones() => Target.BoneVisuals.Count != 0; | ||
|
||
private void Refresh() => Target.RefreshVisualsInEditor(); | ||
|
||
private void GenerateBoneVisualPrefab() => Target.CreatePrimitiveCubeVisualPrefab(); | ||
|
||
private void PopulateSkeleton() => Target.Skeleton = FindBestSkeletonOwner(); | ||
|
||
private void Clear() => Target.ClearBoneVisuals(); | ||
|
||
private BodyPoseBoneTransforms FindBestSkeletonOwner() => | ||
FindFirstObjectByType<BodyPoseBoneTransforms>(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Editor/BodyTrackingForFitness/BodyBoneVisualsEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
Editor/BodyTrackingForFitness/BodyPoseAlignmentDetectorConfigDrawer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Oculus.Movement.BodyTrackingForFitness | ||
{ | ||
/// <summary> | ||
/// Used to simplify drawing of a | ||
/// <see cref="BodyPoseAlignmentDetector.AlignmentState"/> element. | ||
/// </summary> | ||
[CustomPropertyDrawer(typeof(BodyPoseAlignmentDetector.AlignmentState))] | ||
public class BodyPoseAlignmentDetectorStateEditor : PropertyDrawer | ||
{ | ||
/// <inheritdoc /> | ||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
BoneTupleGUI(position, property, label); | ||
} | ||
|
||
/// <summary> | ||
/// Call from OnGUI to draw a <see cref="BodyPoseAlignmentDetector.AlignmentState"/>. | ||
/// </summary> | ||
/// <param name="position"></param> | ||
/// <param name="property"></param> | ||
/// <param name="label"></param> | ||
private static void BoneTupleGUI(Rect position, SerializedProperty property, | ||
GUIContent label) { | ||
SerializedProperty angle = property.FindPropertyRelative( | ||
nameof(BodyPoseAlignmentDetector.AlignmentState.AngleDelta)); | ||
EditorGUI.BeginProperty(position, label, property); | ||
const string ElementLabel = "Element "; | ||
if (!label.text.StartsWith(ElementLabel)) | ||
{ | ||
position = EditorGUI.PrefixLabel(position, | ||
GUIUtility.GetControlID(FocusType.Passive), label); | ||
} | ||
int indent = EditorGUI.indentLevel; | ||
EditorGUI.indentLevel = 0; | ||
Rect rect = new Rect(position.x, position.y, position.width, position.height); | ||
EditorGUI.Slider(rect, "", angle.floatValue, 0, 180); | ||
EditorGUI.indentLevel = indent; | ||
EditorGUI.EndProperty(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Editor/BodyTrackingForFitness/BodyPoseAlignmentDetectorConfigDrawer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
Editor/BodyTrackingForFitness/BodyPoseBoneTransformsEditor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
using System; | ||
using Oculus.Movement.Utils; | ||
using UnityEditor; | ||
|
||
namespace Oculus.Movement.BodyTrackingForFitness | ||
{ | ||
/// <summary> | ||
/// Adds button features in the inspector: | ||
/// * Generate and/or refresh positions of bone visuals childed to bone transforms | ||
/// </summary> | ||
[CustomEditor(typeof(BodyPoseBoneTransforms))] | ||
public class BodyPoseBoneTransformsEditor : Editor | ||
{ | ||
private InspectorGuiHelper[] _helpers; | ||
private InspectorGuiHelper[] Helpers => | ||
_helpers != null ? _helpers : _helpers = new InspectorGuiHelper[] | ||
{ | ||
new InspectorGuiHelper(IsShowingRefreshButton, Refresh, null, | ||
"Refresh Transforms", InspectorGuiHelper.OptionalIcon.None), | ||
new InspectorGuiHelper(IsAbleToTPose, RefreshTPose, null, | ||
"Refresh T-Pose", InspectorGuiHelper.OptionalIcon.None), | ||
new InspectorGuiHelper(IsAbleToSave, SaveAsset, null, | ||
"Export Asset", InspectorGuiHelper.OptionalIcon.None), | ||
}; | ||
|
||
private BodyPoseBoneTransforms Target => (BodyPoseBoneTransforms)target; | ||
|
||
/// <inheritdoc/> | ||
public override void OnInspectorGUI() | ||
{ | ||
Array.ForEach(Helpers, helper => helper.DrawInInspector()); | ||
DrawDefaultInspector(); | ||
} | ||
|
||
private bool IsShowingRefreshButton() => Target.BodyPose != null; | ||
|
||
private bool IsAbleToTPose() => true; | ||
|
||
private bool IsAbleToSave() => Target.BoneContainer != null; | ||
|
||
private void Refresh() | ||
{ | ||
Target.RefreshHierarchyDuringEditor(); | ||
EditorTransformAwareness.RefreshSystem(); | ||
EditorBodyPoseLineSkeleton.RefreshSystem(); | ||
} | ||
|
||
private void RefreshTPose() | ||
{ | ||
Target.RefreshTPose(); | ||
} | ||
|
||
private void SaveAsset() | ||
{ | ||
BodyPoseControllerEditor.SaveAsset(Target); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Editor/BodyTrackingForFitness/BodyPoseBoneTransformsEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.