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

Add point and line shaders #10709

Merged
merged 19 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 15 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
9 changes: 6 additions & 3 deletions src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@
<Compile Include="ViewModels\Watch3D\DynamoGeometryModel3D.cs" />
<Compile Include="ViewModels\Watch3D\DynamoLineGeometryModel3D.cs" />
<Compile Include="ViewModels\Watch3D\DynamoPointGeometryModel3D.cs" />
<Compile Include="ViewModels\Watch3D\DynamoPointLineRenderCore.cs" />
<Compile Include="ViewModels\Watch3D\DynamoRenderCoreDataStore.cs" />
<Compile Include="ViewModels\Watch3D\HelixWatch3DViewModel.cs" />
<Compile Include="ViewModels\Watch3D\DefaultWatch3DViewModel.cs" />
<Compile Include="ViewModels\Watch3D\IWatch3DViewModel.cs" />
Expand Down Expand Up @@ -510,7 +512,10 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ViewModels\Watch3D\compiledShaders\psDynamoMesh" />
<None Include="ViewModels\Watch3D\compiledShaders\psDynamoPoint" />
<None Include="ViewModels\Watch3D\compiledShaders\psDynamoLine" />
<None Include="ViewModels\Watch3D\compiledShaders\vsDynamoMesh" />
<None Include="ViewModels\Watch3D\compiledShaders\vsDynamoPointLine" />
<Resource Include="UI\Images\cursors.psd" />
<Resource Include="UI\Images\cursors1.psd" />
</ItemGroup>
Expand Down Expand Up @@ -1294,9 +1299,7 @@
<Resource Include="UI\Images\icon-whats-new-small.png" />
<Resource Include="UI\Images\icon-dictionary-small.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="ViewModels\Watch3D\shaderSource\" />
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
<MakeDir Directories="$(OutputPath)\viewExtensions\" />
Expand Down
30 changes: 30 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.

9 changes: 9 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2255,4 +2255,13 @@ Uninstall the following packages: {0}?</value>
<data name="RenderingMemoryOutageSummary" xml:space="preserve">
<value>Dynamo has run out of memory trying to render your geometry. The geometry preview has been disabled.</value>
</data>
<data name="vsDynamoPointLine" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\ViewModels\Watch3D\compiledShaders\vsDynamoPointLine;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="psDynamoLine" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\ViewModels\Watch3D\compiledShaders\psDynamoLine;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="psDynamoPoint" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\ViewModels\Watch3D\compiledShaders\psDynamoPoint;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
9 changes: 9 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2255,4 +2255,13 @@ Uninstall the following packages: {0}?</value>
<data name="RenderingMemoryOutageSummary" xml:space="preserve">
<value>Dynamo has run out of memory trying to render your geometry. The geometry preview has been disabled.</value>
</data>
<data name="vsDynamoPointLine" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\ViewModels\Watch3D\compiledShaders\vsDynamoPointLine;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="psDynamoLine" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\ViewModels\Watch3D\compiledShaders\psDynamoLine;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="psDynamoPoint" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\ViewModels\Watch3D\compiledShaders\psDynamoPoint;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
136 changes: 13 additions & 123 deletions src/DynamoCoreWpf/ViewModels/Watch3D/AttachedProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Windows;
using HelixToolkit.Wpf.SharpDX;
using SharpDX;
using Point = SharpDX.Point;

namespace Dynamo.Wpf.ViewModels.Watch3D
{
Expand All @@ -14,46 +15,6 @@ namespace Dynamo.Wpf.ViewModels.Watch3D
[Obsolete("Do not use! This will be moved to a new project in a future version of Dynamo.")]
public static class AttachedProperties
{

// handles determining color of elementGeometry3Ds when any property is set false
// as the state of other properties must be checked to determine the correct color / material.
private static void OnPointOrLinePropertySetFalse(DependencyObject obj)
{
if (!(obj is GeometryModel3D && obj.GetType() != typeof(BillboardTextModel3D)))
{
return;
}

//point or line case
GeometryModel3D geom = obj as GeometryModel3D;
if (geom is DynamoPointGeometryModel3D || geom is DynamoLineGeometryModel3D)
{
//if selection is not enabled determine if we should reset colors or set transparent colors
if (!GetShowSelected(geom))
{
if (GetIsolationMode(geom))
{
SetAlpha(geom, HelixWatch3DViewModel.ptAndLineIsolatedTransparencyColor.Alpha, true);
}
else if (GetIsFrozen(geom))
{
SetAlpha(geom, HelixWatch3DViewModel.FrozenMaterial.DiffuseColor.Alpha, true);
}
//all attached props are false, lets reset colors
else
{
RequestResetColorsForDynamoGeometryModel?.Invoke(geom.Tag as string);
}
}
}
}

/// <summary>
/// Event to raise when the GeometryModel's colors should be reset to the data cached by the HelixViewModel.
/// parameter is the "nodeASTid:HelixGeomType"
/// </summary>
internal static event Action<string> RequestResetColorsForDynamoGeometryModel;

#region Show Selected property

// TODO: Make private in 3.0
Expand Down Expand Up @@ -93,35 +54,7 @@ private static void ShowSelectedPropertyChanged(DependencyObject obj, Dependency
//implementation for lines and points
else if (geom is DynamoPointGeometryModel3D || geom is DynamoLineGeometryModel3D)
{

if ((bool)args.NewValue)
{
//if the item is both selected and isolation mode is on, then we should color the item as normal OR as frozen.
if (GetIsolationMode(geom))
{
//selected, isolated, and frozen.
if (GetIsFrozen(geom))
{
SetAlpha(geom, HelixWatch3DViewModel.FrozenMaterial.DiffuseColor.Alpha, true);
}
//selected and isolated, so we just reset the colors.
else
{
//reset the colors
RequestResetColorsForDynamoGeometryModel?.Invoke(geom.Tag as string);
}
}
//only selected.
else
{
//TODO cache this and update after helix 2.11 is released
SetAllColors(geom, HelixWatch3DViewModel.SelectedMaterial.DiffuseColor);
}
}
else
{
OnPointOrLinePropertySetFalse(geom);
}
HandlePointLinePropertyChange(geom, args);
}
}

Expand Down Expand Up @@ -200,19 +133,11 @@ private static void IsFrozenPropertyChanged(DependencyObject obj, DependencyProp
var meshGeom = geom as DynamoGeometryModel3D;
if (meshGeom != null)
{

HandleMeshPropertyChange(meshGeom, e);
HandleMeshPropertyChange(meshGeom, e);
}
else if (geom is DynamoPointGeometryModel3D || geom is DynamoLineGeometryModel3D)
{
if ((bool)e.NewValue)
{
SetAlpha(geom, HelixWatch3DViewModel.FrozenMaterial.DiffuseColor.Alpha, false);
}
else
{
OnPointOrLinePropertySetFalse(geom);
}
HandlePointLinePropertyChange(geom, e);
}
}

Expand Down Expand Up @@ -258,14 +183,7 @@ private static void IsolationModePropertyChanged(DependencyObject obj, Dependenc
}
else if (geom is DynamoPointGeometryModel3D || geom is DynamoLineGeometryModel3D)
{
if ((bool)e.NewValue)
{
SetAlpha(geom, HelixWatch3DViewModel.ptAndLineIsolatedTransparencyColor.Alpha, false);
}
else
{
OnPointOrLinePropertySetFalse(geom);
}
HandlePointLinePropertyChange(geom, e);
}
}

Expand Down Expand Up @@ -312,49 +230,21 @@ public static bool IsSpecialRenderPackage(DependencyObject element)
/// </summary>
/// <param name="meshGeom"></param>
/// <param name="args"></param>
private static void HandleMeshPropertyChange(DynamoGeometryModel3D meshGeom, DependencyPropertyChangedEventArgs args)
internal static void HandleMeshPropertyChange(DynamoGeometryModel3D meshGeom, DependencyPropertyChangedEventArgs args)
{
var meshCore = meshGeom?.SceneNode?.RenderCore as DynamoGeometryMeshCore;
if (meshCore != null)
{
meshCore.SetPropertyData(args);
}
}

/// <summary>
/// Sets all colors on Geometry to a single color.
/// </summary>
/// <param name="geom">Geometry to modify.</param>
/// <param name="color">Color to set geometry to.</param>
private static void SetAllColors(GeometryModel3D geom, Color4 color)
{
var newColorCollection = new Color4Collection(Enumerable.Repeat(color, geom.Geometry.Colors.Count));
geom.Geometry.Colors = newColorCollection;
meshCore?.SetPropertyData(args);
}

/// <summary>
/// Sets alpha channel of existing colors to given value, optionally attempts to reset all colors
/// first to original colors from renderpackages.
/// </summary>
/// <param name="geom">Geometry to modify.</param>
/// <param name="alpha">Alpha value to set on geometry. Float between 0 and 1.0.</param>
/// <param name="resetColorsFirst">If true, colors are reset to those stored in the original render packages, before having alpha modified
/// one may want to use this to reset colors from a selected state (blue) back to the original colors before freezing the geo for example. </param>
private static void SetAlpha(GeometryModel3D geom, float alpha, bool resetColorsFirst)
private static void HandlePointLinePropertyChange(GeometryModel3D pointLineGeom,
DependencyPropertyChangedEventArgs args)
{
if (resetColorsFirst)
if (pointLineGeom is DynamoPointGeometryModel3D || pointLineGeom is DynamoLineGeometryModel3D)
{
//reset colors if handled
RequestResetColorsForDynamoGeometryModel?.Invoke(geom.Tag as string);
}
//then modify alpha
var newColors = new Color4Collection(geom.Geometry.Colors.Select(col =>
{
col.Alpha = alpha;
return col;
}));
geom.Geometry.Colors = newColors;
(pointLineGeom.SceneNode?.RenderCore as DynamoPointLineRenderCore)?.SetPropertyData(args, pointLineGeom);
}
}

#endregion

}
Expand Down
13 changes: 0 additions & 13 deletions src/DynamoCoreWpf/ViewModels/Watch3D/DefaultWatch3DViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,6 @@ private void RegisterEventHandlers()
RegisterModelEventhandlers(dynamoModel);

RegisterWorkspaceEventHandlers(dynamoModel);

AttachedProperties.RequestResetColorsForDynamoGeometryModel += AttachedProperties_RequestResetColorsForDynamoGeometryModel;
}

/// <summary>
/// Handle requests to reset colors on geometry graphics objects given an id.
/// </summary>
/// <param name="objId">id of the object</param>
[Obsolete("Do not use! This will be moved to a new project in a future version of Dynamo.")]
protected virtual void AttachedProperties_RequestResetColorsForDynamoGeometryModel(string objId)
{
//override in derived classes
}

/// <summary>
Expand Down Expand Up @@ -811,7 +799,6 @@ protected virtual void ZoomToFit(object parameter)

protected virtual void Dispose(bool disposing)
{
AttachedProperties.RequestResetColorsForDynamoGeometryModel -= AttachedProperties_RequestResetColorsForDynamoGeometryModel;
}

public void Dispose()
Expand Down
Loading