python

Mar
13

Interesting Python Shells

I've found several very interesting and active python shells. Each has it's own strength and the most often mentioned feature is syntax highlight, auto-complete and function attributes info.

Here they are:

IPython

ipython

bpython

bpython

DreamPie

dreampie

Interactive server-side Python shell

shell.appspot.com

Jan
27

TIFF file handling in PIL

# TIFF is a flexible, if somewhat aged, image file format originally
# defined by Aldus. Although TIFF supports a wide variety of pixel
# layouts and compression methods, the name doesn't really stand for
# "thousands of incompatible file formats," it just feels that way.

thousands of incompatible file formats, 這個的確有挖苦到 TIFF 這個格式 XD

Feb
8

Maya Scripting: MEL V.S. Python

day fourty: the endless fight by petite corneille @ flickr

Maya scripting 現在有了 MEL 與 Python 可供選擇,對於大部分的 Maya 使用者來說,這是件微不足道的事,但對於天天使用與撰寫 Maya scripting 的人來說(ex, TD?!)(或保守一點的說,很有機會被要求寫點程式的人),這重要極了。

個人淺見,Python 與之後由 Luma Pictures 的 Chad Dombrova 所推出的 pymel (0.7.8),是 Autodesk 買下 Maya 後,在 8.5 所做的 features 裏頭,最最重要的一點了。好吧,我是以 RD/TD/SD 人員的角度來看事的,請先暫時原諒我這有點狹隘的說詞,然後接著繼續看文章。

Maya 8.5 發表以前,在 Maya 上頭工作的技術人員,除了和大家一樣要去了解與使用 Maya 以外(說真的,Maya 的學習曲線有點長,進入門檻有點兒高,以致於很多資訊系所的電腦圖學實驗室,都不容易利用這個工具來做點什麼,實在很可惜),可能還需要去了解一下 Maya ascii file format, Maya nodes, Hierarchy in a Maya scene file, Mel, Maya C++ API, 技術名詞, …好不容易似懂非懂一些東西後,就是寫些程式來試試看。

舉些個例子。如果你想寫個可以自動幫你架好骨架的 joints 與一些 IK/FK 的設定的東西,你可以利用 Mel 來做到;如果你希望有一個特別的材質球,它會在你的模型有互相穿刺時,用紅色這種非常鮮豔且帶警告意味的顏色來提醒人,你可以用 C++ API 寫個 plugin 來提供一個特製化的 material node;如果你想用透過一個放在 Maya shelf 上頭的按鈕,讓 lighter 可以很快的下算圖指令的話,那你可以使用 Mel 外加 RMS/MtoR 提供的指令來做到;如果你想利用 locator 來實作 instance(一些 Maya instance 無法做到的情況下),同時要讓這個 locator 秀出原 reference model 的各種動態的話,你得用 Maya API 外加對於 Maya node 的了解(當然,你也可以使用 billboard(sprite) 做到);…

事情就是這麼複雜,以致於要訓練出一位可以依靠的 3D/CG TD,實在很花時間。如果很不幸地又沒辦法好好留住他,或是他個人不夠積極與拼命學習的話,可能浪費了兩三年,然後拍拍屁股走人,什麼都沒有留下來!!

這邊我們也許應該換個觀點,先來想想:「為什麼 Maya 把事情搞得這麼麻煩?」

Feb
5

把 MSN 放進 Maya 裏頭?!

Maya ChatWin by Chris Chia

Chris Chia 在他的 blog 發表了一篇 Maya ChatWin v0.6.1 (100% Built on Python),完成了一件非常有趣的事:在 Autodesk Maya 裏頭實作了一個 MSN 外加一個遠端的 script editor 出來。

這個 Maya ChatWin 運作起來就像 MSN,只是聯絡人清單是來自於同網段(內網)的電腦,目的…大概是讓你工作到一半有個小問題,想找人問一下時使用的吧,我想基本立意應該是這樣。它另外比較有趣的功能是,可以直接遠端傳送 mel 或 python script,所以可以做到遠端執行一些 fixing scripts 之類的。這功能目前是單向的,不過也夠應付 supporting TD 使用。

我個人覺得,MSN(或更正確一點的說法是 instant messenger)這功能要很實用,得看大家的使用情況,畢竟當你已經有一個更好用的 IM 時(ex, MSN, Pidgin, Adium, ...),你並不會覺得有需要再有一個 IM。不過當這個 IM 與 remote mel/python scripting 結合時,就顯得有價值一些了。

digimax_im_list對於 IM,太極是試著使用自行架設一個 XMPP server(by ejabberd),client 預設是使用 Pidgin,使用率其實不高,原因之一是我們還不是很了解怎麼好好善用這個 IM,有時亂用反而容易影響到其它人,另一方面是,有些情況還不如直接走過去當面問或聊來得好。RD/TD 對於 IM 的使用率高一些,尤其在於一些 scripting writing 或 tool 使用方法之類的,這些問題的答案常常是一兩行 commands,就很適合。

Maya 預設的 commandPort 目前只支援 mel script,所以這個 Maya ChatWin 可以支援 python script 是個非常吸引人的工作,就我所知,有不少 studio 的 TD 都非常渴望 Maya 有這個功能,相信不久的未來 Autodesk 會加入才是。

PS. Koichi Tamura 有寫了一個 Python CommandPort 的玩意兒,而且是 open source 的,有興趣的人可以去玩玩。

PS II. ejabberd 與 pidgin 的網址,最後頭都是 im 也,實在很有趣 ^^

Jan
20

Python Puzzle

Interesting subsequent comparison:

>>> a = 1
>>> b = 10
>>> c = 100
>>> a < b < c
True
>>> (a < b) < c
True

The following 2 code snippets are equal, which can explain why the above code works in that way.

if a < b < c:
    doSomething()

if (a < b) and (b < c):
    doSomething()

How about booleans? Is True bigger than False?

>>> True < c
True
>>> True > c
False
>>> False < True
True
>>> False > True
False

And I just noticed that True / False are 1 / 0 in one implementation of CPython 2.5?! According to official document, the True & False are special type called "bool" which should not be used to compare against other type.

>>> False == 0
True
>>> True == 1
True
>>> True == 2
False
>>> False == 2
False

How about is?

>>> None is None is None
True
>>> (None is None) is None
False
>>> None is (None is None)
False

Because is is also a comparison (not a binary operator)!!! It might be not that intuitive to figure out this situation especially when you are programming some logical expression with if.

Let's do play again True and False and I believe this time you can get it through.

>>> True is True is True
True
>>> False is False
True
>>> (False is False) is False
False

Check this if you wanna get more idea about Python's expression.

Dec
25

Nuke scripting 初體驗:Nuke + Alfred

大約三週之前,開發 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 實在友善太多了。

Syndicate content