Initial Commit
This commit is contained in:
8
ResetHumanoid/Editor.meta
Normal file
8
ResetHumanoid/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89e2972b5cc7da64bb621fd56a97c8b1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
121
ResetHumanoid/Editor/ResetHumanoid.cs
Normal file
121
ResetHumanoid/Editor/ResetHumanoid.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace DreadScripts.ResetHumanoid
|
||||
{
|
||||
public class ResetHumanoid : EditorWindow
|
||||
{
|
||||
private static Animator ani;
|
||||
private static bool full;
|
||||
private static bool pos = true, rot = true, scale = true;
|
||||
|
||||
[MenuItem("DreadTools/Utility/Reset Humanoid")]
|
||||
private static void showWindow()
|
||||
{
|
||||
GetWindow<ResetHumanoid>(false, "Reset Humanoid", true);
|
||||
if (ani == null) ani = FindObjectOfType<Animator>();
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
EditorGUIUtility.labelWidth = 60;
|
||||
ani = (Animator) EditorGUILayout.ObjectField("Avatar", ani, typeof(Animator), true);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
pos = EditorGUILayout.Toggle("Position", pos);
|
||||
rot = EditorGUILayout.Toggle("Rotation", rot);
|
||||
scale = EditorGUILayout.Toggle("Scale", scale);
|
||||
EditorGUIUtility.labelWidth = 0;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
full = EditorGUILayout.Toggle(new GUIContent("Full Reset", "Reset includes the objects that the Model was imported with"), full);
|
||||
if (GUILayout.Button("Reset"))
|
||||
ResetPose(ani, full, pos, rot, scale);
|
||||
|
||||
}
|
||||
|
||||
public static void ResetPose(Animator ani, bool fullReset = false, bool position = true, bool rotation = true, bool scale = true)
|
||||
{
|
||||
if (!ani.avatar)
|
||||
{
|
||||
Debug.LogWarning("Avatar is required to reset pose!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Humans IDs if not full reset, otherwise All Ids
|
||||
// ID > Path
|
||||
// ID > Element > Transform Data
|
||||
Undo.RegisterFullObjectHierarchyUndo(ani.gameObject, "HierarchyReset");
|
||||
SerializedObject sAvi = new SerializedObject(ani.avatar);
|
||||
SerializedProperty humanIds = sAvi.FindProperty("m_Avatar.m_Human.data.m_Skeleton.data.m_ID");
|
||||
SerializedProperty allIds = sAvi.FindProperty("m_Avatar.m_AvatarSkeleton.data.m_ID");
|
||||
SerializedProperty defaultPose = sAvi.FindProperty("m_Avatar.m_DefaultPose.data.m_X");
|
||||
SerializedProperty tos = sAvi.FindProperty("m_TOS");
|
||||
|
||||
Dictionary<long, int> idToElem = new Dictionary<long, int>();
|
||||
Dictionary<int, TransformData> elemToTransform = new Dictionary<int, TransformData>();
|
||||
Dictionary<long, string> IdToPath = new Dictionary<long, string>();
|
||||
|
||||
for (int i = 0; i < allIds.arraySize; i++)
|
||||
idToElem.Add(allIds.GetArrayElementAtIndex(i).longValue, i);
|
||||
|
||||
for (int i = 0; i < defaultPose.arraySize; i++)
|
||||
elemToTransform.Add(i, new TransformData(defaultPose.GetArrayElementAtIndex(i)));
|
||||
|
||||
for (int i = 0; i < tos.arraySize; i++)
|
||||
{
|
||||
SerializedProperty currProp = tos.GetArrayElementAtIndex(i);
|
||||
IdToPath.Add(currProp.FindPropertyRelative("first").longValue, currProp.FindPropertyRelative("second").stringValue);
|
||||
}
|
||||
|
||||
Action<Transform, TransformData> applyTransform = (transform, data) =>
|
||||
{
|
||||
if (transform)
|
||||
{
|
||||
if (position)
|
||||
transform.localPosition = data.pos;
|
||||
if (rotation)
|
||||
transform.localRotation = data.rot;
|
||||
if (scale)
|
||||
transform.localScale = data.scale;
|
||||
}
|
||||
};
|
||||
|
||||
if (!fullReset)
|
||||
{
|
||||
for (int i = 0; i < humanIds.arraySize; i++)
|
||||
{
|
||||
Transform myBone = ani.transform.Find(IdToPath[humanIds.GetArrayElementAtIndex(i).longValue]);
|
||||
TransformData data = elemToTransform[idToElem[humanIds.GetArrayElementAtIndex(i).longValue]];
|
||||
applyTransform(myBone, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < allIds.arraySize; i++)
|
||||
{
|
||||
Transform myBone = ani.transform.Find(IdToPath[allIds.GetArrayElementAtIndex(i).longValue]);
|
||||
TransformData data = elemToTransform[idToElem[allIds.GetArrayElementAtIndex(i).longValue]];
|
||||
applyTransform(myBone, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct TransformData
|
||||
{
|
||||
public Vector3 pos;
|
||||
public Quaternion rot;
|
||||
public Vector3 scale;
|
||||
|
||||
public TransformData(SerializedProperty t)
|
||||
{
|
||||
SerializedProperty tProp = t.FindPropertyRelative("t");
|
||||
SerializedProperty qProp = t.FindPropertyRelative("q");
|
||||
SerializedProperty sProp = t.FindPropertyRelative("s");
|
||||
pos = new Vector3(tProp.FindPropertyRelative("x").floatValue, tProp.FindPropertyRelative("y").floatValue, tProp.FindPropertyRelative("z").floatValue);
|
||||
rot = new Quaternion(qProp.FindPropertyRelative("x").floatValue, qProp.FindPropertyRelative("y").floatValue, qProp.FindPropertyRelative("z").floatValue, qProp.FindPropertyRelative("w").floatValue);
|
||||
scale = new Vector3(sProp.FindPropertyRelative("x").floatValue, sProp.FindPropertyRelative("y").floatValue, sProp.FindPropertyRelative("z").floatValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
ResetHumanoid/Editor/ResetHumanoid.cs.meta
Normal file
11
ResetHumanoid/Editor/ResetHumanoid.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 842214ab484e30f4fb54f3a8c49fe911
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "com.dreadscripts.resethumanoid.Editor",
|
||||
"references": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23482c6621fa978479978cf55ec8f668
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
ResetHumanoid/LICENSE
Normal file
21
ResetHumanoid/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Dreadrith
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
7
ResetHumanoid/LICENSE.meta
Normal file
7
ResetHumanoid/LICENSE.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 852e3f2bfed42d24d9bac30b04123c5d
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
15
ResetHumanoid/README.md
Normal file
15
ResetHumanoid/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Reset Humanoid
|
||||
|
||||
### [Download From Here](https://vpm.dreadscripts.com/)
|
||||
|
||||
## Features
|
||||
- Allows resetting the pose of a humanoid animator.
|
||||
- Choose which properties to reset: position, rotation, and scale.
|
||||
|
||||
## How to Use
|
||||
1. Navigate to `DreadTools > Utility > Reset Humanoid` in the top menu.
|
||||
2. Select the avatar you want to reset the pose for.
|
||||
3. Choose reset options and click "Reset" to apply the pose reset.
|
||||
|
||||
### Thank You
|
||||
If you enjoy Reset Humanoid, please consider [supporting me ♡](https://ko-fi.com/Dreadrith)!
|
7
ResetHumanoid/README.md.meta
Normal file
7
ResetHumanoid/README.md.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d64dd784833ec0f4f8046a38fc7b6b65
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
ResetHumanoid/package.json
Normal file
17
ResetHumanoid/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "com.dreadscripts.resethumanoid",
|
||||
"displayName": "DreadScripts - ResetHumanoid",
|
||||
"version": "1.0.2",
|
||||
"description": "Simple tool to reset the pose of a humanoid animator.",
|
||||
"gitDependencies": {},
|
||||
"vpmDependencies": {},
|
||||
"author": {
|
||||
"name": "Dreadrith",
|
||||
"email": "dreadscripts@gmail.com",
|
||||
"url": "https://www.dreadrith.com"
|
||||
},
|
||||
"legacyFolders": {},
|
||||
"legacyFiles": {},
|
||||
"type": "tool",
|
||||
"unity": "2019.4"
|
||||
}
|
7
ResetHumanoid/package.json.meta
Normal file
7
ResetHumanoid/package.json.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d494f6df5e33e84fbe7bb1718986c67
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user