internal void ClearRender() { DynaShapeViewExtension.ViewModel.RequestViewRefresh -= RequestViewRefreshHandler; DynaShapeViewExtension.DynamoWindow.Dispatcher.Invoke(() => { List <Model3D> sceneItems = DynaShapeViewExtension.GetSceneItems(); if (sceneItems.Contains(pointModel)) { sceneItems.Remove(pointModel); } pointModel.Detach(); pointModel.Dispose(); if (sceneItems.Contains(lineModel)) { sceneItems.Remove(lineModel); } lineModel.Detach(); lineModel.Dispose(); if (sceneItems.Contains(billboardTextModel)) { sceneItems.Remove(billboardTextModel); } billboardTextModel.Detach(); billboardTextModel.Dispose(); foreach (MeshGeometryModel3D meshModel in meshModels) { if (sceneItems.Contains(meshModel)) { sceneItems.Remove(meshModel); } meshModel.Detach(); meshModel.Dispose(); } }); }
private void RenderAction() { Viewport3DX viewport = DynaShapeViewExtension.GetViewport(); List <Model3D> sceneItems = viewport.ItemsSource as List <Model3D>; pointGeometry = new PointGeometry3D { Positions = new Vector3Collection(), Indices = new IntCollection(), Colors = new Color4Collection() }; lineGeometry = new LineGeometry3D() { Positions = new Vector3Collection(), Indices = new IntCollection(), Colors = new Color4Collection() }; foreach (MeshGeometryModel3D meshModel in meshModels) { meshModel.Detach(); if (sceneItems.Contains(meshModel)) { sceneItems.Remove(meshModel); } } meshModels = new List <MeshGeometryModel3D>(); //============================================ // Render nodes as points //============================================ for (int i = 0; i < solver.Nodes.Count; i++) { pointGeometry.Positions.Add(new Vector3( solver.Nodes[i].Position.X, solver.Nodes[i].Position.Z, -solver.Nodes[i].Position.Y)); pointGeometry.Colors.Add(new Color4(0.8f, 0.2f, 0.2f, 1f)); pointGeometry.Indices.Add(i); } //============================================================== // Render geometries from geometry binders //============================================================== foreach (GeometryBinder geometryBinder in solver.GeometryBinders) { geometryBinder.CreateDisplayedGeometries(this, solver.Nodes); } //============================================================================ // Render GUI elements //============================================================================ RenderGUI(); //============================================================== // Attach the geometries to Helix render host //============================================================== if (pointGeometry.Positions.Count >= 1) { pointModel.Geometry = pointGeometry; if (!pointModel.IsAttached) { pointModel.Attach(viewport.RenderHost); } if (!sceneItems.Contains(pointModel)) { sceneItems.Add(pointModel); } } else { pointModel.Detach(); if (sceneItems.Contains(pointModel)) { sceneItems.Remove(pointModel); } } if (lineGeometry.Positions.Count >= 2) { lineModel.Geometry = lineGeometry; if (!lineModel.IsAttached) { lineModel.Attach(viewport.RenderHost); } if (!sceneItems.Contains(lineModel)) { sceneItems.Add(lineModel); } } else { lineModel.Detach(); if (sceneItems.Contains(lineModel)) { sceneItems.Remove(lineModel); } } foreach (MeshGeometryModel3D meshModel in meshModels) { if (meshModel.Geometry.Positions.Count >= 3) { meshModel.Attach(viewport.RenderHost); sceneItems.Add(meshModel); } } }