I have a model that I created in 3ds Max. The model is a simple rectangle. Its texture has overlapping texture coordinates - the model should display the right half of the image file twice, side by side. I exported this model as I .objconverted it to XAML using Microsoft Expression Blend.
I took MeshGeometry3Dfrom blend and added it to Viewport3Dtwo ways:
- Use
Viewport2DVisual3Dwith Labelhow Visual. Set the background Labelto a texture image. Using this method, everything works as expected. - Use
ModelVisual3Dwith GeometryModel3Dhow Content. Set the material GeometryModel3Dto DiffuseMaterialthat uses the image as a brush. Using this method, TextureCoordinatesof MeshGeometry3Dseems to be interpreted differently.
The full code is given below. The code is empty except for InitializeComponent():
<Window x:Class="TestTextureCoordinates.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<MeshGeometry3D x:Key="geometry"
Normals="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1"
Positions="113.8997,102.4171,0 148.9045,102.4171,0 148.9045,148.41161,0 113.8997,148.41161,0 184.5722,102.4171,0 184.5722,148.41161,0 148.9045,148.41161,0 148.9045,102.4171,0"
TextureCoordinates="0.50639999,0.9995 1.0065,0.9995 1.0065,0.00050002337 0.50639999,0.00050002337 1.0022,0.9995 1.0022,0.00050002337 0.5,0.00050002337 0.5,0.9995"
TriangleIndices="0 1 2 0 2 3 4 5 6 4 6 7"/>
<ImageBrush x:Key="brush" ImageSource="img/test.jpg" />
</Grid.Resources>
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="195,125,210" LookDirection="0,0,-1" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<AmbientLight Color="White" />
</ModelVisual3D.Content>
</ModelVisual3D>
<Viewport2DVisual3D Geometry="{StaticResource geometry}">
<Viewport2DVisual3D.Visual>
<Label Background="{StaticResource brush}" />
</Viewport2DVisual3D.Visual>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" />
</Viewport2DVisual3D.Material>
</Viewport2DVisual3D>
<ModelVisual3D>
<ModelVisual3D.Transform>
<TranslateTransform3D OffsetX="90" />
</ModelVisual3D.Transform>
<ModelVisual3D.Content>
<GeometryModel3D Geometry="{StaticResource geometry}">
<GeometryModel3D.Material>
<DiffuseMaterial Brush="{StaticResource brush}" />
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Grid>
Here test.jpg:

Here is the final result. On the left is located Viewport2DVisual3D, which looks the same as in 3ds Max. On the right is ModelVisual3Dthat which apparently interprets TextureCoordinates.

What's going on here? Due to other software requirements I'm working on, I cannot use Viewport2DVisual3D. How can I make it GeometryModel3Dinterpret correctly TextureCoordinates?