Max里的平行光潘靖,不算是傳統(tǒng)意義上的平行光,更像是一盞聚光燈考廉。
求面片上被燈光照得到的頂點。燈光默認方向為-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()