我有一個(gè)夢(mèng)想
如果能在地基內(nèi)種建筑,那是多么美妙的一件事兒,曬曬太陽(yáng)吹吹風(fēng),方案就生成了~ ▼
雖然,上面只是我做的一個(gè)概念圖,但是,整天埋頭畫(huà)圖的建筑師是否已經(jīng)忽略了身邊事物的發(fā)展?AI設(shè)計(jì)其實(shí)已經(jīng)在我們身邊,它如同BIM,VR設(shè)計(jì)一樣席卷而來(lái)??赡荃怎咱勠劊欢〞?huì)來(lái)。
計(jì)算機(jī)替代設(shè)計(jì)師已經(jīng)不可避免,特別是對(duì)大多數(shù)做重復(fù)勞動(dòng)的繪圖員而言,更是如此。學(xué)會(huì)編程將和使用計(jì)算機(jī)一樣變?yōu)榇髣?shì)所趨。
盡管不是編程專(zhuān)業(yè),但已經(jīng)有很多人在自學(xué)Ruby、Python等腳本語(yǔ)言,工作和生活上,用來(lái)爬蟲(chóng)、找方案爬資料,甚至在做設(shè)計(jì),協(xié)同軟件,非常方便。
SketchUp提供了豐富的Ruby API,讓我們不限于現(xiàn)有的工具和插件來(lái)做設(shè)計(jì)。更能直接通過(guò)API操控我們的模型。
如果把建筑的生長(zhǎng)封裝成一個(gè)方法,接受各種場(chǎng)地/時(shí)間/天氣/陽(yáng)光等參數(shù),那這樣生長(zhǎng)出來(lái)的建筑會(huì)是什么樣的呢?
自動(dòng)化建筑道阻且長(zhǎng),
需要各位建筑師的共同努力!!!
今天我們通過(guò)實(shí)現(xiàn)一個(gè)動(dòng)態(tài)時(shí)鐘,
來(lái)學(xué)習(xí)一些自動(dòng)化操作模型的基礎(chǔ)知識(shí)。
?動(dòng)態(tài)時(shí)鐘▼
思路分析
1、繪制表盤(pán)和表針
2、操控秒/分/時(shí)針旋轉(zhuǎn)關(guān)系
3、根據(jù)當(dāng)前時(shí)間初始化指針角度
?1、繪制表盤(pán)和表針▼ ?
對(duì)應(yīng)代碼:(由于頂點(diǎn)參數(shù)太占位置簡(jiǎn)化了表達(dá)式)
# 初始化模型實(shí)例
ent = Sketchup.active_model.entities
?
# 表盤(pán)/時(shí)針/分針/秒針組件
group_circle = ent.add_group
group_hour = ent.add_group
group_minute = ent.add_group
group_second = ent.add_group
?
# 表盤(pán)
circle = group_circle.entities.add_circle [0,0.1,2.2],[0,1,0],2.2
circle_face = group_circle.entities.add_face circle
?
# 時(shí)針/分針/秒針 P1 P2 P3 P4 代表指針面的4個(gè)頂點(diǎn)坐標(biāo)
face_hour = group_hour.entities.add_face Ph1,Ph2,Ph3,Ph4
face_minute = group_minute.entities.add_face Pm1,Pm2,Pm3,Pm4
face_second = group_second.entities.add_face Ps1,Ps2,Ps3,Ps4
?
# 時(shí)針/分針/秒針填色
face_hour.material = "black"
face_minute.material = "black"
face_second.material = "red"
?
# 表盤(pán)/時(shí)針/分針/秒針推拉出高度
circle_face.pushpull -0.1
face_hour.pushpull 0.015
face_minute.pushpull 0.015
face_second.pushpull 0.01
?2、操控秒/分/時(shí)針旋轉(zhuǎn)關(guān)系
首先我們需要知道怎么操控一個(gè)組件旋轉(zhuǎn),
查看官方文檔可以看到:
.rotation(point, vector, angle) ? Geom::Transformation
point = Geom::Point3d.new(10, 20, 0)
vector = Geom::Vector3d.new(0, 0, 1)
angle = 45.degrees # Return 45 degrees in radians.
transformation = Geom::Transformation.rotation(point, vector, angle)
通過(guò)Geom::Transformation.rotation(point, vector, angle)
即可創(chuàng)建一個(gè)旋轉(zhuǎn)動(dòng)效,
point
:旋轉(zhuǎn)中心點(diǎn)
vector
:旋轉(zhuǎn)平面向量
angle
:旋轉(zhuǎn)角度
我們先來(lái)試試操控一條線(xiàn)旋轉(zhuǎn)30度▼
對(duì)應(yīng)代碼:
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
?
# 旋轉(zhuǎn)30度
tr = Geom::Transformation.new [0,0,0],[0,1,0],30.degrees
ent.transform_entities tr, sel
那么怎樣才能讓組件1秒之后旋轉(zhuǎn)30度呢?
這時(shí)候我們需要用到延時(shí)動(dòng)畫(huà),
我們找一下文檔:
# Beep once after 10 seconds.
id = UI.start_timer(10, false) { UI.beep }
把我們的旋轉(zhuǎn)動(dòng)畫(huà)放到3秒的延時(shí)動(dòng)畫(huà)里面:
對(duì)應(yīng)代碼:
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
# 旋轉(zhuǎn)30度
tr = Geom::Transformation.new [0,0,0],[0,1,0],30.degrees
# 10s后開(kāi)始
(0..20).each do |i|
UI.start_timer(i+10,false){
ent.transform_entities tr, sel
}
end
再來(lái)分析一下時(shí)針/分針/秒針的旋轉(zhuǎn)關(guān)系:
秒針1秒旋轉(zhuǎn)6度
分針1 60秒旋轉(zhuǎn)6度
時(shí)針1 60 60 秒旋轉(zhuǎn)30度
# 設(shè)置秒針/分針和時(shí)針的一次旋轉(zhuǎn)角度
tr_ms = Geom::Transformation.new [0,0,2.2],[0,1,0],6.degrees
tr_h = Geom::Transformation.new [0,0,2.2],[0,1,0],30.degrees
?
# 設(shè)置1小時(shí)的持續(xù)時(shí)間
(0..60*60*1).each do |s|
# 9:10
UI.start_timer(s, false) {
group_second.entities.transform_entities tr_ms, group_second
puts "sec:"+s.to_s
}
UI.start_timer(s*60, false) {
group_minute.entities.transform_entities tr_ms, group_minute
puts "min"+s.to_s
}
UI.start_timer(s*60*60, false) {
group_hour.entities.transform_entities tr_h, group_hour
puts "hour"+s.to_s
}
end
如果想要指針更圓滑的旋轉(zhuǎn),
可以拆分一下角度,
比如每0.1秒旋轉(zhuǎn)0.6度。
?3、根據(jù)當(dāng)前時(shí)間初始化指針角度
最后我們來(lái)處理一下指針初始角度,對(duì)應(yīng)上當(dāng)前的時(shí)間。
在Ruby中可用Time.new來(lái)獲取當(dāng)前時(shí)間,
然后計(jì)算出指針到12點(diǎn)的夾角度數(shù)。
# 獲取當(dāng)前時(shí)間轉(zhuǎn)換成指針的初始角度
time = Time.new
tr_hour = Geom::Transformation.new [0,0,0],[0,1,0],time.hour*30.degrees
tr_min = Geom::Transformation.new [0,0,0],[0,1,0],time.min*6.degrees
tr_sec = Geom::Transformation.new [0,0,0],[0,1,0],time.sec*6.degrees
?
# 旋轉(zhuǎn)相應(yīng)角度
group_hour.entities.transform_entities tr_hour, group_hour
group_minute.entities.transform_entities tr_min, group_minute
group_second.entities.transform_entities tr_sec, group_second
至此我們就實(shí)現(xiàn)了我們的目標(biāo)效果。
最后我把這個(gè)時(shí)鐘做成了一個(gè)插件,
掃描下方二維碼,
關(guān)注公眾號(hào)Nicaicaiwo,
回復(fù) 時(shí)鐘,
即可免費(fèi)獲取