C# C语言中三维物体的纹理#
我使用的是VS2008-C#Express。我想将文本块反射到三维网格对象上。我在一个网站上找到了一个示例代码片段。我将其添加到我的项目中,然后运行它,不幸的是,调试器发送了错误消息“找不到类型或命名空间名称“Run…”。我做错了什么?是否缺少命名空间 你能帮我吗。 问候 代码片段:C# C语言中三维物体的纹理#,c#,C#,我使用的是VS2008-C#Express。我想将文本块反射到三维网格对象上。我在一个网站上找到了一个示例代码片段。我将其添加到我的项目中,然后运行它,不幸的是,调试器发送了错误消息“找不到类型或命名空间名称“Run…”。我做错了什么?是否缺少命名空间 你能帮我吗。 问候 代码片段: public static ModelVisual3D CreateTextLabel3D(string text, Brush textColor, bool bDoubleSided, double heigh
public static ModelVisual3D CreateTextLabel3D(string text, Brush textColor, bool bDoubleSided, double height, Point3D center, Vector3D over, Vector3D up)
{
// First we need a textblock containing the text of our label
TextBlock tb = new TextBlock(new Run(text));
tb.Foreground = textColor;
tb.FontFamily = new FontFamily("Arial");
// Now use that TextBlock as the brush for a material
DiffuseMaterial mat = new DiffuseMaterial();
mat.Brush = new VisualBrush(tb);
// We just assume the characters are square
double width = text.Length * height;
// Since the parameter coming in was the center of the label,
// we need to find the four corners
// p0 is the lower left corner
// p1 is the upper left
// p2 is the lower right
// p3 is the upper right
Point3D p0 = center - width / 2 * over - height / 2 * up;
Point3D p1 = p0 + up * 1 * height;
Point3D p2 = p0 + over * width;
Point3D p3 = p0 + up * 1 * height + over * width;
// Now build the geometry for the sign. It's just a
// rectangle made of two triangles, on each side.
MeshGeometry3D mg = new MeshGeometry3D();
mg.Positions = new Point3DCollection();
mg.Positions.Add(p0); // 0
mg.Positions.Add(p1); // 1
mg.Positions.Add(p2); // 2
mg.Positions.Add(p3); // 3
if (bDoubleSided)
{
mg.Positions.Add(p0); // 4
mg.Positions.Add(p1); // 5
mg.Positions.Add(p2); // 6
mg.Positions.Add(p3); // 7
}
mg.TriangleIndices.Add(0);
mg.TriangleIndices.Add(3);
mg.TriangleIndices.Add(1);
mg.TriangleIndices.Add(0);
mg.TriangleIndices.Add(2);
mg.TriangleIndices.Add(3);
if (bDoubleSided)
{
mg.TriangleIndices.Add(4);
mg.TriangleIndices.Add(5);
mg.TriangleIndices.Add(7);
mg.TriangleIndices.Add(4);
mg.TriangleIndices.Add(7);
mg.TriangleIndices.Add(6);
}
// These texture coordinates basically stretch the
// TextBox brush to cover the full side of the label.
mg.TextureCoordinates.Add(new Point(0, 1));
mg.TextureCoordinates.Add(new Point(0, 0));
mg.TextureCoordinates.Add(new Point(1, 1));
mg.TextureCoordinates.Add(new Point(1, 0));
if (bDoubleSided)
{
mg.TextureCoordinates.Add(new Point(1, 1));
mg.TextureCoordinates.Add(new Point(1, 0));
mg.TextureCoordinates.Add(new Point(0, 1));
mg.TextureCoordinates.Add(new Point(0, 0));
}
// And that's all. Return the result.
ModelVisual3D mv3d = new ModelVisual3D();
mv3d.Content = new GeometryModel3D(mg, mat);;
return mv3d;
}
你需要确保你有:
using System.Windows.Documents;
在类所在的代码中
您可能还需要添加对
PresentationFramework.dll的引用。您需要确保:
using System.Windows.Documents;
在类所在的代码中
您可能还需要添加对PresentationFramework.dll的引用。请确保在文件顶部添加:
using System.Windows.Documents;
是System.Windows.Documents.Run-不是System.Windows的一部分。请确保在文件顶部添加:
using System.Windows.Documents;
是System.Windows.Documents.Run-不是System.Windows的一部分。如果下面的人没有回答你的问题,你应该自己回答,并接受这一回答。否则,请接受正确答案below@Allen-给他一个机会。这个问题只问了一个小时!尽管如此,他在我帖子的评论中提到,他已经解决了这个问题;)如果下面的人没有回答你的问题,你应该自己回答并接受这个答案。否则,请接受正确答案below@Allen-给他一个机会。这个问题只问了一个小时!尽管如此,他在我帖子的评论中提到,他已经解决了这个问题;)