Пример #1
0
        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
        /// <summary>
        /// エフェクトのアニメーション画像の位置などを修正します。
        /// </summary>
        private void UpdateImage()
        {
            var brush = this.brush as ImageBrush;

            if (brush == null || string.IsNullOrEmpty(ImageUri))
            {
                return;
            }

            var imageList = EffectImageCache.GetImageList(
                MakeContentUri(ImageUri),
                AnimationImageCount);

            if (imageList == null)
            {
                return;
            }

            var oldImage = brush.ImageSource;
            var newImage = imageList[AnimationImageIndex % imageList.Count()];

            // 必要ならメッシュの更新を行います。
            if (AutoUpdateMesh)
            {
                if (newImage != null)
                {
                    if (oldImage == null ||
                        oldImage.Width != newImage.Width ||
                        oldImage.Height != newImage.Height)
                    {
                        Mesh = WPFUtil.CreateDefaultMesh(
                            1.0, 1.0, newImage.Width, newImage.Height);
                    }
                }
                else
                {
                    Mesh = null;
                }
            }

            brush.ImageSource = newImage;
        }
Пример #3
0
        /// <summary>
        /// モデルの中身を更新します。
        /// </summary>
        private void UpdateModel()
        {
            // 表示用の駒オブジェクトを追加します。
            var model = CreatePieceModel();

            if (model != null)
            {
                ModelGroup.Children.Add(model);
            }

            // 駒台の駒の場合
            if (Square == null)
            {
                // 駒数の表示用オブジェクトを追加します。
                var numberModel = new GeometryModel3D()
                {
                    Geometry  = WPFUtil.CreateDefaultMesh(0.7, 0.4, 0, 0),
                    Material  = new DiffuseMaterial(new VisualBrush(this.numberText)),
                    Transform = new TranslateTransform3D(0.4, -0.4, 0.0),
                };
                ModelGroup.Children.Add(numberModel);
            }
        }
Пример #4
0
        /// <summary>
        /// 駒の表示用モデルを作成します。
        /// </summary>
        private GeometryModel3D CreatePieceModel()
        {
            var brush = CreateBrush(this.shogi, Piece);

            if (brush == null)
            {
                return(null);
            }

            var image = brush.ImageSource;

            if (image == null)
            {
                return(null);
            }

            return(new GeometryModel3D
            {
                Geometry = WPFUtil.CreateDefaultMesh(
                    1.0, 1.0, image.Width, image.Height),
                Material = new DiffuseMaterial(brush),
            }.Apply(_ => _.Freeze()));
        }
Пример #5
0
        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,
                });
            }
        }
Пример #6
0
 /// <summary>
 /// バインディングした値を返します。
 /// </summary>
 public override object ProvideValue(IServiceProvider service)
 {
     return(WPFUtil.CreateDefaultMesh(Width, Height, 0, 0));
 }