Beispiel #1
0
        private void OnEditorModeRadioButtonChecked(object sender, RoutedEventArgs e)
        {
            if (!this.IsLoaded)
            {
                return;
            }

            _currentEditorMode = (CreateRadioButton.IsChecked ?? false) ? EditorModes.Create :
                                 EditorModes.Edit;

            _currentObjectCreationState = (_currentEditorMode == EditorModes.Create) ? ObjectCreationStates.SelectStartPoint :
                                          ObjectCreationStates.None;

            UpdateEditorModeUI();
        }
Beispiel #2
0
        private void ViewportBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (_currentObjectCreationState != ObjectCreationStates.SelectBaseSize)
            {
                return;
            }


            double boxWidth = _selectedObjectScaleTransform.ScaleX;
            double boxDepth = _selectedObjectScaleTransform.ScaleZ;

            if (boxWidth * boxDepth < 1)
            {
                // Box too small - user probably only clicked with the mouse and did not make a drag to define the base size
                // Remove the added object
                _currentObjectCreationState = ObjectCreationStates.SelectStartPoint;
                ObjectsVisual.Children.Remove(_selectedModelVisual3D);

                return;
            }


            _selectHeightStartMousePosition = e.GetPosition(MainViewport);

            // Now we will measure how much is one pixel on screen in 3D
            // This will be used in setting the height of the object with moving the mouse up
            Point3D p1 = _lastIntersectionPoint;
            Point3D p2 = new Point3D(p1.X, p1.Y + 1, p1.Z);

            Point p1_screen = Camera1.Point3DTo2D(p1);
            Point p2_screen = Camera1.Point3DTo2D(p2);


            // We have the base object - now define the height
            _screenTo3DFactor = 1.0 / Math.Abs(p2_screen.Y - p1_screen.Y);

            if (CreateBoxButton.IsChecked ?? false)
            {
                _currentObjectCreationState = ObjectCreationStates.SelectHeight;
            }
            else
            {
                _currentObjectCreationState = ObjectCreationStates.SelectStartPoint;
            }
        }
Beispiel #3
0
        private void ProcessCreateMouseButtonPressed(MouseButtonEventArgs e)
        {
            if (_currentObjectCreationState == ObjectCreationStates.SelectStartPoint)
            {
                _objectStartPosition = _lastIntersectionPoint;

                if (CreateBoxButton.IsChecked ?? false)
                {
                    var newBoxVisual = new BoxVisual3D()
                    {
                        Material     = _standardMaterial,
                        BackMaterial = _standardBackMaterial,

                        FreezeMeshGeometry3D    = false, // Do not freeze and cache the MeshGeometry3D because we can change its positions
                        UseCachedMeshGeometry3D = false
                    };

                    // NOTE:
                    // We create the Box with its default size (1,1,1) and at its default position (0,0,0)
                    // We will not change those two properties because each of them triggers regeneration of the geometry.
                    // Instead we will define scale and translate transform that will update the 3D Box to the correct size and position.
                    // This is much better for performance and much more garbage collection friendly

                    // By default the box is already created on (0,0,0) and with size (1,1,1) so we can comment the following 2 lines:
                    //_newBoxVisual.CenterPosition = new Point3D(0, 0, 0);
                    //_newBoxVisual.Size = new Size3D(1, 1, 1);

                    _selectedObjectScaleTransform       = new ScaleTransform3D(0.0, NEW_OBJECT_HEIGHT, 0.0);
                    _selectedObjectTranslateTransform3D = new TranslateTransform3D(_objectStartPosition.X, _objectStartPosition.Y, _objectStartPosition.Z);

                    var transform3DGroup = new Transform3DGroup();
                    transform3DGroup.Children.Add(_selectedObjectScaleTransform);
                    transform3DGroup.Children.Add(_selectedObjectTranslateTransform3D);

                    newBoxVisual.Transform = transform3DGroup;

                    ObjectsVisual.Children.Add(newBoxVisual);

                    _selectedModelVisual3D = newBoxVisual;
                }
                else
                {
                    var newSphereVisual3D = new SphereVisual3D()
                    {
                        Material     = _standardMaterial,
                        BackMaterial = _standardBackMaterial,

                        FreezeMeshGeometry3D    = false, // Do not freeze and cache the MeshGeometry3D because we can change its positions
                        UseCachedMeshGeometry3D = false
                    };

                    _selectedObjectScaleTransform       = new ScaleTransform3D(NEW_OBJECT_HEIGHT, NEW_OBJECT_HEIGHT, NEW_OBJECT_HEIGHT);
                    _selectedObjectTranslateTransform3D = new TranslateTransform3D(_objectStartPosition.X, _objectStartPosition.Y, _objectStartPosition.Z);

                    var transform3DGroup = new Transform3DGroup();
                    transform3DGroup.Children.Add(_selectedObjectScaleTransform);
                    transform3DGroup.Children.Add(_selectedObjectTranslateTransform3D);

                    newSphereVisual3D.Transform = transform3DGroup;

                    ObjectsVisual.Children.Add(newSphereVisual3D);

                    _selectedModelVisual3D = newSphereVisual3D;
                }

                // Change state from SelectStartPoint => SelectBaseSize
                _currentObjectCreationState = ObjectCreationStates.SelectBaseSize;
            }
            else if (_currentObjectCreationState == ObjectCreationStates.SelectHeight)
            {
                // Finish box creation
                // Change state from SelectBaseSize => SelectStartPoint
                _currentObjectCreationState = ObjectCreationStates.SelectStartPoint;
            }
        }
Beispiel #4
0
        void SceneEditor_Loaded(object sender, RoutedEventArgs e)
        {
            ResetCamera();

            _currentObjectCreationState = ObjectCreationStates.SelectStartPoint;
        }