2009年7月6日 星期一

(12)利用python產生rib並使用*.ptc



~你為什麼在這裡?~


最近在想....該怎麼釐清"依賴"跟"無賴"的感覺。昨天看完了 "生命咖啡館(The WHY ARE YOU HERE CAFE')" 的前面三章,已經很久沒有放慢速度,一字一句的好好看本書了,特別是這種勵志類的書。"我為什麼會在這裡?", 這問題我還沒有個較明確的頭緒~想的到的是"因為我喜歡computer graphic阿"、"因為我喜歡看動畫阿"、"因為我很幸運可以把興趣當職業阿"、"因為我有想要珍惜的人阿"、"因為我宅阿"...etc,但仍是如 書上所敘述,我有一份喜歡的職業,也有一些好朋友,生活還算如意~但是內心深處,總還是有種難以言喻的感覺。昨天看完前三章後,感受到這本書有種讓我想一 口氣看完的吸引力。但還是闔上了書本,覺得這種書就是要看一部份,然後從生活中累積一些感觸後,再看一部份....慢慢的看完,儘管我真的很想一口氣看完 它 XD.


有幾句話真的有被觸動到~

有的時候,換個角度來看事情,確實會挺有幫助的

如果誠實面對自己,我會承認這些年來,我一直在質疑自己的人生,是否還有比我目前所知更深刻的一面

有時候你就是不知道自己早已準備好,可以盡情享受生命中的完美時刻

------------囉哩八嗦分隔線------------
RMS2.0新加了PRman for python,顧名思義,就是它有提供module(prman)讓使用者可以在python使用PRman的API。整個手癢想小小測一下,所以就以上一篇網誌當範例來玩一下,然後整理上來囉。以下是玩出來的python code:

import prman

ri=prman.Ri()

def ptc_RIB(ri):
 rendertarget = "ptc_RIB.rib"
 ri.Begin("ptc_RIB.rib") # set rendertarget to ri.RENDER to render pixels
 ri.Display("helloworld.exr", "it", "rgba")
 ri.DisplayChannel("color _ooxx")
 ri.Format(512,512,1)
 ri.Projection(ri.PERSPECTIVE, {ri.FOV: 60}) # standard Ri tokens are available

 ri.Rotate(180, 1,0, 0)
 ri.Rotate(0, 0,1, 0)
 ri.Translate(0, 0.1, -8)
 ri.WorldBegin()

 ri.Attribute( "cull", {"hidden": 0}) # don't cull hidden surfaces
 ri.Attribute( "cull", {"backfacing": 0}) # don't cull backfacing surfaces
 ri.Attribute( "dice", {"rasterorient": 0}) # view-independent dicing !
 ri.Attribute( "visibility", {"int diffuse": 1}) # make objects visible to rays
 ri.Attribute( "visibility", {"int specular": 1}) # make objects visible to rays

#RenderMan Interface會在RIB中的Lights(ex:spot light), Objects(ex:sphere) 和 Archives 上綁
#一個ID,但我們可以自己給他我們想要的ID名稱,來將RI給它的蓋掉。如下紅色部份的寫法
 ri.LightSource("spherelight", {ri.HANDLEID:"sl1", "point from": (-2.8, 2.0, 2.5),
 "float radius": 0.5, "float intensity": 2, "float samples": 64.0, "float falloff": 0.5})

 a="area_illum_tpt.ptc"
 b="_ooxx"

#在給shader的引數設定數值時,跟C/C++不同的是,PRman for python是要寫成如下面的型
#式(綠色部份)
 ri.Surface("bake_direct_irrad", {"string filename": a,"string displaychannels": b})
 ri.Geometry("teapot")
 ri.WorldEnd()
 ri.End()

ptc_RIB(ri)


下面是上面那段code,經由 RenderMan client library產生出來的code(RenderMan client library是把含有RenderMan Interface的code,output成rib語法的東西):

##RenderMan RIB
version 3.04
Display "helloworld.exr" "it" "rgba"
DisplayChannel "color _ooxx"
Format 512 512 1
Projection "perspective" "uniform float fov" [60]
Rotate 180 1 0 0
Rotate 0 0 1 0
Translate 0 0.1 -8
WorldBegin
Attribute "cull" "hidden" [0]
Attribute "cull" "backfacing" [0]
Attribute "dice" "rasterorient" [0]
Attribute "visibility" "int diffuse" [1]
Attribute "visibility" "int specular" [1]
LightSource "spherelight" "sl1" "float falloff" [0.5] "point from" [-2.8 2 2.5] "float samples" [64] "float radius" [0.5] "float intensity" [2]
Surface "bake_direct_irrad" "string filename" ["area_illum_tpt.ptc"] "string displaychannels" ["_ooxx"]
Geometry "teapot"
WorldEnd

render出來的圖(左)以及*.ptc(右)分別如下:

















沒有留言:

張貼留言