MC9000
MC9000

Reputation: 2403

how to tile 3D mesh with image brush in XAML

I have a 2D square in a ViewPort3D that I want to do a tiling of an image (like a checkerboard or flooring with "tiles" effect).
I've created an image brush (the image is 50x50 pixels, the surface 250x550 pixels) and a viewport (trying to follow MS's site - though their example is for 2D), but only 1 of the colors in the "tile" image shows up and no tiling is seen. I can't find a single example on the Internet and MS's site has no info (that I can find) on 3D XAML anywhere, so I'm stumped as how to actually do this.

<Viewport3D>
        <Viewport3D.Camera>
            <PerspectiveCamera Position="125,790,120" LookDirection="0,-.7,-0.25"  UpDirection="0,0,1" />
        </Viewport3D.Camera>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <Model3DGroup>
                    <AmbientLight Color="white" />
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D Positions="0,0,0 250,0,0 250,550,0 0,550,0 " TriangleIndices="0 1 3 1 2 3  "/>
                        </GeometryModel3D.Geometry>
                        <GeometryModel3D.Material>                               
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>
                                    <ImageBrush ViewportUnits="Absolute" TileMode="Tile" ImageSource="testsquare.gif" Viewport="0,0,50,50" Stretch="None" ViewboxUnits="Absolute" />
                                </DiffuseMaterial.Brush> 
                            </DiffuseMaterial>
                        </GeometryModel3D.Material>
                    </GeometryModel3D>
                </Model3DGroup>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>

Upvotes: 1

Views: 3545

Answers (1)

MC9000
MC9000

Reputation: 2403

OK, Got it figured out. Besides the TextureCoordinates, I needed to set the alignment property of the brush. Here is the final, working code.

<Viewport3D>
        <Viewport3D.Camera>
            <PerspectiveCamera Position="125,790,120" LookDirection="0,-.7,-0.25"  UpDirection="0,0,1" />
        </Viewport3D.Camera>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <Model3DGroup>
                    <AmbientLight Color="white" />
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D Positions="0,0,0 250,0,0 250,550,0 0,550,0 " TriangleIndices="0 1 3 1 2 3" TextureCoordinates="0,0 250,0 250,550 0,550 "/>                             
                        </GeometryModel3D.Geometry>
                        <GeometryModel3D.Material>                               
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>                                       
                                    <ImageBrush ViewportUnits="Absolute" TileMode="Tile"  ImageSource="testsquare.gif" Viewport="0,0,50,50" ViewboxUnits="Absolute" Stretch="None" AlignmentX="Left" AlignmentY="Top" />
                                </DiffuseMaterial.Brush> 
                            </DiffuseMaterial>
                        </GeometryModel3D.Material>

                    </GeometryModel3D>
                </Model3DGroup>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>

Upvotes: 4

Related Questions