开发者

Surface Normals

开发者 https://www.devze.com 2022-12-13 04:06 出处:网络
I have a request about surface normals. At the following code snippet is from the URL: http://www.kindohm.com/technical/wpf3dtutorial.htm

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);
  开发者_JAVA百科  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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消