public MainWindow() { InitializeComponent(); model = new ModelVisual3D(); const int rows = 5; const int columns = 4; const double distance = 120; var turbine = new WindTurbine(); var r = new Random(); for (int i = 0; i < rows; i++) { double y = i * distance; for (int j = 0; j + (i % 2) * 0.5 <= columns - 1; j++) { double x = (j + (i % 2) * 0.5) * distance; var visual = new WindTurbineVisual3D { RotationAngle = r.Next(360), RotationSpeed = 20, WindTurbine = turbine, Transform = new TranslateTransform3D(x, y, 0) }; model.Children.Add(visual); } } var seasurface = new RectangleVisual3D { DivWidth = 100, DivLength = 100, Origin = new Point3D((rows - 2) * distance * 0.5, (columns) * distance * 0.5, 0), Width = rows * distance * 2, Length = columns * distance * 2 }; seasurface.Material = seasurface.BackMaterial = MaterialHelper.CreateMaterial(Colors.SeaGreen, 0.8); model.Children.Add(new GridLinesVisual3D() { Center = seasurface.Origin, Fill = Brushes.Gray, Width = seasurface.Width, Length = seasurface.Length }); model.Children.Add(seasurface); view1.Children.Add(model); Loaded += MainWindowLoaded; Closed += MainWindowClosed; }
internal void showHidePlane() { if (this.Content != null && showPlane) { Rect3D bounds = this.Content.Bounds; //var length = bound.SizeX > bound.SizeY ? bound.SizeX : bound.SizeY > bound.SizeZ ? bound.SizeY : bound.SizeZ > bound.SizeX ? bound.SizeZ : bound.SizeX; var length = Math.Max(bounds.Size.X, Math.Max(bounds.Size.Y, bounds.Size.Z)); length += 10; if(_plane == null) _plane = new RectangleVisual3D{Normal = new Vector3D(0, 1, 0), Fill = new SolidColorBrush(Color.FromArgb(80, 255, 0, 0))}; //_plane.LengthDirection = new Vector3D(0, 0.2, 1); _plane.Width = length; _plane.Length = length; parent.Children.Add(_plane); showPlane = false; //PlaneVisual3D p = new PlaneVisual3D(this); //p.createPlane(); //parent.Children.Add(p); }else if (!showPlane) { parent.Children.Remove(_plane); _plane = null; showPlane = true; } }
/// <summary> /// 3D scene initialization /// </summary> private void InitializeScene() { const double maxVal = 8; var arrowX = new ArrowVisual3D(); arrowX.Direction = new Vector3D(1, 0, 0); arrowX.Point1 = new Point3D(0, 0, 0); arrowX.Point2 = new Point3D(maxVal, 0, 0); arrowX.Diameter = 0.1; arrowX.Fill = System.Windows.Media.Brushes.Black; HelixViewport.Children.Add(arrowX); var arrowMX = new ArrowVisual3D(); arrowMX.Direction = new Vector3D(-1, 0, 0); arrowMX.Point1 = new Point3D(0, 0, 0); arrowMX.Point2 = new Point3D(-maxVal, 0, 0); arrowMX.Diameter = 0.1; arrowMX.Fill = System.Windows.Media.Brushes.Black; HelixViewport.Children.Add(arrowMX); var arrowY = new ArrowVisual3D(); arrowY.Direction = new Vector3D(0, 1, 0); arrowY.Point1 = new Point3D(0, 0, 0); arrowY.Point2 = new Point3D(0, maxVal, 0); arrowY.Diameter = 0.1; arrowY.Fill = System.Windows.Media.Brushes.Black; HelixViewport.Children.Add(arrowY); var arrowMY = new ArrowVisual3D(); arrowMY.Direction = new Vector3D(0, -1, 0); arrowMY.Point1 = new Point3D(0, 0, 0); arrowMY.Point2 = new Point3D(0, -maxVal, 0); arrowMY.Diameter = 0.1; arrowMY.Fill = System.Windows.Media.Brushes.Black; HelixViewport.Children.Add(arrowMY); var arrowZ = new ArrowVisual3D(); arrowZ.Direction = new Vector3D(0, 0, 1); arrowZ.Point1 = new Point3D(0, 0, 0); arrowZ.Point2 = new Point3D(0, 0, maxVal); arrowZ.Diameter = 0.1; arrowZ.Fill = System.Windows.Media.Brushes.Black; HelixViewport.Children.Add(arrowZ); var arrowMZ = new ArrowVisual3D(); arrowMZ.Direction = new Vector3D(0, 0, -1); arrowMZ.Point1 = new Point3D(0, 0, 0); arrowMZ.Point2 = new Point3D(0, 0, -maxVal); arrowMZ.Diameter = 0.1; arrowMZ.Fill = System.Windows.Media.Brushes.Black; HelixViewport.Children.Add(arrowMZ); var xArrowText = new TextVisual3D(); xArrowText.Text = "X"; xArrowText.Position = new Point3D(maxVal - 0.5, 0, 0.5); xArrowText.Height = 0.5; xArrowText.FontWeight = System.Windows.FontWeights.Bold; HelixViewport.Children.Add(xArrowText); var yArrowText = new TextVisual3D(); yArrowText.Text = "Y"; yArrowText.Position = new Point3D(0, maxVal - 0.5, 0.5); yArrowText.Height = 0.5; yArrowText.FontWeight = System.Windows.FontWeights.Bold; HelixViewport.Children.Add(yArrowText); var zArrowText = new TextVisual3D(); zArrowText.Text = "Z"; zArrowText.Position = new Point3D(0.5, 0, maxVal - 0.5); zArrowText.Height = 0.5; zArrowText.FontWeight = System.Windows.FontWeights.Bold; HelixViewport.Children.Add(zArrowText); gravityPlane = new RectangleVisual3D(); gravityPlane.Width = 10; gravityPlane.Length = 10; var brush = new SolidColorBrush(Colors.Green); brush.Opacity = 0.5; gravityPlane.Fill = brush; HelixViewport.Children.Add(gravityPlane); gravityArrow = new ArrowVisual3D(); gravityArrow.Direction = new Vector3D(0, 0, -1); gravityArrow.Point1 = new Point3D(0, 0, 0); gravityArrow.Point2 = new Point3D(0, 0, -3); gravityArrow.Diameter = 0.2; gravityArrow.Fill = Brushes.Green; HelixViewport.Children.Add(gravityArrow); diagonalArrow = new ArrowVisual3D(); diagonalArrow.Direction = new Vector3D(1, 1, 1); diagonalArrow.Point1 = new Point3D(0, 0, 0); diagonalArrow.Point2 = new Point3D(cubeSize, cubeSize, cubeSize); diagonalArrow.Diameter = 0.1; diagonalArrow.Fill = Brushes.Blue; HelixViewport.Children.Add(diagonalArrow); SetupCube(); }
public World() { // instantiate our world WorldObjects = new ModelVisual3D(); Cubes = new ModelVisual3D(); JointObjects = new ModelVisual3D(); // create something to represent where the kinect is Kinect = new CubeVisual3D() { SideLength = 0.1, Center = new Point3D(0, 0, 0), Material = MaterialHelper.CreateMaterial(_Constants.KinectBrush, _Constants.KinectBrush) }; // something to represent the floor RectangleVisual3D Floor = new RectangleVisual3D() { LengthDirection = new Vector3D(0, 0, 1), Normal = new Vector3D(0, 1, 0), Origin = new Point3D(0, -0.01, 0), Length = 20, Width = 20, Fill = Brushes.White, Material = MaterialHelper.CreateMaterial(Brushes.White, Brushes.White) }; WorldObjects.Children.Add(Floor); // grid lines to layer on top of the floor GridLines = new GridLinesVisual3D() { LengthDirection = new Vector3D(0, 0, 1), Normal = new Vector3D(0, 1, 0), Transform = new ScaleTransform3D(0.025, 0.025, 0.025), Center = new Point3D(0, 0, 100), }; WorldObjects.Children.Add(GridLines); // and a reference co-ordinate system CoordinateSystem = new CoordinateSystemVisual3D() { ArrowLengths = 0.3 }; WorldObjects.Children.Add(CoordinateSystem); // setup our world transformations FloorTransform = new TranslateTransform3D(); AngleRotationTransform = new RotateTransform3D(Rotation3D.Identity, Kinect.Center); WorldTransforms = new Transform3DGroup(); WorldTransforms.Children.Add(FloorTransform); WorldTransforms.Children.Add(AngleRotationTransform); Kinect.Transform = WorldTransforms; JointObjects.Transform = FloorTransform; }
private void manip(object sender, MouseButtonEventArgs e) { var pt = view1.FindNearestPoint(e.GetPosition(view1)); if (cutLineBool && pt != null) { Point3D endPoint = pt.Value; Model3D d = vm.CurrentModel; //var position = new Point3D(startPoint.Y + ((endPoint.Y - startPoint.Y) / 2), startPoint.X, startPoint.Z); //Vector3D v = (endPoint - startPoint); var position = startPoint + (endPoint - startPoint) * 0.5; //var position = new Point3D(0, 0, 0); RectangleVisual3D r = new RectangleVisual3D(); //r.LengthDirection = new Vector3D(0, 1, 0); if (d != null) { r.Normal = new Vector3D(1,0,0); r.LengthDirection = new Vector3D(0,1,0); //startPoint + (endPoint - startPoint) * 0.5; r.Width = (d.Bounds.SizeX* 1.5); r.Length = (d.Bounds.SizeY * 1.5); r.Origin = position; } var combinedM = new CombinedManipulator(); combinedM.Position = position; combinedM.Offset = new Vector3D(0, 0, 0); combinedM.Diameter = r.Length/2; combinedM.Bind(r); view1.Children.Add(combinedM); view1.Children.Add(r); cutLineBool = false; } }
private void backup_addPlane1_Click(object sender, RoutedEventArgs e) { Model3D d = vm.RawVisual.Content; Rect3D bounds = d.Bounds; //var length = bound.SizeX > bound.SizeY ? bound.SizeX : bound.SizeY > bound.SizeZ ? bound.SizeY : bound.SizeZ > bound.SizeX ? bound.SizeZ : bound.SizeX; var length = Math.Max(bounds.Size.X, Math.Max(bounds.Size.Y, bounds.Size.Z)); length += 10; RectangleVisual3D r = new RectangleVisual3D(); r.LengthDirection = new Vector3D(0,1,0); if (d != null) { r.Width = length; r.Length = length; } view1.Children.Add(r); Model3DGroup mg = (Model3DGroup)d; Model3DGroup nm = new Model3DGroup(); foreach (GeometryModel3D gm in mg.Children) { MeshGeometry3D mesh = (MeshGeometry3D)gm.Geometry; Point3DCollection positions = mesh.Positions; Vector3DCollection normals = mesh.Normals; Int32Collection indices = mesh.TriangleIndices; Point3DCollection newPositions = new Point3DCollection() ; Vector3DCollection newNormals = new Vector3DCollection(); Int32Collection newIndices = new Int32Collection(); int c = 0; foreach (Point3D p in positions) { if (p.Y >= 0) { newPositions.Add(p); newIndices.Add(c); } else { newPositions.Add(new Point3D(p.X, 0, p.Z)); newIndices.Add(c); } c++; } GeometryModel3D gd = new GeometryModel3D(); MeshGeometry3D g = new MeshGeometry3D(); g.Positions = newPositions; g.TriangleIndices = newIndices; gd.Geometry = g; gd.Material = MaterialHelper.CreateMaterial(Colors.Aquamarine); nm.Children.Add(gd); nm.Transform = new TranslateTransform3D(new Vector3D(d.Bounds.X, d.Bounds.Y, d.Bounds.Z)); } ModelVisual3D v = new ModelVisual3D(); v.Content = nm; view1.Children.Add(v); foreach (GeometryModel3D gm in mg.Children) { MeshGeometry3D mesh = (MeshGeometry3D)gm.Geometry; Point3DCollection newPositions = new Point3DCollection(); Vector3DCollection newNormals = new Vector3DCollection(); Int32Collection newIndices = new Int32Collection(); for (int i = 0; i < mesh.TriangleIndices.Count; i = i + 3) { int index1 = mesh.TriangleIndices[i]; int index2 = mesh.TriangleIndices[i + 1]; int index3 = mesh.TriangleIndices[i + 2]; Point3D point1 = mesh.Positions[index1]; Point3D point2 = mesh.Positions[index2]; Point3D point3 = mesh.Positions[index3]; if (point1.Y < 0 || point2.Y < 0 || point3.Y < 0) continue; newIndices.Add(index1); newIndices.Add(index2); newIndices.Add(index3); newPositions.Add(point1); newPositions.Add(point2); newPositions.Add(point3); newNormals.Add(CalculateNormal(ref point1, ref point2, ref point3)); } GeometryModel3D gd = new GeometryModel3D(); MeshGeometry3D g = new MeshGeometry3D(); g.Positions = newPositions; g.Normals = newNormals; g.TriangleIndices = newIndices; gd.Geometry = g; gd.Material = MaterialHelper.CreateMaterial(Colors.AliceBlue); Model3DGroup x = new Model3DGroup(); x.Children.Add(gd); x.Transform = new TranslateTransform3D(new Vector3D(-d.Bounds.X, -d.Bounds.Y, -d.Bounds.Z)); ModelVisual3D v2 = new ModelVisual3D(); v2.Content = x; view1.Children.Add(v2); } }