private void AddPlaneVisual3D(Point3D centerPosition, System.Windows.Media.Media3D.Material material, Size planeSize, bool isBillboard)
        {
            PlaneVisual3D planeVisual3D;

            if (isBillboard)
            {
                planeVisual3D = new BillboardVisual3D(); // BillboardVisual3D is defined in this sample and is the same as PlaneVisual3D but when BillboardVisual3D is there, we know that it needs to be aligned with the camera on each camera change
            }
            else
            {
                planeVisual3D = new PlaneVisual3D();
            }

            planeVisual3D.CenterPosition  = centerPosition;
            planeVisual3D.Size            = planeSize;
            planeVisual3D.Normal          = new Vector3D(0, 0, 1);
            planeVisual3D.HeightDirection = new Vector3D(0, 1, 0);
            planeVisual3D.Material        = material;

            if (!isBillboard)
            {
                planeVisual3D.BackMaterial = material;
            }

            SemiTransparentRootVisual3D.Children.Add(planeVisual3D);
        }
Example #2
0
        public MainWindow()
        {
            InitializeComponent();

            model = new ModelVisual3D();

            const int    rows     = 5;
            const int    columns  = 4;
            const double distance = 120;

            var turbine = new WindTurbine();
            var r       = new Random();

            for (int i = 0; i < rows; i++)
            {
                double y = i * distance;
                for (int j = 0; j + (i % 2) * 0.5 <= columns - 1; j++)
                {
                    double x      = (j + (i % 2) * 0.5) * distance;
                    var    visual = new WindTurbineVisual3D
                    {
                        RotationAngle = r.Next(360),
                        RotationSpeed = 20,
                        WindTurbine   = turbine,
                        Transform     = new TranslateTransform3D(x, y, 0)
                    };
                    model.Children.Add(visual);
                }
            }


            var seasurface = new PlaneVisual3D
            {
                DivWidth  = 100,
                DivLength = 100,
                Origin    = new Point3D((rows - 2) * distance * 0.5, (columns) * distance * 0.5, 0),
                Width     = rows * distance * 2,
                Length    = columns * distance * 2
            };

            seasurface.Material = seasurface.BackMaterial = MaterialHelper.CreateMaterial(Colors.SeaGreen, 0.8);

            model.Children.Add(new GridLinesVisual3D()
            {
                Center = seasurface.Origin, Fill = Brushes.Gray, Width = seasurface.Width, Length = seasurface.Length
            });

            model.Children.Add(seasurface);
            view1.Children.Add(model);

            Loaded += MainWindowLoaded;
            Closed += MainWindowClosed;
        }
        private void OnShowShadowCheckBoxCheckedChanged(object sender, RoutedEventArgs e)
        {
            if (_planarShadowRenderingProvider == null)
            {
                return;
            }

            if (ShowShadowCheckBox.IsChecked ?? false)
            {
                if (_planeVisual3D != null)
                {
                    MainViewport.Children.Remove(_planeVisual3D);
                    _planeVisual3D = null;
                }

                if (MainDXViewportView.DXScene.ShadowRenderingProvider == null)
                {
                    MainDXViewportView.DXScene.InitializeShadowRendering(_planarShadowRenderingProvider);
                }
            }
            else
            {
                if (MainDXViewportView.DXScene.ShadowRenderingProvider != null)
                {
                    MainDXViewportView.DXScene.InitializeShadowRendering(null);
                }

                // Because we are rendering the plane with ShadowRenderingProvider,
                // we need to add a new plane to the scene after disabling the ShadowRenderingProvider.
                //
                // NOTE:
                // If we would always have a PlaneVisual3D on the scene, then it would also generate a shadow.
                // To prevent casting a shadow, we could change the rendering queue of the plane.
                // This way it would not be rendered as standard object, but would be rendered specially.
                // For example:
                //_planeVisual3D.SetDXAttribute(DXAttributeType.CustomRenderingQueue, _planarShadowRenderingProvider.ShadowPlaneRenderingQueue);

                _planeVisual3D = new PlaneVisual3D()
                {
                    Size     = new Size(400, 400),
                    Material = new DiffuseMaterial(new ImageBrush(new BitmapImage(new Uri(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources/10x10-texture.png")))))
                };

                MainViewport.Children.Add(_planeVisual3D);
            }
        }
Example #4
0
        private void CreateTestScene()
        {
            MainViewport.Children.Clear();

            string fileName = AppDomain.CurrentDomain.BaseDirectory + @"Resources\ObjFiles\house with trees.obj";

            var readerObj    = new Ab3d.ReaderObj();
            var sceneModel3D = readerObj.ReadModel3D(fileName);

            LogMessage("Loaded:\r\n" + Ab3d.Utilities.Dumper.GetObjectHierarchyString(sceneModel3D));

            Ab3d.Utilities.ModelUtils.CenterAndScaleModel3D(sceneModel3D,
                                                            centerPosition: new Point3D(0, 0, 0),
                                                            finalSize: new Size3D(100, 100, 100),
                                                            preserveAspectRatio: true);

            _sceneVisual3D         = new ModelVisual3D();
            _sceneVisual3D.Content = sceneModel3D;
            _sceneVisual3D.SetName("SceneVisual3D"); // Set Name dependency properties so that we can read then when getting hit test result

            MainViewport.Children.Add(_sceneVisual3D);


            _glassPlaneVisual3D = new Ab3d.Visuals.PlaneVisual3D()
            {
                CenterPosition  = new Point3D(0, 0, 45),
                Size            = new Size(70, 10),
                Normal          = new Vector3D(0, 0, 1),
                HeightDirection = new Vector3D(0, 1, 0),
                Material        = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(100, 200, 200, 255)))
            };

            _glassPlaneVisual3D.BackMaterial = _glassPlaneVisual3D.Material;
            _glassPlaneVisual3D.SetName("GlassPlaneVisual3D");

            MainViewport.Children.Add(_glassPlaneVisual3D);


            Camera1.Refresh(); // This will recreate camera's light that was removed when we called MainViewport.Children.Clear()
        }
        private void CreateTestSemiTransparentObjects()
        {
            if (_disposables != null)
            {
                _disposables.Dispose();
            }

            _disposables = new DisposeList();

            SemiTransparentRootVisual3D.Children.Clear();

            string texturesFolder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\");

            AddSmallForest(new Point3D(0, 20, -100), texturesFolder + @"AlphaTextures\tree0.dds");

            AddSmallForest(new Point3D(-100, 20, -100), texturesFolder + "TreeTexture.png");


            var wireFenceMaterial = CreateDiffuseMaterial(texturesFolder + @"AlphaTextures\WireFence.dds");

            SetMaterialsDXAttributes(wireFenceMaterial);

            var boxVisual3D = new BoxVisual3D()
            {
                CenterPosition = new Point3D(100, 20, -100),
                Size           = new Size3D(40, 40, 40),
                Material       = wireFenceMaterial,
                BackMaterial   = wireFenceMaterial
            };

            SemiTransparentRootVisual3D.Children.Add(boxVisual3D);


            AddPlaneGroup(new Point3D(0, 30, 70), new Vector3D(0, 0, 20), 5, texturesFolder + "SemiTransparentFrame.png");


            var textBlockVisual1 = new TextBlockVisual3D()
            {
                Text             = "ABCDE\r\nFGHIJ",
                Position         = new Point3D(-100, 20, 0),
                PositionType     = PositionTypes.Bottom,
                Size             = new Size(60, 40),
                Background       = Brushes.Transparent,
                RenderBitmapSize = new Size(256, 128),
                TextPadding      = new Thickness(5, 0, 5, 0),
                BorderBrush      = Brushes.Yellow,
                BorderThickness  = new Thickness(0, 2, 0, 2)
            };

            SetMaterialsDXAttributes(textBlockVisual1.Material);
            SetMaterialsDXAttributes(textBlockVisual1.BackMaterial);

            SemiTransparentRootVisual3D.Children.Add(textBlockVisual1);



            var textBlockVisual2 = new TextBlockVisual3D()
            {
                Text             = "12345\r\n67890",
                Position         = new Point3D(100, 20, 0),
                PositionType     = PositionTypes.Bottom,
                Size             = new Size(60, 40),
                Background       = Brushes.Transparent,
                RenderBitmapSize = new Size(256, 128),
                TextPadding      = new Thickness(5, 0, 5, 0),
                BorderBrush      = Brushes.Yellow,
                BorderThickness  = new Thickness(0, 2, 0, 2)
            };

            SetMaterialsDXAttributes(textBlockVisual2.Material);
            SetMaterialsDXAttributes(textBlockVisual2.BackMaterial);


            SemiTransparentRootVisual3D.Children.Add(textBlockVisual2);


            var gradientBrush    = new RadialGradientBrush(Colors.White, Color.FromArgb(0, 255, 255, 255)); // Gradient from White to fully transparent
            var gradientMaterial = new DiffuseMaterial(gradientBrush);

            SetMaterialsDXAttributes(gradientMaterial);

            var planeVisual3D = new PlaneVisual3D()
            {
                CenterPosition  = new Point3D(0, 60, 0),
                Size            = new Size(80, 80),
                Normal          = new Vector3D(0, 0, 1),
                HeightDirection = new Vector3D(0, 1, 0),
                Material        = gradientMaterial,
                BackMaterial    = gradientMaterial
            };

            SemiTransparentRootVisual3D.Children.Add(planeVisual3D);

            AlignBillboards();


            _originalObjects = SemiTransparentRootVisual3D.Children.ToList();

            // if there was a saved objects order because of previous sorting or randomizing, we apply that same objects order now
            ApplySavedObjectsOrder();
        }