Skip to content

[VFX] Fix orient error feedback failing in subblocks #2544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override IEnumerable<string> filteredOutSettings

public override IEnumerable<int> GetFilteredOutEnumerators(string name)
{
if (name == "mode")
if (name == "mode" && canTestStrips)
{
if (hasStrips)
{
Expand All @@ -78,14 +78,8 @@ public override IEnumerable<int> GetFilteredOutEnumerators(string name)
}
}

private bool hasStrips
{
get
{
var parent = GetParent() as VFXAbstractParticleOutput;
return parent && parent.HasStrips();
}
}
private bool canTestStrips => flattenedParent as VFXAbstractParticleOutput; // Cannot check strip in subblock context or not child of a context
private bool hasStrips => ((VFXAbstractParticleOutput)flattenedParent).HasStrips(); // direct cast as canTestStrips is supposed to have been called priorly

public override string name { get { return "Orient : " + ObjectNames.NicifyVariableName(mode.ToString()); } }

Expand Down Expand Up @@ -153,7 +147,7 @@ public override IEnumerable<VFXNamedExpression> parameters
foreach (var exp in base.parameters)
yield return exp;

if (hasStrips && mode != Mode.Advanced)
if (canTestStrips && hasStrips && mode != Mode.Advanced)
yield return new VFXNamedExpression(new VFXExpressionStripTangent(), "stripTangent");
}
}
Expand All @@ -165,8 +159,8 @@ public override string source
switch (mode)
{
case Mode.FaceCameraPlane:
if (hasStrips)
throw new NotImplementedException("This orient mode is only available for strips");
if (canTestStrips && hasStrips)
throw new NotImplementedException("This orient mode (FaceCameraPlane) is only available for strips");

return @"
float3x3 viewRot = GetVFXToViewRotMatrix();
Expand All @@ -181,7 +175,7 @@ public override string source
";

case Mode.FaceCameraPosition:
if (hasStrips)
if (canTestStrips && hasStrips)
{
return @"
axisX = stripTangent;
Expand Down Expand Up @@ -223,7 +217,7 @@ public override string source
";

case Mode.LookAtPosition:
if (hasStrips)
if (canTestStrips && hasStrips)
return @"
axisX = stripTangent;
axisZ = -normalize(position - Position);
Expand All @@ -238,7 +232,7 @@ public override string source
";

case Mode.LookAtLine:
if (hasStrips)
if (canTestStrips && hasStrips)
return @"
float3 lineDir = normalize(Line_end - Line_start);
float3 target = dot(position - Line_start,lineDir) * lineDir + Line_start;
Expand Down Expand Up @@ -271,8 +265,8 @@ public override string source
}

case Mode.FixedAxis:
if (hasStrips)
throw new NotImplementedException("This orient mode is not available for strips");
if (canTestStrips && hasStrips)
throw new NotImplementedException("This orient (FixedAxis) mode is not available for strips");

return @"
axisY = Up;
Expand All @@ -282,8 +276,8 @@ public override string source
";

case Mode.AlongVelocity:
if (hasStrips)
throw new NotImplementedException("This orient mode is not available for strips");
if (canTestStrips && hasStrips)
throw new NotImplementedException("This orient mode (AlongVelocity) is not available for strips");

return @"
axisY = normalize(velocity);
Expand All @@ -293,8 +287,8 @@ public override string source
";

case Mode.CustomZ:
if (!hasStrips)
throw new NotImplementedException("This orient mode is only available for strips");
if (canTestStrips && !hasStrips)
throw new NotImplementedException("This orient mode (CustomZ) is only available for strips");

return
@"axisX = stripTangent;
Expand All @@ -304,8 +298,8 @@ public override string source
";

case Mode.CustomY:
if (!hasStrips)
throw new NotImplementedException("This orient mode is only available for strips");
if (canTestStrips && !hasStrips)
throw new NotImplementedException("This orient mode (CustomY) is only available for strips");

return
@"axisX = stripTangent;
Expand Down Expand Up @@ -337,6 +331,9 @@ public override void Sanitize(int version)

protected override void GenerateErrors(VFXInvalidateErrorReporter manager)
{
if (!canTestStrips)
return;

bool hasInvalidMode = false;
if (hasStrips)
hasInvalidMode =
Expand Down
14 changes: 14 additions & 0 deletions com.unity.visualeffectgraph/Editor/Models/Blocks/VFXBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,19 @@ public sealed override VFXCoordinateSpace GetOutputSpaceFromSlot(VFXSlot slot)
return GetParent().space;
return (VFXCoordinateSpace)int.MaxValue;
}

public VFXContext flattenedParent
{
get
{
return m_FlattenedParent != null ? m_FlattenedParent : GetParent();
}
set
{
m_FlattenedParent = value;
}
}

private VFXContext m_FlattenedParent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ public override void CollectDependencies(HashSet<ScriptableObject> objs, bool ow
}
}

public void SetSubblocksFlattenedParent()
{
VFXContext parent = GetParent();
foreach (var block in recursiveSubBlocks)
block.flattenedParent = parent;
}

protected internal override void Invalidate(VFXModel model, InvalidationCause cause)
{
if (cause == InvalidationCause.kSettingChanged)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override IEnumerable<VFXPropertyWithValue> inputProperties
}
}

[VFXSetting]
[VFXSetting, SerializeField]
ContextType m_SuitableContexts = ContextType.InitAndUpdateAndOutput;

public VFXContextType compatibleContextType
Expand Down
11 changes: 9 additions & 2 deletions com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class VFXGraphPreprocessor : AssetPostprocessor
{
void OnPreprocessAsset()
{
bool isVFX = assetPath.EndsWith(VisualEffectResource.Extension);
bool isVFX = VisualEffectAssetModicationProcessor.HasVFXExtension(assetPath);
if (isVFX)
{
VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath);
Expand Down Expand Up @@ -124,7 +124,6 @@ public static void Build()
if (resource != null)
{
VFXGraph graph = resource.GetOrCreateGraph();
graph.SanitizeGraph(); // tmp Necessary for subgraphs
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph));
EditorUtility.SetDirty(resource);
}
Expand Down Expand Up @@ -647,6 +646,13 @@ void RecurseSubgraphRecreateCopy(IEnumerable<VFXModel> children)
}
}

private void SetFlattenedParentToSubblocks( )
{
foreach (var child in children.OfType<VFXContext>())
foreach (var block in child.children.OfType<VFXSubgraphBlock>())
block.SetSubblocksFlattenedParent();
}

void RecurseSubgraphPatchInputExpression(IEnumerable<VFXModel> children)
{
foreach (var child in children)
Expand Down Expand Up @@ -709,6 +715,7 @@ private void PrepareSubgraphs()
{
Profiler.BeginSample("PrepareSubgraphs");
RecurseSubgraphRecreateCopy(children);
SetFlattenedParentToSubblocks();
RecurseSubgraphPatchInputExpression(children);
Profiler.EndSample();
}
Expand Down