/// <summary> /// set start point or end point /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void viewport3D_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { var point = e.GetPosition((IInputElement)sender); var p = viewport3D.FindNearestPoint(point); if (!p.HasValue) { return; } if (StartBall == null) { StartBall = CreateBall(PhongMaterials.Green); } if (EndBall == null) { EndBall = CreateBall(PhongMaterials.Red); } if (WayPath == null) { WayPath = new LineGeometryModel3D(); WayPath.Color = SharpDX.Color.Blue; mViewModel.PlayersGeometry.Add(WayPath); WayPath.Attach(mViewModel.modelView.RenderHost); } if (Keyboard.IsKeyDown(Key.LeftShift)) { EndBall.Transform = new TranslateTransform3D(p.Value.X, p.Value.Y, p.Value.Z); } else { StartBall.Transform = new TranslateTransform3D(p.Value.X, p.Value.Y, p.Value.Z); } RenderPath(); }
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); } } }
private void RenderAction() { IRenderHost renderHost = DynaShapeViewExtension.GetViewport().RenderHost; List <Model3D> sceneItems = DynaShapeViewExtension.GetSceneItems(); pointGeometry = new PointGeometry3D { Positions = new Vector3Collection(), Indices = new IntCollection(), Colors = new Color4Collection() }; lineGeometry = new LineGeometry3D() { Positions = new Vector3Collection(), Indices = new IntCollection(), Colors = new Color4Collection() }; billboardText = new BillboardText3D(); foreach (MeshGeometryModel3D meshModel in meshModels) { meshModel.Detach(); if (sceneItems.Contains(meshModel)) { sceneItems.Remove(meshModel); } } meshModels.Clear(); //============================================ // Render nodes as points //============================================ int n = pointGeometry.Indices.Count; for (int i = 0; i < solver.Nodes.Count; i++) { pointGeometry.Positions.Add(solver.Nodes[i].Position.ToVector3()); pointGeometry.Colors.Add(DefaultPointColor); pointGeometry.Indices.Add(n + i); } //============================================================== // Render geometries from geometry binders //============================================================== foreach (GeometryBinder geometryBinder in solver.GeometryBinders) { if (geometryBinder.Show) { 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 (!sceneItems.Contains(pointModel)) { sceneItems.Add(pointModel); } if (!pointModel.IsAttached) { pointModel.Attach(renderHost); } // sceneItems.Remove(pointModel); // pointModel.Detach(); // sceneItems.Add(pointModel); // sw.Restart(); // pointModel.Attach(renderHost); // DynamoLogger.Instance.Log(sw.Elapsed.TotalMilliseconds + "ms (Attach)"); } else { if (sceneItems.Contains(pointModel)) { sceneItems.Remove(pointModel); } pointModel.Detach(); } if (lineGeometry.Positions.Count >= 2) { lineModel.Geometry = lineGeometry; if (!sceneItems.Contains(lineModel)) { sceneItems.Add(lineModel); } if (!lineModel.IsAttached) { lineModel.Attach(renderHost); } } else { if (sceneItems.Contains(lineModel)) { sceneItems.Remove(lineModel); } lineModel.Detach(); } foreach (MeshGeometryModel3D meshModel in meshModels) { sceneItems.Add(meshModel); meshModel.Attach(renderHost); } if (billboardText.TextInfo.Count >= 1) { billboardTextModel.Geometry = billboardText; if (!sceneItems.Contains(billboardTextModel)) { sceneItems.Add(billboardTextModel); } if (!billboardTextModel.IsAttached) { billboardTextModel.Attach(renderHost); } } else { if (sceneItems.Contains(billboardTextModel)) { sceneItems.Remove(billboardTextModel); } billboardTextModel.Detach(); } }