Hello guys!
With the following code I create my ModelVisual3D model.
private ImageBrush texture = new ImageBrush(new BitmapImage(new Uri("Images//texture.png", UriKind.RelativeOrAbsolute))) { ViewboxUnits = BrushMappingMode.Absolute };
model = new ModelVisual3D();
Point3D pA = new Point3D(pos.X + 0.86602 * size, pos.Y, pos.Z + 0.50000 * size);
Point3D pB = new Point3D(pos.X + 0.86602 * size, pos.Y, pos.Z + -0.50000 * size);
Point3D pC = new Point3D(pos.X, pos.Y, pos.Z + size);
Point3D pD = new Point3D(pos.X + -0.86602 * size, pos.Y, pos.Z + -0.50000 * size);
Point3D pE = new Point3D(pos.X + -0.86602 * size, pos.Y, pos.Z + 0.50000 * size);
Point3D pF = new Point3D(pos.X, pos.Y, pos.Z - size);
Model3DGroup grp = new Model3DGroup();
grp.Children.Add(CreateTriangleModel(new DiffuseMaterial(texture), pB, pF, pD, new Point(0, 0), new Point(0, 100), new Point(100, 100)));
grp.Children.Add(CreateTriangleModel(new DiffuseMaterial(texture), pD, pE, pA, new Point(0, 0), new Point(0, 0.5), new Point(0.5, 0.5)));
grp.Children.Add(CreateTriangleModel(new DiffuseMaterial(texture), pB, pD, pA, new Point(0, 0), new Point(100, 0), new Point(100, 100)));
grp.Children.Add(CreateTriangleModel(new DiffuseMaterial(texture), pA, pE, pC, new Point(0, 0), new Point(0, 100), new Point(100, 100)));
I use this method to create my triangle models:
public static Model3DGroup CreateTriangleModel(Material material, Point3D p0, Point3D p1, Point3D p2, Point tc0, Point tc1, Point tc2)
{
MeshGeometry3D mesh = new MeshGeometry3D();
Vector3D normal = CalculateNormal(p0, p1, p2);
mesh.Positions.Add(p0);
mesh.Positions.Add(p1);
mesh.Positions.Add(p2);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
mesh.TextureCoordinates.Add(tc0);
mesh.TextureCoordinates.Add(tc1);
mesh.TextureCoordinates.Add(tc2);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
GeometryModel3D model = new GeometryModel3D(mesh, material);
Model3DGroup group = new Model3DGroup();
group.Children.Add(model);
return group;
}
well the problem is, the image is not displayed correctly. it always shows the full image, no matter what points I use for TextureCoordinates. And I want to select a special triangle on my image for every triangleModel... thats why i use "ViewboxUnits = BrushMappingMode.Absolute"... but somehow this doesnt work. And if i set ViewboxUNits to AccordingToBoundingBox and use Points like (0, 0.5) it doesnt work either. It always shows the full image on my triangleModel and not only a part of it...
regards