Skip to content

Commit e80720c

Browse files
committed
Improve packer to properly handle folder inclusion
- Allow to set the texture array names (and path) - Change default for height normalization to false - Properly refresh unity asset DB on TA creation
1 parent f4d92f7 commit e80720c

3 files changed

Lines changed: 50 additions & 13 deletions

File tree

Assets/Exporter Scripts/Editor/OcbMicroSplatArrayCreator.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.IO;
12
using UnityEditor;
23
using UnityEngine;
34

@@ -8,8 +9,7 @@ public static class OcbMicroSplatArrayCreator
89
{
910

1011

11-
public static void CopyTextureAlbedo(OcbMicroSplatArrayEntry cfg,
12-
Texture2DArray dst, int i, bool linear = true)
12+
public static void CopyTextureAlbedo(OcbMicroSplatArrayEntry cfg, Texture2DArray dst, int i)
1313
{
1414

1515
int Width = dst.width;
@@ -169,9 +169,12 @@ public static void CreateTextureArrays(OcbMicroSplatArray cfg, string path)
169169

170170
var textures = cfg.Textures;
171171

172-
var DiffPath = path.Replace(".asset", "_diff_tarray.asset");
173-
var NormPath = path.Replace(".asset", "_norm_tarray.asset");
174-
var ShaoPath = path.Replace(".asset", "_shao_tarray.asset");
172+
string root = Path.GetDirectoryName(path);
173+
string fname = Path.GetFileName(path);
174+
175+
var DiffPath = Path.Combine(root, cfg.AlbedoTexArrName.Replace("{name}", fname.Replace(".asset", "")) + ".asset");
176+
var NormPath = Path.Combine(root, cfg.NormTexArrName.Replace("{name}", fname.Replace(".asset", "")) + ".asset");
177+
var ShaoPath = Path.Combine(root, cfg.SmaoTexArrName.Replace("{name}", fname.Replace(".asset", "")) + ".asset");
175178

176179
var DiffArray = new Texture2DArray(Width, Height, textures.Length, TextureFormat.DXT5, true, false);
177180
var NormArray = new Texture2DArray(Width, Height, textures.Length, TextureFormat.DXT5, true, true);
@@ -243,9 +246,9 @@ public static void CreateTextureArrays(OcbMicroSplatArray cfg, string path)
243246
// var height = texture.Height;
244247

245248

246-
CopyTextureAlbedo(texture, DiffArray, i, false);
249+
CopyTextureAlbedo(texture, DiffArray, i);
247250
CopyTextureNormal(texture, NormArray, i);
248-
CopyTextureSHAO(texture, ShaoArray, i, true);
251+
CopyTextureSHAO(texture, ShaoArray, i);
249252

250253
// texture.Albedo = albedo;
251254
// texture.Normal = normal;
@@ -258,6 +261,9 @@ public static void CreateTextureArrays(OcbMicroSplatArray cfg, string path)
258261
CreateArrayAsset(DiffArray, DiffPath);
259262
CreateArrayAsset(NormArray, NormPath);
260263
CreateArrayAsset(ShaoArray, ShaoPath);
264+
265+
AssetDatabase.SaveAssets();
266+
AssetDatabase.Refresh();
261267
}
262268

263269
static Shader mergeInChannelShader;

Assets/Exporter Scripts/Editor/OcbMicroSplatArrayEditor.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ private void CollectAssets(UnityEngine.Object root,
5656
"128", "256", "512", "1024", "2048", "4096", "8128"
5757
};
5858

59+
static GUIContent diffLabel = new GUIContent("Diffues", "Albedo red, Albedo green, Albedo blue, height");
60+
static GUIContent normLabel = new GUIContent("Normal", "Emission (r), normal (x), Emission(g), normal (y)");
61+
static GUIContent shaoLabel = new GUIContent("SHAO", "Emission (b), smoothness, metallic, occlusion");
62+
5963
public override void OnInspectorGUI()
6064
{
6165
base.OnInspectorGUI();
@@ -82,6 +86,19 @@ public override void OnInspectorGUI()
8286
script.AnisoLevel = EditorGUILayout.IntSlider(
8387
"Aniso Level", script.AnisoLevel, 0, 16);
8488

89+
script.openTaNames = EditorGUILayout.Foldout(script.openTaNames, "Texture Array Names");
90+
91+
if (script.openTaNames)
92+
{
93+
script.AlbedoTexArrName = EditorGUILayout.TextField(diffLabel, script.AlbedoTexArrName);
94+
script.NormTexArrName = EditorGUILayout.TextField(normLabel, script.NormTexArrName);
95+
script.SmaoTexArrName = EditorGUILayout.TextField(shaoLabel, script.SmaoTexArrName);
96+
}
97+
98+
GUI.enabled = script.Textures.All(t => t.Albedo != null); // && t.Normal != null
99+
bool generate = GUILayout.Button("Generate Texture2D Array", GUILayout.Height(24));
100+
GUI.enabled = true;
101+
85102
// int clear = -1;
86103
// int remove = -1
87104

@@ -235,18 +252,20 @@ public override void OnInspectorGUI()
235252
}
236253

237254
GUI.enabled = script.Textures.All(t => t.Albedo != null); // && t.Normal != null
238-
if (GUILayout.Button("Generate Texture2D Array", GUILayout.Height(24)))
239-
{
240-
string path = AssetDatabase.GetAssetPath(target).Replace("\\", "/");
241-
OcbMicroSplatArrayCreator.CreateTextureArrays(script, path);
242-
}
255+
generate |= GUILayout.Button("Generate Texture2D Array", GUILayout.Height(24));
243256
GUI.enabled = true;
244257

245258
if (EditorGUI.EndChangeCheck())
246259
{
247260
EditorUtility.SetDirty(target);
248261
}
249262

263+
if (generate)
264+
{
265+
string path = AssetDatabase.GetAssetPath(target).Replace("\\", "/");
266+
OcbMicroSplatArrayCreator.CreateTextureArrays(script, path);
267+
}
268+
250269
}
251270

252271
// Recognized path tails for different textures

Assets/Exporter Scripts/Runtime/OcbMicroSplatArray.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public class OcbMicroSplatArray : ScriptableObject
2929
[HideInInspector]
3030
public OcbMicroSplatArrayEntry[] Textures = null;
3131

32+
[HideInInspector]
33+
public bool openTaNames = false;
34+
35+
[HideInInspector]
36+
public string AlbedoTexArrName = "{name}_ta_rgbh";
37+
38+
[HideInInspector]
39+
public string NormTexArrName = "{name}_ta_enen";
40+
41+
[HideInInspector]
42+
public string SmaoTexArrName = "{name}_ta_esmo";
43+
3244
}
3345

3446
[System.Serializable]
@@ -50,7 +62,7 @@ public class OcbMicroSplatArrayEntry
5062
public bool IsNormalSwitched = true;
5163
public bool IsNormalInverted = false;
5264
public bool IsHeightCentered = false;
53-
public bool IsHeightNormalized = true;
65+
public bool IsHeightNormalized = false;
5466
public TextureChannel HeightChannel = TextureChannel.Blue;
5567
public TextureChannel SmoothChannel = TextureChannel.Alpha;
5668
public TextureChannel OcclusionChannel = TextureChannel.Green;

0 commit comments

Comments
 (0)