public void HideModelMover()
        {
            this.Children.Clear();

            _directionalLight   = null;
            _modelMoverVisual3D = null;
        }
        private void SetupModelMover()
        {
            // Create a new ModelMover
            _modelMover = new ModelMoverVisual3D();

            var selectedModelBounds = RootModelVisual3D.Content.Bounds;

            _modelMover.Position = _initialPosition;

            // Calculate axis length from model size
            double axisLength = Math.Max(selectedModelBounds.Size.X, Math.Max(selectedModelBounds.Size.Y, selectedModelBounds.Size.Z));

            _modelMover.AxisLength = axisLength;

            // Set AxisRadius and AxisArrowRadius based on axis length
            _modelMover.AxisRadius      = axisLength / 100;
            _modelMover.AxisArrowRadius = _modelMover.AxisRadius * 3;


            // Setup event handlers
            _modelMover.ModelMoveStarted += delegate(object o, EventArgs eventArgs)
            {
                _startMovePosition   = new Point3D(_translateTransform3D.OffsetX, _translateTransform3D.OffsetY, _translateTransform3D.OffsetZ);
                _modelMover.Position = _initialPosition.ToVector3D() + _startMovePosition;
            };

            _modelMover.ModelMoved += delegate(object o, Ab3d.Common.ModelMovedEventArgs e)
            {
                var newCenterPosition = _startMovePosition + e.MoveVector3D;

                //if (Math.Abs(newCenterPosition.X) > 2000 ||
                //    Math.Abs(newCenterPosition.Y) > 2000 ||
                //    Math.Abs(newCenterPosition.Z) > 2000)
                //{
                //    InfoTextBlock.Text = "Move out of range";
                //    return;
                //}

                // When model is moved we get the updated MoveVector3D
                // We use MoveVector3D to change the _currentTranslateTransform3D that is used on the currently selected model and on the ModelMover object
                _translateTransform3D.OffsetX = newCenterPosition.X;
                _translateTransform3D.OffsetY = newCenterPosition.Y;
                _translateTransform3D.OffsetZ = newCenterPosition.Z;

                _modelMover.Position = _initialPosition.ToVector3D() + newCenterPosition;

                if (_modelRotator != null)
                {
                    _modelRotator.Position = newCenterPosition;
                }
            };

            _modelMover.ModelMoveEnded += delegate(object sender, EventArgs args)
            {
            };


            OverlayViewport.Children.Add(_modelMover);
        }
Exemple #3
0
        private void EnsureModelMover()
        {
            if (_modelMover != null)
            {
                return;
            }


            _modelMover = new ModelMoverVisual3D();

            _modelMover.IsYAxisShown = false; // Prevent moving the duck up and down


            // Setup event handlers on ModelMoverVisual3D
            _modelMover.ModelMoveStarted += delegate(object o, EventArgs eventArgs)
            {
                if (_selectedVisual3D == null || _standardTransform3D == null)
                {
                    return;
                }

                //_standardTransform3D = StandardTransform3D.GetStandardTransform3D(_selectedVisual3D);

                _startTranslateVector3D = _standardTransform3D.GetTranslateVector3D();
            };

            _modelMover.ModelMoved += delegate(object o, Ab3d.Common.ModelMovedEventArgs e)
            {
                if (_selectedVisual3D == null || _standardTransform3D == null)
                {
                    return;
                }

                var newCenterPosition = _startTranslateVector3D + e.MoveVector3D;


                // If position is outside of 90% of lake radius, then do not make the move
                double distanceToLakeCenter = (newCenterPosition.ToPoint3D() - LakeCircleVisual3D.CenterPosition).Length;
                if (distanceToLakeCenter > (LakeCircleVisual3D.Radius * 0.90))
                {
                    // Move outside the lake
                    return;
                }

                _standardTransform3D.TranslateX = newCenterPosition.X;
                _standardTransform3D.TranslateY = newCenterPosition.Y;
                _standardTransform3D.TranslateZ = newCenterPosition.Z;

                _modelMover.Position = newCenterPosition.ToPoint3D();
            };

            // Nothing to do in ModelMoveEnded
            //_modelMover.ModelMoveEnded += delegate (object sender, EventArgs args)
            //{

            //};
        }
Exemple #4
0
        private void HideModelMover()
        {
            if (_modelMover != null)
            {
                OverlayViewport.Children.Remove(_modelMover);
                _modelMover = null;
            }

            MoveButton.IsChecked = false;
        }
        public void SetupModelMover()
        {
            if (_modelMoverVisual3D == null)
            {
                _modelMoverVisual3D = new ModelMoverVisual3D();

                // Setup event handlers on ModelMoverVisual3D
                _modelMoverVisual3D.ModelMoveStarted += delegate(object o, EventArgs eventArgs)
                {
                    if (ModelMoveStarted != null)
                    {
                        ModelMoveStarted();
                    }
                };

                _modelMoverVisual3D.ModelMoved += delegate(object o, Ab3d.Common.ModelMovedEventArgs e)
                {
                    if (ModelMoved != null)
                    {
                        ModelMoved(e.MoveVector3D);
                    }
                };

                _modelMoverVisual3D.ModelMoveEnded += delegate(object sender, EventArgs args)
                {
                    if (ModelMoveEnded != null)
                    {
                        ModelMoveEnded();
                    }
                };

                this.Children.Add(_modelMoverVisual3D);
            }

            UpdateDirectionalLight();
        }
        public ModelMoverOverlayWithZUpAxisSample()
        {
            // To use custom axes in ModelMoverVisual3D we could also change the default axes direction with the changing the following static fields:
            // This way we could define the ModelMoverVisual3D in XAML.
            // But here we will rather use a ModelMoverVisual3D constructor that takes custom axes as parameters.
            //ModelMoverVisual3D.DefaultXAxis = new Vector3D(1, 0, 0);
            //ModelMoverVisual3D.DefaultYAxis = new Vector3D(0, 0, -1);
            //ModelMoverVisual3D.DefaultZAxis = new Vector3D(0, 1, 0);


            InitializeComponent();


            // Calculate the inverted matrix at startup (used to convert from standard Y up to our Z up coordinate system)
            var invertedZUpMatrix = ZUpMatrix;

            invertedZUpMatrix.Invert();

            _zUpTransform3D         = new MatrixTransform3D(ZUpMatrix);
            _invertedZUpTransform3D = new MatrixTransform3D(invertedZUpMatrix);



            // To define custom axes directions for ModelMoverVisual3D, use the constructor that takes axes direction (note that this cannot be done in XAML)
            _modelMover = new ModelMoverVisual3D(xAxisVector3D: new Vector3D(ZUpMatrix.M11, ZUpMatrix.M12, ZUpMatrix.M13),
                                                 yAxisVector3D: new Vector3D(ZUpMatrix.M21, ZUpMatrix.M22, ZUpMatrix.M23),
                                                 zAxisVector3D: new Vector3D(ZUpMatrix.M31, ZUpMatrix.M32, ZUpMatrix.M33))
            {
                AxisLength      = 50,
                AxisRadius      = 1.5,
                AxisArrowRadius = 5
            };


            // Setup event handlers on ModelMoverVisual3D
            _modelMover.ModelMoveStarted += delegate(object o, EventArgs eventArgs)
            {
                if (_selectedBoxModel == null)
                {
                    return;
                }

                _startMovePosition = _selectedBoxModel.CenterPosition;
            };

            _modelMover.ModelMoved += delegate(object o, Ab3d.Common.ModelMovedEventArgs e)
            {
                if (_selectedBoxModel == null)
                {
                    return;
                }


                // When using custom coordinate system we need to transform the e.MoveVector3D.
                // Because the e.MoveVector3D is defined in standard Y up WPF 3D coordinate system,
                // we need to convert that into out Z up coordinate system.
                // This is done with using the inverted YUpMatrix:
                var transformedMoveVector3D = _invertedZUpTransform3D.Transform(e.MoveVector3D);

                var newCenterPosition = _startMovePosition + transformedMoveVector3D;

                if (Math.Abs(newCenterPosition.X) > 2000 ||
                    Math.Abs(newCenterPosition.Y) > 2000 ||
                    Math.Abs(newCenterPosition.Z) > 2000)
                {
                    InfoTextBlock.Text = "Move out of range";
                    return;
                }

                _selectedBoxModel.CenterPosition = newCenterPosition;


                var position = GetSelectedModelWorldPosition(); // GetSelectedModelPosition gets the _selectedBoxModel.CenterPosition and transforms it with the transformations of parent ModelVisual3D objects

                // Because ModelMoverVisual3D is in a separate Viewport3D that does not use the ZUpMatrix transformation,
                // we need to transform the position from z up coordinate system into the standard WPF 3D coordinate system:
                _modelMover.Position = _zUpTransform3D.Transform(position);


                InfoTextBlock.Text = string.Format("MoveVector3D: {0:0}", e.MoveVector3D);
            };

            _modelMover.ModelMoveEnded += delegate(object sender, EventArgs args)
            {
                InfoTextBlock.Text = "";
            };

            RootOverlayModelVisual3D.Children.Add(_modelMover);



            // Update the axes for CameraAxisPanel
            CustomCameraAxisPanel1.CustomizeAxes(new Vector3D(1, 0, 0), "X", Colors.Red,
                                                 new Vector3D(0, 1, 0), "Z", Colors.Blue,
                                                 new Vector3D(0, 0, -1), "Y", Colors.Green);



            // Set the ZUpMatrix to transform all the shown objects.
            // This way the objects will use the Z up matrix, but before rendering this will be transformed into the standard WPF 3D y up coordinate system.
            ZUpRootVisual.Transform = _zUpTransform3D;


            // We need to synchronize the Camera and Lights in OverlayViewport with the camera in the MainViewport
            Camera1.CameraChanged += delegate(object s, CameraChangedRoutedEventArgs args)
            {
                OverlayViewport.Camera         = MainViewport.Camera;
                OverlayViewportLight.Direction = ((DirectionalLight)Camera1.CameraLight).Direction;
            };


            _normalMaterial = new DiffuseMaterial(Brushes.Silver);
            _eventManager   = new Ab3d.Utilities.EventManager3D(MainViewport);

            CreateRandomScene();
        }
Exemple #7
0
        // Called when a 3D model is selected
        // It add ModelMover to the scene and sets its event handlers
        private void SetupModelMover()
        {
            // Creat a new ModelMover
            _modelMover = new ModelMoverVisual3D();


            // Position ModelMover at the center of selected model
#if !USE_GENERIC_MODEL3D
            _modelMover.Position = _selectedBoxModel.CenterPosition;
#else
            _modelMover.Position = GetSelectedModelCenter();
#endif

            // Calculate axis length from model size
            var    modelBounds = _selectedBoxModel.Model.Bounds; // Because we know that we are using BoxVisual3D, we could also use _selectedBoxVisual3D.Size; But using Bounds is more generic
            double axisLength  = Math.Max(modelBounds.Size.X, Math.Max(modelBounds.Size.Y, modelBounds.Size.Z));

            _modelMover.AxisLength = axisLength;

            // Set AxisRadius and AxisArrowRadius based on axis length
            _modelMover.AxisRadius      = axisLength / 30;
            _modelMover.AxisArrowRadius = _modelMover.AxisRadius * 3;

            UpdatedShownAxes();


            // Setup event handlers
            _modelMover.ModelMoveStarted += delegate(object o, EventArgs eventArgs)
            {
                if (_selectedBoxModel == null)
                {
                    return;
                }

#if !USE_GENERIC_MODEL3D
                _startMovePosition   = _selectedBoxModel.CenterPosition;
                _modelMover.Position = _startMovePosition;
#else
                // When the move starts we create a new TranslateTransform3D that will be used to move the model.
                _currentTranslateTransform3D = new TranslateTransform3D();

                // The new TranslateTransform3D is added to existing transformations on the object (if they exist)

                var currentTransform = _selectedBoxModel.Transform;

                if (currentTransform == null)
                {
                    _selectedBoxModel.Transform = _currentTranslateTransform3D;
                }
                else
                {
                    // transformation already exist

                    // Check if we already have Transform3DGroup
                    var currentTransformGroup = currentTransform as Transform3DGroup;
                    if (currentTransformGroup == null)
                    {
                        // Create new Transform3DGroup and add existing Transformation to the new Group
                        currentTransformGroup = new Transform3DGroup();
                        currentTransformGroup.Children.Add(_selectedBoxModel.Transform);

                        _selectedBoxModel.Transform = currentTransformGroup;
                    }

                    currentTransformGroup.Children.Add(_currentTranslateTransform3D);
                }

                // Move the ModelMover to current model center
                _startMovePosition   = GetSelectedModelCenter();
                _modelMover.Position = _startMovePosition;
#endif
            };

            _modelMover.ModelMoved += delegate(object o, Ab3d.Common.ModelMovedEventArgs e)
            {
                if (_selectedBoxModel == null)
                {
                    return;
                }

                var newCenterPosition = _startMovePosition + e.MoveVector3D;

                if (Math.Abs(newCenterPosition.X) > 2000 ||
                    Math.Abs(newCenterPosition.Y) > 2000 ||
                    Math.Abs(newCenterPosition.Z) > 2000)
                {
                    InfoTextBlock.Text = "Move out of range";
                    return;
                }

#if !USE_GENERIC_MODEL3D
                _selectedBoxModel.CenterPosition = newCenterPosition;
                _modelMover.Position             = newCenterPosition;
#else
                // When model is moved we get the updated MoveVector3D
                // We use MoveVector3D to change the _currentTranslateTransform3D that is used on the currently selected model and on the ModelMover object
                _currentTranslateTransform3D.OffsetX = moveVector3D.X;
                _currentTranslateTransform3D.OffsetY = moveVector3D.Y;
                _currentTranslateTransform3D.OffsetZ = moveVector3D.Z;

                _modelMover.Position = newCenterPosition;
#endif

                InfoTextBlock.Text = string.Format("MoveVector3D: {0:0}", e.MoveVector3D);
            };

            _modelMover.ModelMoveEnded += delegate(object sender, EventArgs args)
            {
                InfoTextBlock.Text = "";
            };


            // Add ModelMover to Viewport3D
            // We need to insert it before other objects so that the transparent objects are correctly visible (transparent objects must be shown after other objects)
            SceneObjectsContainer.Children.Insert(0, _modelMover);
        }