If you’ve never encountered texture coordinates before, DanLehen has a detailed introduction that you can find here.
If you have used texture coordinates before in another API you may have noticed that we are a little different. Here’s what you need to know:
- Traditionally, the vertical texture coordinate axis (v) points up but in WPF3D it points down. This is for consistency with 2D. If you’re trying to dispay a mesh from a system where v points up, you can either convert the texture coordinates by hand or use a Transform on the Brush to flip it.
- If you don’t set TileBrush.ViewportUnits to BrushMappingMode.Absolute, your texture coordinates will be relative to the bounding box of your geometry. For example, let’s say you only want half of your texture in v to be mapped to the mesh. In other APIs, you would just range your coordinate from 0.0 -> 0.5. If you do that in WPF3D without setting ViewportUnits to Absolute, it’ll still map the entire thing. Essentially any time you don’t want one copy of the entire texture you’ll want to set Absolute.
- We do not generate texture coordinates if you do not specify them. The only Brush that doesn’t need texture coordinates is SolidColorBrush.
- Tiling is controlled by TileBrush.TileMode which defaults to None. If you want to tile your texture, set Absolute, set TileMode to Tile, and then use texture coordinates that go past 1.0 (e.g. 0.0 -> 3.0 would tile it three times). Check out the TileMode docs for more options.
If you’re having trouble coming up with texture coordinates, 3DTools has some basic texture coordinate generators.