This line of the code is a “quick backface culling”. It does not take into account the camera FOV, so if you use it in an orthographic view you’ll see faces are correctly isolated, but not in perspective or camera views.
if (faceNormal*viewTM).z > 0 then
If you remove that line, all faces will be parsed.
Unfortunately that won’t work with the script that uses the viewport image to get the colors.
But you can modify the first code to use some sample points and average them, same as does the second code.
The first one only gets the color at the center of the face, but if you use more samples you’ll get a more accurate value.
Regarding the default viewports lighting, the script does not work with them and their parameters are unknown, and I could not find anything in the SDK that would help to reproduce them. Using the menu command to create the default lights does not create the same lights as the default ones, or I was unable to set the scale value properly.
Perhaps you can experiment a little to re-create what the default lights are, or perhaps someone else already knows it.


