当我终于找到如何在Direct3D中渲染几个方格时,我就去找我如何将图像应用到它而不是纯色......所以我试图将图像作为纹理放在平面上表面......这是我的代码和一些屏幕截图......
private void DrawTerrain(float Max_X, float Max_Y)
{
ModelVisual3D visual = new ModelVisual3D();// Visual
Model3DGroup group = new Model3DGroup();// Group
GeometryModel3D mod = new GeometryModel3D();// Model
MeshGeometry3D mesh = new MeshGeometry3D();// Mesh
PointLight light = new PointLight() { Color = Color.FromArgb(255, 255, 255, 0), Position = new Point3D(1, 1, -1), Range = 3 };// Light
DiffuseMaterial Mat = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(255, 255, 255, 0)));// This is the solid Color brush that works (Screen Shot 1)
DiffuseMaterial Material = new DiffuseMaterial(new ImageBrush(new BitmapImage(new Uri(@"Image.png"))));// This is the image brush that does nothing (Screen Shot 2) (Image Path is a placeholder, this is an absolute path in the code when testing it)
for (var Y = 0; Y < Max_Y; Y++)
{
for (var X = 0; X < Max_X; X++)
{
mesh.Positions.Add(new Point3D(X, Y, 0));
mesh.Positions.Add(new Point3D(X, Y + 1, 0));
mesh.Positions.Add(new Point3D(X + 1, Y, 0));
mesh.Positions.Add(new Point3D(X, Y + 1, 0));
mesh.Positions.Add(new Point3D(X + 1, Y + 1, 0));
mesh.Positions.Add(new Point3D(X + 1, Y, 0));
}
}
mod.Geometry = mesh;
mod.Material = Material;
group.Children.Add(mod);
group.Children.Add(light);
visual.Content = group;
_Table.Children.Add(visual);
}
Color Brush Render
Image Brush Render
我会更改DiffuseMaterial Material = new DiffuseMaterial(new ImageBrush(new BitmapImage(new Uri(@"Image.png"))));// Meterial
或我做错了什么?
编辑:我正在尝试解决此问题而不使用应用程序编译图像,因为使用此应用程序的每个用户都将拥有自己的资源。它需要是完全动态的