表面法线

发布于 2024-08-12 14:56:59 字数 1288 浏览 4 评论 0原文

我有一个关于表面法线的请求。以下代码片段来自 URL: http://www.kindohm.com/technical/wpf3dtutorial.htm

private Model3DGroup CreateTriangleModel(Point3D p0, Point3D p1, Point3D p2)
{
    MeshGeometry3D mesh = new MeshGeometry3D();

    mesh.Positions.Add(p0);
    mesh.Positions.Add(p1);
    mesh.Positions.Add(p2);
    mesh.TriangleIndices.Add(0);
    mesh.TriangleIndices.Add(1);
    mesh.TriangleIndices.Add(2);
    Vector3D normal = CalculateNormal(p0, p1, p2);
    //
    mesh.Normals.Add(normal);
    mesh.Normals.Add(normal);
    mesh.Normals.Add(normal);
    //
    Material material = new DiffuseMaterial(
        new SolidColorBrush(Colors.DarkKhaki));
    GeometryModel3D model = new GeometryModel3D(
        mesh, material);
    Model3DGroup group = new Model3DGroup();
    group.Children.Add(model);
    return group;

}

private Vector3D CalculateNormal(Point3D p0, Point3D p1, Point3D p2)

{
    Vector3D v0 = new Vector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);

    Vector3D v1 = new Vector3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);

    return Vector3D.CrossProduct(v0, v1);
}

我可以不明白为什么代码行“mesh.Normals.Add(normal);”重复3次。

能告诉我原因吗?

问候

J·弗兰克

I have a request about surface normals. At the following code snippet is from the URL :
http://www.kindohm.com/technical/wpf3dtutorial.htm

private Model3DGroup CreateTriangleModel(Point3D p0, Point3D p1, Point3D p2)
{
    MeshGeometry3D mesh = new MeshGeometry3D();

    mesh.Positions.Add(p0);
    mesh.Positions.Add(p1);
    mesh.Positions.Add(p2);
    mesh.TriangleIndices.Add(0);
    mesh.TriangleIndices.Add(1);
    mesh.TriangleIndices.Add(2);
    Vector3D normal = CalculateNormal(p0, p1, p2);
    //
    mesh.Normals.Add(normal);
    mesh.Normals.Add(normal);
    mesh.Normals.Add(normal);
    //
    Material material = new DiffuseMaterial(
        new SolidColorBrush(Colors.DarkKhaki));
    GeometryModel3D model = new GeometryModel3D(
        mesh, material);
    Model3DGroup group = new Model3DGroup();
    group.Children.Add(model);
    return group;

}

private Vector3D CalculateNormal(Point3D p0, Point3D p1, Point3D p2)

{
    Vector3D v0 = new Vector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);

    Vector3D v1 = new Vector3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);

    return Vector3D.CrossProduct(v0, v1);
}

I can't understand why the code line "mesh.Normals.Add(normal);" is repeated three times.

Could you say me the reason.

Regards

J.Frank

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平生欢 2024-08-19 14:56:59

看起来您正在用三个点创建一个三角形。法线是该三角形中每个点的法线。碰巧的是,在这种情况下,所有法线都指向同一方向。也就是说,它们与表面法线相同。

有时您希望点法线与表面法线不同。就像,当三角形是球体等物体的一部分时。然后您希望点法线是其周围表面法线的平均值。这将允许您进行平滑的阴影和突出显示,而不仅仅是平面阴影。

It looks like you're creating a triangle out of three points. The normals are normals for each point in that triangle. It just so happens that in this case all the normals point in the same direction. That is, they are the same as the surface normal.

There are times when you'd want your point normals to be different from the surface normal. Like, when the triangle is a part of an object like a sphere. Then you'd want the point normals to be an average of the surface normals around it. That would allow you to do smooth shading and highlighting instead of just flat shading.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文