Exemple #1
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            UpdateMaterial();
            UpdateTrianglesAndNormals();

            Camera1.Refresh(); // This will measure the models on the scene and reposition the scene camera
        }
Exemple #2
0
        public BillboardsSample()
        {
            InitializeComponent();

            _transparencySorter = new Ab3d.Utilities.TransparencySorter(TreesPlaceholerVisual3D)
            {
                UsedCamera = Camera1
            };

            // Explicitly set which Visual3D objects should be considered transparent.
            // This is needed because TransparencySorter does not know if texture image have transparency or not and therefore does not consider them transparent.
            // With calling AddTransparentModels we define that.
            // Another option to "persuade" TransparencySorter to consider objects are transparent is to set very small opacity to the ImageBrush - for example set Opacity to 0.99
            _transparencySorter.AddTransparentModels(TreePlaneVisual1, TreePlaneVisual2, TreePlaneVisual3, TreePlaneVisual4);

            _transparencySorter.Sort(TransparencySorter.SortingModeTypes.ByCameraDistance);


            Camera1.CameraChanged += Camera1OnCameraChanged;

            Camera1.StartRotation(30, 0);

            // PlaneVisual3D uses MatrixTransform3D to position, scale and orient the plane. This greatly improves the performance.
            // To disable that and change MeshGeometry3D instead of MatrixTransform3D, set UseMatrixTransform3D to false:
            //PlaneVisual1.UseMatrixTransform3D = false;

            MainViewport.SizeChanged += (sender, args) => UpdateOverlayCanvasElements();
        }
Exemple #3
0
        private void StartAnimation(bool isActionImmediate)
        {
            // Camera can be animated with using StartRotation method.
            // StartRotation take two parameters - headingChangeInSecond and attitudeChangeInSecond
            // Advantage of using StartRotation method over using Storyboard animation of Heading or Attitude properties is that
            // StartRotation does not lock the Heading and Attitude properties.
            // The StartRotation also works very good with CameraControlPanel and MouseCameraController - while the camera is rotating it is possible
            // to manually change camera with the mouse or with the buttons on CameraControlPanel

            double headingChangeInSecond  = HeadingChangeInSecondSlider.Value;
            double attitudeChangeInSecond = AttitudeChangeInSecondSlider.Value;

            if (isActionImmediate)
            {
                Camera1.StartRotation(headingChangeInSecond, attitudeChangeInSecond); // No easing
            }
            else
            {
                double accelerationSpeed = AccelerationSpeedSlider.Value;
                SphericalCamera.EasingFunctionDelegate easingFunction = GetEaseInFunction(); // NOTE that ease in and ease out are different functions

                Camera1.StartRotation(headingChangeInSecond, attitudeChangeInSecond, accelerationSpeed, easingFunction);
            }

            StartStopSlowlyButton.Content   = "STOP rotation slowly";
            StartStopNowButton.Content      = "STOP rotation now";
            AccelerationSpeedTextBlock.Text = "decelerationSpeed (0 = disabled):";

            _isRotationStarted = true;
        }
Exemple #4
0
        private void UpdateOverlayCanvasElements()
        {
            if (!this.IsLoaded)
            {
                return;
            }

            // Start with right top back edge of the Box
            //var position3D = GoldBoxVisual3D.CenterPosition + new Vector3D(-GoldBoxVisual3D.Size.X / 2, GoldBoxVisual3D.Size.Y / 2, GoldBoxVisual3D.Size.Z / 2);
            var position3D = GoldBoxVisual3D.CenterPosition + new Vector3D(0, GoldBoxVisual3D.Size.Y / 2, 0);

            if (_overlayBrushHeight < 0.001)
            {
                OverlayInfoTextBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                _overlayBrushHeight = OverlayInfoTextBlock.DesiredSize.Height + OverlayInfoBorder.BorderThickness.Bottom + OverlayInfoBorder.BorderThickness.Top;
            }

            var pos1 = Camera1.Point3DTo2D(position3D);
            var pos2 = pos1 + new Vector(30, -20);

            OverlayLine.X1 = pos1.X;
            OverlayLine.Y1 = pos1.Y;

            OverlayLine.X2 = pos2.X;
            OverlayLine.Y2 = pos2.Y;

            Canvas.SetLeft(OverlayInfoBorder, pos2.X);
            Canvas.SetTop(OverlayInfoBorder, pos2.Y - _overlayBrushHeight / 2);
        }
Exemple #5
0
        public void ShowModel(Model3D model3D, bool updateCamera)
        {
            try
            {
                ContentVisual.SetCurrentValue(ModelVisual3D.ContentProperty, model3D);

                // NOTE:
                // We could show both solid model and wireframe in WireframeVisual3D (ContentWireframeVisual) with using WireframeWithOriginalSolidModel for WireframeType.
                // But in this sample we show solid frame is separate ModelVisual3D and therefore we show only wireframe in WireframeVisual3D.
                ContentWireframeVisual.BeginInit();
                ContentWireframeVisual.SetCurrentValue(Ab3d.Visuals.WireframeVisual3D.ShowPolygonLinesProperty, ReadPolygonIndicesCheckBox.IsChecked ?? false);
                ContentWireframeVisual.SetCurrentValue(Ab3d.Visuals.WireframeVisual3D.OriginalModelProperty, model3D);
                ContentWireframeVisual.EndInit();

                if (AddLineDepthBiasCheckBox.IsChecked ?? false)
                {
                    // To specify line depth bias to the Ab3d.PowerToys line Visual3D objects,
                    // we use SetDXAttribute extension method and use LineDepthBias as DXAttributeType
                    // NOTE: This can be used only before the Visual3D is created by DXEngine.
                    // If you want to change the line bias after the object has been rendered, use the SetDepthBias method (see OnAddLineDepthBiasCheckBoxCheckedChanged)
                    //
                    // See DXEngineVisuals/LineDepthBiasSample for more info.
                    ContentWireframeVisual.SetDXAttribute(DXAttributeType.LineDepthBias, model3D.Bounds.GetDiagonalLength() * 0.001);
                }

                // Calculate the center of the model and its size
                // This will be used to position the camera

                if (updateCamera)
                {
                    var bounds = model3D.Bounds;

                    var modelCenter = new Point3D(bounds.X + bounds.SizeX / 2,
                                                  bounds.Y + bounds.SizeY / 2,
                                                  bounds.Z + bounds.SizeZ / 2);

                    var modelSize = Math.Sqrt(bounds.SizeX * bounds.SizeX +
                                              bounds.SizeY * bounds.SizeY +
                                              bounds.SizeZ * bounds.SizeZ);

                    Camera1.TargetPosition = modelCenter;
                    Camera1.SetCurrentValue(Ab3d.Cameras.BaseTargetPositionCamera.DistanceProperty, modelSize * 2);
                }

                // If the read model already define some lights, then do not show the Camera's light
                if (ModelUtils.HasAnyLight(model3D))
                {
                    Camera1.SetCurrentValue(Ab3d.Cameras.BaseCamera.ShowCameraLightProperty, ShowCameraLightType.Never);
                }
                else
                {
                    Camera1.SetCurrentValue(Ab3d.Cameras.BaseCamera.ShowCameraLightProperty, ShowCameraLightType.Always);
                }

                ShowInfoButton.SetCurrentValue(IsEnabledProperty, true);
            }
            catch
            {
            }
        }
        private void ExportToImageButton_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog fileDialog;

            fileDialog            = new Microsoft.Win32.SaveFileDialog();
            fileDialog.DefaultExt = "png";
            fileDialog.Filter     = "Png files(*.png)|*.png";
            fileDialog.Title      = "Select output png file";
            fileDialog.FileName   = "Plot3D.png";

            if (fileDialog.ShowDialog() ?? false)
            {
                BitmapSource plotImage = Camera1.RenderToBitmap(backgroundBrush: MainGrid.Background); // We are calling RenderToBitmap, but it is possible to specify many parameters - background brush, dpi, custom image size and antialiasing level

                if (plotImage != null)
                {
                    using (var fileStream = new System.IO.FileStream(fileDialog.FileName, System.IO.FileMode.Create))
                    {
                        BitmapEncoder encoder = new PngBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create(plotImage));
                        encoder.Save(fileStream);
                    }
                }
            }
        }
Exemple #7
0
        private void StartAnimation()
        {
            Camera1.StartRotation(20, 0); // animate 20 degrees in second
            AnimationButton.Content = "Stop camera animation";

            _isAnimationStarted = true;
        }
Exemple #8
0
        // Billboard effect orients the mesh so that it is always turned towards the camera
        private void ApplyBillboardMatrix()
        {
            Matrix3D view, proj;
            bool     isMatrixValid = Camera1.GetCameraMatrices(out view, out proj);

            if (!isMatrixValid)
            {
                return;
            }

            // To create a billboard effect, we invert the camera's view matrix and reset the offset components
            view.Invert();
            view.OffsetX = 0;
            view.OffsetY = 0;
            view.OffsetZ = 0;

            var matrixTransform3D = _shownLineModel3D.Transform as MatrixTransform3D;

            if (matrixTransform3D != null && !matrixTransform3D.IsFrozen)
            {
                matrixTransform3D.Matrix = view;
            }
            else
            {
                _shownLineModel3D.Transform = new MatrixTransform3D(view);
                MeshInspector.Transform     = _shownLineModel3D.Transform;
            }
        }
Exemple #9
0
        private void StartAnimation(AnimationNodeBase animationNode)
        {
            // First stop current animation and ...
            if (Camera1.AnimationController.IsAnimating)
            {
                Camera1.AnimationController.StopAnimation();
            }


            // NormalizeAngles normalizes the Heading, Attitude and Bank angles so that their values are between -180 and 180 (because normalizeTo180Degrees is true).
            // For example, this methods converts 390 value into 30. This prevent animating 390 to 40 instead of 30 to 40.
            Camera1.NormalizeAngles(normalizeTo180Degrees: true);


            // ... clear any existing AnimationNodes
            Camera1.AnimationController.AnimationNodes.Clear();

            // Set animation speed with setting FramesPerSecond.
            // Though this value does not have any effect on rendering, its default value is set to 60.
            // But with setting the FramesPerSecond to 100, it is easier to define the FrameNumber values for KeyFrames,
            // for example FrameNumber = 300 is at 3rd second; FrameNumber = 500 is at 5th second, etc.
            Camera1.AnimationController.FramesPerSecond = 100;

            Camera1.AnimationController.AutoRepeat        = false;
            Camera1.AnimationController.AutoReverse       = false;
            Camera1.AnimationController.AutoStopAnimation = true;


            // Add the CameraAnimationNode to animation controller
            Camera1.AnimationController.AnimationNodes.Add(animationNode);

            // And start the animation
            Camera1.AnimationController.StartAnimation();
        }
Exemple #10
0
        private void MeshTypeRadioButtonChanged(object sender, RoutedEventArgs e)
        {
            if (!this.IsLoaded)
            {
                return;
            }

            MainViewport.Children.Clear();

            // Because we have cleared all the MainViewport.Children
            // we have also removed the camera light object.
            // To add it back, we need to manually call Refresh method on the camera.
            Camera1.Refresh();


            // Reset timers
            _meshMorphTimes.Clear();
            _meshUpdateTimes.Clear();
            _dxEngineUpdateTimes.Clear();

            if (UseSimpleMeshRadioButton.IsChecked ?? false)
            {
                AddSimpleMesh();
                UseDynamicBufferCheckBox.IsEnabled = true;
            }
            else
            {
                AddMeshGeometry3D();
                UseDynamicBufferCheckBox.IsEnabled = false;
            }

            // Resert animation
            _animationStartTime = DateTime.Now;
        }
        private void RecreateControlPointNumbers()
        {
            if (_controlPoints == null)
            {
                return;
            }

            OverlayCanvas.Children.Clear();

            for (int i = 0; i < _controlPoints.Count; i++)
            {
                TextBlock textBlock = new TextBlock();
                textBlock.FontSize   = 10;
                textBlock.Foreground = Brushes.Red;
                textBlock.FontWeight = FontWeights.Bold;
                textBlock.Text       = i.ToString();

                // Calculate the 2D position of the 3D control point
                Point point2D = Camera1.Point3DTo2D(_controlPoints[i]);

                Canvas.SetLeft(textBlock, point2D.X + 10);
                Canvas.SetTop(textBlock, point2D.Y - 7);

                OverlayCanvas.Children.Add(textBlock);
            }
        }
        private void StopAnimation()
        {
            AnimationButton.Content = "Start camera rotation";
            Camera1.StopRotation();

            _isAnimationStarted = false;
        }
Exemple #13
0
        private void UpdateSelectedObjectsWithBoundsIn2D(Rect selectionRectangle)
        {
            // TODO: When there is many objects in the scene, then
            // when the selected is started we can convert the 3D bounds of all objects to 2D bounds.
            // Then in this method we would just call IntersectsWith without calling Rect3DTo2D.

            foreach (var model3D in _objectsModel3DGroup.Children)
            {
                var bounds = model3D.Bounds;

                // TODO: If parent Model3DGroup or parent Visual3D use any transformation,
                //       then we need to transform the bounds with that transformation.
                //       If the hierarchy of parents is not simple or not known, then you can use:
                //       Ab3d.Utilities.TransformationsHelper.GetModelTotalTransform() or GetVisual3DTotalTransform()

                // Convert 3D object bounds to 2D bounds on the screen
                var bounds2D = Camera1.Rect3DTo2D(bounds);

                // Check if our selection rectangle intersects with the 2D object bounds
                if (selectionRectangle.IntersectsWith(bounds2D))
                {
                    _selectedObjects.Add(model3D);
                }
            }
        }
Exemple #14
0
        private void OnCameraRotateStarted(object sender, EventArgs e)
        {
            var mousePosition = Mouse.GetPosition(ViewportBorder);

            Point3D rotatedPosition; // Hit position or position on horizontal plane

            var hitTestResult = VisualTreeHelper.HitTest(MainViewport, mousePosition) as RayMeshGeometry3DHitTestResult;

            if (hitTestResult != null)
            {
                rotatedPosition = hitTestResult.PointHit;
            }
            else
            {
                // Get intersection of ray created from mouse position and the horizontal plane (position: 0,0,0; normal: 0,1,0)
                bool hasIntersection = Camera1.GetMousePositionOnPlane(mousePosition, Constants.ZeroPoint3D, Constants.YAxis, out rotatedPosition);

                if (!hasIntersection)
                {
                    return;
                }
            }

            PositionCross.Position  = rotatedPosition;
            PositionCross.IsVisible = true;

            ShowCameraRotationHelpers();
        }
        void SphereVisual3DSample_Loaded(object sender, RoutedEventArgs e)
        {
            UpdateMaterial();
            UpdateTrianglesAndNormals();

            Camera1.Refresh(); // This will measure the models on the scene and reposition the scene camera
        }
 public void ChangeCamera3()
 {
     Camera2.SetActive(false);
     Camera3.SetActive(false);
     Camera4.SetActive(false);
     Camera1.SetActive(true);
 }
        private void LoadObjFile(string fileName)
        {
            var readerObj  = new Ab3d.ReaderObj();
            var wpf3DModel = readerObj.ReadModel3D(fileName);

            // To change all material to Gray use the following line:
            //Ab3d.Utilities.ModelUtils.ChangeMaterial(wpf3DModel, new DiffuseMaterial(Brushes.Gray), null);

            double readObjectSize = Math.Sqrt(wpf3DModel.Bounds.SizeX * wpf3DModel.Bounds.SizeX + wpf3DModel.Bounds.SizeY * wpf3DModel.Bounds.SizeY + wpf3DModel.Bounds.SizeZ + wpf3DModel.Bounds.SizeZ);
            var    objectsCenter  = new Point3D(wpf3DModel.Bounds.X + wpf3DModel.Bounds.SizeX / 2, wpf3DModel.Bounds.Y + wpf3DModel.Bounds.SizeY / 2, wpf3DModel.Bounds.Z + wpf3DModel.Bounds.SizeZ / 2);
            double scaleFactor    = 3.0 / readObjectSize; // Scale object to 3 meters


            var modelVisual3D = new ModelVisual3D();

            modelVisual3D.Content = wpf3DModel;

            var transform3DGroup = new Transform3DGroup();

            transform3DGroup.Children.Add(new TranslateTransform3D(-objectsCenter.X, -objectsCenter.Y, -objectsCenter.Z));
            transform3DGroup.Children.Add(new ScaleTransform3D(scaleFactor, scaleFactor, scaleFactor));
            modelVisual3D.Transform = transform3DGroup;


            MainViewport.Children.Clear();
            MainViewport.Children.Add(modelVisual3D);

            // Refresh the camea because with cleating all the objects, we have also removed the camera light.
            // Calling Refresh will recreate the light
            Camera1.Refresh();
        }
Exemple #18
0
        public override void InitCalib()
        {
            Camera1.Disconnect();
            Camera1.Connect();

            Platform.MoveAbs("Wait");
        }
        private void StartButton_OnClick(object sender, RoutedEventArgs e)
        {
            StartButton.IsEnabled = false;

            Camera1.RotateTo(20, -30, 500, Ab3d.Animation.EasingFunctions.CubicEaseInOutFunction);
            Camera1.AnimationController.AnimationCompleted += OnStartupAnimationCompleted;
        }
Exemple #20
0
        private void ShowModelScalar()
        {
            HideModelMover();
            HideModelRotator();

            if (_selectedVisual3D == null || _standardTransform3D == null)
            {
                return;
            }


            EnsureModelScalar();

            _modelScalar.Position = _standardTransform3D.GetTranslateVector3D().ToPoint3D();

            // If the 3D scene would not be shown yet, we would need to refresh the camera
            //Camera1.Refresh();

            // We need to set the size of the model mover's axes to an appropriate size so that it will look big enough
            // regardless of how far away the selected model is.
            // This can be done with calculating how big a 80 x 80 rectangle (in screen coordinates) would be in 3D space at the specified distance:
            double lookDirectionDistance = (_modelScalar.Position - Camera1.GetCameraPosition()).Length;
            var    worldSize             = Ab3d.Utilities.CameraUtils.GetPerspectiveWorldSize(new Size(80, 80), lookDirectionDistance, Camera1.FieldOfView, new Size(MainViewport.ActualWidth, MainViewport.ActualHeight));


            _modelScalar.AxisLength     = (worldSize.Width + worldSize.Height) / 2; // average the width and height
            _modelScalar.InnerBoxWidth  = _modelScalar.AxisLength * 0.06;
            _modelScalar.OuterBoxWidth  = _modelScalar.InnerBoxWidth * 3;
            _modelScalar.CenterBoxWidth = _modelScalar.InnerBoxWidth * 5;

            if (!OverlayViewport.Children.Contains(_modelScalar))
            {
                OverlayViewport.Children.Add(_modelScalar);
            }
        }
Exemple #21
0
        private void StartAnimation(AnimationNodeBase animationNode)
        {
            // First stop current animation and ...
            if (_animationController.IsAnimating)
            {
                _animationController.StopAnimation();
            }


            // NormalizeAngles normalizes the Heading, Attitude and Bank angles so that their values are between -180 and 180 (because normalizeTo180Degrees is true).
            // For example, this methods converts 390 value into 30. This prevent animating 390 to 40 instead of 30 to 40.
            Camera1.NormalizeAngles(normalizeTo180Degrees: true);


            // ... clear any existing AnimationNodes
            _animationController.AnimationNodes.Clear();


            // Add the CameraAnimationNode to animation controller
            _animationController.AnimationNodes.Add(animationNode);

            // And start the animation
            _animationController.StartAnimation();


            // We can get details about the animation with calling GetDumpString method on AnimationController or any other animation related class.
            // It is also possible to call Dump method in the Visual Studio immediate method. This will dump the details to the same window.
            DumpTextBox.Text = _animationController.GetDumpString();
        }
        private void ChangeCameraButton_OnClick(object sender, RoutedEventArgs e)
        {
            _cameraIndex++;

            switch (_cameraIndex)
            {
            case 1:
                Camera1.BeginInit();
                Camera1.Heading        = 47;
                Camera1.Attitude       = -8.6;
                Camera1.Distance       = 1200;
                Camera1.TargetPosition = new Point3D(0, 60, 0);
                Camera1.Offset         = new Vector3D(-46, -227, 66);
                Camera1.EndInit();
                break;

            case 2:
                Camera1.BeginInit();
                Camera1.Heading        = -1.4;
                Camera1.Attitude       = -4;
                Camera1.Distance       = 1776;
                Camera1.TargetPosition = new Point3D(0, 60, 0);
                Camera1.Offset         = new Vector3D(-16, -109, 37);
                Camera1.EndInit();
                break;

            case 3:
                Camera1.BeginInit();
                Camera1.Heading        = 0;
                Camera1.Attitude       = -31;
                Camera1.Distance       = 1325;
                Camera1.TargetPosition = new Point3D(0, 60, 0);
                Camera1.Offset         = new Vector3D(10, -134, -130);
                Camera1.EndInit();
                break;

            case 4:
                Camera1.BeginInit();
                Camera1.Heading        = -0.57;
                Camera1.Attitude       = -89;
                Camera1.Distance       = 4275;
                Camera1.TargetPosition = new Point3D(0, 60, 0);
                Camera1.Offset         = new Vector3D(-16, -109, 37);
                Camera1.EndInit();
                break;

            default:
                Camera1.BeginInit();
                Camera1.Heading        = 30;
                Camera1.Attitude       = -20;
                Camera1.Distance       = 2500;
                Camera1.TargetPosition = new Point3D(0, 60, 0);
                Camera1.Offset         = new Vector3D(0, 0, 0);
                Camera1.EndInit();

                _cameraIndex = 0;
                break;
            }
        }
Exemple #23
0
        private void AnimateCameraRotationTo(double targetHeading, double targetAttitude, bool useShortestPath = true)
        {
            Camera1.RotateTo(targetHeading,
                             targetAttitude,
                             animationDurationInMilliseconds: 1000,
                             easingFunction: Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction,
                             useShortestPath: true);

            DumpTextBox.Text = string.Format("Camera1.RotateTo({0}, {1}, 1000, Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction, useShortestPath: true);\r\n\r\n", targetHeading, targetAttitude);

            // We can get details about the animation with calling GetDumpString method on AnimationController or any other animation related class.
            // It is also possible to call Dump method in the Visual Studio immediate method. This will dump the details to the same window.
            DumpTextBox.Text += Camera1.AnimationController.GetDumpString();


            // The following commented code shows how to start animation manually without RotateTo method:

            /*
             * double startHeading  = Camera1.Heading;
             * double startAttitude = Camera1.Attitude;
             *
             * if (double.IsNaN(targetHeading))
             *  targetHeading = startHeading;
             *
             * if (double.IsNaN(targetAttitude))
             *  targetAttitude = startAttitude;
             *
             *
             * // Adjust start heading and attitude so that we will come with the shortest path to the target heading and attitude
             * if (useShortestPath)
             * {
             *  startHeading  = Ab3d.Utilities.CameraUtils.GetClosestPathStartAngle(startHeading,  targetHeading);
             *  startAttitude = Ab3d.Utilities.CameraUtils.GetClosestPathStartAngle(startAttitude, targetAttitude);
             * }
             *
             *
             * // Create a new CameraAnimationNode that will animate the Camera1
             * var cameraAnimationNode = new CameraAnimationNode(Camera1);
             *
             * // Start with current camera Heading and Attitude
             * cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(0, startHeading, startAttitude));
             *
             * // Animate to the specified heading and attitude in 100 frames
             * cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(100, targetHeading, targetAttitude));
             *
             *
             * // It is possible to set different interpolation mode to each KeyFrame, but it is easier
             * // to set the same interpolation mode to all key frames with SetInterpolationToAllKeys method.
             * cameraAnimationNode.RotationTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);
             *
             *
             * // Set this animation as one-time only
             * _animationController.AutoRepeat = false;
             * _animationController.AutoReverse = false;
             *
             * // Use StartAnimation helper method to stop current animation and start the animation defined in cameraAnimationNode
             * StartAnimation(cameraAnimationNode);
             */
        }
        public AdjustingTextDirectionSample()
        {
            InitializeComponent();

            Camera1.StartRotation(45, 0);

            Camera1.CameraChanged += Camera1OnCameraChanged;
        }
        private void CreateArrows()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            try
            {
                Mouse.OverrideCursor = Cursors.Hand;

                MainViewport.Children.Clear();


                var selectedArrowsNumber = GetSelectedArrowsNumber();

                _xCount = selectedArrowsNumber;
                _yCount = selectedArrowsNumber;


                var sphereVisual3D = new SphereVisual3D()
                {
                    CenterPosition = new Point3D(0, 0, 0),
                    Radius         = 10,
                    Material       = new DiffuseMaterial(Brushes.Gold)
                };

                _sphereTranslate         = new TranslateTransform3D(_sphereStartPosition.ToWpfVector3D());
                sphereVisual3D.Transform = _sphereTranslate;


                MainViewport.Children.Add(sphereVisual3D);



                _instanceData = new InstanceData[_xCount * _yCount];
                UpdateInstanceData();

                var arrowMesh3D = new Ab3d.Meshes.ArrowMesh3D(new Point3D(0, 0, 0), new Point3D(1, 0, 0), 1.0 / 15.0, 2.0 / 15.0, 45, 10, false).Geometry;

                _instancedMeshGeometryVisual3D = new InstancedMeshGeometryVisual3D(arrowMesh3D);
                _instancedMeshGeometryVisual3D.InstancesData = _instanceData;

                MainViewport.Children.Add(_instancedMeshGeometryVisual3D);


                Camera1.Refresh(); // This will regenerate camera light if it was removed with MainViewport.Children.Clear()

                TotalTextBlock.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                    "Total positions: {0:#,###}; total triangles: {1:#,###}",
                                                    _xCount * _yCount * _instancedMeshGeometryVisual3D.MeshGeometry3D.Positions.Count,
                                                    _xCount * _yCount * _instancedMeshGeometryVisual3D.MeshGeometry3D.TriangleIndices.Count / 3);
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
Exemple #26
0
        private void RotateToSideButton_OnClick(object sender, RoutedEventArgs e)
        {
            Camera1.RotateTo(targetHeading: 30,
                             targetAttitude: -20,
                             animationDurationInMilliseconds: 800,
                             easingFunction: Ab3d.Animation.EasingFunctions.CubicEaseInOutFunction);

            // See Animations/CameraAnimation for advanced camera animation samples.
        }
        private void UpdateLights()
        {
            TopDirectionalLight.Color   = (TopLightCheckBox.IsChecked ?? false) ? Colors.White : Colors.Black; // Setting light color to black is equal as removing it from the scene
            FrontDirectionalLight.Color = (FrontLightCheckBox.IsChecked ?? false) ? Colors.White : Colors.Black;
            AmbientLight1.Color         = (AmbientLightCheckBox.IsChecked ?? false) ? Colors.White : Colors.Black;

            Camera1.ShowCameraLight = (CameraLightCheckBox.IsChecked ?? false) ? ShowCameraLightType.Always : ShowCameraLightType.Never;
            Camera1.Refresh();
        }
        private void UpdateLights()
        {
            TopDirectionalLight.Color   = (TopLightCheckBox.IsChecked ?? false) ? Colors.White : Colors.Black; // Setting light color to black is equal as removing it from the scene
            FrontDirectionalLight.Color = (FrontLightCheckBox.IsChecked ?? false) ? Colors.White : Colors.Black;
            //AmbientLight1.Color = (AmbientLightCheckBox.IsChecked ?? false) ? System.Windows.Media.Color.FromRgb(85, 85, 85) : Colors.Black; // 0x55 = 85
            AmbientLight1.Color = (AmbientLightCheckBox.IsChecked ?? false) ? System.Windows.Media.Color.FromRgb(255, 255, 255) : Colors.Black; // 0x55 = 85

            Camera1.ShowCameraLight = (CameraLightCheckBox.IsChecked ?? false) ? ShowCameraLightType.Always : ShowCameraLightType.Never;
            Camera1.Refresh();
        }
Exemple #29
0
        private void IncreaseHeadingButton_OnClick(object sender, RoutedEventArgs e)
        {
            // Instead of RotateTo was can also use RotateFor method:
            Camera1.RotateFor(changedHeading: 90,
                              changedAttitude: 0,
                              animationDurationInMilliseconds: 800,
                              easingFunction: Ab3d.Animation.EasingFunctions.CubicEaseInOutFunction);

            // See Animations/CameraAnimation for advanced camera animation samples.
        }
        private void StartAnimation()
        {
            AnimationButton.Content = "Stop camera rotation";

            // start rotating the camera with changing heading by 30 degrees per second.
            // Note that while the camera is rotating, it is still possible to rotate the camera with the mouse (during mouse rotation the animation is suspended).
            Camera1.StartRotation(30, 0);

            _isAnimationStarted = true;
        }