因?yàn)橐媽?shí)驗(yàn)結(jié)果圖,想把通過算法重建出來(lái)的line/curve和模型疊在一起進(jìn)行展示,所以學(xué)習(xí)了一下用MaxScript畫線的技能。
畫直線Line
此處是直接創(chuàng)建了cylinder圖形,設(shè)置了半徑為0.01戚啥。調(diào)用的時(shí)候直接drawCylinderBetweenTwoPoints [0,0,0] [1,1,1]
就行了。
fn drawCylinderBetweenTwoPoints pt1 pt2=
cylinder radius:0.01 pos:pt1 dir:(pt2-pt1) height:(distance pt1 pt2)
畫曲線Curve
theShape = SplineShape pos:[x,y,z]
addNewSpline theShape
addKnot theShape 1 #corner 1
addKnot theShape 1 #corner 2
...
updateShape theShape
不過由于這里創(chuàng)建的是spline樣條線锉试,是沒有粗細(xì)的虑鼎,所以渲染之前需要在修改器列表中選擇添加“可渲染樣條線”,然后修改“徑向”為合適的參數(shù)键痛。
讀文件
下面提供使用讀文件方式來(lái)讀取控制點(diǎn)坐標(biāo)數(shù)據(jù)進(jìn)行繪制的方案炫彩,代碼參考來(lái)自于can use maxscript control the point curve points。原代碼是從一個(gè)只存了一條curve的控制點(diǎn)坐標(biāo)的txt文本中讀取數(shù)據(jù)絮短,而我的txt文本中存了多條curve的控制點(diǎn)數(shù)據(jù)江兢,格式如下:
x1, y1, z1
x1, y1, z1
...
x1, y1, z1
x2, y2, z2
x2, y2, z2
...
x2, y2, z2
x3, y3, z3
...
...
其中每一行xi, yi, zi
都是分別屬于第i根curve的控制點(diǎn),不同curve之間用空行隔開丁频。完整代碼如下:
dataFilename = getOpenFileName filename:"pointcloud.txt"
if dataFilename != undefined then
(
textFilestream = openFile dataFilename mode:"rt"
if textFilestream != undefined then
(
while not(eof textFilestream) do
(
ss = (readLine textFilestream) as stringstream
x = (readToken ss) as float
y = (readToken ss) as float
z = (readToken ss) as float
theShape = SplineShape pos:[x,y,z]
addNewSpline theShape
ss = (readLine textFilestream) as stringstream
while not(eof ss) do
(
x = (readToken ss) as float
y = (readToken ss) as float
z = (readToken ss) as float
-- assuming we only have one spline within the shape
addKnot theShape 1 #corner #line [-x,y,z] --add the tangents to the end here
if not(eof textFilestream) do
ss = (readLine textFilestream) as stringstream
)
updateShape theShape -- don't forget to update
)
)
)