Skip to content

Commit

Permalink
DYN-6842 Convert Helix instancing feature flag to a Preference Setting (
Browse files Browse the repository at this point in the history
#14675)

* First pass

* PR comments

* Spelling and wording

* Fix preference settings.

* Spelling

* Update API

* Update default state to true
  • Loading branch information
saintentropy authored Apr 11, 2024
1 parent bef8e58 commit bfd2408
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 23 deletions.
7 changes: 7 additions & 0 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ public bool IsBackgroundPreviewActive
/// </summary>
public bool ShowEdges { get; set; }

/// <summary>
/// Indicates whether background preview use instancing when rendering geometry.
/// be rendered.
/// </summary>
public bool UseRenderInstancing { get; set; }

/// <summary>
/// Indicates whether show detailed or compact layout during search.
/// </summary>
Expand Down Expand Up @@ -936,6 +942,7 @@ public PreferenceSettings()
maxNumRecentFiles = DefaultMaxNumRecentFiles;
RenderPrecision = DefaultRenderPrecision;
ShowEdges = false;
UseRenderInstancing = true;
OpenFileInManualExecutionMode = false;
ShowDetailedLayout = true;
NamespacesToExcludeFromLibrary = new List<string>();
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCore/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ Dynamo.Configuration.PreferenceSettings.UseHardwareAcceleration.get -> bool
Dynamo.Configuration.PreferenceSettings.UseHardwareAcceleration.set -> void
Dynamo.Configuration.PreferenceSettings.UseHostScaleUnits.get -> bool
Dynamo.Configuration.PreferenceSettings.UseHostScaleUnits.set -> void
Dynamo.Configuration.PreferenceSettings.UseRenderInstancing.get -> bool
Dynamo.Configuration.PreferenceSettings.UseRenderInstancing.set -> void
Dynamo.Configuration.PreferenceSettings.ViewExtensionSettings.get -> System.Collections.Generic.List<Dynamo.Configuration.ViewExtensionSettings>
Dynamo.Configuration.PreferenceSettings.ViewExtensionSettings.set -> void
Dynamo.Configuration.PreferenceSettings.WindowH.get -> double
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCore/Scheduler/UpdateRenderPackageAsyncTask.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -230,7 +230,7 @@ private void GetTessellationDataFromGraphicItem(Guid outputPortId, IGraphicItem
var previousMeshVertexCount = package.MeshVertexCount;

//Todo Plane tessellation needs to be handled here vs in LibG currently
bool instancingEnabled = DynamoModel.FeatureFlags?.CheckFeatureFlag<bool>("graphics-primitive-instancing", false) ?? false;
bool instancingEnabled = factory.TessellationParameters.UseRenderInstancing;
if (graphicItem is Plane plane)
{
CreatePlaneTessellation(package, plane);
Expand Down
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 @@ -3864,6 +3864,12 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="ElementBindingDesc" xml:space="preserve">
<value>Element Binding allows a two-way interaction between Dynamo and the host application like Revit or Civil3D where a user can select an element in the host document and have Dynamo "bind" that element to a node in the workspace.</value>
</data>
<data name="PreferencesViewVisualSettingUseInstancing" xml:space="preserve">
<value>Use Instancing (Beta)</value>
</data>
<data name="PreferencesWindowUseInstancingTooltip" xml:space="preserve">
<value>When toggled on, some symmetric geometry types such as cubes, rectangles, or spheres will render faster due to mutiple copies being drawn at once vs sequentially.</value>
</data>
<data name="NotificationToAgreeMLNodeautocompleteTOU" xml:space="preserve">
<value>To access the Recommended Nodes feature, please read and accept Dynamo &gt; Agreements for Data Collection.</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3851,6 +3851,12 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="ElementBindingDesc" xml:space="preserve">
<value>Element Binding allows a two-way interaction between Dynamo and the host application like Revit or Civil3D where a user can select an element in the host document and have Dynamo "bind" that element to a node in the workspace.</value>
</data>
<data name="PreferencesViewVisualSettingUseInstancing" xml:space="preserve">
<value>Use Instancing (Beta)</value>
</data>
<data name="PreferencesWindowUseInstancingTooltip" xml:space="preserve">
<value>When toggled on, some symmetric geometry types such as cubes, rectangles, or spheres will render faster due to mutiple copies being drawn at once vs sequentially.</value>
</data>
<data name="NotificationToAgreeMLNodeautocompleteTOU" xml:space="preserve">
<value>To access the Recommended Nodes feature, please read and accept Dynamo &gt; Agreements for Data Collection.</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,8 @@ Dynamo.ViewModels.PreferencesViewModel.ShowCodeBlockLineNumber.get -> bool
Dynamo.ViewModels.PreferencesViewModel.ShowCodeBlockLineNumber.set -> void
Dynamo.ViewModels.PreferencesViewModel.ShowEdges.get -> bool
Dynamo.ViewModels.PreferencesViewModel.ShowEdges.set -> void
Dynamo.ViewModels.PreferencesViewModel.UseRenderInstancing.get -> bool
Dynamo.ViewModels.PreferencesViewModel.UseRenderInstancing.set -> void
Dynamo.ViewModels.PreferencesViewModel.ShowPreviewBubbles.get -> bool
Dynamo.ViewModels.PreferencesViewModel.ShowPreviewBubbles.set -> void
Dynamo.ViewModels.PreferencesViewModel.ShowWhitespaceIsChecked.get -> bool
Expand Down Expand Up @@ -3804,6 +3806,8 @@ Dynamo.Wpf.ViewModels.RenderPackageFactoryViewModel.MaxTessellationDivisions.set
Dynamo.Wpf.ViewModels.RenderPackageFactoryViewModel.RenderPackageFactoryViewModel(Dynamo.Interfaces.IPreferences preferenceSettings) -> void
Dynamo.Wpf.ViewModels.RenderPackageFactoryViewModel.ShowEdges.get -> bool
Dynamo.Wpf.ViewModels.RenderPackageFactoryViewModel.ShowEdges.set -> void
Dynamo.Wpf.ViewModels.RenderPackageFactoryViewModel.UseRenderInstancing.get -> bool
Dynamo.Wpf.ViewModels.RenderPackageFactoryViewModel.UseRenderInstancing.set -> void
Dynamo.Wpf.ViewModels.RootNodeCategoryViewModel
Dynamo.Wpf.ViewModels.RootNodeCategoryViewModel.RootNodeCategoryViewModel(string name) -> void
Dynamo.Wpf.ViewModels.RootNodeCategoryViewModel.RootNodeCategoryViewModel(string name, System.Collections.Generic.IEnumerable<Dynamo.Wpf.ViewModels.NodeSearchElementViewModel> entries, System.Collections.Generic.IEnumerable<Dynamo.Wpf.ViewModels.NodeCategoryViewModel> subs) -> void
Expand Down Expand Up @@ -5188,6 +5192,7 @@ static Dynamo.Wpf.Properties.Resources.PreferencesViewVisualSettingShowEdges.get
static Dynamo.Wpf.Properties.Resources.PreferencesViewVisualSettingsIsolateSelectedGeo.get -> string
static Dynamo.Wpf.Properties.Resources.PreferencesViewVisualSettingsRenderPrecision.get -> string
static Dynamo.Wpf.Properties.Resources.PreferencesViewVisualSettingsTab.get -> string
static Dynamo.Wpf.Properties.Resources.PreferencesViewVisualSettingUseInstancing.get -> string
static Dynamo.Wpf.Properties.Resources.PreferencesViewZoomScaling0Percent.get -> string
static Dynamo.Wpf.Properties.Resources.PreferencesViewZoomScaling100Percent.get -> string
static Dynamo.Wpf.Properties.Resources.PreferencesViewZoomScaling25Percent.get -> string
Expand All @@ -5198,6 +5203,7 @@ static Dynamo.Wpf.Properties.Resources.PreferencesWindowIsolateSelectedGeoToolti
static Dynamo.Wpf.Properties.Resources.PreferencesWindowShowCodeBlockNodeLineNumberTooltip.get -> string
static Dynamo.Wpf.Properties.Resources.PreferencesWindowShowEdgesTooltip.get -> string
static Dynamo.Wpf.Properties.Resources.PreferencesWindowShowPreviewBubblesTooltip.get -> string
static Dynamo.Wpf.Properties.Resources.PreferencesWindowUseInstancingTooltip.get -> string
static Dynamo.Wpf.Properties.Resources.PreferredConfidenceLevel.get -> string
static Dynamo.Wpf.Properties.Resources.PreferredConfidenceLevelInfo.get -> string
static Dynamo.Wpf.Properties.Resources.PrePackagePublishMessage.get -> string
Expand Down
11 changes: 11 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,17 @@ private void RenderPackageFactoryViewModel_PropertyChanged(object sender, Proper
}
}
break;
case "UseRenderInstancing":
model.PreferenceSettings.UseRenderInstancing = factoryVm.Factory.TessellationParameters.UseRenderInstancing;
// A full regeneration is required to use instancing.
foreach (var vm in Watch3DViewModels)
{
if (vm is HelixWatch3DViewModel) // just need a full regeneration when vm is HelixWatch3DViewModel
{
vm.RegenerateAllPackages();
}
}
break;
case "MaxTessellationDivisions":
model.PreferenceSettings.RenderPrecision = factoryVm.Factory.TessellationParameters.MaxTessellationDivisions;
break;
Expand Down
38 changes: 29 additions & 9 deletions src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public bool RunSettingsIsChecked
}

/// <summary>
/// Controls the IsChecked property in the Show Run Preview toogle button
/// Controls the IsChecked property in the Show Run Preview toggle button
/// </summary>
public bool RunPreviewIsChecked
{
Expand All @@ -386,7 +386,7 @@ public bool RunPreviewIsChecked
}

/// <summary>
/// Controls the IsChecked property in the Show Static Splash Screen toogle button
/// Controls the IsChecked property in the Show Static Splash Screen toggle button
/// </summary>
public bool StaticSplashScreenEnabled
{
Expand Down Expand Up @@ -418,7 +418,7 @@ public bool IsTimeStampIncludedInExportFilePath
}

/// <summary>
/// Controls the Enabled property in the Show Run Preview toogle button
/// Controls the Enabled property in the Show Run Preview toggle button
/// </summary>
public bool RunPreviewEnabled
{
Expand Down Expand Up @@ -716,7 +716,7 @@ public GeometryScalingOptions OptionsGeometryScale
}

/// <summary>
/// Controls the binding for the ShowEdges toogle in the Preferences->Visual Settings->Display Settings section
/// Controls the binding for the ShowEdges toggle in the Preferences->Visual Settings->Display Settings section
/// </summary>
public bool ShowEdges
{
Expand All @@ -731,6 +731,22 @@ public bool ShowEdges
}
}

/// <summary>
/// Controls the binding for the UseRenderInstancing toggle in the Preferences->Visual Settings->Display Settings section
/// </summary>
public bool UseRenderInstancing
{
get
{
return dynamoViewModel.RenderPackageFactoryViewModel.UseRenderInstancing;
}
set
{
dynamoViewModel.RenderPackageFactoryViewModel.UseRenderInstancing = value;
RaisePropertyChanged(nameof(UseRenderInstancing));
}
}

/// <summary>
/// Control to use hardware acceleration
/// </summary>
Expand All @@ -748,7 +764,7 @@ public bool UseHardwareAcceleration
}

/// <summary>
/// Controls the binding for the IsolateSelectedGeometry toogle in the Preferences->Visual Settings->Display Settings section
/// Controls the binding for the IsolateSelectedGeometry toggle in the Preferences->Visual Settings->Display Settings section
/// </summary>
public bool IsolateSelectedGeometry
{
Expand Down Expand Up @@ -1077,7 +1093,7 @@ public bool IsDynamoRevit
}

/// <summary>
/// Controls the IsChecked property in the "Node autocomplete" toogle button
/// Controls the IsChecked property in the "Node autocomplete" toggle button
/// </summary>
public bool NodeAutocompleteIsChecked
{
Expand Down Expand Up @@ -1174,7 +1190,7 @@ public int MLRecommendationNumberOfResults
}

/// <summary>
/// Controls the IsChecked property in the "Hide nodes below a specific confidence level" toogle button
/// Controls the IsChecked property in the "Hide nodes below a specific confidence level" toggle button
/// </summary>
public bool HideNodesBelowSpecificConfidenceLevelIsChecked
{
Expand Down Expand Up @@ -1231,7 +1247,7 @@ public bool EnableConfidenceLevelSlider
#endregion

/// <summary>
/// Controls the IsChecked property in the "Enable T-spline nodes" toogle button
/// Controls the IsChecked property in the "Enable T-spline nodes" toggle button
/// </summary>
public bool EnableTSplineIsChecked
{
Expand All @@ -1248,7 +1264,7 @@ public bool EnableTSplineIsChecked
}

/// <summary>
/// Controls the IsChecked property in the "Enable Paneling nodes" toogle button
/// Controls the IsChecked property in the "Enable Paneling nodes" toggle button
/// </summary>
public bool EnablePanelingIsChecked
{
Expand Down Expand Up @@ -1393,6 +1409,7 @@ private bool setSettings(PreferenceSettings newPreferences)
SelectedPythonEngine = string.IsNullOrEmpty(engine) ? Res.DefaultPythonEngineNone : preferenceSettings.DefaultPythonEngine;
dynamoViewModel.RenderPackageFactoryViewModel.MaxTessellationDivisions = preferenceSettings.RenderPrecision;
dynamoViewModel.RenderPackageFactoryViewModel.ShowEdges = preferenceSettings.ShowEdges;
dynamoViewModel.RenderPackageFactoryViewModel.UseRenderInstancing = preferenceSettings.UseRenderInstancing;
PackagePathsForInstall = null;
PackagePathsViewModel?.InitializeRootLocations();
SelectedPackagePathForInstall = preferenceSettings.SelectedPackagePathForInstall;
Expand Down Expand Up @@ -1767,6 +1784,9 @@ private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
case nameof(ShowEdges):
description = Res.ResourceManager.GetString(nameof(Res.PreferencesViewVisualSettingShowEdges), System.Globalization.CultureInfo.InvariantCulture);
goto default;
case nameof(UseRenderInstancing):
description = Res.ResourceManager.GetString(nameof(Res.PreferencesViewVisualSettingUseInstancing), System.Globalization.CultureInfo.InvariantCulture);
goto default;
case nameof(IsolateSelectedGeometry):
description = Res.ResourceManager.GetString(nameof(Res.PreferencesViewVisualSettingsIsolateSelectedGeo), System.Globalization.CultureInfo.InvariantCulture);
goto default;
Expand Down
15 changes: 13 additions & 2 deletions src/DynamoCoreWpf/ViewModels/RenderPackageFactoryViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dynamo.Interfaces;
using Dynamo.Interfaces;
using Dynamo.ViewModels;
using Dynamo.Visualization;
using Dynamo.Configuration;
Expand Down Expand Up @@ -26,6 +26,17 @@ public bool ShowEdges
}
}

public bool UseRenderInstancing
{
get { return factory.TessellationParameters.UseRenderInstancing; }
set
{
if (factory.TessellationParameters.UseRenderInstancing == value) return;
factory.TessellationParameters.UseRenderInstancing = value;
RaisePropertyChanged("UseRenderInstancing");
}
}

public int MaxTessellationDivisions
{
get { return factory.TessellationParameters.MaxTessellationDivisions; }
Expand All @@ -51,7 +62,7 @@ public RenderPackageFactoryViewModel(IPreferences preferenceSettings)
{
this.factory = new HelixRenderPackageFactory()
{
TessellationParameters = { ShowEdges = ps.ShowEdges, MaxTessellationDivisions = ps.RenderPrecision }
TessellationParameters = { ShowEdges = ps.ShowEdges, MaxTessellationDivisions = ps.RenderPrecision, UseRenderInstancing = ps.UseRenderInstancing }
};
}
else
Expand Down
7 changes: 3 additions & 4 deletions src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
using MeshBuilder = HelixToolkit.SharpDX.Core.MeshBuilder;
using MeshGeometry3D = HelixToolkit.SharpDX.Core.MeshGeometry3D;
using TextInfo = HelixToolkit.SharpDX.Core.TextInfo;
using Dynamo.Configuration;


namespace Dynamo.Wpf.ViewModels.Watch3D
Expand Down Expand Up @@ -1878,8 +1879,7 @@ internal virtual void AggregateRenderPackages(IEnumerable<HelixRenderPackage> pa
//for each instancable item and add instance transforms.
//If we have any line geometry that was not associated with an instance,
//remove the previously added line data from the render package so the remaining lines can be added to the scene.
if (rp.LineVertexRangesAssociatedWithInstancing.Any()
&& DynamoModel.FeatureFlags?.CheckFeatureFlag<bool>("graphics-primitive-instancing", false) == true)
if (rp.LineVertexRangesAssociatedWithInstancing.Any())
{
//For each range of line vertices add the line data and instances to the scene
var j = 0;
Expand Down Expand Up @@ -1971,8 +1971,7 @@ internal virtual void AggregateRenderPackages(IEnumerable<HelixRenderPackage> pa
//for each instancable item and add instance transforms.
//If we have any mesh geometry that was not associated with an instance, remove the previously added
//mesh data from the render package so the remaining mesh can be added to the scene.
if (rp.MeshVertexRangesAssociatedWithInstancing.Any()
&& DynamoModel.FeatureFlags?.CheckFeatureFlag<bool>("graphics-primitive-instancing", false) == true)
if (rp.MeshVertexRangesAssociatedWithInstancing.Any())
{
//For each range of mesh vertices add the mesh data and instances to the scene
var j = 0;
Expand Down
Loading

0 comments on commit bfd2408

Please sign in to comment.