Beispiel #1
0
        private void LoadRawFile(string CurrentModelPath)
        {
            try
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                CurrentModel = ModelImporter.Load(CurrentModelPath);
                Model3DGroup group = new Model3DGroup();
                if (CurrentModel != null)
                {
                    var    mb = new MeshBuilder(false, false);
                    Rect3D r  = CurrentModel.Bounds;

                    Model3DGroup g = (Model3DGroup)CurrentModel;
                    foreach (GeometryModel3D gm in g.Children)
                    {
                        MeshGeometry3D    mesh = (MeshGeometry3D)gm.Geometry;
                        Point3DCollection ind  = mesh.Positions;
                        for (int i = 0; i < ind.Count; i++)
                        {
                            var p0 = ind[i];

                            p0 = new Point3D(p0.X + (-(r.X + (r.SizeX / 2))), p0.Y + (-(r.Y + (r.SizeY / 2))), p0.Z + (-(r.Z + (r.SizeZ / 2))));

                            mb.Positions.Add(p0);
                        }

                        for (int i = 0; i < mesh.TriangleIndices.Count; i++)
                        {
                            mb.TriangleIndices.Add(mesh.TriangleIndices[i]);
                        }
                    }
                    var geom = new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(Colors.BlueViolet));
                    geom.BackMaterial = MaterialHelper.CreateMaterial(Colors.Chocolate);
                    group.Children.Add(geom);

                    CurrentModel = group;
                    if (RawVisual == null)
                    {
                        RawVisual = new RawVisual3D(RootVisual);
                    }
                    RawVisual.Content         = CurrentModel;
                    RawVisual.ShowBoundingBox = true;
                    RawVisual.showHideBoundingBox();
                    RootVisual.Children.Add(RawVisual);
                    smileMode        = "RAW";
                    ApplicationTitle = String.Format(TitleFormatString, CurrentModelPath);
                    HelixView.ZoomExtents(100);
                }

                showStatus(stopWatch, "Loaded");
            }
            catch (FileNotFoundException fnfe)
            {
                MessageBox.Show("File not found. Make sure your Path Setting is correct.");
            }
        }
Beispiel #2
0
        private void FileOpenRaw()
        {
            CurrentModelPath = FileDialogService.OpenFileDialog("models", null, OpenFileFilter, ".3ds");
#if !DEBUG
            try
            {
#endif
            ///*
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();

            CurrentModel = ModelImporter.Load(CurrentModelPath);
            Model3DGroup group = new Model3DGroup();
            if (CurrentModel != null)
            {
                var    mb = new MeshBuilder(false, false);
                Rect3D r  = CurrentModel.Bounds;

                Model3DGroup g = (Model3DGroup)CurrentModel;
                foreach (GeometryModel3D gm in g.Children)
                {
                    MeshGeometry3D    mesh = (MeshGeometry3D)gm.Geometry;
                    Point3DCollection ind  = mesh.Positions;
                    for (int i = 0; i < ind.Count; i++)
                    {
                        var p0 = ind[i];

                        p0 = new Point3D(p0.X + (-(r.X + (r.SizeX / 2))), p0.Y + (-(r.Y + (r.SizeY / 2))), p0.Z + (-(r.Z + (r.SizeZ / 2))));

                        mb.Positions.Add(p0);
                    }

                    for (int i = 0; i < mesh.TriangleIndices.Count; i++)
                    {
                        mb.TriangleIndices.Add(mesh.TriangleIndices[i]);
                    }
                }
                var geom = new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(Colors.BlueViolet));
                geom.BackMaterial = MaterialHelper.CreateMaterial(Colors.Chocolate);
                group.Children.Add(geom);


                /*
                 * //ADD COUNTOUR
                 * var segments = MeshGeometryHelper.GetContourSegments(geom.Geometry as MeshGeometry3D, new Point3D(0,0,0), new Vector3D(0,0,1));
                 * foreach (var contour in MeshGeometryHelper.CombineSegments(segments, 1e-6))
                 * {
                 *  if (contour.Count == 0)
                 *      continue;
                 *  HelixView.Viewport.Children.Add(new TubeVisual3D { Diameter = 0.03, Path = new Point3DCollection(contour), Fill = Brushes.Green });
                 * }
                 * //*/
                /*
                 * //FIND EDGES
                 * var edges = MeshGeometryHelper.FindEdges(geom.Geometry as MeshGeometry3D);
                 * for (int i = 0; i < edges.Count; i+=2)
                 * {
                 *  Point3DCollection points = new Point3DCollection();
                 *  MeshGeometry3D ms = geom.Geometry as MeshGeometry3D;
                 *  Point3D p0 = ms.Positions[edges[i]];
                 *  Point3D p1 = ms.Positions[edges[i+1]];
                 *  points.Add(p0);
                 *  points.Add(p1);
                 *  HelixView.Viewport.Children.Add(new TubeVisual3D { Diameter = 0.03,  Path = new Point3DCollection(points), Fill = Brushes.Black});
                 * }
                 * //*/
                CurrentModel = group;
                //Transform3DGroup tgroup = new Transform3DGroup();
                //tgroup.Children.Add(new TranslateTransform3D(-(r.X + (r.SizeX / 2)), -(r.Y + (r.SizeY / 2)), -(r.Z + (r.SizeZ / 2))));
                //tgroup.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0,1,0), 45)));
                //CurrentModel.Transform = tgroup;
                //CurrentModel.Freeze();
                if (RawVisual == null)
                {
                    RawVisual = new RawVisual3D(RootVisual);
                }
                //RawVisual.Content = CurrentModel;
                RawVisual.Content         = CurrentModel;
                RawVisual.ShowBoundingBox = true;
                RawVisual.showHideBoundingBox();
                RootVisual.Children.Add(RawVisual);
                smileMode = "RAW";

                //if(!HelixView.Viewport.Children.Contains(RootVisual)) HelixView.Viewport.Children.Add(RootVisual);

                //ModelVisual3D v = new ModelVisual3D();
                //v.Content = CurrentModel;
                //RootVisual.Children.Add(v);

                //*/

                /*
                 * List<Point3D> pts = new List<Point3D>();
                 * pts.Add(new Point3D(30.4960694492679, 5.52461072334257, 9.44661196022868));
                 * pts.Add(new Point3D(28.0998337010248, 6.66945199865937, 14.4798151385421));
                 * pts.Add(new Point3D(28.2102015086476, -0.126599907551222, 19.0159875772706));
                 * pts.Add(new Point3D(29.7392389441408, -4.1789883548182, 14.8532955485325));
                 * pts.Add(new Point3D(28.4974026994517, -2.89939719282193, 8.04165108434179));
                 * pts.Add(new Point3D(24.1236797131164, 1.10693238332609, 6.46814289839299));
                 *
                 * for (var i = 0; i < pts.Count; i++)
                 * {
                 *  BoxVisual3D b = new BoxVisual3D();
                 *  b.Center = pts[i];
                 *  b.Length = 2;
                 *  b.Height = 2;
                 *  b.Width = 2;
                 *  HelixView.Viewport.Children.Add(b);
                 * }
                 */

                ApplicationTitle = String.Format(TitleFormatString, CurrentModelPath);
                HelixView.ZoomExtents(0);

                showStatus(stopWatch, "Loaded");
            }
#if !DEBUG
        }

        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }
#endif
        }