Skip to content

Commit

Permalink
Merge pull request #64 from peeweek/qol-external-output
Browse files Browse the repository at this point in the history
Draft: External Output QoL improvements
  • Loading branch information
alelievr authored Nov 29, 2024
2 parents 08b596a + a36b49d commit a506c34
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#SettingsButton
{
visibility: hidden;
}

#title
{
background-color: #003355;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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 =
Expand Down
19 changes: 18 additions & 1 deletion Packages/com.alelievr.mixture/Runtime/Graph/MixtureGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using Object = UnityEngine.Object;
using UnityEngine.Serialization;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a506c34

Please sign in to comment.