Exemplo n.º 1
0
        void Mouse3DEventArgsPanel_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            // Manually check if hit object was MultiModelEventSource3D or MultiVisualEventSource3D
            // and in this case show HitModelName / HitVisualName

            HitNameTitleTextBlock.Visibility = Visibility.Collapsed;
            HitNameValueTextBlock.Visibility = Visibility.Collapsed;

            if (this.DataContext is BaseMouse3DEventArgs)
            {
                BaseMouse3DEventArgs mouse3DEventArgs = this.DataContext as BaseMouse3DEventArgs;

                if (mouse3DEventArgs.HitEventSource3D is MultiModelEventSource3D)
                {
                    MultiModelEventSource3D multiModelEventSource3D = mouse3DEventArgs.HitEventSource3D as MultiModelEventSource3D;

                    if (!string.IsNullOrEmpty(multiModelEventSource3D.HitModelName))
                    {
                        HitNameValueTextBlock.Text = multiModelEventSource3D.HitModelName;

                        HitNameTitleTextBlock.Visibility = Visibility.Visible;
                        HitNameValueTextBlock.Visibility = Visibility.Visible;
                    }
                }
                else if (mouse3DEventArgs.HitEventSource3D is MultiVisualEventSource3D)
                {
                    MultiVisualEventSource3D multiVisualEventSource3D = mouse3DEventArgs.HitEventSource3D as MultiVisualEventSource3D;

                    if (!string.IsNullOrEmpty(multiVisualEventSource3D.HitVisualName))
                    {
                        HitNameValueTextBlock.Text = multiVisualEventSource3D.HitVisualName;

                        HitNameTitleTextBlock.Visibility = Visibility.Visible;
                        HitNameValueTextBlock.Visibility = Visibility.Visible;
                    }
                }

                var touch3DEventArgs = DataContext as Touch3DEventArgs;
                if (touch3DEventArgs != null)
                {
                    TouchDeviceTextBlock.Text = touch3DEventArgs.TouchData.TouchDevice.GetType().Name;
                }
            }
        }
        private void CreateSceneObjects()
        {
            for (int x = 0; x < 10; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    var boxVisual3D = new Ab3d.Visuals.BoxVisual3D()
                    {
                        CenterPosition = new Point3D(-100 + 20 * x, 50 + y * 30, 0),
                        Size           = new Size3D(10, 10, 10),
                        Material       = _standardMaterial
                    };

                    if (x == 4 && y == 2)
                    {
                        boxVisual3D.Material = _selectedMaterial;
                        _selectedModel       = boxVisual3D;
                    }

                    SelectionRootModelVisual3D.Children.Add(boxVisual3D);
                }
            }

            var eventManager3D = new Ab3d.Utilities.EventManager3D(MainViewport);

            var multiVisualEventSource3D = new MultiVisualEventSource3D(SelectionRootModelVisual3D.Children);

            multiVisualEventSource3D.MouseEnter += delegate(object sender, Mouse3DEventArgs args)
            {
                Mouse.OverrideCursor = Cursors.Hand;
            };

            multiVisualEventSource3D.MouseLeave += delegate(object sender, Mouse3DEventArgs args)
            {
                Mouse.OverrideCursor = null;
            };

            multiVisualEventSource3D.MouseClick += delegate(object sender, MouseButton3DEventArgs e)
            {
                if (_selectedModel != null)
                {
                    _selectedModel.Material = _standardMaterial;
                }

                var baseModelVisual3D = e.HitObject as Ab3d.Visuals.BaseModelVisual3D;
                if (baseModelVisual3D != null)
                {
                    baseModelVisual3D.Material = _selectedMaterial;
                    _selectedModel             = baseModelVisual3D;
                }
                else
                {
                    _selectedModel = null;
                }

                string logText = string.Format("Camera1.TurnTo(new Point3D({0:0}, {1:0}, {2:0})", e.FinalPointHit.X, e.FinalPointHit.Y, e.FinalPointHit.Z);

                if (AnimateCheckBox.IsChecked ?? false)
                {
                    // Animate the camera turn. Animation duration is 0.5 second and use QuadraticEaseInOutFunction for easing.
                    Camera1.TurnTo(position: e.FinalPointHit,
                                   animationDurationInMilliseconds: 500,
                                   easingFunction: Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);

                    logText += ", 500, QuadraticEaseInOutFunction)";
                }
                else
                {
                    Camera1.TurnTo(e.FinalPointHit); // Turn immediately
                    logText += ")";
                }

                LogCommandText(logText);

                // You can also call this with direction vector - for example:

                //var directionVector = e.FinalPointHit - Camera1.Position;
                //Camera1.TurnTo(directionVector);
            };

            eventManager3D.RegisterEventSource3D(multiVisualEventSource3D);
        }
Exemplo n.º 3
0
        private void CreateSceneObjects()
        {
            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 6; x++)
                {
                    var boxVisual3D = new Ab3d.Visuals.BoxVisual3D()
                    {
                        CenterPosition = new Point3D(40 * x - 100, 6, y * 40 - 80),
                        Size           = new Size3D(10, 10, 10),
                        Material       = _standardMaterial
                    };

                    SelectionRootModelVisual3D.Children.Add(boxVisual3D);
                }
            }

            // Use EventManager3D to handle clicking on selected boxes
            var eventManager3D = new Ab3d.Utilities.EventManager3D(MainViewport);

            var multiVisualEventSource3D = new MultiVisualEventSource3D(SelectionRootModelVisual3D.Children);

            multiVisualEventSource3D.MouseEnter += delegate(object sender, Mouse3DEventArgs e)
            {
                Mouse.OverrideCursor = Cursors.Hand;

                var hitBoxVisual3D = e.HitObject as Ab3d.Visuals.BoxVisual3D;
                if (hitBoxVisual3D != null)
                {
                    _wireBoxVisual3D.CenterPosition = hitBoxVisual3D.CenterPosition;
                    _wireBoxVisual3D.Size           = hitBoxVisual3D.Size;

                    MainViewport.Children.Add(_wireBoxVisual3D);
                }
            };

            multiVisualEventSource3D.MouseLeave += delegate(object sender, Mouse3DEventArgs e)
            {
                Mouse.OverrideCursor = null;

                if (_wireBoxVisual3D != null)
                {
                    MainViewport.Children.Remove(_wireBoxVisual3D);
                }
            };

            multiVisualEventSource3D.MouseClick += delegate(object sender, MouseButton3DEventArgs e)
            {
                if (_selectedBoxVisual3D != null)
                {
                    _selectedBoxVisual3D.Material = _standardMaterial;
                }

                var hitBoxVisual3D = e.HitObject as Ab3d.Visuals.BoxVisual3D;
                if (hitBoxVisual3D != null)
                {
                    hitBoxVisual3D.Material = _selectedMaterial;
                    _selectedBoxVisual3D    = hitBoxVisual3D;

                    if (_wireBoxVisual3D != null)
                    {
                        MainViewport.Children.Remove(_wireBoxVisual3D);
                    }

                    MoveCameraTo(hitBoxVisual3D);
                }
                else
                {
                    _selectedBoxVisual3D = null;
                }
            };

            eventManager3D.RegisterEventSource3D(multiVisualEventSource3D);

            // Exclude _wireBoxVisual3D from receiving mouse events
            eventManager3D.RegisterExcludedVisual3D(_wireBoxVisual3D);
        }