points = 100;
mesh = {15, 15};
f = {x, y} \[Function] x y;
νf = {x, y} \[Function] Evaluate[-Cross @@ Transpose[D[{x, y, f[x, y]}, {{x, y}, 1}]]];
cfsurface =
With[{code = {Compile`GetElement[X, 1], Compile`GetElement[X, 2],
f[Compile`GetElement[X, 1], Compile`GetElement[X, 2]]}},
Compile[{{X, _Real, 1}}, code, RuntimeAttributes -> {Listable}, Parallelization -> True]
];
cνf =
With[{code = νf[Compile`GetElement[X, 1], Compile`GetElement[X, 2]]},
Compile[{{X, _Real, 1}}, code, RuntimeAttributes -> {Listable},
Parallelization -> True]
];
getQuads = Compile[{{m, _Integer}, {n, _Integer}},
Flatten[Table[
{m (j - 1) + i, m (j - 1) + i + 1, m j + i + 1, m j + i},
{j, 1, n - 1}, {i, 1, m - 1}], 1],
CompilationTarget -> "C",
RuntimeOptions -> "Speed"
];
points = 100;
pts2D = Tuples[{Subdivide[-2., 2., points - 1], Subdivide[-2., 2., points - 1]}];
lines = cfsurface@Outer[List, Subdivide[-2., 2., mesh[[1]] - 1], Subdivide[-2., 2., mesh[[2]] - 1]];
Graphics3D[{
GraphicsComplex[
cfsurface[pts2D], {EdgeForm[], Orange, Specularity[White, 30],
Polygon[getQuads[points, points]]},
VertexNormals -> c\[Nu]f[pts2D]],
Line@lines,
Line@Transpose[lines]
},
Lighting -> "Neutral"
]