예제 #1
0
        public override void OnApplyTemplate()
        {
            if (adornerLayer == null)
            {
                adornerLayer = Template.FindName(PART_ADORNER_LAYER, this) as AdornerDecorator;
                if (adornerLayer != null)
                {
                    adornerLayer.Child = viewport;
                }
            }
            Debug.Assert(adornerLayer != null, String.Format("{0} is missing from the template.", PART_ADORNER_LAYER));

            if (cameraController == null)
            {
                cameraController = Template.FindName(PART_CAMERA_CONTROLLER, this) as CameraController;
                if (cameraController != null)
                {
                    cameraController.Viewport          = Viewport;
                    cameraController.SelectionChanged += CameraControllerSelectionChanged;
                }
            }
            Debug.Assert(cameraController != null,
                         String.Format("{0} is missing from the template.", PART_CAMERA_CONTROLLER));

            if (coordinateView == null)
            {
                coordinateView = Template.FindName(PART_COORDINATE_VIEW, this) as Viewport3D;

                coordinateSystemLights = new Model3DGroup();
                coordinateSystemLights.Children.Add(new DirectionalLight(Colors.White, new Vector3D(1, 1, 1)));
                coordinateSystemLights.Children.Add(new AmbientLight(Colors.DarkGray));
                if (coordinateView != null)
                {
                    coordinateView.Camera = new PerspectiveCamera();
                    coordinateView.Children.Add(new ModelVisual3D {
                        Content = coordinateSystemLights
                    });
                }
            }
            Debug.Assert(coordinateView != null, String.Format("{0} is missing from the template.", PART_COORDINATE_VIEW));

            if (viewCubeView == null)
            {
                viewCubeView = Template.FindName(PART_VIEW_CUBE_VIEW, this) as Viewport3D;

                viewCubeLights = new Model3DGroup();
                // _viewCubeLights.Children.Add(new DirectionalLight(Colors.White, new Vector3D(1, 1, 1)));
                viewCubeLights.Children.Add(new AmbientLight(Colors.White));
                if (viewCubeView != null)
                {
                    viewCubeView.Camera = new PerspectiveCamera();
                    viewCubeView.Children.Add(new ModelVisual3D {
                        Content = viewCubeLights
                    });
                    viewCubeView.MouseEnter += ViewCubeViewMouseEnter;
                    viewCubeView.MouseLeave += ViewCubeViewMouseLeave;
                }
                viewCube = Template.FindName(PART_VIEW_CUBE, this) as ViewCubeVisual3D;
                if (viewCube != null)
                {
                    viewCube.Viewport = Viewport;
                }
            }
            Debug.Assert(coordinateView != null, String.Format("{0} is missing from the template.", PART_COORDINATE_VIEW));

            // update the coordinateview camera
            OnCameraChanged();

            // add the default headlight
            OnHeadlightChanged();
            base.OnApplyTemplate();
        }
예제 #2
0
        public override void OnApplyTemplate()
        {
            if (adornerLayer == null)
            {
                adornerLayer = Template.FindName(PART_ADORNER_LAYER, this) as AdornerDecorator;
                if (adornerLayer != null)
                    adornerLayer.Child = viewport;
            }
            Debug.Assert(adornerLayer != null, String.Format("{0} is missing from the template.", PART_ADORNER_LAYER));

            if (cameraController == null)
            {
                cameraController = Template.FindName(PART_CAMERA_CONTROLLER, this) as CameraController;
                if (cameraController != null)
                {
                    cameraController.Viewport = Viewport;
                    cameraController.SelectionChanged += CameraControllerSelectionChanged;
                }
            }
            Debug.Assert(cameraController != null,
                         String.Format("{0} is missing from the template.", PART_CAMERA_CONTROLLER));

            if (coordinateView == null)
            {
                coordinateView = Template.FindName(PART_COORDINATE_VIEW, this) as Viewport3D;

                coordinateSystemLights = new Model3DGroup();
                coordinateSystemLights.Children.Add(new DirectionalLight(Colors.White, new Vector3D(1, 1, 1)));
                coordinateSystemLights.Children.Add(new AmbientLight(Colors.DarkGray));
                if (coordinateView != null)
                {
                    coordinateView.Camera = new PerspectiveCamera();
                    coordinateView.Children.Add(new ModelVisual3D { Content = coordinateSystemLights });
                }
            }
            Debug.Assert(coordinateView != null, String.Format("{0} is missing from the template.", PART_COORDINATE_VIEW));

            if (viewCubeView == null)
            {
                viewCubeView = Template.FindName(PART_VIEW_CUBE_VIEW, this) as Viewport3D;

                viewCubeLights = new Model3DGroup();
                // _viewCubeLights.Children.Add(new DirectionalLight(Colors.White, new Vector3D(1, 1, 1)));
                viewCubeLights.Children.Add(new AmbientLight(Colors.White));
                if (viewCubeView != null)
                {
                    viewCubeView.Camera = new PerspectiveCamera();
                    viewCubeView.Children.Add(new ModelVisual3D { Content = viewCubeLights });
                    viewCubeView.MouseEnter += ViewCubeViewMouseEnter;
                    viewCubeView.MouseLeave += ViewCubeViewMouseLeave;
                }
                viewCube = Template.FindName(PART_VIEW_CUBE, this) as ViewCubeVisual3D;
                if (viewCube != null)
                    viewCube.Viewport = Viewport;
            }
            Debug.Assert(coordinateView != null, String.Format("{0} is missing from the template.", PART_COORDINATE_VIEW));

            // update the coordinateview camera
            OnCameraChanged();

            // add the default headlight
            OnHeadlightChanged();
            base.OnApplyTemplate();
        }