How to fill with tile texture?

Anonymous 9 years ago updated by Michael Powell 8 years ago 2
This discussion was imported from CodePlex

veerammalkumaran wrote at 2014-08-01 08:53:

I want to fill a polygon with image (tile).

below is my XAML
         <h:HelixViewport3D Name="viewPort3D" >
            <h:SunLight />
            <ModelVisual3D x:Name="vis3D">
below is my code
            var mb = new MeshBuilder(false, true);

            IList<Point3D> pnts = new List<Point3D>();
            pnts.Add(new Point3D(0, 0, 0));
            pnts.Add(new Point3D(100, 0, 0));
            pnts.Add(new Point3D(100, 100, 0));
            pnts.Add(new Point3D(0, 100, 0));


            var mesh = mb.ToMesh(true);

            ImageBrush brush = new ImageBrush();
            brush.ImageSource = new BitmapImage(new Uri(@"C:\box.jpg"));
            brush.TileMode = TileMode.Tile;
            brush.ViewportUnits = BrushMappingMode.Absolute;
            brush.ViewboxUnits = BrushMappingMode.Absolute;
            brush.Stretch = Stretch.None;
            brush.AlignmentX = AlignmentX.Left;
            brush.AlignmentY = AlignmentY.Top;
            brush.Viewport = new Rect(0, 0, brush.ImageSource.Width, brush.ImageSource.Height);
            DiffuseMaterial mat = new DiffuseMaterial(brush);

            GeometryModel3D gModel3D = new GeometryModel3D { Geometry = mesh, Material = mat };

            vis3D.Content = gModel3D;
The above code doesn't work. What I missed in this?

veerammalkumaran wrote at 2014-08-01 10:12:

This is the output window I am getting

below is the box.jpg

veerammalkumaran wrote at 2014-08-14 06:53:

I have found the solution and the detailed code is available here
Thank you, it's a great clue for me.

You don't happen to know the Xaml do you?

For example, I'd like to pick up the image (Jpg, Png, whatever) from an embedded resource, etc, etc.

Thank you...
After putzing around with resources and Uri's, I was able to get an image to tile after all.

<ImageBrush TileMode="Tile"
Viewport="0 0 0.1 0.1"
Viewbox="0 0 1 1"
ImageSource="pack://application:,,,/Editor.Wpf;component/Resources/grass.png" />