Max里的平行光,不算是传统意义上的平行光,更像是一盏聚光灯。
求面片上被灯光照得到的顶点。灯光默认方向为-Z
clearlistener()
polyop.SetMapSupport $plane01 0 true
for i = 1 to (polyop.getNumVerts $plane01) do(
currentVert = polyop.getvert $plane01 i
l=$FDirect01
theRot = l.rotation --the quat value
theTM = inverse(theRot as matrix3) --the quat as matrix
theZ = normalize theTM.row3 --通过旋转矩阵获取方向向量
theZ = $.dir --grab the Z axis
fn pointLineDist2 pA pB pC =(
local vAB=pB-pA
local vAC=pC-pA
return (length (cross vAB vAC))/(length vAB)
)
dd = pointLineDist2 l.pos (l.pos+theZ) currentVert --顶点到灯光中心线的距离
if dd > l.falloff-50 then (dd = 0) else (dd = 255)
dd_col = (color dd dd dd 255)
polyop.setVertColor $plane01 0 i dd_col
)
update $plane01
gc()
redrawViews()
射线求遮挡
clearlistener()
meshAsset = $Sphere001
polyop.SetMapSupport meshAsset 0 true
fn getTheVertexNormal processObject vertexIndex =
(
normal = [0.0,0.0,0.0]
if classof processObject.baseobject == Editable_Poly then
(
vertexPolygons = polyOp.getFacesUsingVert processObject vertexIndex
for i in vertexPolygons do
(
normal+=in coordsys world polyOp.getFaceNormal processObject i
)
)else
(
normal= getNormal processObject vertexIndex
)
normal=normalize normal
normal
)
for i = 1 to (polyop.getNumVerts meshAsset) do
(
currentVert = polyop.getvert meshAsset i
l_v = [0,1,1]
l_v = normalize(l_v)
dd = 0
normal = getTheVertexNormal meshAsset i
if (dot normal l_v) > 0 then
(
theRay = ray (currentVert + (l_v * 0.001)) (l_v)
intRay = (intersectRay $Sphere001 theRay)
if intRay != undefined then
(
n = normalize(intRay.pos - currentVert )
--print (dot n l_v)
if (dot n l_v) < 0 then
( dd = 255 )
else( dd = 0)
--print dd
)else (dd = 255)
)
dd_col = (color dd dd dd 255)
polyop.setVertColor meshAsset 0 i dd_col
--print dd_col
)
update meshAsset
gc()
redrawViews()