private void LoadObjFile()
        {
            // Use ObjModelVisual3D to load robotarm.obj and then set objModelVisual3D.Content (as Model3D) to WireframeVisual
            _objModelVisual3D = new ObjModelVisual3D()
            {
                Source       = new Uri("pack://application:,,,/Ab3d.PowerToys.Samples;component/Resources/ObjFiles/robotarm.obj", UriKind.Absolute),
                SizeX        = 50,
                Position     = new Point3D(0, 0, 0),
                PositionType = ObjModelVisual3D.VisualPositionType.BottomCenter
            };

            _loadedModel3D = _objModelVisual3D.Content;
            ShowModel(_loadedModel3D);

            // We could also use Ab3d.ReaderObj, but this does not give us option to specify object size and position
        }
        private void UpdateScene()
        {
            _originalModelVisual3D = null;
            _originalModel3D       = null;
            _originalMesh3D        = null;
            _model3DFor2DSlice     = null;

            RootModelVisual3D.Children.Clear();

            WireframeModels1.OriginalModel = null;
            WireframeModels2.OriginalModel = null;


            if (Model1RadioButton.IsChecked ?? false)
            {
                // Use ObjModelVisual3D to load robotarm.obj and then read its Content to get Model3D
                var objModelVisual3D = new ObjModelVisual3D()
                {
                    Source       = new Uri("pack://application:,,,/Ab3d.PowerToys.Samples;component/Resources/ObjFiles/robotarm.obj", UriKind.Absolute),
                    SizeX        = 100,
                    Position     = new Point3D(0, 0, 0),
                    PositionType = ObjModelVisual3D.VisualPositionType.BottomCenter
                };

                _originalModel3D = objModelVisual3D.Content;
                _modelBounds     = _originalModel3D.Bounds;
            }
            else if (Model2RadioButton.IsChecked ?? false)
            {
                _originalMesh3D = new Ab3d.Meshes.SphereMesh3D(new Point3D(0, 0, 0), 50, 20).Geometry;
                _modelBounds    = _originalMesh3D.Bounds;
            }
            else if (Model3RadioButton.IsChecked ?? false)
            {
                _originalModelVisual3D = new ModelVisual3D();

                _originalModelVisual3D.Children.Add(new Ab3d.Visuals.PyramidVisual3D()
                {
                    BottomCenterPosition = new Point3D(-280, -60, 0), Size = new Size3D(120, 120, 120), Material = new DiffuseMaterial(Brushes.Green)
                });
                _originalModelVisual3D.Children.Add(new Ab3d.Visuals.BoxVisual3D()
                {
                    CenterPosition = new Point3D(-100, 0, 0), Size = new Size3D(120, 120, 60), Material = new DiffuseMaterial(Brushes.Green)
                });
                _originalModelVisual3D.Children.Add(new Ab3d.Visuals.TubeVisual3D()
                {
                    BottomCenterPosition = new Point3D(80, -60, 0), InnerRadius = 40, OuterRadius = 60, Height = 120, Material = new DiffuseMaterial(Brushes.Green)
                });
                _originalModelVisual3D.Children.Add(new Ab3d.Visuals.SphereVisual3D()
                {
                    CenterPosition = new Point3D(240, 0, 0), Radius = 60, Material = new DiffuseMaterial(Brushes.Green)
                });

                _modelBounds = new Rect3D();
                foreach (var visual3D in _originalModelVisual3D.Children.OfType <ModelVisual3D>())
                {
                    _modelBounds.Union(visual3D.Content.Bounds);
                }
            }

            _rootModelSize   = Math.Sqrt(_modelBounds.SizeX * _modelBounds.SizeX + _modelBounds.SizeY * _modelBounds.SizeY + _modelBounds.SizeZ * _modelBounds.SizeZ);
            Camera1.Distance = 2 * _rootModelSize;
        }
        private void CreateScene()
        {
            // Create material with 10 x 10 numbers grid
            var imageBrush = new ImageBrush(new BitmapImage(new Uri(@"pack://application:,,,/Resources/10x10-texture.png")));

            var material = new DiffuseMaterial(imageBrush);
            //var material = new DiffuseMaterial(Brushes.Silver);


            // Create box with 10 x 10 x 10 cells
            var boxVisual3D = new BoxVisual3D()
            {
                UseCachedMeshGeometry3D = false, // This will generate a new MeshGeometry3D for this BoxVisual3D,
                FreezeMeshGeometry3D    = false, // This will allow us to change the TextureCoordinates
                CenterPosition          = new Point3D(-150, 0, -50),
                Size        = new Size3D(60, 60, 60),
                XCellsCount = 10,
                YCellsCount = 10,
                ZCellsCount = 10,
                Material    = material,
            };

            MainViewport.Children.Add(boxVisual3D);


            var cylinderVisual3D = new CylinderVisual3D()
            {
                BottomCenterPosition = new Point3D(-50, -30, -50),
                Radius   = 30,
                Height   = 60,
                Segments = 10,
                IsSmooth = false,
                Material = material
            };

            MainViewport.Children.Add(cylinderVisual3D);


            var sphereVisual3D = new SphereVisual3D()
            {
                UseCachedMeshGeometry3D = false, // This will generate a new MeshGeometry3D for this BoxVisual3D,
                FreezeMeshGeometry3D    = false, // This will allow us to change the TextureCoordinates
                CenterPosition          = new Point3D(50, 0, -50),
                Radius   = 30,
                Material = material
            };

            MainViewport.Children.Add(sphereVisual3D);


            // Add dragon model
            string fileName         = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\ObjFiles\\dragon_vrip_res3.obj");
            var    objModelVisual3D = new ObjModelVisual3D()
            {
                Source          = new Uri(fileName, UriKind.Absolute),
                SizeX           = 70,
                Position        = new Point3D(-150, 0, 100),
                PositionType    = ObjModelVisual3D.VisualPositionType.Center,
                DefaultMaterial = material,
            };

            Ab3d.Utilities.ModelUtils.ChangeMaterial(objModelVisual3D.Content, material, newBackMaterial: null);

            MainViewport.Children.Add(objModelVisual3D);


            // Add simple extruded shape
            var extrudePositions = new Point[]
            {
                new Point(-1, 54),
                new Point(13, 35),
                new Point(8, 32),
                new Point(18, 13),
                new Point(11, 9),
                new Point(23, -13),
                new Point(6, -14),
                new Point(6, -29),
                new Point(-8, -30),
                new Point(-7, -13),
                new Point(-25, -9),
                new Point(-12, 9),
                new Point(-25, 16),
                new Point(-8, 31),
                new Point(-16, 38)
            };

            var extrudedMesh = Mesh3DFactory.CreateExtrudedMeshGeometry(positions: extrudePositions.ToList(),
                                                                        isSmooth: false,
                                                                        modelOffset: new Vector3D(-50, -15, 100),
                                                                        extrudeVector: new Vector3D(0, 30, 0),
                                                                        shapeYVector: new Vector3D(0, 0, -1),
                                                                        textureCoordinatesGenerationType: ExtrudeTextureCoordinatesGenerationType.AddAdditionalPositions);

            var geometryModel3D = new GeometryModel3D(extrudedMesh, material);

            var modelVisual3D = new ModelVisual3D();

            modelVisual3D.Content = geometryModel3D;

            MainViewport.Children.Add(modelVisual3D);
        }