private void UpdateInit() { Circle3D circle3d = generalFiguresList[iterator] as Circle3D; if (circle3d != null) { figureName = "circle"; } Rectangle3D rectangle3d = generalFiguresList[iterator] as Rectangle3D; if (rectangle3d != null) { if (rectangle3d.figureType == 3) { figureName = "triang"; } else { figureName = "rectan"; } } Custom3D custom3d = generalFiguresList[iterator] as Custom3D; if (custom3d != null) { figureName = "custom"; } string modelName = string.Concat(comboBox.SelectedItem.ToString(), figureName); int it = 0; Model3DCollection model3Ds = model3DGroup.Children; foreach (Model3D t in model3Ds) { if (t.GetValue(FrameworkElement.NameProperty).ToString() == modelName) { model3Ds.RemoveAt(it); break; } it++; } generalFiguresList.RemoveAt(iterator); MainWindow.FiguresListChanges(); }
private void InitRect() { Model3DCollection model3Ds = model3DGroup.Children; int index = 0; foreach (GeometryModel3D model in model3Ds) { if (model.GetValue(FrameworkElement.NameProperty).ToString() == name) { model3Ds.RemoveAt(index); break; } index++; } Int32Collection triangles = new Int32Collection(); foreach (Point3D t in triangles3Ds) { triangles.Add(Convert.ToInt32(t.X)); triangles.Add(Convert.ToInt32(t.Y)); triangles.Add(Convert.ToInt32(t.Z)); } MeshGeometry3D meshGeometry3D = new MeshGeometry3D(); meshGeometry3D.Positions = point3Ds; meshGeometry3D.TriangleIndices = triangles; GeometryModel3D geometry = new GeometryModel3D(meshGeometry3D, new DiffuseMaterial(new SolidColorBrush(color))); geometry.SetValue(FrameworkElement.NameProperty, name); model3DGroup.Children.Add(geometry); Custom3D custom3D = new Custom3D(model3DGroup, point3Ds, triangles3Ds, name, color, generalFiguresList, false); generalFiguresList.Add(custom3D); MainWindow.FiguresListChanges(); }
private void InitCircle() { Model3DCollection model3Ds = model3DGroup.Children; int index = 0; foreach (GeometryModel3D model in model3Ds) { if (model.GetValue(FrameworkElement.NameProperty).ToString() == name) { model3Ds.RemoveAt(index); break; } index++; } MeshGeometry3D meshGeometry3D = new MeshGeometry3D(); meshGeometry3D.Positions.Add(new Point3D(0, 0, 0)); double t = 2 * Math.PI / resolution; for (int i = 0; i < resolution; i++) { meshGeometry3D.Positions.Add(new Point3D(radius * Math.Cos(t * i), 0, -radius * Math.Sin(t * i))); } for (int i = 0; i < resolution; i++) { int a = 0; int b = i + 1; int c = (i < (resolution - 1)) ? i + 2 : 1; meshGeometry3D.TriangleIndices.Add(a); meshGeometry3D.TriangleIndices.Add(b); meshGeometry3D.TriangleIndices.Add(c); } Transform3DGroup trn = new Transform3DGroup(); Vector3D up = new Vector3D(0, 100, 0); Vector3D vector3D = normal; normal.Normalize(); Vector3D axis = Vector3D.CrossProduct(up, normal); double angle = Vector3D.AngleBetween(up, normal); trn.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(axis, angle))); trn.Children.Add(new TranslateTransform3D(new Vector3D(center.X, center.Y, center.Z))); GeometryModel3D geometry = new GeometryModel3D(meshGeometry3D, new DiffuseMaterial(new SolidColorBrush(color))); geometry.Transform = trn; geometry.SetValue(FrameworkElement.NameProperty, name); model3DGroup.Children.Add(geometry); Circle3D circle3D = new Circle3D(radius, resolution, vector3D, center, model3DGroup, color, name, generalFiguresList, false); generalFiguresList.Add(circle3D); MainWindow.FiguresListChanges(); }
private void InitRect() { Model3DCollection model3Ds = model3DGroup.Children; int index = 0; foreach (GeometryModel3D model in model3Ds) { string valid = model.GetValue(FrameworkElement.NameProperty).ToString(); if (valid.Substring(0, valid.Length - 6) == name) { model3Ds.RemoveAt(index); break; } index++; } Point3DCollection point3Ds = new Point3DCollection(); point3Ds.Add(pointLU); point3Ds.Add(pointLD); point3Ds.Add(pointRD); if (figureType == 4) { Point3D pointRU = Get4Point3D(); point3Ds.Add(pointRU); } Int32Collection triangles = new Int32Collection(); if (figureType == 4) { triangles.Add(0); triangles.Add(1); triangles.Add(2); triangles.Add(0); triangles.Add(2); triangles.Add(3); triangles.Add(3); triangles.Add(2); triangles.Add(1); triangles.Add(3); triangles.Add(1); triangles.Add(0); name = string.Concat(name, "rectan"); } else { triangles.Add(0); triangles.Add(1); triangles.Add(2); triangles.Add(2); triangles.Add(1); triangles.Add(0); name = string.Concat(name, "triang"); } MeshGeometry3D meshGeometry3D = new MeshGeometry3D(); meshGeometry3D.Positions = point3Ds; meshGeometry3D.TriangleIndices = triangles; GeometryModel3D geometry = new GeometryModel3D(meshGeometry3D, new DiffuseMaterial(new SolidColorBrush(color))); geometry.SetValue(FrameworkElement.NameProperty, name); model3DGroup.Children.Add(geometry); Rectangle3D Rectangle3D = new Rectangle3D(pointLU, pointRD, pointLD, color, model3DGroup, name, figureType, generalFiguresList, false); generalFiguresList.Add(Rectangle3D); MainWindow.FiguresListChanges(); }