Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
pixtur committed Apr 19, 2022
2 parents f0834a8 + 3ec2eb8 commit 4d17c95
Show file tree
Hide file tree
Showing 434 changed files with 33,891 additions and 4,008 deletions.
27 changes: 27 additions & 0 deletions .Presets/c8590f8f-cca1-434a-a880-67bb91920e1a.var
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"SymbolId": "c8590f8f-cca1-434a-a880-67bb91920e1a",
"Variations": [
{
"Id": "77666666-9996-401e-9aa6-328dd6292beb",
"Title": "Sharp",
"ActivationIndex": 1,
"IsPreset": true,
"InputValuesForChildIds": {
"00000000-0000-0000-0000-000000000000": {
"8846aa50-e4d0-433c-9e5b-013a93f17f79": 0.4
}
}
},
{
"Id": "88666666-9996-401e-9aa6-328dd6292beb",
"Title": "Blurry",
"ActivationIndex": 2,
"IsPreset": true,
"InputValuesForChildIds": {
"00000000-0000-0000-0000-000000000000": {
"8846aa50-e4d0-433c-9e5b-013a93f17f79": 1.5
}
}
}
]
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,8 @@ T3/ImGui
T3/imgui.ini
imgui.ini
userSettings.json
Temp
.backup
Resources/user/1x/mars-express/sequence
Resources/user/1x/mars-express/references
Resources/user/1x/mars-express/soundtrack
47 changes: 31 additions & 16 deletions Core/DataTypes/Gradient.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Core.Resource;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using T3.Core.Animation;
using T3.Core.Logging;
using Vector4 = System.Numerics.Vector4;

namespace T3.Core.DataTypes
{
Expand Down Expand Up @@ -41,9 +41,9 @@ public virtual void Write(JsonTextWriter writer)
writer.WriteEndObject();
}

public List<Step> Steps = CreateDefaultSteps();
public Interpolations Interpolation;

public List<Step> Steps { get; set; } = CreateDefaultSteps();
public Interpolations Interpolation { get; set; }
public virtual void Read(JToken inputToken)
{
Steps.Clear();
Expand Down Expand Up @@ -104,23 +104,37 @@ public Vector4 Sample(float t)
t = t.Clamp(0, 1);
Step previousStep = null;

foreach (var step in Steps)
{
if (step.NormalizedPosition >= t)
foreach (var step in Steps)
{
if (previousStep == null || previousStep.NormalizedPosition >= step.NormalizedPosition)
if (step.NormalizedPosition >= t)
{
return step.Color;
if (previousStep == null || previousStep.NormalizedPosition >= step.NormalizedPosition)
{
return step.Color;
}

float amount = 0; // Hold
switch (Interpolation)
{
case Interpolations.Linear:
amount = MathUtils.RemapAndClamp(t, previousStep.NormalizedPosition, step.NormalizedPosition, 0, 1);
break;
case Interpolations.Smooth:
amount = MathUtils.RemapAndClamp(t, previousStep.NormalizedPosition, step.NormalizedPosition, 0, 1);
amount = MathUtils.SmootherStep(0, 1, amount);
break;

case Interpolations.OkLab:
amount = MathUtils.RemapAndClamp(t, previousStep.NormalizedPosition, step.NormalizedPosition, 0, 1);
return OkLab.Mix(previousStep.Color, step.Color, amount);
}

return Vector4.Lerp(previousStep.Color, step.Color, amount);
}

float amount = MathUtils.RemapAndClamp(t, previousStep.NormalizedPosition, step.NormalizedPosition, 0, 1);

return Vector4.Lerp(previousStep.Color, step.Color, amount);
previousStep = step;
}

previousStep = step;
}

return previousStep?.Color ?? Vector4.One;
}

Expand Down Expand Up @@ -155,6 +169,7 @@ public enum Interpolations
Linear,
Hold,
Smooth,
OkLab
}
}
}
7 changes: 6 additions & 1 deletion Core/Operator/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using T3.Core.Logging;
using T3.Core.Operator.Attributes;
using T3.Core.Operator.Slots;

Expand Down Expand Up @@ -101,7 +102,11 @@ public void RemoveConnection(Symbol.Connection connection, int index)
}
else
{
Debug.Assert(connection.SourceParentOrChildId == Guid.Empty);
if (connection.SourceParentOrChildId != Guid.Empty)
{
Log.Error($"connection has incorrect Source: { connection.SourceParentOrChildId}");
return (null, null, null, null);
}
sourceInstance = compositionInstance;
sourceSlot = sourceInstance.Inputs.SingleOrDefault(input => input.Id == connection.SourceSlotId);
}
Expand Down
16 changes: 11 additions & 5 deletions Core/Operator/Interfaces/ITransformable.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using System;
using T3.Core.Operator.Slots;

namespace T3.Core.Operator.Interfaces
{
public interface ITransformable
{
// Type Type { get; } // c#8 default interface impl would be nice for this
System.Numerics.Vector3 Translation { get; set; }
System.Numerics.Vector3 Rotation { get; set; }
System.Numerics.Vector3 Scale { get; set; }
Action<ITransformable, EvaluationContext> TransformCallback { get; set; }
// // Type Type { get; } // c#8 default interface impl would be nice for this
// System.Numerics.Vector3 Translation { get; set; }
// System.Numerics.Vector3 Rotation { get; set; }
// System.Numerics.Vector3 Scale { get; set; }

IInputSlot TranslationInput { get; }
IInputSlot RotationInput { get; }
IInputSlot ScaleInput { get; }

Action<Instance, EvaluationContext> TransformCallback { get; set; }
}
}
5 changes: 2 additions & 3 deletions Core/Operator/Slots/TransformCallbackSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ namespace T3.Core.Operator.Slots
{
public class TransformCallbackSlot<T> : Slot<T>
{
public Action<ITransformable, EvaluationContext> TransformCallback { get; set; }

public ITransformable TransformableOp { get; set; }

private new void Update(EvaluationContext context)
{
TransformCallback?.Invoke(TransformableOp, context);
// FIXME: Casting is ugly. TransformCall should us ITransformable instead
TransformableOp.TransformCallback?.Invoke(TransformableOp as Instance, context);
if (_baseUpdateAction == null)
{
Log.Warning("Failed to call base transform gizmo update for " + Parent.SymbolChildId, this.Parent.SymbolChildId);
Expand Down
76 changes: 67 additions & 9 deletions Core/Resource/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class Command
public class Model
{
public Assembly OperatorsAssembly { get; }
protected string Path { get; } = @"Operators\Types\";
protected string SymbolExtension { get; } = ".t3";
protected string OperatorTypesFolder { get; } = @"Operators\Types\";


public Model(Assembly operatorAssembly, bool enabledLogging)
{
Expand Down Expand Up @@ -448,7 +448,7 @@ public static void RegisterType(Type type, string typeName, Func<InputValue> def

public virtual void Load()
{
var symbolFiles = Directory.GetFiles(Path, $"*{SymbolExtension}");
var symbolFiles = Directory.GetFiles(OperatorTypesFolder, $"*{SymbolExtension}");
foreach (var symbolFile in symbolFiles)
{
ReadSymbolFromFile(symbolFile);
Expand Down Expand Up @@ -495,7 +495,7 @@ public Symbol ReadSymbolFromFile(string symbolFile)
var symbol = json.ReadSymbol(this);
if (symbol != null)
{
symbol.SourcePath = Path + symbol.Name + ".cs";
symbol.SourcePath = OperatorTypesFolder + symbol.Name + SourceExtension;
SymbolRegistry.Entries.Add(symbol.Id, symbol);
}

Expand All @@ -505,7 +505,7 @@ public Symbol ReadSymbolFromFile(string symbolFile)

public Symbol ReadSymbolWithId(Guid id)
{
var symbolFile = Directory.GetFiles(Path, $"*{id}*{SymbolExtension}").FirstOrDefault();
var symbolFile = Directory.GetFiles(OperatorTypesFolder, $"*{id}*{SymbolExtension}").FirstOrDefault();
if (symbolFile == null)
{
Log.Error($"Could not find symbol file containing the id '{id}'");
Expand All @@ -516,12 +516,12 @@ public Symbol ReadSymbolWithId(Guid id)
return symbol;
}

public virtual void Save()
public virtual void SaveAll()
{
ResourceManager.Instance().DisableOperatorFileWatcher(); // don't update ops if file is written during save

// remove all old t3 files before storing to get rid off invalid ones
DirectoryInfo di = new DirectoryInfo(Path);
DirectoryInfo di = new DirectoryInfo(OperatorTypesFolder);
FileInfo[] files = di.GetFiles("*" + SymbolExtension).ToArray();
foreach (FileInfo file in files)
{
Expand All @@ -539,7 +539,7 @@ public virtual void Save()
// store all symbols in corresponding files
foreach (var (_, symbol) in SymbolRegistry.Entries)
{
using (var sw = new StreamWriter(Path + symbol.Name + "_" + symbol.Id + SymbolExtension))
using (var sw = new StreamWriter(OperatorTypesFolder + symbol.Name + "_" + symbol.Id + SymbolExtension))
using (var writer = new JsonTextWriter(sw))
{
json.Writer = writer;
Expand All @@ -556,9 +556,55 @@ public virtual void Save()
ResourceManager.Instance().EnableOperatorFileWatcher();
}

public void SaveModifiedSymbol(Symbol symbol)
{
RemoveObsoleteSymbolFiles(symbol);

Json json = new Json();

using (var sw = new StreamWriter(GetFilePathForSymbol(symbol)))
using (var writer = new JsonTextWriter(sw))
{
json.Writer = writer;
json.Writer.Formatting = Formatting.Indented;
json.WriteSymbol(symbol);
}

if (!string.IsNullOrEmpty(symbol.PendingSource))
{
WriteSymbolSourceToFile(symbol);
}
}


private void RemoveObsoleteSymbolFiles(Symbol symbol)
{
if (string.IsNullOrEmpty(symbol.DeprecatedSourcePath))
return;

foreach (var fileExtension in FileExtensions)
{
var sourceFilepath = Path.Combine(OperatorTypesFolder, symbol.DeprecatedSourcePath + "_" + symbol.Id + fileExtension);
try
{
File.Delete(sourceFilepath);
}
catch (Exception e)
{
Log.Warning("Failed to deleted file '" + sourceFilepath + "': " + e);
}
}
symbol.DeprecatedSourcePath = String.Empty;
}

private string GetFilePathForSymbol(Symbol symbol)
{
return OperatorTypesFolder + symbol.Name + "_" + symbol.Id + SymbolExtension;
}

private void WriteSymbolSourceToFile(Symbol symbol)
{
string sourcePath = Path + symbol.Name + ".cs";
string sourcePath = OperatorTypesFolder + symbol.Name + ".cs";
using (var sw = new StreamWriter(sourcePath))
{
sw.Write(symbol.PendingSource);
Expand Down Expand Up @@ -642,5 +688,17 @@ public static void RemoveSourceFileFromProject(string sourceFilePath)
var newContent = File.ReadAllText(projectFilePath).Replace(orgLine, string.Empty);
File.WriteAllText(projectFilePath, newContent);
}

private static string SymbolExtension { get; } = ".t3";
private static string SymbolUiExtension { get; } = ".t3ui";
private static string SourceExtension { get; } = ".cs";

private static List<string> FileExtensions= new ()
{
SymbolExtension,
SymbolUiExtension,
SourceExtension,
};

}
}
Loading

0 comments on commit 4d17c95

Please sign in to comment.