Update custom pass to global custom pass
This commit is contained in:
77
Editor/NormalBaker/SmoothNormalBakerWindow.cs
Normal file
77
Editor/NormalBaker/SmoothNormalBakerWindow.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Unity.Toonshader.Editor
|
||||
{
|
||||
public class SmoothNormalBakerWindow : EditorWindow
|
||||
{
|
||||
[MenuItem("Tools/UTS/Smooth Normal Baker")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
var window = GetWindow<SmoothNormalBakerWindow>("Smooth Normal Baker");
|
||||
window.ShowUtility();
|
||||
}
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
var objectField = new ObjectField("Input Object")
|
||||
{
|
||||
allowSceneObjects = false,
|
||||
objectType = typeof(Mesh)
|
||||
};
|
||||
|
||||
var directBakeToggle = new Toggle("Direct Bake");
|
||||
|
||||
var bakeButton = new Button()
|
||||
{
|
||||
text = "Bake"
|
||||
};
|
||||
|
||||
bakeButton.clicked += () =>
|
||||
{
|
||||
if (objectField.value is not GameObject inputObject)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var outputObject = inputObject;
|
||||
if (!directBakeToggle.value)
|
||||
{
|
||||
var saveLocation = EditorUtility.OpenFolderPanel("Save location", "", "");
|
||||
|
||||
if (!Directory.Exists(saveLocation))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var inputMeshLocation = AssetDatabase.GetAssetPath(inputObject);
|
||||
var outputMeshLocation = Path.Combine(saveLocation, $"{Path.GetFileNameWithoutExtension(inputMeshLocation)}_UtsSmoothedNormal{Path.GetExtension(inputMeshLocation)}");
|
||||
|
||||
if (!File.Exists(outputMeshLocation))
|
||||
{
|
||||
AssetDatabase.CopyAsset(inputMeshLocation, outputMeshLocation);
|
||||
AssetDatabase.ImportAsset(outputMeshLocation);
|
||||
}
|
||||
|
||||
outputObject = AssetDatabase.LoadAssetAtPath<GameObject>(outputMeshLocation);
|
||||
}
|
||||
|
||||
var originalMesh = UTSNormalBakerHelper.GetMesh(inputObject);
|
||||
var smoothedMesh = UTSNormalBakerHelper.GetMesh(outputObject);
|
||||
|
||||
foreach (var item in originalMesh)
|
||||
{
|
||||
var m = item.Value;
|
||||
UTSNormalBakerHelper.ComputeSmoothedNormalByJob(smoothedMesh[item.Key], m);
|
||||
}
|
||||
};
|
||||
|
||||
rootVisualElement.Add(objectField);
|
||||
rootVisualElement.Add(directBakeToggle);
|
||||
rootVisualElement.Add(bakeButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user