路徑
個人理解,路徑實質上是多條連續的線段進行組合起來具備某些特殊意義,最主要的作用還是爲了讓自定義的截面進行跟隨形成一些我們想要的模型。
代碼演示會更直接理解一點:
model = Sketchup.active_model
entities = model.entities
sel = model.selection
pt0 = Array.new()
# 原點用數組(矩陣)表示
orignPoint = Array.new(3,0)
# 繪製簡易曲線路徑
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
繪製面:
# 新建面的頂點數組
facePointArr = [
[0,0,10],
[10,0,10],
[10,10,10],
[0,10,10]
]
test_face = entities.add_face facePointArr
# 此時我們知道 entities 數組中就有了 5個實體 1曲線、1面、4線
# 選中一個面
# 提取出這個面的頂點
sel.add test_face
verticesArr = sel[0].vertices
for item in verticesArr
puts item.position
end
補充關於方向:
# Sketchup 某些矩陣特定意義
# X 軸 :[1,0,0] [-1,0,0]
# Y 軸 :[0,1,0] [0,-1,0]
# Z 軸 :[0,0,1] [0,0,-1]
# 某些函數(add_circle、add_nogn)需要指定某些面進行繪製,就要設置normal 參數
# XY面 設置 [0,0,1] [0,0,-1]
# XZ面 設置 [0,1,0] [0,-1,0]
# ZY面 設置 [1,0,0] [-1,0,0]
# 我們在建立面時,並沒有指定方向
# 但我們發現:Z軸不爲 0 是 [0,0,1] 爲 0 時是 [0,0,-1]
# 這個與存儲與取出機制有關,實際應用中 正負影響不大
puts test_face.normal
# 面朝向反向
reverseFace = test_face.reverse!
# 面的面積 (這裏的單位 10 * 10 平方英寸)
puts reverseFace.area
# 組成面的線對象數組
puts reverseFace.edges
pt = [5,5,-10]
# 對於 Face 與 點 關係的判斷
result = reverseFace.classify_point(pt)
puts result
# 官方提供了一個枚舉類型
# 點在面裏
if result == Sketchup::Face::PointInside
puts "#{pt.to_s} is inside the face"
end
# 點在端點上
if result == Sketchup::Face::PointOnVertex
puts "#{pt.to_s} is on a vertex"
end
# 點在邊線上
if result == Sketchup::Face::PointOnEdge
puts "#{pt.to_s} is on an edge of the face"
end
# 點與面處於同一平面
if result == Sketchup::Face::PointNotOnPlane
puts "#{pt.to_s} is not on the same plane as the face"
end
平面拉昇
# pushpull 推的方向是按照圖形的normal方向
# face 沒有對於向量進行定義,所以pushpull按照的是face的normal值的反向
reverseFace.pushpull 10
# 推一個圓柱體
circle = entities.add_circle [0,0,40],[0,0,1],5
circle_face = entities.add_face circle
circle_face.pushpull 20
# followme 進行3D模型構建
# 使用followme 對模型進行環切
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