Пример #1
0
        public MainViewModel()
        {
            EffectsManager = new EffectsManager();

            var builder = new MeshBuilder();

            builder.AddSphere(new Vector3(), 2);
            builder.AddTorus(5, 1);
            MeshModel = builder.ToMesh();

            var lineBuilder = new LineBuilder();

            lineBuilder.AddGrid(BoxFaces.All, 10, 10, 10, 10);
            LineModel = lineBuilder.ToLineGeometry3D();

            var offset = new Vector3(-4, 0, 0);

            PointModel = new PointGeometry3D()
            {
                Positions = new Vector3Collection(MeshModel.Positions.Select(x => x + offset))
            };

            ExportCommand         = new RelayCommand((o) => { Export(); });
            ImportCommand         = new RelayCommand((o) => { Import(); });
            ExportSingleTechnique = new RelayCommand((o) => { Export(SelectedTechnique); });
        }
        /// <summary>
        /// Constructor of the MainViewModel
        /// Sets up allProperties
        /// </summary>
        public MainViewModel(Size2 pcSize)
        {
            Size = pcSize;
            // Render Setup
            EffectsManager  = new DefaultEffectsManager();
            RenderTechnique = EffectsManager[DefaultRenderTechniqueNames.Blinn];

            // Window Setup
            this.Title    = "Point Cloud";
            this.SubTitle = null;

            // Camera Setup
            this.Camera = new HelixToolkit.Wpf.SharpDX.PerspectiveCamera
            {
                Position      = new Point3D(0, 3, -3),
                LookDirection = new Vector3D(0, -1, 4),
                UpDirection   = new Vector3D(0, 1, 0)
            };
            this.Camera.LookAt(new Point3D(0, 0, 0), 0);

            // Lines Setup
            this.LineThickness          = 1;
            this.TriangulationThickness = .5;
            this.ShowTriangleLines      = true;

            // Lighting Setup
            this.AmbientLightColor         = System.Windows.Media.Colors.White;
            this.DirectionalLightColor     = Color.White;
            this.DirectionalLightDirection = new Vector3(0, -1, 0);

            // Model Materials and Colors
            this.Material = PhongMaterials.PolishedBronze;


            // Grid Setup
            int GRID_SIZE            = 10;
            int GRID_LONG_RANGE_SIZE = 40;
            var gridTransform        = new Transform3DGroup();

            gridTransform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90)));
            gridTransform.Children.Add(new TranslateTransform3D(-GRID_SIZE / 2, -0.01, -GRID_SIZE / 2));
            GridTransform = gridTransform;

            // Major
            LineBuilder lb = new LineBuilder();

            lb.AddGrid(BoxFaces.Bottom, 11, 11, GRID_SIZE, GRID_SIZE);
            this.GridMajor = lb.ToLineGeometry3D();
            this.GridColor = System.Windows.Media.Color.FromArgb(15, 200, 200, 200);

            // Minor
            lb = new LineBuilder();
            lb.AddGrid(BoxFaces.Bottom, 101, 101, GRID_SIZE, GRID_SIZE);
            this.GridMinor = lb.ToLineGeometry3D();

            // Long range
            lb = new LineBuilder();
            lb.AddGrid(BoxFaces.Bottom, GRID_LONG_RANGE_SIZE + 1, GRID_LONG_RANGE_SIZE + 1, GRID_LONG_RANGE_SIZE, GRID_LONG_RANGE_SIZE);
            this.GridLongRange = lb.ToLineGeometry3D();
            GridLRTransform    = new TranslateTransform3D(-(GRID_LONG_RANGE_SIZE - GRID_SIZE) / 2, -(GRID_LONG_RANGE_SIZE - GRID_SIZE) / 2, 0);

            // Long range major
            lb = new LineBuilder();
            lb.AddGrid(BoxFaces.Bottom, GRID_LONG_RANGE_SIZE / 5 + 1, GRID_LONG_RANGE_SIZE / 5 + 1, GRID_LONG_RANGE_SIZE, GRID_LONG_RANGE_SIZE);
            this.GridLongRangeMajor = lb.ToLineGeometry3D();


            lb = new LineBuilder();
            lb.AddLine(new Vector3(0, 0, 0), new Vector3(GRID_SIZE / 2, 0, 0));
            this.XAxis = lb.ToLineGeometry3D();

            lb = new LineBuilder();
            lb.AddLine(new Vector3(0, 0, 0), new Vector3(0, GRID_SIZE / 2, 0));
            this.YAxis = lb.ToLineGeometry3D();

            lb = new LineBuilder();
            lb.AddLine(new Vector3(0, 0, 0), new Vector3(0, 0, GRID_SIZE / 2));
            this.ZAxis = lb.ToLineGeometry3D();

            var mb = new MeshBuilder();

            mb.AddSphere(new Vector3(0, 0, 0), 0.05);
            this.Origin = mb.ToMeshGeometry3D();

            OriginMaterial = new PhongMaterial()
            {
                AmbientColor      = System.Windows.Media.Colors.Gray.ToColor4(),
                DiffuseColor      = System.Windows.Media.Colors.Yellow.ToColor4(),
                SpecularColor     = System.Windows.Media.Colors.White.ToColor4(),
                SpecularShininess = 100f,
            };



            PointCloud           = new PointGeometry3D();
            PointCloud.IsDynamic = true;
            InitPointCloud(Color4Extensions.FromArgb(255, 0, 0));
        }