-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
[CustomEditor(typeof(TransformRecorder))] | ||
public class TransformsRecorderEditor : Editor | ||
{ | ||
public override void OnInspectorGUI() | ||
{ | ||
if (GUILayout.Button("Record Transforms", EditorStyles.miniButton)) | ||
{ | ||
((TransformRecorder)target).RecordTransforms(); | ||
} | ||
if (GUILayout.Button("Load Transforms", EditorStyles.miniButton)) | ||
{ | ||
((TransformRecorder)target).LoadTransforms(); | ||
} | ||
DrawDefaultInspector (); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "TransformsRecorder.Editor", | ||
"references": [ | ||
"TransformsRecorder" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
The MIT License (MIT) | ||
Copyright © 2022 Amit Netanel, Abbabon | ||
|
||
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. |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Transforms Recorder | ||
|
||
[![openupm]() | ||
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FAbbabon%2FTransformsRecorder&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com) | ||
|
||
This tool can be used to record a complex hierarchy of GameObject's child transforms (during editor or runtime) in a ScriptableObject. This allows you to pose the character around your scene, take marketing screenshots, or anything similar. | ||
|
||
More motivations and implementation details [can be found at my blog](https://abbabon.github.io/2020-11-09-serializing-transforms/) | ||
|
||
# Install | ||
|
||
## Open UPM | ||
|
||
TransformsRecorder can be installed via [OpenUPM](https://openupm.com/). It's recommended to install it via [openupm-cli](https://github.com/openupm/openupm-cli): | ||
|
||
`openupm add com.mezookan.transforms-recorder` | ||
|
||
## Git Dependency | ||
|
||
You can add the package to your project as a [git upm dependency](https://docs.unity3d.com/Manual/upm-git.html). | ||
|
||
Either add the following line to your project's `Packages/manifest.json` file's dependencies: | ||
|
||
"com.mezookan.transforms-recorder":"https://github.com/abbabon/TransformsRecorder.git?path=Packages/TransformsRecorder", | ||
|
||
or via the `Windows/PackageManager` menu, by adding the following git repo: `https://github.com/abbabon/TransformsRecorder.git?path=Packages/TransformsRecorder` | ||
|
||
# How to use | ||
|
||
1. Place the 'TransformRecorder' script on any object in your scene. | ||
2. Drag the parent of the transform hierarchy you wish to record to the 'Parent Transform' field. | ||
3. Create a scriptable object from TransformDataContainer by right clicking on you project window, and then `Create->ScriptableObjects->TransformDataContainer` | ||
4. Drag the new TransformDataContainer to the TransformRecorder's relevant field. | ||
|
||
You can now save the transform hierarchy by pressing the 'Record Transforms' button, or load with 'Load Transforms'. | ||
Just remember to create a scriptable object for each pose / sate. I encourage you to experiment further and expand the system. | ||
|
||
An example scene is setup in the [repo](https://github.com/Abbabon/TransformsRecorder) (not in the package), so you can see it in action. | ||
|
||
# License | ||
|
||
Free to use under the [MIT License](https://opensource.org/licenses/MIT) | ||
|
||
# Third Party Notices | ||
|
||
'The Boss' Model and animations supplied by Adobe (taken from Mixamo.com). |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
[Serializable] | ||
public class TransformData | ||
{ | ||
public Vector3 Position; | ||
public Quaternion Rotation; | ||
public Vector3 Scale; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using UnityEngine; | ||
|
||
[CreateAssetMenu(fileName = "TransformDataContainer", menuName = "ScriptableObjects/TransformDataContainer")] | ||
public class TransformDataContainer : ScriptableObject | ||
{ | ||
public TransformNode parentNode; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
[Serializable] | ||
public class TransformNode | ||
{ | ||
public TransformData NodeTransformData; | ||
public List<TransformNode> ChildrenTransformsData; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class TransformRecorder : MonoBehaviour | ||
{ | ||
[SerializeField] private Transform _transformsParent; | ||
[SerializeField] private TransformDataContainer _transformDataContainer; | ||
|
||
public void RecordTransforms() | ||
{ | ||
if (_transformDataContainer != null) | ||
{ | ||
_transformDataContainer.parentNode = RecordTransformsRecursively(_transformsParent); | ||
} | ||
} | ||
|
||
public void LoadTransforms() | ||
{ | ||
if (_transformDataContainer != null) | ||
{ | ||
LoadTransformsRecursively(_transformsParent, _transformDataContainer.parentNode); | ||
} | ||
} | ||
|
||
private TransformNode RecordTransformsRecursively(Transform parent) | ||
{ | ||
var directChildren = GetDirectChildrenOfTransform(parent); | ||
|
||
var nodeData = new TransformNode | ||
{ | ||
NodeTransformData = new TransformData | ||
{ | ||
Position = parent.localPosition, | ||
Rotation = parent.localRotation, | ||
Scale = parent.localScale | ||
} | ||
}; | ||
|
||
if (directChildren.Count > 0) | ||
{ | ||
nodeData.ChildrenTransformsData = new List<TransformNode>(); | ||
foreach (var child in directChildren) | ||
{ | ||
nodeData.ChildrenTransformsData.Add(RecordTransformsRecursively(child)); | ||
} | ||
} | ||
else | ||
{ | ||
nodeData.ChildrenTransformsData = null; | ||
} | ||
|
||
return nodeData; | ||
} | ||
|
||
private void LoadTransformsRecursively(Transform parent, TransformNode nodeNode) | ||
{ | ||
var directChildren = GetDirectChildrenOfTransform(parent); | ||
|
||
if (directChildren.Count > 0) | ||
{ | ||
for (var nodeIndex = 0; nodeIndex < nodeNode.ChildrenTransformsData.Count; nodeIndex++) | ||
{ | ||
LoadTransformsRecursively(directChildren[nodeIndex], nodeNode.ChildrenTransformsData[nodeIndex]); | ||
} | ||
} | ||
|
||
parent.localPosition = nodeNode.NodeTransformData.Position; | ||
parent.localRotation = nodeNode.NodeTransformData.Rotation; | ||
parent.localScale = nodeNode.NodeTransformData.Scale; | ||
} | ||
|
||
private List<Transform> GetDirectChildrenOfTransform(Transform parent) | ||
{ | ||
var directChildren = new List<Transform>(); | ||
foreach (Transform directChild in parent) | ||
{ | ||
directChildren.Add(directChild); | ||
} | ||
return directChildren; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "TransformsRecorder" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "com.mezookan.transforms-recorder", | ||
"displayName": "Transforms Recorder", | ||
"version": "1.0.0", | ||
"description": "Transforms Recorder", | ||
"keywords": [ | ||
"3d", | ||
"modeling" | ||
], | ||
"unity": "2019.4" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.