Update custom pass to global custom pass

This commit is contained in:
Misaki
2024-10-23 20:15:07 +09:00
parent e441bb7911
commit d0554a73bb
64 changed files with 949 additions and 46128 deletions

View 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);
}
}
}