diff --git a/src/DynamoCore/Configuration/PreferenceSettings.cs b/src/DynamoCore/Configuration/PreferenceSettings.cs index 4393df1b25a..b004a7937bc 100644 --- a/src/DynamoCore/Configuration/PreferenceSettings.cs +++ b/src/DynamoCore/Configuration/PreferenceSettings.cs @@ -358,6 +358,12 @@ public bool IsBackgroundPreviewActive /// public bool ShowEdges { get; set; } + /// + /// Indicates whether background preview use instancing when rendering geometry. + /// be rendered. + /// + public bool UseRenderInstancing { get; set; } + /// /// Indicates whether show detailed or compact layout during search. /// @@ -936,6 +942,7 @@ public PreferenceSettings() maxNumRecentFiles = DefaultMaxNumRecentFiles; RenderPrecision = DefaultRenderPrecision; ShowEdges = false; + UseRenderInstancing = true; OpenFileInManualExecutionMode = false; ShowDetailedLayout = true; NamespacesToExcludeFromLibrary = new List(); diff --git a/src/DynamoCore/PublicAPI.Unshipped.txt b/src/DynamoCore/PublicAPI.Unshipped.txt index 7e6805f0d88..b2d6700c3d2 100644 --- a/src/DynamoCore/PublicAPI.Unshipped.txt +++ b/src/DynamoCore/PublicAPI.Unshipped.txt @@ -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.PreferenceSettings.ViewExtensionSettings.set -> void Dynamo.Configuration.PreferenceSettings.WindowH.get -> double diff --git a/src/DynamoCore/Scheduler/UpdateRenderPackageAsyncTask.cs b/src/DynamoCore/Scheduler/UpdateRenderPackageAsyncTask.cs index 5acce1fc58d..7b760e395cc 100644 --- a/src/DynamoCore/Scheduler/UpdateRenderPackageAsyncTask.cs +++ b/src/DynamoCore/Scheduler/UpdateRenderPackageAsyncTask.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -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("graphics-primitive-instancing", false) ?? false; + bool instancingEnabled = factory.TessellationParameters.UseRenderInstancing; if (graphicItem is Plane plane) { CreatePlaneTessellation(package, plane); diff --git a/src/DynamoCoreWpf/Properties/Resources.Designer.cs b/src/DynamoCoreWpf/Properties/Resources.Designer.cs index 50455dd8668..2178cc53626 100644 --- a/src/DynamoCoreWpf/Properties/Resources.Designer.cs +++ b/src/DynamoCoreWpf/Properties/Resources.Designer.cs @@ -7961,6 +7961,15 @@ public static string PreferencesViewVisualSettingsTab { } } + /// + /// Looks up a localized string similar to Use Instancing (Beta). + /// + public static string PreferencesViewVisualSettingUseInstancing { + get { + return ResourceManager.GetString("PreferencesViewVisualSettingUseInstancing", resourceCulture); + } + } + /// /// Looks up a localized string similar to 0%. /// @@ -8051,6 +8060,15 @@ public static string PreferencesWindowShowPreviewBubblesTooltip { } } + /// + /// Looks up a localized string similar to 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.. + /// + public static string PreferencesWindowUseInstancingTooltip { + get { + return ResourceManager.GetString("PreferencesWindowUseInstancingTooltip", resourceCulture); + } + } + /// /// Looks up a localized string similar to Preferred confidence level. /// diff --git a/src/DynamoCoreWpf/Properties/Resources.en-US.resx b/src/DynamoCoreWpf/Properties/Resources.en-US.resx index 0d602c1baa3..fa87b99dffb 100644 --- a/src/DynamoCoreWpf/Properties/Resources.en-US.resx +++ b/src/DynamoCoreWpf/Properties/Resources.en-US.resx @@ -3864,6 +3864,12 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in 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. + + Use Instancing (Beta) + + + 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. + To access the Recommended Nodes feature, please read and accept Dynamo > Agreements for Data Collection. diff --git a/src/DynamoCoreWpf/Properties/Resources.resx b/src/DynamoCoreWpf/Properties/Resources.resx index 304558b8fdb..482a4b9a06c 100644 --- a/src/DynamoCoreWpf/Properties/Resources.resx +++ b/src/DynamoCoreWpf/Properties/Resources.resx @@ -3851,6 +3851,12 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in 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. + + Use Instancing (Beta) + + + 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. + To access the Recommended Nodes feature, please read and accept Dynamo > Agreements for Data Collection. diff --git a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt index 7686c023c59..0811f62292f 100644 --- a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt +++ b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt @@ -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 @@ -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 entries, System.Collections.Generic.IEnumerable subs) -> void @@ -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 @@ -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 diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index ed61d8279af..b4a08922a4a 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -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; diff --git a/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs index b867bc289c4..7acf847085c 100644 --- a/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs @@ -369,7 +369,7 @@ public bool RunSettingsIsChecked } /// - /// Controls the IsChecked property in the Show Run Preview toogle button + /// Controls the IsChecked property in the Show Run Preview toggle button /// public bool RunPreviewIsChecked { @@ -386,7 +386,7 @@ public bool RunPreviewIsChecked } /// - /// Controls the IsChecked property in the Show Static Splash Screen toogle button + /// Controls the IsChecked property in the Show Static Splash Screen toggle button /// public bool StaticSplashScreenEnabled { @@ -418,7 +418,7 @@ public bool IsTimeStampIncludedInExportFilePath } /// - /// Controls the Enabled property in the Show Run Preview toogle button + /// Controls the Enabled property in the Show Run Preview toggle button /// public bool RunPreviewEnabled { @@ -716,7 +716,7 @@ public GeometryScalingOptions OptionsGeometryScale } /// - /// 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 /// public bool ShowEdges { @@ -731,6 +731,22 @@ public bool ShowEdges } } + /// + /// Controls the binding for the UseRenderInstancing toggle in the Preferences->Visual Settings->Display Settings section + /// + public bool UseRenderInstancing + { + get + { + return dynamoViewModel.RenderPackageFactoryViewModel.UseRenderInstancing; + } + set + { + dynamoViewModel.RenderPackageFactoryViewModel.UseRenderInstancing = value; + RaisePropertyChanged(nameof(UseRenderInstancing)); + } + } + /// /// Control to use hardware acceleration /// @@ -748,7 +764,7 @@ public bool UseHardwareAcceleration } /// - /// 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 /// public bool IsolateSelectedGeometry { @@ -1077,7 +1093,7 @@ public bool IsDynamoRevit } /// - /// Controls the IsChecked property in the "Node autocomplete" toogle button + /// Controls the IsChecked property in the "Node autocomplete" toggle button /// public bool NodeAutocompleteIsChecked { @@ -1174,7 +1190,7 @@ public int MLRecommendationNumberOfResults } /// - /// 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 /// public bool HideNodesBelowSpecificConfidenceLevelIsChecked { @@ -1231,7 +1247,7 @@ public bool EnableConfidenceLevelSlider #endregion /// - /// Controls the IsChecked property in the "Enable T-spline nodes" toogle button + /// Controls the IsChecked property in the "Enable T-spline nodes" toggle button /// public bool EnableTSplineIsChecked { @@ -1248,7 +1264,7 @@ public bool EnableTSplineIsChecked } /// - /// Controls the IsChecked property in the "Enable Paneling nodes" toogle button + /// Controls the IsChecked property in the "Enable Paneling nodes" toggle button /// public bool EnablePanelingIsChecked { @@ -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; @@ -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; diff --git a/src/DynamoCoreWpf/ViewModels/RenderPackageFactoryViewModel.cs b/src/DynamoCoreWpf/ViewModels/RenderPackageFactoryViewModel.cs index 2cb3070ac8f..a0f3bfd92df 100644 --- a/src/DynamoCoreWpf/ViewModels/RenderPackageFactoryViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/RenderPackageFactoryViewModel.cs @@ -1,4 +1,4 @@ -using Dynamo.Interfaces; +using Dynamo.Interfaces; using Dynamo.ViewModels; using Dynamo.Visualization; using Dynamo.Configuration; @@ -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; } @@ -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 diff --git a/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs b/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs index 0f45cdcc675..2770bd1bdf3 100644 --- a/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs @@ -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 @@ -1878,8 +1879,7 @@ internal virtual void AggregateRenderPackages(IEnumerable 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("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; @@ -1971,8 +1971,7 @@ internal virtual void AggregateRenderPackages(IEnumerable 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("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; diff --git a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml index e2952b7bb1c..b3f72861426 100644 --- a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml +++ b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml @@ -1451,10 +1451,44 @@ - + + + + + + Grid.Row="5"> + Grid.Row="6"> diff --git a/src/NodeServices/GraphicsDataInterfaces.cs b/src/NodeServices/GraphicsDataInterfaces.cs index cb59b84677f..9f52daad24a 100644 --- a/src/NodeServices/GraphicsDataInterfaces.cs +++ b/src/NodeServices/GraphicsDataInterfaces.cs @@ -348,7 +348,7 @@ public interface IRenderLabels /// /// Internal interface to enable adding labels that are related to an instanceableGraphicItem. /// - internal interface IRenderInstancedLabels + public interface IRenderInstancedLabels { /// /// Adds a label to the render package, but first transforms the label by the transform matrix of the @@ -372,7 +372,7 @@ internal interface IRenderInstancedLabels /// /// Represents instance matrices and references to tessellated geometry in the RenderPackage /// - internal interface IInstancingRenderPackage + public interface IInstancingRenderPackage { /// /// Checks if a base tessellation guid has already been registered with this . @@ -528,7 +528,7 @@ void SetTransform(double m11, double m12, double m13, double m14, /// /// An interface that defines items whose graphics are defined by a single base tessellation and instance transforms defined by 4x4 transformation matrices. /// - internal interface IInstanceableGraphicItem + public interface IInstanceableGraphicItem { /// /// A Guid used to reference the base tessellation geometry that will be transformed for all related instances @@ -580,6 +580,12 @@ public class TessellationParameters /// public bool ShowEdges { get; set; } + /// + /// A flag indicating whether rendering data for instancing + /// is included in the RenderPackage. Default is false. + /// + public bool UseRenderInstancing { get; set; } + /// /// The scale factor set in the workspace that must be applied to /// distance and coordinate values used in rendering only ASM geometry. @@ -592,6 +598,7 @@ public TessellationParameters() Tolerance = -1; MaxTessellationDivisions = 512; ShowEdges = false; + UseRenderInstancing = false; ScaleFactor = 1.0; } }