[問題] 請問有關如何自動抓邊(SketchUp裡的Ruby)

作者: pugboy   2024-05-13 10:33:30
不好意思想請問各位大大先進
小弟目前想把SketchUp的圖檔匯入到Unity裡
但是因為Unity的問題所以會缺少SketchU原本的一些邊的線條
所以想在SketchUp裡就把一些單獨的邊直接轉成3D物件
找到了可以在SketchUp裡寫Ruby讓他自動轉成3D物件
但是在自動抓邊我卡住了
我抓不到門的垂直的邊,只抓到平行的邊
想請問各位大大先進要如何改寫才可以抓到門的平行跟垂直的邊呢?
謝謝!
如下圖
https://lurl.cc/43z2D
我的程式碼如下:
# 定義一個方法來遞迴搜尋並抓取單獨的Edges
def collect_lonely_edges(entities)
edges = []
# 迭代所有實體
entities.each do |entity|
if entity.is_a?(Sketchup::Edge)
# 檢查這條 Edge 是否與任何面相連
connected_faces = entity.faces
edges << entity if connected_faces.empty?
elsif entity.is_a?(Sketchup::Group) || entity.is_a?(Sketchup::ComponentInstance)
# 如果是群組或組件,遞迴搜尋其子實體
edges.concat(collect_lonely_edges(entity.definition.entities))
end
end
edges
end
# 抓取場景上所有單獨的Edges
lonely_edges = collect_lonely_edges(Sketchup.active_model.entities)
# 將找到的Edges標記為選取狀態
model = Sketchup.active_model
model.selection.clear
model.selection.add(lonely_edges)
# 輸出Edges的數量
puts "共找到 #{lonely_edges.length} 條單獨的Edges,已標記為選取狀態"

Links booklink

Contact Us: admin [ a t ] ucptt.com