Skip to content
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

DYN-2538 Generate single RenderPackage per Node #11395

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
73d2244
Add additional interfaces to support adding colors in chunks to rende…
saintentropy Jan 5, 2021
f512c4a
Add interfaces for adding label data to a render package vs overloadi…
saintentropy Jan 5, 2021
59d653e
Add implementation of new Interfaces to HelixRenderPackage
saintentropy Jan 5, 2021
8aefd74
Change GetRenderPackagesFromMirrorData implementation to only use one…
saintentropy Jan 5, 2021
8f6d369
Modify AggregateRenderPackages to utilize the IRenderLabels data for …
saintentropy Jan 5, 2021
0a36ee9
Modify mesh creation to support multiple texture maps per render package
saintentropy Jan 5, 2021
4aefed2
Update GeometryColor nodes to utilize the new Interface API's
saintentropy Jan 5, 2021
703b7b5
Extract plane tessellation method
saintentropy Jan 10, 2021
aca3964
Validate vertex lists and vertexcolor lists stay in sync after tessel…
saintentropy Jan 10, 2021
91a1149
Fix Test failures
saintentropy Jan 10, 2021
2b3b2db
clean up internal method for LabelPlaces. Match same pattern as othe…
saintentropy Jan 10, 2021
2c060f9
Add obsolete attributes to IRenderPackage methods
saintentropy Jan 10, 2021
e7840ba
Add property and exception to allow detection and handling of legacy …
saintentropy Jan 10, 2021
f49d8e6
Modify GetRenderPackageFromMirrorData to support detecting legacy col…
saintentropy Jan 10, 2021
2bffdad
Clean up comment and simplify implementation.
saintentropy Jan 10, 2021
76b58a0
Fix crash
saintentropy Jan 11, 2021
82f035a
Don't push empty render packages onto the cache
saintentropy Jan 11, 2021
c6242f9
Add IRenderPackageSupplement to DefaultRenderPackage for DynamoWPFCLI
saintentropy Jan 11, 2021
ffe80dd
Fix label node and tests
saintentropy Jan 12, 2021
8202546
Merge branch 'master' into SingleRenderPackagePerNode
saintentropy Jan 16, 2021
cdc90b0
Update method name and add comments
saintentropy Apr 23, 2021
54ae3cd
Update comments on plane tessellation
saintentropy Apr 23, 2021
d299072
Dispose temp geometry in plane tessellation
saintentropy Apr 23, 2021
a547190
Update the Legacy mechanism with clear comments for the use of count
saintentropy Apr 24, 2021
e4a73f4
Update method descriptions and method names for interfaces
saintentropy Apr 24, 2021
b7f5652
Update per PR comments
saintentropy Apr 24, 2021
657002f
remove field references from instance methods
saintentropy Apr 25, 2021
d5dbb6b
Fix label regeression introduced in Dyn 3026
saintentropy Apr 25, 2021
c652d30
pash package by ref
saintentropy Apr 26, 2021
ef33e81
Rename Insert color ranges to Update to match validation behavior
saintentropy Apr 26, 2021
207247f
Fix bug in AppendMethod validation
saintentropy Apr 26, 2021
55758b6
Add visualization tests and dyn files
saintentropy Apr 26, 2021
8627930
Add Helix Render package tests
saintentropy Apr 26, 2021
11ca407
PR comment
saintentropy Apr 26, 2021
ea432c1
Merge branch 'master' into SingleRenderPackagePerNode
saintentropy Apr 26, 2021
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
465 changes: 360 additions & 105 deletions src/DynamoCore/Scheduler/UpdateRenderPackageAsyncTask.cs

Large diffs are not rendered by default.

177 changes: 175 additions & 2 deletions src/DynamoCore/Visualization/DefaultRenderPackageFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.DesignScript.Interfaces;

Expand Down Expand Up @@ -38,7 +39,7 @@ public IRenderPackage CreateRenderPackage()
/// Example implementation of IRenderPackage.
/// DefaultRenderPackage can be used as package for your visualization.
/// </summary>
public class DefaultRenderPackage : IRenderPackage
public class DefaultRenderPackage : IRenderPackage, IRenderPackageSupplement
{
private List<double> pointVertices = new List<double>();
private List<byte> pointColors = new List<byte>();
Expand All @@ -57,6 +58,10 @@ public class DefaultRenderPackage : IRenderPackage
private List<int> lineStripVertexCounts = new List<int>();
private byte[] colors;

private List<byte[]> colorsList = new List<byte[]>();
private List<int> colorStrideList = new List<int>();
private List<Tuple<int, int>> colorsMeshVerticesRange = new List<Tuple<int, int>>();

/// <summary>
/// Add a point vertex to the render package.
/// </summary>
Expand Down Expand Up @@ -154,6 +159,7 @@ public void AddLineStripVertexColor(byte red, byte green, byte blue, byte alpha)
/// Apply a color to each point vertex.
/// </summary>
/// <param name="colors">A buffer of R,G,B,A values corresponding to each vertex.</param>
[Obsolete("Do not use! Use the methods in IRenderPackageSupplement to add ranges of vertex colors.")]
public void ApplyPointVertexColors(byte[] colors)
{
pointColors.Clear();
Expand All @@ -163,6 +169,7 @@ public void ApplyPointVertexColors(byte[] colors)
/// <summary>
/// Apply a color to a sequence of line vertices.
/// </summary>
[Obsolete("Do not use! Use the methods in IRenderPackageSupplement to add ranges of vertex colors.")]
public void ApplyLineVertexColors(byte[] colors)
{
lineColors.Clear();
Expand All @@ -173,6 +180,7 @@ public void ApplyLineVertexColors(byte[] colors)
/// Apply a color to each mesh vertex.
/// </summary>
/// <param name="colors">A buffer of R,G,B,A values corresponding to each vertex.</param>
[Obsolete("Do not use! Use the methods in IRenderPackageSupplement to add ranges of vertex colors.")]
public void ApplyMeshVertexColors(byte[] colors)
{
meshColors.Clear();
Expand All @@ -183,6 +191,7 @@ public void ApplyMeshVertexColors(byte[] colors)
/// Sets an array of bytes that is used as a color map.
/// </summary>
/// <param name="colors"></param>
[Obsolete("Do not use! Use the methods in IRenderPackageSupplement to add mesh texture maps.")]
public void SetColors(byte[] colors)
{
this.colors = colors;
Expand Down Expand Up @@ -214,6 +223,10 @@ public void Clear()
IsSelected = false;
RequiresPerVertexColoration = false;
DisplayLabels = false;

colorsList.Clear();
colorStrideList.Clear();
colorsMeshVerticesRange.Clear();
}

/// <summary>
Expand Down Expand Up @@ -370,11 +383,171 @@ public IEnumerable<int> PointIndices
/// for mapping onto surfaces. Use the ColorsStride property to define the
/// size of one dimension of the collection.
/// </summary>
[Obsolete("Do not use! Use the methods in IRenderPackageSupplement to add mesh texture maps.")]
public IEnumerable<byte> Colors { get; private set; }

/// <summary>
/// The size of one dimension of the Colors collection.
/// </summary>
[Obsolete("Do not use! Use the methods in IRenderPackageSupplement to add mesh texture maps.")]
public int ColorsStride { get; set; }

#region IRenderPackageSupplement implementation

/// <summary>
/// The number of point vertices colors in the package (Optimized for speed).
/// </summary>
public int PointVertexColorCount => pointColors.Count / 4;

/// <summary>
/// The number of line vertices colors in the package (Optimized for speed).
/// </summary>
public int LineVertexColorCount => lineColors.Count / 4;

/// <summary>
/// The number of mesh vertices colors in the package (Optimized for speed).
/// </summary>
public int MeshVertexColorCount => meshColors.Count / 4;

/// <summary>
/// Update a color to a range of point vertices.
/// </summary>
/// <param name="startIndex">The index associated with the first vertex in PointVertices we want to associate with a color</param>
/// <param name="endIndex">The index associated with the last vertex in PointVertices we want to associate with a color</param>
/// <param name="red">byte for the red RGB value</param>
/// <param name="green">byte for the green RGB value</param>
/// <param name="blue">byte for the blue RGB value</param>
/// <param name="alpha">byte for the alpha RGB value</param>
public void UpdatePointVertexColorForRange(int startIndex, int endIndex, byte red, byte green, byte blue, byte alpha)
{
for (var i = startIndex; i <= endIndex; i++)
{
var j = i * 4;
pointColors[j] = red;
pointColors[j + 1] = green;
pointColors[j + 2] = blue;
pointColors[j + 3] = alpha;
}
}

/// <summary>
/// Append a color range for point vertices.
/// </summary>
/// <param name="colors">A buffer of R,G,B,A values corresponding to each vertex.</param>
public void AppendPointVertexColorRange(byte[] colors)
{
pointColors.AddRange(colors);
}

/// <summary>
/// Update a color to a range of line vertices.
/// </summary>
/// <param name="startIndex">The index associated with the first vertex in LineVertices we want to associate with a color</param>
/// <param name="endIndex">The index associated with the last vertex in LineVertices we want to associate with a color</param>
/// <param name="red">byte for the red RGB value</param>
/// <param name="green">byte for the green RGB value</param>
/// <param name="blue">byte for the blue RGB value</param>
/// <param name="alpha">byte for the alpha RGB value</param>
public void UpdateLineVertexColorForRange(int startIndex, int endIndex, byte red, byte green, byte blue, byte alpha)
{
for (var i = startIndex; i <= endIndex; i++)
{
var j = i * 4;
lineColors[j] = red;
lineColors[j + 1] = green;
lineColors[j + 2] = blue;
lineColors[j + 3] = alpha;
}
}

/// <summary>
/// Append a color range for line vertices.
/// </summary>
/// <param name="colors">A buffer of R,G,B,A values corresponding to each vertex.</param>
public void AppendLineVertexColorRange(byte[] colors)
{
lineColors.AddRange(colors);
}

/// <summary>
/// Update a color to a range of of mesh vertices.
/// </summary>
/// <param name="startIndex">The index associated with the first vertex in MeshVertices we want to associate with a color</param>
/// <param name="endIndex">The index associated with the last vertex in MeshVertices we want to associate with a color</param>
/// <param name="red">byte for the red RGB value</param>
/// <param name="green">byte for the green RGB value</param>
/// <param name="blue">byte for the blue RGB value</param>
/// <param name="alpha">byte for the alpha RGB value</param>
public void UpdateMeshVertexColorForRange(int startIndex, int endIndex, byte red, byte green, byte blue, byte alpha)
{
for (var i = startIndex; i <= endIndex; i++)
{
var j = i* 4;
meshColors[j] = red;
meshColors[j + 1] = green;
meshColors[j + 2] = blue;
meshColors[j + 3] = alpha;
}
RequiresPerVertexColoration = true;
}

/// <summary>
/// Append a color range for mesh vertex.
/// </summary>
/// <param name="colors">A buffer of R,G,B,A values corresponding to each vertex.</param>
public void AppendMeshVertexColorRange(byte[] colors)
{
meshColors.AddRange(colors);
RequiresPerVertexColoration = true;
}

/// <summary>
/// A List containing arrays of bytes representing RGBA colors.
/// These arrays can be used to populate textures for mapping onto specific meshes
/// </summary>
public List<byte[]> TextureMapsList
{
get { return colorsList; }
}

/// <summary>
/// A list containing the size of one dimension of the associated texture map array in TextureMapsList.
/// </summary>
public List<int> TextureMapsStrideList
{
get { return colorStrideList; }
}

/// <summary>
/// A list of mesh vertices ranges that have associated texture maps
/// </summary>
public List<Tuple<int, int>> MeshVerticesRangesAssociatedWithTextureMaps
{
get { return colorsMeshVerticesRange; }
}

/// <summary>
/// Set a color map for a range of mesh vertices
/// </summary>
/// <param name="startIndex">The index associated with the first vertex in MeshVertices we want to associate with the texture map</param>
/// <param name="endIndex">The index associated with the last vertex in MeshVertices we want to associate with the texture map</param>
/// <param name="textureMap">An array of bytes representing RGBA colors to be used as a color texture map</param>
/// <param name="stride">The size of one dimension of the colors array</param>
public void AddTextureMapForMeshVerticesRange(int startIndex, int endIndex, byte[] textureMap, int stride)
{
colorsMeshVerticesRange.Add(new Tuple<int, int>(startIndex, endIndex));
colorsList.Add(textureMap);
colorStrideList.Add(stride);
}

/// <summary>
/// Allow legacy usage of the color methods in IRenderPackage
/// This flag is used by the UpdateRenderPackageAsyncTask implementation to flag
/// any third party usage of deprecated color methods in IRenderPackage API
/// </summary>
[Obsolete("Do not use! This will be removed in Dynamo 3.0")]
public bool AllowLegacyColorOperations { get; set; } = true;

#endregion
}
}
Loading