コード例 #1
0
        /// <summary>
        /// Generates a mesh model
        /// </summary>
        /// <param name="mesh">Mesh</param>
        static void Generate(MeshGeometry3D mesh)
        {
            const int slices = 12;
             const double slice = (2.0 * Math.PI) / (double)slices;

             for(int i = 0; i < slices; i++)
             {
                 int secondIndex = (i == slice - 1) ? 0 : i + 1;
                 Point3D topFirst = Function(1, slice * i);
                 Point3D topSecond = Function(1, slice * secondIndex);
                 Point3D bottomFirst = Function(0, slice * i);
                 Point3D bottomSecond = Function(0, slice * secondIndex);

                 Vector3D firstNormal = new Vector3D(bottomFirst.X, bottomFirst.Y, bottomFirst.Z);
                 Vector3D secondNormal = new Vector3D(bottomSecond.X, bottomSecond.Y, bottomSecond.Z);

                 /*0*/ mesh.Positions.Add(topFirst);
                 /*1*/ mesh.Positions.Add(topSecond);
                 /*2*/ mesh.Positions.Add(bottomFirst);
                 /*3*/ mesh.Positions.Add(bottomSecond);

                 mesh.Normals.Add(firstNormal);
                 mesh.Normals.Add(secondNormal);
                 mesh.Normals.Add(firstNormal);
                 mesh.Normals.Add(secondNormal);

                 mesh.TriangleIndices.Add(i * 4 + 0);
                 mesh.TriangleIndices.Add(i * 4 + 3);
                 mesh.TriangleIndices.Add(i * 4 + 1);

                 mesh.TriangleIndices.Add(i * 4 + 0);
                 mesh.TriangleIndices.Add(i * 4 + 2);
                 mesh.TriangleIndices.Add(i * 4 + 3);
             }

             mesh.GenerateCylindricalTextureCoordinates(new Vector3D(0, 1, 0));
        }