Skip to content

Commit

Permalink
Cherry Pick DYN-7103, DYN-7127 Fix crash error in Instancing Renderin…
Browse files Browse the repository at this point in the history
…g logic, Fix issue with code block rendering (#15313)
  • Loading branch information
saintentropy authored Jun 13, 2024
1 parent 1594ac6 commit 1a830a9
Show file tree
Hide file tree
Showing 8 changed files with 1,193 additions and 33 deletions.
18 changes: 18 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

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

6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -4004,4 +4004,10 @@ To make this file into a new template, save it to a different folder, then move
<data name="NodeInCanvasSearchCreationError" xml:space="preserve">
<value>Failed to create node: </value>
</data>
<data name="InstancingRenderFailureDescription" xml:space="preserve">
<value>Please disable Use Instancing in the Display Settings section of Visual Settings.</value>
</data>
<data name="PartialRenderFailureTitle" xml:space="preserve">
<value>Background Preview had an issue</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3991,4 +3991,10 @@ To make this file into a new template, save it to a different folder, then move
<data name="NodeInCanvasSearchCreationError" xml:space="preserve">
<value>Failed to create node: </value>
</data>
<data name="InstancingRenderFailureDescription" xml:space="preserve">
<value>Please disable Use Instancing in the Display Settings section of Visual Settings.</value>
</data>
<data name="PartialRenderFailureTitle" xml:space="preserve">
<value>Background Preview had an issue</value>
</data>
</root>
2 changes: 2 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4784,6 +4784,7 @@ static Dynamo.Wpf.Properties.Resources.InstalledPackageViewNodeLibrariesLabel.ge
static Dynamo.Wpf.Properties.Resources.InstalledPackageViewPendingInstallButton.get -> string
static Dynamo.Wpf.Properties.Resources.InstalledPackageViewTitle.get -> string
static Dynamo.Wpf.Properties.Resources.InstallMessageCaption.get -> string
static Dynamo.Wpf.Properties.Resources.InstancingRenderFailureDescription.get -> string
static Dynamo.Wpf.Properties.Resources.InteractiveGuides.get -> string
static Dynamo.Wpf.Properties.Resources.InvalidDraggingOperationMessgae.get -> string
static Dynamo.Wpf.Properties.Resources.InvalidLoginUrl.get -> string
Expand Down Expand Up @@ -5133,6 +5134,7 @@ static Dynamo.Wpf.Properties.Resources.PackageViewContextMenuLoadText.get -> str
static Dynamo.Wpf.Properties.Resources.PackageViewContextMenuLoadTooltip.get -> string
static Dynamo.Wpf.Properties.Resources.PackageWarningMessageBoxTitle.get -> string
static Dynamo.Wpf.Properties.Resources.PackageWebsiteLabel.get -> string
static Dynamo.Wpf.Properties.Resources.PartialRenderFailureTitle.get -> string
static Dynamo.Wpf.Properties.Resources.Periodic.get -> string
static Dynamo.Wpf.Properties.Resources.PersistentVisualStatusOfLinterIssues.get -> string
static Dynamo.Wpf.Properties.Resources.PortPropertiesPromptDescriptionTooltip.get -> string
Expand Down
230 changes: 197 additions & 33 deletions src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions test/VisualizationTests/HelixWatch3DViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,41 @@ public void InstancedShowEdgesAreCorrect()
System.String.Join(Environment.NewLine, edgeVerts.Select(x=>x.ToString())).Replace(" ",string.Empty));
}

[Test]
public void StandardCurvesAndInstancedCurvesAndAreAddedToBackGroundPreviewForWhenTesselatedFromOneNodeExample1()
{
ViewModel.RenderPackageFactoryViewModel.UseRenderInstancing = true;

Model.LibraryServices.ImportLibrary("FFITarget.dll");
OpenVisualizationTest("MixedListOfInstancedAndStandardCurves.dyn");
RunCurrentModel();
DispatcherUtil.DoEvents();

//this graph displays a 3 lines.
Assert.AreEqual(3, BackgroundPreviewGeometry.TotalCurvesMinusInstances());

//this graph displays 2 rectangle instances.
Assert.AreEqual(2, BackgroundPreviewGeometry.TotalLineInstancesToRender());

Assert.AreEqual(false, BackgroundPreviewGeometry.AnyLargerIndicesThanVertexCount());

Assert.AreEqual(false, BackgroundPreviewGeometry.AnyNegativeIndices());
}

[Test]
public void InstanceGeometryWithinCodeBlock()
{
ViewModel.RenderPackageFactoryViewModel.UseRenderInstancing = true;

Model.LibraryServices.ImportLibrary("FFITarget.dll");
OpenVisualizationTest("InstancingWithinCodeBlock.dyn");
RunCurrentModel();
DispatcherUtil.DoEvents();

//this graph displays 2 rectangle instances.
Assert.AreEqual(2, BackgroundPreviewGeometry.TotalLineInstancesToRender());
}

[Test]
public void Watch3dNodeDisposal_DoesNotBreakBackGroundPreview()
{
Expand Down Expand Up @@ -1598,6 +1633,45 @@ public static int TotalCurves(this IEnumerable<Element3D> dictionary)
: 0;
}

public static int TotalCurvesMinusInstances(this IEnumerable<Element3D> dictionary)
{
var lines = dictionary.Where(g => g is LineGeometryModel3D && !keyList.Contains(g.Name) && ((LineGeometryModel3D)g).Instances == null).ToArray();

return lines.Any()
? lines.SelectMany(g => ((LineGeometryModel3D)g).Geometry.Positions).Count() / 2
: 0;
}

public static bool AnyNegativeIndices(this IEnumerable<Element3D> dictionary)
{
var lines = dictionary.Where(g => g is LineGeometryModel3D && !keyList.Contains(g.Name) && ((LineGeometryModel3D)g).Instances == null).ToArray();

foreach(var line in lines)
{
var indices = ((LineGeometryModel3D)line).Geometry.Indices;
if (indices.Any(i => i < 0))
return true;
}

return false;
}

public static bool AnyLargerIndicesThanVertexCount(this IEnumerable<Element3D> dictionary)
{
var lines = dictionary.Where(g => g is LineGeometryModel3D && !keyList.Contains(g.Name) && ((LineGeometryModel3D)g).Instances == null).ToArray();

foreach (var line in lines)
{
var max = ((LineGeometryModel3D)line).Geometry.Positions.Count();

var indices = ((LineGeometryModel3D)line).Geometry.Indices;
if (indices.Any(i => i > max))
return true;
}

return false;
}

public static int TotalText(this IEnumerable<Element3D> dictionary)
{
var text = dictionary
Expand Down
128 changes: 128 additions & 0 deletions test/core/visualization/InstancingWithinCodeBlock.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"Uuid": "db6f1cd5-06d1-47c7-83a2-9865a281864a",
"IsCustomNode": false,
"Description": "",
"Name": "InstancingWithinCodeBlock",
"ElementResolver": {
"ResolutionMap": {
"Cuboid": {
"Key": "Autodesk.DesignScript.Geometry.Cuboid",
"Value": "ProtoGeometry.dll"
},
"Circle": {
"Key": "Autodesk.DesignScript.Geometry.Circle",
"Value": "ProtoGeometry.dll"
},
"Point": {
"Key": "Autodesk.DesignScript.Geometry.Point",
"Value": "ProtoGeometry.dll"
},
"Sphere": {
"Key": "Autodesk.DesignScript.Geometry.Sphere",
"Value": "ProtoGeometry.dll"
},
"Line": {
"Key": "Autodesk.DesignScript.Geometry.Line",
"Value": "ProtoGeometry.dll"
},
"Rectangle": {
"Key": "Autodesk.DesignScript.Geometry.Rectangle",
"Value": "ProtoGeometry.dll"
}
}
},
"Inputs": [],
"Outputs": [],
"Nodes": [
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"Id": "c0a1361e543f46858c92564816649e7d",
"NodeType": "CodeBlockNode",
"Inputs": [],
"Outputs": [
{
"Id": "cda3b41512bc427c8c0829cb70650ebe",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "9195bd7048384b09b1477631d0a9f135",
"Name": "",
"Description": "Value of expression at line 2",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly",
"Code": "Rectangle.ByWidthLength(2,4);\nRectangle.ByWidthLength(1,2);"
}
],
"Connectors": [],
"Dependencies": [],
"NodeLibraryDependencies": [],
"EnableLegacyPolyCurveBehavior": true,
"Thumbnail": "",
"GraphDocumentationURL": null,
"ExtensionWorkspaceData": [
{
"ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670",
"Name": "Properties",
"Version": "3.3",
"Data": {}
}
],
"Author": "",
"Linting": {
"activeLinter": "None",
"activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a",
"warningCount": 0,
"errorCount": 0
},
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "3.3.0.5237",
"RunType": "Automatic",
"RunPeriod": "1000"
},
"Camera": {
"Name": "_Background Preview",
"EyeX": -18.08238983154297,
"EyeY": 25.974166870117188,
"EyeZ": 2.616847038269043,
"LookX": 13.082389831542969,
"LookY": -14.974166870117188,
"LookZ": -10.616847038269043,
"UpX": 0.3794049024581909,
"UpY": 0.872495710849762,
"UpZ": -0.3079013228416443
},
"ConnectorPins": [],
"NodeViews": [
{
"Id": "c0a1361e543f46858c92564816649e7d",
"Name": "Code Block",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"ShowGeometry": true,
"X": 2097.06910448662,
"Y": 724.121483527379
}
],
"Annotations": [],
"X": -2146.757813379982,
"Y": -478.75882791579454,
"Zoom": 1.1129446513066208
}
}
Loading

0 comments on commit 1a830a9

Please sign in to comment.