Skip to content

Commit

Permalink
Merge branch 'helix-upgrade' of https://github.com/DynamoDS/Dynamo in…
Browse files Browse the repository at this point in the history
…to helix-upgrade
  • Loading branch information
mjkkirschner committed Jan 29, 2020
2 parents 9f639bf + d1f0344 commit fa0f1bc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 76 deletions.
8 changes: 1 addition & 7 deletions src/DynamoCoreWpf/ViewModels/Watch3D/DynamoEffectsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ public DynamoEffectsManager() : base() {
AddDynamoTechniques();
}

/// <summary>
/// Load effects used by Dynamo for rendering. Custom input layouts are
/// created which specify extra COLOR components used to hold data
/// about the selection state and vertex coloration of objects.
/// See <see cref="T:DynamoMeshVertex"/>, <see cref="T:DynamoPointVertex"/>, and <see cref="T:DynamoLineVertex"/>
/// for examples of how these layouts are used.
/// </summary>

protected void AddDynamoTechniques()
{
var custom = new TechniqueDescription("RenderCustom")
Expand Down
81 changes: 33 additions & 48 deletions src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,25 +258,6 @@ protected void OnRequestZoomToFit(BoundingBox bounds)
RequestZoomToFit(bounds);
}
}

public event Func<Element3D, bool> RequestRemoveViewportItem;
private bool OnRequestRemoveViewportItem(Element3D item)
{
if(RequestRemoveViewportItem != null)
{
return RequestRemoveViewportItem(item);
}
return false;
}

public event Action<Element3D> RequestAddViewportItem;
private void OnRequestAddViewportItem(Element3D item)
{
if(RequestAddViewportItem != null)
{
RequestAddViewportItem(item);
}
}
#endregion

#region properties
Expand Down Expand Up @@ -461,6 +442,20 @@ private void UpdateSceneItems()
if (sceneItems == null)
sceneItems = new ObservableElement3DCollection();

//perform these updates here instead of everytime we add a single render package.
foreach(var geoModel3d in values)
{
if(geoModel3d is HelixToolkit.Wpf.SharpDX.GeometryModel3D)
{
var geo = (geoModel3d as HelixToolkit.Wpf.SharpDX.GeometryModel3D).Geometry;

geo.UpdateVertices();
geo.UpdateColors();
geo.UpdateBounds();
geo.UpdateTriangles();
}
}

sceneItems.Clear();
sceneItems.AddRange(values);
}
Expand All @@ -480,6 +475,7 @@ public IEnumerable<Element3D> SceneItems

public IEffectsManager EffectsManager { get; private set; }

[Obsolete("Not Implemented - Do Not Use.")]
public bool SupportDeferredRender { get; private set; }

#endregion
Expand Down Expand Up @@ -644,7 +640,6 @@ protected override void OnClear()
foreach (var key in Element3DDictionary.Keys.Except(keysList).ToList())
{
var model = Element3DDictionary[key] as GeometryModel3D;
OnRequestRemoveViewportItem(model);
Element3DDictionary.Remove(key);

model.Dispose();
Expand Down Expand Up @@ -886,7 +881,6 @@ private void DeleteGeometries(KeyValuePair<string, Element3D>[] geometryModels,
var frozenModel = AttachedProperties.GetIsFrozen(model3D);
if (frozenModel) continue;

OnRequestRemoveViewportItem(model3D);
Element3DDictionary.Remove(kvp.Key);
model3D.Dispose();

Expand Down Expand Up @@ -1065,6 +1059,9 @@ internal void ComputeFrameUpdate()
private void OnSceneItemsChanged()
{
UpdateSceneItems();
//TODO unclear if these are still required.
//since sceneItems are observable and we force them to update
//by clearing and readdding all items.
RaisePropertyChanged("SceneItems");
OnRequestViewRefresh();
}
Expand Down Expand Up @@ -1488,7 +1485,6 @@ public override void AddLabelForPath(string path)
{
// first, remove current labels of the node
// it does not crash if there is no such key in dictionary
OnRequestRemoveViewportItem(Element3DDictionary[labelName]);
var sceneItemsChanged = Element3DDictionary.Remove(labelName);

// it may be requested an array of items to put labels
Expand Down Expand Up @@ -1529,7 +1525,6 @@ public override void AddLabelForPath(string path)
}

Element3DDictionary.Add(labelName, bbText);
OnRequestAddViewportItem(bbText);

sceneItemsChanged = true;
nodesSelected[nodePath] = path;
Expand Down Expand Up @@ -1564,7 +1559,6 @@ public override void ClearPathLabel(string path)
var labelName = nodePath + TextKey;
lock (Element3DDictionaryMutex)
{
OnRequestRemoveViewportItem(Element3DDictionary[labelName]);
var sceneItemsChanged = Element3DDictionary.Remove(labelName);

if (sceneItemsChanged)
Expand Down Expand Up @@ -1673,10 +1667,10 @@ private void AggregateRenderPackages(IEnumerable<HelixRenderPackage> packages)
{
pointGeometry3D = CreatePointGeometryModel3D(rp);
Element3DDictionary.Add(id, pointGeometry3D);
OnRequestAddViewportItem(pointGeometry3D);
}

var points = pointGeometry3D.Geometry as PointGeometry3D;
var points = pointGeometry3D.Geometry == null ? HelixRenderPackage.InitPointGeometry()
: pointGeometry3D.Geometry as PointGeometry3D;
var startIdx = points.Positions.Count;

points.Positions.AddRange(p.Positions);
Expand All @@ -1694,11 +1688,12 @@ private void AggregateRenderPackages(IEnumerable<HelixRenderPackage> packages)
}

AddLabelPlace(baseId, p.Positions[0], rp);
pointGeometry3D.Geometry = points;
if (pointGeometry3D.Geometry == null)
{
pointGeometry3D.Geometry = points;
}
pointGeometry3D.Name = baseId;

points.UpdateVertices();
points.UpdateColors();
}

var l = rp.Lines;
Expand All @@ -1719,10 +1714,10 @@ private void AggregateRenderPackages(IEnumerable<HelixRenderPackage> packages)
// edges of meshes. Draw them with a different thickness.
lineGeometry3D = CreateLineGeometryModel3D(rp, rp.MeshVertices.Any()?0.5:1.0);
Element3DDictionary.Add(id, lineGeometry3D);
OnRequestAddViewportItem(lineGeometry3D);
}

var lineSet = lineGeometry3D.Geometry as LineGeometry3D;
var lineSet = lineGeometry3D.Geometry == null ? HelixRenderPackage.InitLineGeometry()
: lineGeometry3D.Geometry as LineGeometry3D;
var startIdx = lineSet.Positions.Count;

lineSet.Positions.AddRange(l.Positions);
Expand All @@ -1742,11 +1737,13 @@ private void AggregateRenderPackages(IEnumerable<HelixRenderPackage> packages)
: Enumerable.Range(startIdx, startIdx + l.Positions.Count));

AddLabelPlace(baseId, lineSet.Positions[startIdx], rp);
lineGeometry3D.Geometry = lineSet;
if(lineGeometry3D.Geometry == null)
{
lineGeometry3D.Geometry = lineSet;
}

lineGeometry3D.Name = baseId;

lineSet.UpdateVertices();
lineSet.UpdateColors();
}

var m = rp.Mesh;
Expand All @@ -1765,7 +1762,6 @@ private void AggregateRenderPackages(IEnumerable<HelixRenderPackage> packages)
{
meshGeometry3D = CreateDynamoGeometryModel3D(rp);
Element3DDictionary.Add(id, meshGeometry3D);
OnRequestAddViewportItem(meshGeometry3D);
}

var mesh = meshGeometry3D.Geometry == null ? HelixRenderPackage.InitMeshGeometry()
Expand Down Expand Up @@ -1803,10 +1799,6 @@ private void AggregateRenderPackages(IEnumerable<HelixRenderPackage> packages)
meshGeometry3D.Geometry = mesh;
meshGeometry3D.Name = baseId;

mesh.UpdateVertices();
mesh.UpdateColors();
mesh.UpdateTextureCoordinates();
mesh.UpdateTriangles();
}

}
Expand Down Expand Up @@ -1877,8 +1869,6 @@ private bool UpdateGeometryModelForSpecialRenderPackage(HelixRenderPackage rp, s
manipulator.Material = PhongMaterials.Blue;

Element3DDictionary[id] = manipulator;
OnRequestRemoveViewportItem(model);
OnRequestAddViewportItem(manipulator);
return true;
case RenderDescriptions.AxisLine:
var centerline = model as DynamoLineGeometryModel3D;
Expand All @@ -1889,8 +1879,6 @@ private bool UpdateGeometryModelForSpecialRenderPackage(HelixRenderPackage rp, s
}
centerline.Geometry = rp.Lines;
Element3DDictionary[id] = centerline;
OnRequestRemoveViewportItem(model);
OnRequestAddViewportItem(centerline);
return true;
case RenderDescriptions.ManipulatorPlane:
var plane = model as DynamoLineGeometryModel3D;
Expand All @@ -1901,8 +1889,6 @@ private bool UpdateGeometryModelForSpecialRenderPackage(HelixRenderPackage rp, s
}
plane.Geometry = rp.Lines;
Element3DDictionary[id] = plane;
OnRequestRemoveViewportItem(model);
OnRequestAddViewportItem(plane);
return true;
default:
return false;
Expand Down Expand Up @@ -1997,7 +1983,6 @@ private void CreateOrUpdateText(string baseId, Vector3 pt, IRenderPackage rp)
Geometry = HelixRenderPackage.InitText3D(),
};
Element3DDictionary.Add(textId, bbText);
OnRequestAddViewportItem(bbText);
}
var geom = bbText.Geometry as BillboardText3D;

Expand Down Expand Up @@ -2051,7 +2036,7 @@ private DynamoLineGeometryModel3D CreateLineGeometryModel3D(HelixRenderPackage r
{
var lineGeometry3D = new DynamoLineGeometryModel3D()
{
Geometry = HelixRenderPackage.InitLineGeometry(),
//Do not set Geometry here
Transform = new MatrixTransform3D(rp.Transform.ToMatrix3D()),
Color = Colors.White,
Thickness = thickness,
Expand All @@ -2065,7 +2050,7 @@ private DynamoPointGeometryModel3D CreatePointGeometryModel3D(HelixRenderPackage
{
var pointGeometry3D = new DynamoPointGeometryModel3D
{
Geometry = HelixRenderPackage.InitPointGeometry(),
//Do not set Geometry here
Transform = new MatrixTransform3D(rp.Transform.ToMatrix3D()),
Color = Colors.White,
Figure = PointFigure.Ellipse,
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/Views/Preview/Watch3DView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@
<MouseBinding Command="hx:ViewportCommands.Reset" Gesture="Ctrl+MiddleDoubleClick"/>
<MouseBinding Command="{Binding LeftClickCommand}" Gesture="LeftClick"/>
</hx:Viewport3DX.InputBindings>
<!--<hx:GroupModel3D
<hx:GroupModel3D
x:Name="Models"
ItemsSource="{Binding SceneItems}"
/>-->
/>
</hx:Viewport3DX>

<Thumb Name ="resizeThumb"
Expand Down
19 changes: 0 additions & 19 deletions src/DynamoCoreWpf/Views/Preview/Watch3DView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ private void UnregisterEventHandlers()
ViewModel.RequestClickRay -= GetClickRay;
ViewModel.RequestCameraPosition -= GetCameraPosition;
ViewModel.RequestZoomToFit -= ViewModel_RequestZoomToFit;
ViewModel.RequestAddViewportItem -= AddViewportItem;
ViewModel.RequestRemoveViewportItem -= RemoveViewportItem;
}

private void RegisterEventHandlers()
Expand All @@ -87,8 +85,6 @@ private void RegisterEventHandlers()
ViewModel.RequestClickRay += GetClickRay;
ViewModel.RequestCameraPosition += GetCameraPosition;
ViewModel.RequestZoomToFit += ViewModel_RequestZoomToFit;
ViewModel.RequestRemoveViewportItem += RemoveViewportItem;
ViewModel.RequestAddViewportItem += AddViewportItem;

ViewModel.UpdateUpstream();
ViewModel.OnWatchExecution();
Expand Down Expand Up @@ -177,11 +173,6 @@ private void ViewLoadedHandler(object sender, RoutedEventArgs e)
var directionalLight = ViewModel.Element3DDictionary[HelixWatch3DViewModel.DefaultLightName];
var headlight = ViewModel.Element3DDictionary[HelixWatch3DViewModel.HeadLightName];

watch_view.Items.Add(directionalLight);
watch_view.Items.Add(headlight);
watch_view.Items.Add(grid);
watch_view.Items.Add(axes);

RegisterEventHandlers();
}

Expand Down Expand Up @@ -304,16 +295,6 @@ private Point3D GetCameraPosition()
{
return View.GetCameraPosition();
}

private bool RemoveViewportItem(Element3D item)
{
return watch_view.Items.Remove(item);
}

private void AddViewportItem(Element3D item)
{
watch_view.Items.Add(item);
}
}


Expand Down

0 comments on commit fa0f1bc

Please sign in to comment.