コード例 #1
0
ファイル: WPFImageLoader.cs プロジェクト: leontius/Ragnarok
        public IImageData LoadImage(Uri imageUri, MaterialType materialType)
        {
            var image = GetImage(imageUri);
            var brush = new ImageBrush()
            {
                ImageSource = image,
            };

            var mesh = WPFUtil.CreateDefaultMesh(1.0, 1.0, image.Width, image.Height);

            mesh.Freeze();

            var materialWrap = new MaterialWrap
            {
                MaterialType = materialType,
                Brush        = brush,
                Color        = Colors.White,
            };

            GeometryModel3D model = new GeometryModel3D()
            {
                Geometry = mesh,
                Material = materialWrap.Create(),
            };

            return(new WPFImageData
            {
                Model = model,
                Brush = brush,
                Material = model.Material,
            });
        }
コード例 #2
0
ファイル: WPFImageLoader.cs プロジェクト: leontius/Ragnarok
        public IImageData LoadParticleImage(bool isSingle, MaterialType materialType)
        {
            BitmapImage image = GetParticleImage();
            ImageBrush  brush = new ImageBrush(image);

            if (isSingle)
            {
                MaterialWrap materialWrap = new MaterialWrap()
                {
                    MaterialType = materialType,
                    Brush        = brush,
                    Color        = Colors.White,
                };
                Material material = materialWrap.Create();

                var mesh = WPFUtil.CreateDefaultMesh(1.0, 1.0, image.Width, image.Height);
                mesh.Freeze();

                GeometryModel3D model = new GeometryModel3D()
                {
                    Geometry = mesh,
                    Material = material,
                };

                return(new WPFImageData
                {
                    Brush = brush,
                    Material = material,
                    Model = model,
                });
            }
            else
            {
                // front
                MaterialWrap materialWrap1 = new MaterialWrap()
                {
                    MaterialType = materialType,
                    Brush        = brush,
                    Color        = Colors.White,
                };

                // back
                MaterialWrap materialWrap2 = new MaterialWrap()
                {
                    MaterialType = materialType,
                    Brush        = brush,
                    Color        = Color.FromArgb(0xC0, 0xFF, 0xFF, 0xFF),
                };

                Material material1 = materialWrap1.Create();
                Material material2 = materialWrap2.Create();

                MaterialGroup matGroup = new MaterialGroup();
                matGroup.Children.Add(material2);
                matGroup.Children.Add(material1);

                var mesh = WPFUtil.CreateDefaultMesh(1.0, 1.0, image.Width, image.Height);
                mesh.Freeze();

                GeometryModel3D model = new GeometryModel3D()
                {
                    Geometry = mesh,
                    Material = matGroup,
                };

                return(new WPFImageData
                {
                    Brush = brush,
                    Material = material1,
                    Model = model,
                });
            }
        }