Updated GenerateMask helper

This commit is contained in:
Misaki
2025-01-23 23:56:11 +09:00
parent b00b63cfb4
commit eb6c2d9e54
16 changed files with 503 additions and 232 deletions

View File

@@ -1,4 +1,5 @@
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
@@ -20,7 +21,8 @@ namespace Misaki.ArtToolEditor
public TextureChannel BChannelSource = TextureChannel.B;
public TextureChannel AChannelSource = TextureChannel.A;
public string outputNameSuffix = "_ChannelMixer";
public string outputNameRegex = "$";
public string outputNameReplacement = "_ChannelMixer";
public void OnPreProcess(AssetsProcessContext context)
{
@@ -36,10 +38,18 @@ namespace Misaki.ArtToolEditor
var tempRT = RenderTexture.GetTemporary(texture.width, texture.height, 0, GraphicsFormat.R8G8B8A8_UNorm);
var material = new Material(Shader.Find(ShaderConstants.Channel_Mixer_Shader_Path));
material.SetVector(ShaderConstants.Channel_Source_Property, new Vector4((int)RChannelSource, (int)GChannelSource, (int)BChannelSource, (int)AChannelSource));
material.SetVector(
ShaderConstants.Channel_Source_Property,
new Vector4(
RChannelSource.ToColorIndex(),
GChannelSource.ToColorIndex(),
BChannelSource.ToColorIndex(),
AChannelSource.ToColorIndex()));
Graphics.Blit(texture, tempRT, material);
var texturePath = Path.Combine(outputDirectory, texture.name + outputNameSuffix + Constants.Extensions.PNG);
var outputName = Regex.Replace(texture.name, outputNameRegex, outputNameReplacement, RegexOptions.Compiled);
var texturePath = Path.Combine(outputDirectory, outputName + Constants.Extensions.PNG);
TextureHelpers.ExportRenderTextureToPNG(tempRT, texturePath);
AssetDatabase.ImportAsset(texturePath);

View File

@@ -5,28 +5,33 @@ namespace Misaki.ArtToolEditor
{
internal class ChannelMixerVisualProvider : OptionsVisualProvider
{
public override VisualElement ContentAfterList()
public override void ContentAfterList(VisualElement rootVisualElement)
{
var root = new VisualElement();
rootVisualElement.dataSource = processor;
root.Add(CreateChannelSelector("Set Channel R From", nameof(ChannelMixerProcessor.RChannelSource)));
root.Add(CreateChannelSelector("Set Channel G From", nameof(ChannelMixerProcessor.GChannelSource)));
root.Add(CreateChannelSelector("Set Channel B From", nameof(ChannelMixerProcessor.BChannelSource)));
root.Add(CreateChannelSelector("Set Channel A From", nameof(ChannelMixerProcessor.AChannelSource)));
rootVisualElement.Add(CreateChannelSelector("Set Channel R From", nameof(ChannelMixerProcessor.RChannelSource)));
rootVisualElement.Add(CreateChannelSelector("Set Channel G From", nameof(ChannelMixerProcessor.GChannelSource)));
rootVisualElement.Add(CreateChannelSelector("Set Channel B From", nameof(ChannelMixerProcessor.BChannelSource)));
rootVisualElement.Add(CreateChannelSelector("Set Channel A From", nameof(ChannelMixerProcessor.AChannelSource)));
var nameSuffixField = new TextField("Output Name Suffix")
var nameRegexField = new TextField("Output Name Regx")
{
tooltip = "The suffix to append to the output texture name. Will overwrite original texture if set it to empty and use CurrentDirectory as output directory.",
tooltip = "The regex to match when replace the name",
};
nameSuffixField.SetBinding(nameof(TextField.value), new DataBinding() { dataSourcePath = PropertyPath.FromName(nameof(ChannelMixerProcessor.outputNameSuffix)) });
root.Add(nameSuffixField);
nameRegexField.SetBinding(nameof(TextField.value), new DataBinding() { dataSourcePath = PropertyPath.FromName(nameof(ChannelMixerProcessor.outputNameRegex)) });
rootVisualElement.Add(nameRegexField);
return root;
var nameReplaceField = new TextField("Output Name Replacement")
{
tooltip = "The string to replace with",
};
nameReplaceField.SetBinding(nameof(TextField.value), new DataBinding() { dataSourcePath = PropertyPath.FromName(nameof(ChannelMixerProcessor.outputNameReplacement)) });
rootVisualElement.Add(nameReplaceField);
}
private static VisualElement CreateChannelSelector(string label, string binding)
{
var enumField = new EnumField(label, TextureChannel.R);
var enumField = new EnumField(label, TextureChannel.None);
enumField.SetBinding(nameof(EnumField.value), new DataBinding() { dataSourcePath = PropertyPath.FromName(binding) });
return enumField;