Skip to content

Commit

Permalink
cleanup / renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Mar 27, 2023
1 parent 49b6f69 commit bd1bec7
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 70 deletions.
3 changes: 0 additions & 3 deletions UnityGLTF/Assets/UnityGLTF/Editor/Scripts/Humanoid.meta

This file was deleted.

8 changes: 8 additions & 0 deletions UnityGLTF/Assets/UnityGLTF/Editor/Scripts/InternalUI.meta

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace UnityGLTF
{
public class AvatarUtils
internal class AvatarUtils
{
// A static dictionary containing the mapping from joint/bones names in the model
// to the names Unity uses for them internally.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,53 @@

namespace UnityGLTF
{
public static class HumanoidSetup
internal static class HumanoidSetup
{
// Start is called before the first frame update
private static MethodInfo _SetupHumanSkeleton;

internal static Avatar AddAvatarToGameObject(GameObject gameObject)
{
HumanDescription description = AvatarUtils.CreateHumanDescription(gameObject);
var bones = description.human;
SetupHumanSkeleton(gameObject, ref bones, out var skeletonBones, out var hasTranslationDoF);
description.human = bones;
description.skeleton = skeletonBones;
description.hasTranslationDoF = hasTranslationDoF;

Avatar avatar = AvatarBuilder.BuildHumanAvatar(gameObject, description);
avatar.name = "Avatar";

if (!avatar.isValid)
{
Object.DestroyImmediate(avatar);
return null;
}

var animator = gameObject.GetComponent<Animator>();
if (animator) animator.avatar = avatar;
return avatar;
}

private static void SetupHumanSkeleton(
GameObject modelPrefab,
ref HumanBone[] humanBoneMappingArray,
out SkeletonBone[] skeletonBones,
out bool hasTranslationDoF)
{
_SetupHumanSkeleton = typeof(AvatarSetupTool).GetMethod(nameof(SetupHumanSkeleton), (BindingFlags)(-1));
skeletonBones = Array.Empty<SkeletonBone>();
hasTranslationDoF = false;

_SetupHumanSkeleton?.Invoke(null, new object[]
{
modelPrefab,
humanBoneMappingArray,
skeletonBones,
hasTranslationDoF
});
}


// AvatarSetupTools
// AvatarBuilder.BuildHumanAvatar
// AvatarConfigurationStage.CreateStage
Expand Down Expand Up @@ -56,47 +98,5 @@ static void _OpenEditor(MenuCommand command)
e.SwitchToEditMode();
}
#endif

internal static Avatar AddAvatarToGameObject(GameObject gameObject)
{
HumanDescription description = AvatarUtils.CreateHumanDescription(gameObject);
var bones = description.human;
SetupHumanSkeleton(gameObject, ref bones, out var skeletonBones, out var hasTranslationDoF);
description.human = bones;
description.skeleton = skeletonBones;
description.hasTranslationDoF = hasTranslationDoF;

Avatar avatar = AvatarBuilder.BuildHumanAvatar(gameObject, description);
avatar.name = "Avatar";

if (!avatar.isValid)
{
Object.DestroyImmediate(avatar);
return null;
}

var animator = gameObject.GetComponent<Animator>();
if (animator) animator.avatar = avatar;
return avatar;
}

private static void SetupHumanSkeleton(
GameObject modelPrefab,
ref HumanBone[] humanBoneMappingArray,
out SkeletonBone[] skeletonBones,
out bool hasTranslationDoF)
{
_SetupHumanSkeleton = typeof(AvatarSetupTool).GetMethod(nameof(SetupHumanSkeleton), (BindingFlags)(-1));
skeletonBones = Array.Empty<SkeletonBone>();
hasTranslationDoF = false;

_SetupHumanSkeleton?.Invoke(null, new object[]
{
modelPrefab,
humanBoneMappingArray,
skeletonBones,
hasTranslationDoF
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ namespace UnityGLTF
{
internal class UnityGLTFTabbedEditor : AssetImporterTabbedEditor
{
private List<GltfAssetImporterTab> _tabs;
private readonly List<GltfAssetImporterTab> _tabs = new List<GltfAssetImporterTab>();

public void AddTab(GltfAssetImporterTab tab)
protected void AddTab(GltfAssetImporterTab tab)
{
if (_tabs == null) _tabs = new List<GltfAssetImporterTab>();
if (!_tabs.Contains(tab)) _tabs.Add(tab);
tabs = _tabs.Select(x => (BaseAssetImporterTabUI) x).ToArray();
m_TabNames = _tabs.Select(t => t.label).ToArray();
m_TabNames = _tabs.Select(t => t.Label).ToArray();
}

public GltfAssetImporterTab GetTab(int index)
Expand All @@ -30,32 +29,21 @@ public GltfAssetImporterTab GetTab(int index)
return _tabs[index];
}

public override void OnEnable()
{
Debug.Log("Enabling Active Tabs");
base.OnEnable();
}
public override void OnEnable() => base.OnEnable();
}

internal class GltfAssetImporterTab : BaseAssetImporterTabUI
{
internal string label;
private Action tabGui;
internal readonly string Label;
private readonly Action _tabGui;

public GltfAssetImporterTab(AssetImporterEditor panelContainer, string label, Action tabGui) : base(panelContainer)
{
this.label = label;
this.tabGui = tabGui;
this.Label = label;
this._tabGui = tabGui;
}

internal override void OnEnable()
{
}

public override void OnInspectorGUI()
{
if (tabGui != null) tabGui();
else EditorGUILayout.LabelField("Name", label);
}
internal override void OnEnable() { }
public override void OnInspectorGUI() => _tabGui?.Invoke();
}
}

0 comments on commit bd1bec7

Please sign in to comment.