Ejemplo n.º 1
0
        private void createModel3D()
        {
            var m = wfl.LoadObjFile(@"C:\Users\libo\source\repos\WpfApp7\WpfApp7\桌子.obj");//此处为obj文件的路径

            string ad = GetFilepath();

            myModel3DGroup = new Model3DGroup();
            myModel3DGroup.Children.Add(myDirectionalLight);
            if (ad != null)
            {
                m = wfl.LoadObjFile(ad);//此处为obj文件的路径
            }

            m.Content = myModel3DGroup;

            vp.Children.Add(m);
            #region //三视图模型导入
            //上
            myModel3DGroup2 = new Model3DGroup();
            myModel3DGroup2.Children.Add(myDirectionalLight);
            var m2 = wfl.LoadObjFile(@"C:\Users\libo\source\repos\WpfApp7\WpfApp7\直升机.obj");//此处为obj文件的路径
            m2         = wfl.LoadObjFile(ad);
            m2.Content = myModel3DGroup2;
            vp2.Children.Add(m2);

            //左
            myModel3DGroup3 = new Model3DGroup();
            myModel3DGroup3.Children.Add(myDirectionalLight);
            var m3 = wfl.LoadObjFile(@"C:\Users\libo\source\repos\WpfApp7\WpfApp7\直升机.obj");//此处为obj文件的路径
            m3         = wfl.LoadObjFile(ad);
            m3.Content = myModel3DGroup3;
            vp3.Children.Add(m3);
            //正
            myModel3DGroup4 = new Model3DGroup();
            myModel3DGroup4.Children.Add(myDirectionalLight);
            var m4 = wfl.LoadObjFile(@"C:\Users\libo\source\repos\WpfApp7\WpfApp7\直升机.obj");//此处为obj文件的路径
            m4         = wfl.LoadObjFile(ad);
            m4.Content = myModel3DGroup4;
            vp4.Children.Add(m4);
            #endregion
        }
Ejemplo n.º 2
0
        double keyDeltaFactor   = 4; // determine the angle delta when the ddirection key pressed

        public MainWindow()
        {
            InitializeComponent();

            WavefrontObjLoader wfl = new WavefrontObjLoader();

            slider1.ValueChanged += new RoutedPropertyChangedEventHandler <double>(slider1_ValueChanged);
            slider2.ValueChanged += new RoutedPropertyChangedEventHandler <double>(slider1_ValueChanged);
            slider3.ValueChanged += new RoutedPropertyChangedEventHandler <double>(slider1_ValueChanged);

            // Specify where in the 3D scene the camera is.
            camera.Position = new Point3D(0, 0, 0);

            // Specify the direction that the camera is pointing.
            camera.LookDirection = new Vector3D(0, 0, -1);

            // Define camera's horizontal field of view in degrees.
            camera.FieldOfView = 1000;

            // Asign the camera to the viewport
            vp.Camera = camera;

            Model3DGroup myModel3DGroup = new Model3DGroup();

            DirectionalLight myDirectionalLight = new DirectionalLight();

            myDirectionalLight.Color     = Colors.White;
            myDirectionalLight.Direction = new Vector3D(-0.61, -0.5, -0.61);

            myModel3DGroup.Children.Add(myDirectionalLight);
            var m = wfl.LoadObjFile(@"F:\MeshedReconstruction.obj");

            m.Content = myModel3DGroup;
            vp.Children.Add(m);

            camera.UpDirection.Normalize();
            this.MouseMove           += Viewport3D_MouseMove;
            this.MouseLeftButtonDown += Viewport3D_MouseLeftButtonDown;
            this.MouseWheel          += Viewport3D_MouseWheel;
            this.KeyDown             += Window_KeyDown;
        }
Ejemplo n.º 3
0
        public MainWindow()
        {
            InitializeComponent();

            //摄像头
            myPCamera               = new PerspectiveCamera();
            myPCamera.Position      = new Point3D(0, 0, 200);
            myPCamera.LookDirection = new Vector3D(0, 0, -1);
            myPCamera.FieldOfView   = 1000;
            vp.Camera               = myPCamera;

            Model3DGroup myModel3DGroup = new Model3DGroup();
            //光源
            //AmbientLight (自然光)
            //DirectionalLight (方向光)
            //PointLight (点光源)
            //SpotLight (聚光源)
            DirectionalLight myDirectionalLight = new DirectionalLight();

            myDirectionalLight.Color     = Colors.White;
            myDirectionalLight.Direction = new Vector3D(197.862232727069, 17.7047755886957, -11.8470804909344);
            myModel3DGroup.Children.Add(myDirectionalLight);

            //DirectionalLight myDirectionalLight2 = new DirectionalLight();
            //myDirectionalLight2.Color = Colors.White;
            //myDirectionalLight2.Direction = new Vector3D(0.61, 0.5, 0.61);
            //myModel3DGroup.Children.Add(myDirectionalLight2);



            //new一个loader对象
            WavefrontObjLoader wfl = new WavefrontObjLoader();
            //ModelVisual3DWithName是WavefrontObjLoader定义的继承ModelVisual3D的对象,直接使用ModelVisual3D也是可以的
            //导入obj,第一个模型命名为m
            //ModelVisual3DWithName m = wfl.LoadObjFile(@"C:\Users\renzeming\Downloads\WpfApplication2\Lancer_Evolution_10.obj");
            //m.Content = myModel3DGroup;
            //导入obj,第二个模型命名为n
            var n = wfl.LoadObjFile(@"E:\Mine\Items\Demos\WebApplication1\Example_WPF_donghua\texttrue\low.obj");

            n.Content = myModel3DGroup;

            //下面是调整n的位置,初学者可以先注释掉。
            var tt = new TranslateTransform3D();
            //tt.OffsetX = 110;
            //tt.OffsetZ = -50;
            //tt.OffsetY = -100;
            var tr = new RotateTransform3D();

            tr.Rotation = new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90);

            var tr2 = new RotateTransform3D();

            tr2.Rotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90);

            var ts = new ScaleTransform3D();

            ts.ScaleX = 1.5;
            ts.ScaleY = 1.5;
            ts.ScaleZ = 1.6;
            var tg = new Transform3DGroup();

            tg.Children.Add(tr); tg.Children.Add(tr2);
            tg.Children.Add(tt); tg.Children.Add(ts);
            n.Transform = tg;

            //将两个模型添加到场景中
            //vp.Children.Add(m);
            //197.862232727069,17.7047755886957,-11.8470804909344



            vp.Children.Add(n);

            InitializeComponent();
        }