Drake's Weblog

python

2 minute read

Sometimes you need to delete unknown nodes in a Maya scene. You can do it in the following python snippet.
from pymel import * def deleteUnknownNodes(): # 2 things to take care of: # 1) you can't delete nodes from references. # 2) "delete" will delete all children nodes (hierarchy) in default. unknown = ls(type="unknown") unknown = filter(lambda node: not node.isReferenced(), unknown) for node in unknown: if not objExists(node): continue delete(node) Compare it to the MEL way:

2 minute read

大約三週之前,開發 Nuke 的 The Foundry,由 CEO, Bill Collis, 偕同技術人員 Matt Plec 與兩位美麗的華裔女士來台,參與了 SIGGRAPH 2008 Taipei Chapter 的活動,會後立即趕來太極,面對太極的幾位 compositors,給了一個更加深入一點的 talk + demonstration。
Matte 就 Nuke 與 Ocula 做了不少的 demo,像是 3D scene/model/camera importing by FBX、multi-channel manipulation、customized gizmo、stereoscopic vector viewing by Ocula、stereoscopic offset、stereoscopic filein handling…其中我最感興趣的,是 Nuke 的可程式化能力。
Nuke 5 發佈的特色之一是對 Python scripting 的支援。根據我 k 了文件後的了解,幾乎所有在 Nuke 裏頭的操作,都可以使用 Python 來做到,於是乎,有很大的空間可以就「自動化」與「整合其它軟體或服務」做延伸上的開發。我對於這一點感到非常的興奮。相對於 Apple Shake 限制多多的 shake macros 與我們一直無緣拿到手的 Shake SDK,Nuke 對 programmer 實在友善太多了。
我立即寫了個 python script,做了點設定上的調整,在 Nuke 上頭多新增了一個 Digimax 的 menu,然後裏頭有個 Submit To Render Farm 的功能。目的是透過它來產生一個 alfscript 來,然後呼叫 alfred 把 nuke rendering 給送進 render farm。

1 minute read

Guido van Rossum 於 1991 年創造出 Python 這個 scripting language 時,應該是沒有料想到它的風行全球,更不可能會猜到 3D 軟體產業是多麼的愛戴這個語言:
Maya 在被 Autodesk 併購了後,於 2007 年年初釋出了 8.5 版,支援 Python 的環境。 相傳,原本和 Maya 拼得你死我活的 Softimage (不過現在和 Maya 成了親家了@@ 還真的是世事難料呀~)也早就有了 Python 的 binding。 台灣新聞台的最愛 Poser 軟體,2000 的 4.0 版支援 Python。 特效軟體界的傳說 Houdini(也是目前我知道最貴的軟體之一,不過據說 Massive 更貴 @@)於 2007 年投入 Python 的懷抱。 流體模擬(Fluid & Dynamic Simulation)界的第一把交椅 RealFlow 也在最近發表的 RF4 (?) 新增了對 Python 的支援。 因為與 Peter Jackson 的魔戒合作下問世的 Massive,一樣有提供 Python(不過也一樣是有 TCL)。 趁著被 Apple 收購的 Shake 不會有下一版,然後挾天子以令諸侯(啊,不是,是有 Digital Domain 當靠山)的 Nuke ,在今年(2008)推出 5.

2 minute read

Pymel solution:
def getSGFromMaterial(mat): mat = PyNode(mat) return mat.shadingGroups() The following is the original article and mel codes by Bryan Ewert.
To determine which Material is associated to a Shading Group, get a list of all connection from the Material’s “.outColor” attribute. Iterate this array to find all Shading Groups. The 『nodeType』 command will identify a Shading Group with the string “shadingEngine”.
// //////////////////////////////////////////////////////////////////// // getSGFromMaterial // // Description: Returns the Shading Group set whose '.

1 minute read

今天聽莊永裕教授的 Digital Image Synthesis 課時,聽到一個 Cancellation Error 的東西,是個與 IEEE floating point 有關的「數值計算問題」。
投影片上如是說:
Cancellation error: devastating loss of precision when small numbers are computed from large numbers by addition or subtraction.
寫了個簡單的 c 程式親身試驗一下。
void main(){ double x1 = 10.000000000000004; double x2 = 10.000000000000000; double y1 = 10.00000000000004; double y2 = 10.00000000000000; double z = (y1-y2)/(x1-x2); printf("%f\n", z); } // output: // # 11.500000 接著我在想,Python 會不會有這個問題呢? 結果試了一下…一樣!! 看來 CPython 的 number 這個 type 真的是用 double 實作的 :o

1 minute read

Quick Answer:
from pymel import * # Is the object.attr a source of a connection? len(object.tx.inputs()) > 0 # Is the object.attr the destination of a connection? len(object.tx.outputs()) > 0 # List an object.attr's source connection, meaning, list the input connection. # This will return a single object.attr. object.tx.inputs() # List an object.attr's destination connection, meaning, list the all output connections: # This could return multiple object.attrs. object.tx.outputs() # In other words, you can just use inputs() and outputs() to get if there is a connection # (source or destination), how many connections there are, and what they are!

3 minute read

The quick answer is as below:
from pymel import * filter( lambda n: 'light' in n.classification(), ls(sl=True, dag=True, leaf=True)) In pymel’s google group, there are 2 people giving different opinions for this and the following are from their post:
take out the ‘sl=True’ by using pymel’s “selected()” function by Ofer Koren
from pymel import * filter( lambda n: 'light' in n.classification(), selected(dag=True, leaf=True)) Doing it through the API requires more code but is considerably faster by Dean Edmonds

2 minute read

話說在前頭,這是一篇非常的無聊,可以被當作火星文的 blog,所以如果你是來看裸女或 3D/CG 的,請離開吧…
原文
2007 年, 遊俠沈崴經過 Python 在 Mangbar 的營地, 賢者 Tomz 和 Andelf 邀請他向眾人敘說他在各地的見聞, 於是便有了這本歷史書。
第一章、世界的形成 初, 只是一片混沌。大師圖靈沉睡在這片漫無邊際的黑暗中。先知書《編程之道》說, 有一天, 大師夢見自己變成了一台機器, 渾然不知是機器夢見了自己還是自己夢見了機器。他醒來, 天地就分開了。無數巨大的計算機從天而降, 秩序由此建立。
過了一千年, 第一批人類從原始的混沌之夢中醒來。沒有人知道大師的去處, 他們好奇地圍繞在那些巨大的機器周圍, 他們相信這些機器是世界秩序的源泉並奉之為神明。太古的機器也許諾給他們無窮的力量, 幫助他們把世界變得更為繁榮。
第二章、諸神的黃昏 百年後, 當世界變得足夠繁榮的時候, 那些來自於遠古的巨大機器就離開了。這時第二批人類才從混沌中醒來, 他們對過去一無所知, 以為這個世界本應如此。他們用泥土和金屬塑造了自己的偶像, 取名微機, 並頂禮膜拜。
們對微機的狂熱, 讓最初的聖人們非常憂慮, 又感到無能為力。在意識到人類將不可避免地滑向混亂的深淵之後, 他們建立了自己的神殿, 將最後的信仰和古老的力量保護起來。異教徒嘲笑他們, 並向他們發動了聖戰。那些異教徒人數眾多, 守衛陣營也發生了叛變和分裂, 聖人們不能抵抗, 他們離開神殿, 在世界各地建立了諸多被稱為學院的據點, 來自於太古的神聖力量在那裡得以保存下來。
後, 在人類的狂熱中, 世界經歷了一段混亂不堪的歷史, 在戰火中誕生了許多人類最為古老的王國。一切都平靜下來, 世界被微機統治。但是先知不屑地說, 世界其實仍然運轉在太古的神力之下, 人類被自己的幻覺所欺騙。在合適的時候, 諸神會回來修復大地的傷痕。
第三章、新大陸的誕生 過了八十年, 關於新大陸的傳言開始流傳。兩年後, 學院 MIT 開始向海外探險, 他們最終發現了一塊全新的大陸。這是一塊神秘的未知之地, 所以他們把它命名為 X。不久之後, 貪婪的人類蜂擁而至, 傳說在那裡他們看到了巨大的彩色雲彩, 於是, 人們將新大陸重新命名為 GUI。

Recent posts

Categories

About

You're looking at Drake's words or statements. All opinions are my own.