public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if ((values != null) &&
                (values.Length == 3) &&
                (values[0] is EffectsManager effectManager) &&
                (values[1] is WColor startColor) &&
                (values[2] is WColor stopColor))
            {
                var c1     = new SXColor(startColor.R, startColor.G, startColor.B, startColor.A);
                var c2     = new SXColor(stopColor.R, stopColor.G, stopColor.B, stopColor.A);
                var stream = BitmapExtensions.CreateLinearGradientBitmapStream(effectManager,
                                                                               128,
                                                                               128,
                                                                               Direct2DImageFormat.Bmp,
                                                                               new Vector2(0, 0),
                                                                               new Vector2(0, 128),
                                                                               new SharpDX.Direct2D1.GradientStop[]
                {
                    new SharpDX.Direct2D1.GradientStop()
                    {
                        Color = c1, Position = 0f
                    },
                    new SharpDX.Direct2D1.GradientStop()
                    {
                        Color = c2, Position = 1f
                    }
                });

                return(new TextureModel(stream));
            }
            else
            {
                throw new ArgumentException();
            }
        }
Ejemplo n.º 2
0
        public MainViewModel()
        {
            EffectsManager = new DefaultEffectsManager();
            // titles
            Title    = "Simple Demo";
            SubTitle = "WPF & SharpDX";

            // camera setup
            Camera = new PerspectiveCamera {
                Position         = new Point3D(3, 3, 5),
                LookDirection    = new Vector3D(-3, -3, -5),
                UpDirection      = new Vector3D(0, 1, 0),
                FarPlaneDistance = 5000000
            };

            // setup lighting
            AmbientLightColor         = Colors.DimGray;
            DirectionalLightColor     = Colors.White;
            DirectionalLightDirection = new Vector3D(-2, -5, -2);

            // floor plane grid
            Grid          = LineBuilder.GenerateGrid(new Vector3(0, 1, 0), -5, 5, -5, 5);
            GridColor     = Colors.Black;
            GridTransform = new Media3D.TranslateTransform3D(0, -3, 0);

            // scene model3d
            var b1 = new MeshBuilder();

            b1.AddSphere(new Vector3(0, 0, 0), 0.5);
            b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All);

            var meshGeometry = b1.ToMeshGeometry3D();

            meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4()));
            Model = meshGeometry;

            // lines model3d
            var e1 = new LineBuilder();

            e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2);
            Lines = e1.ToLineGeometry3D();

            var textBuilder = new MeshBuilder();

            textBuilder.ExtrudeText("HelixToolkit.SharpDX", "Arial", System.Windows.FontStyles.Normal, System.Windows.FontWeights.Bold,
                                    14, new Vector3(1, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 1));
            TextModel = textBuilder.ToMesh();

            // model trafos
            Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0);
            Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0);
            Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0);
            Model4Transform = new Media3D.TranslateTransform3D(-8, 0, -5);

            // model materials
            RedMaterial   = PhongMaterials.Red;
            GreenMaterial = PhongMaterials.Green;
            BlueMaterial  = PhongMaterials.Blue;
            //var diffColor = this.RedMaterial.DiffuseColor;
            //diffColor.Alpha = 0.5f;
            //this.RedMaterial.DiffuseColor = diffColor;

            Points = new PointGeometry3D();
            var ptPos = new Vector3Collection();
            var ptIdx = new IntCollection();

            for (int x = 0; x < 10; x++)
            {
                for (int y = 0; y < 10; y++)
                {
                    for (int z = 0; z < 10; z++)
                    {
                        ptIdx.Add(ptPos.Count);
                        ptPos.Add(new Vector3(x, y, z));
                    }
                }
            }

            Points.Positions = ptPos;
            Points.Indices   = ptIdx;

            Text = new BillboardText3D();
            int numRows    = 11;
            int numColumns = 11;

            string[] texts = new string[]
            {
                "HelixToolkit",
                "abcde",
                "random",
                "SharpDX",
                "DirectX"
            };
            float angle = 0;

            for (var i = 0; i < numRows; i++)
            {
                for (var j = 0; j < numColumns; j++)
                {
                    angle += (float)Math.PI / 10;
                    Text.TextInfo.Add(new TextInfo(texts[(i + j) % texts.Length], new Vector3((i - numRows / 2), 0.0f, (j - numColumns / 2)))
                    {
                        Foreground = new Color4((float)i / numRows, 1 - (float)i / numRows, (float)(numColumns - j) / numColumns, 1f),
                        Background = new Color4(1 - (float)i / numRows, (float)(numColumns - j) / numColumns, (float)i / numRows, 0.8f),
                        Scale      = Math.Max(0.01f, (float)i / numRows * 0.02f),
                        Angle      = angle
                    });
                }
            }

            Billboard1Model = new BillboardSingleText3D()
            {
                TextInfo = new TextInfo("Model 1", new Vector3(0, 1, 0))
                {
                    Angle = 0
                },
                FontColor       = Colors.Blue.ToColor4(),
                FontSize        = 12,
                BackgroundColor = Colors.Plum.ToColor4(),
                FontStyle       = System.Windows.FontStyles.Italic,
                Padding         = new System.Windows.Thickness(2),
            };

            var background = Colors.Blue;

            background.A    = (byte)120;
            Billboard2Model = new BillboardSingleText3D()
            {
                TextInfo = new TextInfo("Model 2", new Vector3(2, 1, 0))
                {
                    Angle = -(float)Math.PI / 3
                },
                FontSize        = 12,
                FontColor       = Colors.Green.ToColor4(),
                BackgroundColor = background.ToColor4(),
                FontWeight      = System.Windows.FontWeights.Bold,
                Padding         = new System.Windows.Thickness(2),
            };
            background      = Colors.Purple;
            background.A    = (byte)50;
            Billboard3Model = new BillboardSingleText3D(2, 0.8f)
            {
                TextInfo = new TextInfo("Model 3", new Vector3(-2, 1, 0))
                {
                    Angle = -(float)Math.PI / 6
                },
                FontSize        = 12,
                FontColor       = Colors.Red.ToColor4(),
                BackgroundColor = background.ToColor4(),
                FontFamily      = "Times New Roman",
                FontStyle       = System.Windows.FontStyles.Italic,
                Padding         = new System.Windows.Thickness(2),
            };


            //BillboardImageModel = new BillboardSingleImage3D(CreateBitmapSample()) { MaskColor = Color.Black };
            BillboardImageModel = new BillboardSingleImage3D(CreatePNGSample(), 1, 1)
            {
                Angle = -(float)Math.PI / 5
            };
            BillboardImageModel.Center = new Vector3(2, 2, 0);

            UpXCommand        = new RelayCommand(x => { UpDirection = new Vector3D(1, 0, 0); });
            UpYCommand        = new RelayCommand(x => { UpDirection = new Vector3D(0, 1, 0); });
            UpZCommand        = new RelayCommand(x => { UpDirection = new Vector3D(0, 0, 1); });
            BackgroundTexture =
                BitmapExtensions.CreateLinearGradientBitmapStream(EffectsManager, 128, 128, Direct2DImageFormat.Bmp,
                                                                  new Vector2(0, 0), new Vector2(0, 128), new SharpDX.Direct2D1.GradientStop[]
            {
                new SharpDX.Direct2D1.GradientStop()
                {
                    Color = Colors.White.ToColor4(), Position = 0f
                },
                new SharpDX.Direct2D1.GradientStop()
                {
                    Color = Colors.DarkGray.ToColor4(), Position = 1f
                }
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real"
            ////}
            //GenerateFibonacciSphereCommand = new RelayCommand(() => CreateFibonacciSphereMesh(),() => true,true);
            EffectsManager = new DefaultEffectsManager();
            // titles
            // camera setup
            Camera = new PerspectiveCamera {
                Position         = new Point3D(3, 3, 5),
                LookDirection    = new Vector3D(-3, -3, -5),
                UpDirection      = new Vector3D(0, 1, 0),
                FarPlaneDistance = 5000000
            };

            // setup lighting
            AmbientLightColor         = Color.White;
            DirectionalLightColor     = Color.White;
            DirectionalLightDirection = new Vector3D(-2, -5, -2);

            //// scene model3d
            //var b1 = new MeshBuilder();
            //b1.AddSphere(new Vector3(0, 0, 0), 0.5);
            //b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All);

            //var meshGeometry = b1.ToMeshGeometry3D();
            //meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4()));
            //Model = meshGeometry;

            //// lines model3d
            var e1 = new LineBuilder();

            e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2);

            VertexColorMaterial = new VertColorMaterial();
            RedMaterial         = PhongMaterials.BlackPlastic;

            //var diffColor = this.RedMaterial.DiffuseColor;
            //diffColor.Alpha = 0.5f;
            //this.RedMaterial.DiffuseColor = diffColor;

            Points = new PointGeometry3D();

            BackgroundTexture =
                BitmapExtensions.CreateLinearGradientBitmapStream(EffectsManager, 128, 128, Direct2DImageFormat.Bmp,
                                                                  new Vector2(0, 0), new Vector2(0, 128), new SharpDX.Direct2D1.GradientStop[]
            {
                new SharpDX.Direct2D1.GradientStop()
                {
                    Color = Color.DarkGray, Position = 0f
                },
                new SharpDX.Direct2D1.GradientStop()
                {
                    Color = Color.Black.ToColor4(), Position = 1.0f
                }
            });

            SubdividedIcosahedronCommand = new RelayCommand(CreateSubdividedIcosahedron);
        }