diff --git a/Packages/com.alelievr.mixture/Editor/Resources/ExternalOutputNodeView.uss b/Packages/com.alelievr.mixture/Editor/Resources/ExternalOutputNodeView.uss index 6a65e20f..139ea318 100644 --- a/Packages/com.alelievr.mixture/Editor/Resources/ExternalOutputNodeView.uss +++ b/Packages/com.alelievr.mixture/Editor/Resources/ExternalOutputNodeView.uss @@ -1,4 +1,9 @@ #SettingsButton { visibility: hidden; +} + +#title +{ + background-color: #003355; } \ No newline at end of file diff --git a/Packages/com.alelievr.mixture/Editor/Views/ExternalOutputNodeView.cs b/Packages/com.alelievr.mixture/Editor/Views/ExternalOutputNodeView.cs index bb42a33d..d5e23cb6 100644 --- a/Packages/com.alelievr.mixture/Editor/Views/ExternalOutputNodeView.cs +++ b/Packages/com.alelievr.mixture/Editor/Views/ExternalOutputNodeView.cs @@ -33,7 +33,7 @@ protected override void BuildOutputNodeSettings() var externalOutputNode = nodeTarget as ExternalOutputNode; var nodeSettings = new IMGUIContainer(() => { - if(externalOutputNode.asset == null) + if (externalOutputNode.asset == null) { EditorGUILayout.HelpBox("This output has not been saved yet, please click Save As to save the output texture.", MessageType.Info); } @@ -48,7 +48,7 @@ protected override void BuildOutputNodeSettings() if (EditorGUI.EndChangeCheck()) { externalOutputNode.externalOutputDimension = (ExternalOutputNode.ExternalOutputDimension)outputDimension; - switch(outputDimension) + switch (outputDimension) { case ExternalOutputNode.ExternalOutputDimension.Texture2D: externalOutputNode.settings.dimension = OutputDimension.Texture2D; @@ -78,7 +78,7 @@ protected override void BuildOutputNodeSettings() { EditorGUI.BeginChangeCheck(); var outputType = EditorGUILayout.EnumPopup("Type", externalOutputNode.external2DOoutputType); - if(EditorGUI.EndChangeCheck()) + if (EditorGUI.EndChangeCheck()) { externalOutputNode.external2DOoutputType = (ExternalOutputNode.External2DOutputType)outputType; MarkDirtyRepaint(); @@ -105,12 +105,15 @@ protected override void BuildOutputNodeSettings() } } - EditorGUI.BeginChangeCheck(); - var exportAlpha = EditorGUILayout.Toggle("Export Alpha", externalOutputNode.exportAlpha); - if (EditorGUI.EndChangeCheck()) + if (externalOutputNode.externalOutputDimension == ExternalOutputNode.ExternalOutputDimension.Texture2D) { - externalOutputNode.exportAlpha = exportAlpha; - MarkDirtyRepaint(); + EditorGUI.BeginChangeCheck(); + var exportAlpha = EditorGUILayout.Toggle("Export Alpha", externalOutputNode.exportAlpha); + if (EditorGUI.EndChangeCheck()) + { + externalOutputNode.exportAlpha = exportAlpha; + MarkDirtyRepaint(); + } } externalOutputNode.previewSRGB = diff --git a/Packages/com.alelievr.mixture/Runtime/Graph/MixtureGraph.cs b/Packages/com.alelievr.mixture/Runtime/Graph/MixtureGraph.cs index 15ddaade..01b6634d 100644 --- a/Packages/com.alelievr.mixture/Runtime/Graph/MixtureGraph.cs +++ b/Packages/com.alelievr.mixture/Runtime/Graph/MixtureGraph.cs @@ -8,6 +8,7 @@ using System; using Object = UnityEngine.Object; using UnityEngine.Serialization; +using System.IO; #if UNITY_EDITOR using UnityEditor; #endif @@ -596,7 +597,8 @@ public void SaveExternalTexture(ExternalOutputNode external, bool saveAs = false throw new NotImplementedException($"File type not handled : '{external.externalFileType}'"); } - assetPath = EditorUtility.SaveFilePanelInProject("Save Texture", external.name, extension, "Save Texture"); + + assetPath = EditorUtility.SaveFilePanelInProject("Save Texture", external.name, extension, "Save Texture", Path.GetDirectoryName(external.graph.mainAssetPath)); if (string.IsNullOrEmpty(assetPath)) { @@ -630,6 +632,21 @@ public void SaveExternalTexture(ExternalOutputNode external, bool saveAs = false } else if (dimension == TextureDimension.Tex2D) { + // Pre-process (fill alpha with 1s when export alpha is false) + if(!external.exportAlpha) + { + var pixels = (outputTexture as Texture2D).GetPixels(); + for(int i = 0; i< pixels.Length; i++) + { + var c = pixels[i]; + c.a = 1f; + pixels[i] = c; + } + (outputTexture as Texture2D).SetPixels(pixels); + (outputTexture as Texture2D).Apply(); + } + + byte[] contents = null; if (external.externalFileType == ExternalOutputNode.ExternalFileType.EXR)