路徑
個(gè)人理解,路徑實(shí)質(zhì)上是多條連續(xù)的線段進(jìn)行組合起來(lái)具備某些特殊意義,最主要的作用還是為了讓自定義的截面進(jìn)行跟隨形成一些我們想要的模型。
代碼演示會(huì)更直接理解一點(diǎn):
model = Sketchup.active_model
entities = model.entities
sel = model.selection
pt0 = Array.new()
# 原點(diǎn)用數(shù)組(矩陣)表示
orignPoint = Array.new(3,0)
# 繪制簡(jiǎn)易曲線路徑
for i in 90..270
pt = [orignPoint.x + i,orignPoint.y + 100 * Math::sin(i.degrees),orignPoint.z]
pt0 << pt
end
curveline = entities.add_curve pt0
繪制面:
# 新建面的頂點(diǎn)數(shù)組
facePointArr = [
[0,0,10],
[10,0,10],
[10,10,10],
[0,10,10]
]
test_face = entities.add_face facePointArr
# 此時(shí)我們知道 entities 數(shù)組中就有了 5個(gè)實(shí)體 1曲線、1面、4線
# 選中一個(gè)面
# 提取出這個(gè)面的頂點(diǎn)
sel.add test_face
verticesArr = sel[0].vertices
for item in verticesArr
puts item.position
end
補(bǔ)充關(guān)于方向:
# Sketchup 某些矩陣特定意義
# X 軸 :[1,0,0] [-1,0,0]
# Y 軸 :[0,1,0] [0,-1,0]
# Z 軸 :[0,0,1] [0,0,-1]
# 某些函數(shù)(add_circle、add_nogn)需要指定某些面進(jìn)行繪制,就要設(shè)置normal 參數(shù)
# XY面 設(shè)置 [0,0,1] [0,0,-1]
# XZ面 設(shè)置 [0,1,0] [0,-1,0]
# ZY面 設(shè)置 [1,0,0] [-1,0,0]
# 我們?cè)诮⒚鏁r(shí),并沒(méi)有指定方向
# 但我們發(fā)現(xiàn):Z軸不為 0 是 [0,0,1] 為 0 時(shí)是 [0,0,-1]
# 這個(gè)與存儲(chǔ)與取出機(jī)制有關(guān),實(shí)際應(yīng)用中 正負(fù)影響不大
puts test_face.normal
# 面朝向反向
reverseFace = test_face.reverse!
# 面的面積 (這里的單位 10 * 10 平方英寸)
puts reverseFace.area
# 組成面的線對(duì)象數(shù)組
puts reverseFace.edges
pt = [5,5,-10]
# 對(duì)于 Face 與 點(diǎn) 關(guān)系的判斷
result = reverseFace.classify_point(pt)
puts result
# 官方提供了一個(gè)枚舉類型
# 點(diǎn)在面里
if result == Sketchup::Face::PointInside
puts "#{pt.to_s} is inside the face"
end
# 點(diǎn)在端點(diǎn)上
if result == Sketchup::Face::PointOnVertex
puts "#{pt.to_s} is on a vertex"
end
# 點(diǎn)在邊線上
if result == Sketchup::Face::PointOnEdge
puts "#{pt.to_s} is on an edge of the face"
end
# 點(diǎn)與面處于同一平面
if result == Sketchup::Face::PointNotOnPlane
puts "#{pt.to_s} is not on the same plane as the face"
end
平面拉升
# pushpull 推的方向是按照?qǐng)D形的normal方向
# face 沒(méi)有對(duì)于向量進(jìn)行定義,所以pushpull按照的是face的normal值的反向
reverseFace.pushpull 10
# 推一個(gè)圓柱體
circle = entities.add_circle [0,0,40],[0,0,1],5
circle_face = entities.add_face circle
circle_face.pushpull 20
# followme 進(jìn)行3D模型構(gòu)建
# 使用followme 對(duì)模型進(jìn)行環(huán)切
cut_face = entities.add_face Geom::Point3d.new(0,0,10),Geom::Point3d.new(2,2,10),Geom::Point3d.new(0,0,8)
cut_face.followme reverseFace.edges
# followface
followFace = [
Geom::Point3d.new(100,95,-5),
Geom::Point3d.new(100,105,-5),
Geom::Point3d.new(100,105,5),
Geom::Point3d.new(100,95,5)
]
followFace = entities.add_face followFace
# 跟隨的界面一定是在路徑的一端
followFace.followme curveline