0

How to fill with tile texture?

Anonymous 6 years ago updated by Michael Powell 6 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">
            </ModelVisual3D>
         </h:HelixViewport3D>
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));

            mb.AddPolygon(pnts);

            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
Image

below is the box.jpg
Image

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

I have found the solution and the detailed code is available here
http://uselesstechnical.wordpress.com/2014/08/14/helix-3d-toolkit-tile-texture/
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.

<h:RectangleVisual3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush TileMode="Tile"
Stretch="None"
ViewportUnits="Absolute"
Viewport="0 0 0.1 0.1"
ViewboxUnits="Absolute"
Viewbox="0 0 1 1"
ImageSource="pack://application:,,,/Editor.Wpf;component/Resources/grass.png" />
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</h:RectangleVisual3D.Material>