Here is a working code using the .net API. You still need to debug and improve it.
The Logarithmic Exposure Control seems to work consistently in viewport and render, but not all the others, so this solution is a partial workaround for what you need. If you switch to another Exposure algorithm, it might not give the values you need.
A better solution would be to implement the Exposure algorithm in the code, or perhaps you can adjust the exposure externally and use something different. After all, it is just a color curve.
(
global GW_DisplayFacesColors
local data_front = #()
local data_back = #()
local data_type = 1
local showSamples = false
fn GW_DisplayFacesColors =
(
for j in data_front do
(
val = case data_type 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:red
if showSamples do for k in j[3] do gw.Marker k #asterisk color:red
)
for j in data_back do
(
val = case data_type 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
if showSamples do for k in j[3] do gw.Marker k #asterisk color:black
)
gw.enlargeUpdateRect #whole
)
try destroydialog ::RO_DISPLAY_FACES_COLORS catch()
rollout RO_DISPLAY_FACES_COLORS "Faces Colors" width:172 height:172
(
button bt_vp1 "Set Font View" pos:[ 8, 8] width:72 height:32
button bt_vp2 "Set Back View" pos:[88, 8] width:72 height:32
spinner sp_sampleDist "Samples Distance" pos:[ 8,48] range:[0,100,50] fieldwidth:56
checkbox chk_showSamples "Show Smaple Points" pos:[ 8,72]
radioButtons rdo1 "Display:" pos:[8, 96] labels:#("RGB","H","S","B") columns:4
checkbutton btn1 "Enable" pos:[8,136] width:154 height:28
timer clock interval:20 active:false
local GetFaceVerts = polyop.getfaceverts
local GetfaceNormal = polyop.getfaceNormal
local GetFaceCenter = polyop.getFaceCenter
local GetVert = polyop.getvert
local node
local vp_front = undefined
local vp_back = undefined
local gw_front = undefined
local gw_back = undefined
local gbl = (dotnetclass "Autodesk.Max.GlobalInterface").Instance
local ip = gbl.COREInterface
local identityTM = gbl.IdentityTM.Create()
fn ConvertMatrix tm =
(
r1 = tm.GetRow 0
r2 = tm.GetRow 1
r3 = tm.GetRow 2
return (matrix3 [r1.x, r1.y, r1.z] [r2.x, r2.y, r2.z] [r3.x, r3.y, r3.z] [0,0,0])
)
fn CalculateFacesColors viewGW viewTM =
(
dib = viewGW.DIB
tm = viewTM.AffineTM
viewTM = ConvertMatrix tm
viewGW.transform = identityTM
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
numverts = fverts.count
faceColor = black
samplePoints = #()
for j in fverts do
(
d = distance faceCenter (GetVert node j)
n = normalize (faceCenter - (GetVert node j))
d = sp_sampleDist.value * d / 100.0
pt = faceCenter + (d*n)
pt = gbl.Point3.Create pt.x pt.y pt.z
px = gbl.Point3.Create 0 0 0
viewGW.TransPoint pt px
if px.x > 0 and px.x < dib.width and px.y > 0 and px.y < dib.height do
(
pcolor = dib.GetPixel px.x px.y
if pcolor != undefined then
(
faceColor.r += pcolor.r
faceColor.g += pcolor.g
faceColor.b += pcolor.b
)else(
numverts -= 1
)
)
append samplePoints [pt.x, pt.y, pt.z]
px.Dispose()
pt.Dispose()
)
faceColor.r = int (faceColor.r/numverts)
faceColor.g = int (faceColor.g/numverts)
faceColor.b = int (faceColor.b/numverts)
#(faceCenter, faceColor, samplePoints)
)else(
dontcollect
)
)
tm.Dispose()
dib.Dispose()
return result
)
fn GetDisplayData =
(
data_front = CalculateFacesColors gw_front vp_front
data_back = CalculateFacesColors gw_back vp_back
)
fn GetViewExp =
(
viewHwnd = dotnetobject "system.intptr" ip.ActiveViewExp.Hwnd
return ip.GetViewExp viewHwnd
)
on clock tick do
(
GetDisplayData()
)
on RO_DISPLAY_FACES_COLORS close do
(
unregisterRedrawViewsCallback GW_DisplayFacesColors
completeredraw()
)
on btn1 changed arg do
(
if vp_front == undefined or vp_back == undefined do
(
btn1.checked = false
return messagebox "Select Front and Back Views"
)
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
(
data_type = arg
completeredraw()
)
on bt_vp1 pressed do
(
vp_front = GetViewExp()
gw_front = vp_front.Gw
bt_vp1.text = viewport.activeViewport as string
)
on bt_vp2 pressed do
(
vp_back = GetViewExp()
gw_back = vp_back.Gw
bt_vp2.text = viewport.activeViewport as string
)
on chk_showSamples changed arg do
(
showSamples = arg
GetDisplayData()
completeredraw()
)
on sp_sampleDist changed arg do
(
GetDisplayData()
completeredraw()
)
)
createdialog RO_DISPLAY_FACES_COLORS
)