Skip to content

Commit

Permalink
Add everything
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienlagarde committed Jul 7, 2017
0 parents commit 6ff3bce
Show file tree
Hide file tree
Showing 430 changed files with 19,411 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/Assets/AssetStoreTools*

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd


# Unity3D generated meta files
*.pidb.meta

# Unity3D Generated File On Crash Reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# Mercurial
.hg*

# Data files
/Assets/DeLightingTool_Data
9 changes: 9 additions & 0 deletions Assets/DeLightingTool.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/DeLightingTool/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/DeLightingTool/Editor/API.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

221 changes: 221 additions & 0 deletions Assets/DeLightingTool/Editor/API/Delighting.CLI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor.Experimental.DelightingInternal;
using UnityEngine;

public class DelightingCLI
{
public static void Run()
{
UnityEditor.Experimental.Delighting.CLI.Run();
}
}

namespace UnityEditor.Experimental
{
using UnityDebug = UnityEngine.Debug;

public static partial class Delighting
{
public static class CLI
{
struct Command
{
internal string baseTexturePath;
internal string normalsTexturePath;
internal string bentNormalsTexturePath;
internal string ambientOcclusionTexturePath;
internal string positionTexturePath;
internal string maskTexturePath;

internal string inputFolderPath;

internal bool? switchYZ;
internal float? separateDarkAreas;
internal float? forceLocalDelighting;
internal float? removeHighlights;
internal float? removeDarkNoise;

internal string delightedTexturePath;
}

public static void Run()
{
var args = System.Environment.GetCommandLineArgs();
RunArgs(args);
}

public static void RunArgs(string[] args)
{
var command = Parse(args);
Execute(command);
}

static void Execute(Command command)
{
if (string.IsNullOrEmpty(command.delightedTexturePath))
throw new Exception("-output must be defined");

var service = Delighting.NewService();

var input = new Input()
.SetSwitchYZ(command.switchYZ)
.SetForceLocalDelighting(command.forceLocalDelighting)
.SetSeparateDarkAreas(command.separateDarkAreas)
.SetRemoveHighlights(command.removeHighlights)
.SetRemoveDarkNoise(command.removeDarkNoise);

if (!string.IsNullOrEmpty(command.inputFolderPath))
{
var loadOp = service.LoadInputFolderAsync(command.inputFolderPath);
loadOp.Execute();
if (loadOp.error != null)
{
var width = 0;
var height = 0;
if (loadOp.data != null && loadOp.data.baseTexture != null)
{
width = loadOp.data.baseTexture.width;
height = loadOp.data.baseTexture.height;
}
var errors = new List<string>();
DelightingHelpers.GetErrorMessagesFrom(((ProcessException)loadOp.error).errorCode, errors, width, height);
for (int i = 0; i < errors.Count; i++)
UnityDebug.LogError(errors[i]);

return;
}

input
.SetBaseTexture(loadOp.data.baseTexture)
.SetNormalsTexture(loadOp.data.normalsTexture)
.SetBentNormalsTexture(loadOp.data.bentNormalsTexture)
.SetAmbientOcclusionTexture(loadOp.data.ambientOcclusionTexture)
.SetPositionTexture(loadOp.data.positionTexture)
.SetMaskTexture(loadOp.data.maskTexture);

service.SetInput(loadOp.data);
}
else
{
input
.SetBaseTexture(command.baseTexturePath)
.SetNormalsTexture(command.normalsTexturePath)
.SetBentNormalsTexture(command.bentNormalsTexturePath)
.SetAmbientOcclusionTexture(command.ambientOcclusionTexturePath)
.SetPositionTexture(command.positionTexturePath)
.SetMaskTexture(command.maskTexturePath);
service.SetInput(input);
}

var processOp = service.ProcessAsync(new ProcessArgs { fromStep = ProcessStep.Gather, calculateResult = true });
processOp.Execute();

if (processOp.error != null)
{
UnityDebug.LogException(processOp.error);
return;
}

var bytes = processOp.data.result.EncodeToPNG();
File.WriteAllBytes(command.delightedTexturePath, bytes);
}

static Command Parse(string[] args)
{
var result = new Command();
var index = 0;
while (index < args.Length)
{
switch (args[index])
{
case "-base":
++index;
if (index < args.Length)
result.baseTexturePath = args[index];
break;
case "-normals":
++index;
if (index < args.Length)
result.normalsTexturePath = args[index];
break;
case "-bentNormals":
++index;
if (index < args.Length)
result.bentNormalsTexturePath = args[index];
break;
case "-ao":
++index;
if (index < args.Length)
result.ambientOcclusionTexturePath = args[index];
break;
case "-position":
++index;
if (index < args.Length)
result.positionTexturePath = args[index];
break;
case "-mask":
++index;
if (index < args.Length)
result.maskTexturePath = args[index];
break;
case "-inputFolder":
++index;
if (index < args.Length)
result.inputFolderPath = args[index];
break;
case "-output":
++index;
if (index < args.Length)
result.delightedTexturePath = args[index];
break;
case "-separateDarkAreas":
{
++index;
float value;
if (index < args.Length && float.TryParse(args[index], out value))
result.separateDarkAreas = value;
break;
}
case "-forceLocalDelighting":
{
++index;
float value;
if (index < args.Length && float.TryParse(args[index], out value))
result.forceLocalDelighting = value;
break;
}
case "-removeHighlights":
{
++index;
float value;
if (index < args.Length && float.TryParse(args[index], out value))
result.removeHighlights = value;
break;
}
case "-removeDarkNoise":
{
++index;
float value;
if (index < args.Length && float.TryParse(args[index], out value))
result.removeDarkNoise = value;
break;
}
case "-switchYZ":
{
++index;
bool value;
if (index < args.Length && bool.TryParse(args[index], out value))
result.switchYZ = value;
break;
}

}
++index;
}
return result;
}
}
}
}
12 changes: 12 additions & 0 deletions Assets/DeLightingTool/Editor/API/Delighting.CLI.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Assets/DeLightingTool/Editor/API/Delighting.ErrorCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace UnityEditor.Experimental
{
public static partial class Delighting
{
[Flags]
public enum ErrorCode
{
NoErrors = 0,
MissingBaseTexture = 1 << 0,
MissingNormalsTexture = 1 << 1,
MissingBentNormalsTexture = 1 << 2,
MissingAmbientOcclusionTexture = 1 << 3,
PreviewNotAvailable = 1 << 4,
WrongSizeNormalsTexture = 1 << 5,
WrongSizeBentNormalsTexture = 1 << 6,
WrongSizeAmbientOcclusionTexture = 1 << 7,
WrongSizePositionTexture = 1 << 8,
WrongSizeMaskTexture = 1 << 9,
ColorSpaceNotLinear = 1 << 10
}
}
}
12 changes: 12 additions & 0 deletions Assets/DeLightingTool/Editor/API/Delighting.ErrorCode.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Assets/DeLightingTool/Editor/API/Delighting.IInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using UnityEngine;

namespace UnityEditor.Experimental
{
public static partial class Delighting
{
public interface IInput
{
bool hasBaseTexture { get; }
Texture2D baseTexture { get; }
bool hasNormalsTexture { get; }
Texture2D normalsTexture { get; }
bool hasBentNormalsTexture { get; }
Texture2D bentNormalsTexture { get; }
bool hasAmbientOcclusionTexture { get; }
Texture2D ambientOcclusionTexture { get; }
bool hasPositionTexture { get; }
Texture2D positionTexture { get; }
bool hasMaskTexture { get; }
Texture2D maskTexture { get; }
bool? switchYZ { get; }
float? separateDarkAreas { get; }
float? forceLocalDelighting { get; }
float? removeHighlights { get; }
float? removeDarkNoise { get; }
}
}
}
12 changes: 12 additions & 0 deletions Assets/DeLightingTool/Editor/API/Delighting.IInput.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6ff3bce

Please sign in to comment.