Here is another version using the viewport image to average pixels colors.
Currently the sample pixels are the number of face verts + 1, and they are at the average position between each vertex and the face center, but you can modify it to use more samples and a better distribution if you need.
(
try destroydialog ::RO_DISPLAY_FACES_COLORS catch()
rollout RO_DISPLAY_FACES_COLORS "Faces Colors" width:172 height:88
(
radioButtons rdo1 "Display:" pos:[8,8] labels:#("RGB","H","S","B") columns:4
checkbutton btn1 "Enable" pos:[8,48] width:154 height:28
timer clock interval:20 active:false
global GW_DisplayFacesColors
local GetFaceVerts = polyop.getfaceverts
local GetfaceNormal = polyop.getfaceNormal
local GetFaceCenter = polyop.getFaceCenter
local GetVert = polyop.getvert
local node
local data = #()
fn CalculateFacesColors =
(
dib = gw.getViewportDib()
viewTM = viewport.getTM()
viewTM.row4 = [0,0,0]
gw.setTransform (matrix3 1)
result = for f = 1 to node.numfaces collect
(
faceNormal = normalize (GetfaceNormal node f)
if (faceNormal*viewTM).z > 0 then
(
faceCenter = GetFaceCenter node f
fverts = GetFaceVerts node f
verts = for j in fverts collect (faceCenter + (GetVert node j)) / 2.0
append verts faceCenter
numverts = verts.count
faceColor = black
for j in verts do
(
px = gw.transPoint j
if px.x > 1 and px.y < dib.width do
(
pcolor = (getpixels dib [px[1], px[2]] 1)[1]
if pcolor != undefined then faceColor += pcolor else numverts -= 1
)
)
faceColor.r = int (faceColor.r/numverts)
faceColor.g = int (faceColor.g/numverts)
faceColor.b = int (faceColor.b/numverts)
#(faceCenter, faceColor)
)else(
dontcollect
)
)
free dib
return result
)
on clock tick do
(
data = CalculateFacesColors()
)
fn GW_DisplayFacesColors =
(
for j in data do
(
val = case rdo1.state of
(
1: j[2] as point3
2: int j[2].h
3: int j[2].s
4: int j[2].v
)
gw.text j[1] (val as string) color:black
--gw.enlargeUpdateRect #whole
)
)
on RO_DISPLAY_FACES_COLORS open do
(
unregisterRedrawViewsCallback GW_DisplayFacesColors
completeredraw()
)
on RO_DISPLAY_FACES_COLORS close do
(
unregisterRedrawViewsCallback GW_DisplayFacesColors
completeredraw()
)
on btn1 changed arg do
(
unregisterRedrawViewsCallback GW_DisplayFacesColors
if arg then
(
if selection.count == 1 and iskindof selection[1] editable_poly then
(
node = selection[1]
clock.tick()
clock.active = true
registerRedrawViewsCallback GW_DisplayFacesColors
)else(
node = undefined
btn1.checked = false
clock.active = false
messagebox "Select an object"
)
)else(
clock.active = false
)
completeredraw()
)
on rdo1 changed arg do completeredraw()
)
createdialog RO_DISPLAY_FACES_COLORS
)



