MaxScript 射线记录

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()

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 这一期代码超长,个人建议你还是复制比较好。 代码是: <!DOCTYPE html> 櫻花飄落 /*Sakura ...
    六代火影阅读 1,116评论 0 1
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,505评论 0 13
  • IQ大神博客阅读心得1 the game of life:一个简单有趣的算法 Plane deformations...
    JMX_dc51阅读 628评论 0 0
  • 早期在读研的时候,就在找把PDF扫描文件清晰化,有些扫描书籍出来的PDF,又是歪的,又是糊的,看起来非常费劲,网上...
    girlfull阅读 6,482评论 1 1
  • 16宿命:用概率思维提高你的胜算 以前的我是风险厌恶者,不喜欢去冒险,但是人生放弃了冒险,也就放弃了无数的可能。 ...
    yichen大刀阅读 6,109评论 0 4