Saqoosha

WordPress でマルチリンガルなサイトを作るの巻

Blog

FLARToolKit のおかげで日本国外からのアクセスが増えてるわけです。でー、いちおう FLARToolKit 関連についてはつたない感じではあるものの英語で書いてたのだけど、日本語と英語混ざってるのもアレですよねえと思いまして。分けました。てら子のこととかは日本人だけ読めばいいですし。なんで英語版ねーの的なこと言われるし。

・・・

本題。作り方。

1. qTranslate っていうプラグインをいれます。最新版の WordPress 2.7 以上じゃないと入れれない。入れるのは簡単。2.7 なら管理画面の Plugins → Add New → qTranslate で検索 → Install → Activate。

2. 言語の設定する。Settings → Languages が qTranslate の設定画面。デフォルトでは日本語がないのでページ下の Add Language てとこから追加。以下入力内容。

Language Code: ja
Flag: jp.png (ま、べつになんでもお好きなのをどうぞ)
Name: Japanese
Locale: ja_JP(どこでつかってんのかよくわからない)
Date Format: %Y/%m/%d (2009/01/01 みたいな。お好みで。)
Time Format: %H:%M:%S (12:34:56 みたいな。お好みで。)
Not Available Message: Sorry, this entry is only available in %LANG:, : and %. (この言語で記事を書かなかったときに出るやつ、だけど、そんな状況ってたぶんないから Example として書いてあるやつをコピペ。)

追加したら Default Language を Japanese に。あとデフォルトで Enable になってる中文とかを Disable に。(書くんならそのまま)

設定は完了。簡単。

3. ブログを書く。
WordPress 上で書くんなら、記事編集画面に Japanese と English のタブが増えてるのでそれぞれ切り替えて書けばよろし。タイトルも両方の欄があるのでそれぞれ書く。ecto とかのエディタを使う場合は、それぞれの言語用の記事を


<!--:en-->
hogehoge
<!--:-->
<!--:ja-->
ほげほげ
<!--:-->

みたいなコメントタグで区切る。

はい完成。

ああ、まだ書くことあった。。
FeedBurner で RSS 配信してる場合、FeedBurner FeedSmith プラグインを使って転送してると思うのだけど、これが qTranslate と当たる。FeedSmith いれてなければ自動的にそれぞれの言語で RSS が吐かれるのだけど、いれてると両方とも同じ FeedBurner の URL に転送されちゃう。のでうちの場合は、FeedBurner に Japanese と English の 2 つの RSS を登録して、FeedSmith のプラグインを改造して、、、って疲れたので一旦終了。詳細聞きたいひといたらリクエストしてくだちい。

Papervision3D で穴の中身だけレンダリングする

BlogFLARToolKit

英国から質問 1 ついただきましたー。「年賀サイト見たんですけど FLARToolKit で穴あいたような表現ってどうやるんですか?」ですって。

そうねえ。見てるだけだとなんてことない普通の穴なんだけどいざ FLARToolKit (Papervision3D) でやろうとすると難しいっていうね。

何も考えずに穴の内側だからつって法線内向きの Cube を作るとこうなる↓

2009010801-Cubichole1

中が全部見えちゃってる。まあそらそうだ。隠すべきオブジェクトがない。どこを隠さないといけないかつーと↓の絵でいうグリーンの部分。

2009010802-Cubichole2

ここを消せば(アルファ値を 0 にすれば)見えるべき穴の中身だけが残るはず。んでどうやるかってーと↓こういう ColorMatrixFilter を使う。

new ColorMatrixFilter([
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
1, -1, 1, 1, 0
])

うえの絵で緑色 (0x00ff00) を使ったのは説明用っていうわけじゃなくってこのフィルタで抜くための色なのでした。このフィルタは 0x00ff00 に近い色ほどアルファ値が低くなるっていうやつ。んでこれを適用しするとこうなる。

2009010803-Cubichole3

できたー、穴の中身だけできたー。(あー背景色もっと暗いのにしとけばよかったみにくいなでもめんどいのでそのまま。)ん、消さないといけない部分の緑色ってのは ColorMaterial(0x00ff00) を設定した Cube の側面だけのやつをちょうど穴オブジェクトと同じ位置に同じサイズで置けばいい。つーわけでそのへんひととおり組んだ動くデモソース

この方法はあれですねブルーバックで抜くやつみたいな、そんな感じね。んでブルーバックで抜くのと同じような問題がこれにもあって。デモで Stage Quality を HIGH にするとわかるんだけど、レンダリング時にアンチエイリアスをかけるとグリーンのエッジが残るのね。あとグリーン系のオブジェクトは透けるっていう。なのであの年賀サイトではまあデザイン上の理由の法がデカいんだけどグリーンは使ってない。

ってなところで寝る。英語版は明日書こう。

Categories: FLARToolKit

Comments (19)

  • Timbo
    Great tutorial, thanks for explaining!

    I worked it out and fixed it in my FLAR project.. only the green cube becomes white. An idea?
    And how do you manage dat de cube is 'under' the marker, or at the same level as the 'marker'. Z property won't work with correction.

    And the marker image capturing, like in your NY video..Has it something to do with the 'FLARRgbRaster_BitmapData' class?

    Thanks Saqoosha, great work.
  • Saqoosha
    Timbo,
    hmmm, I cannot understand the result what you got...
    I uploaded all of source code of New Year Greeting site.
    http://saqoosha.net/en/2009/01/08/1677/
    Please try to read that source code.
  • Timbo
    Sweet code, got the cube working now. Only trying to find out how to set the depth of the cube.

    Thanks already!
  • Kountz
    Thanks for releasing the code Saqoosha!!! Awesome work!
  • ReDrUm
    Hey Sagoosha.
    Great example! I think I'm having the same issue that Timbo was referring to. When I compile your source code the example works except that the ColourMatrixFilter replaces the green with the stage background colour rather than whatever is underneath (such as your background bitmap). Any idea's what might cause this?
    Cheers.
  • ReDrUm
    Actually nevermind, I figured it out with the help of Timbo :)

    For anyone else experiencing the same issue, you need to set the filter on your pv3d viewport instead. this.viewport.filter = [...] rather than this.filter=[...].

    Again, cheers for the great example! :D
  • Felipe Barone
    Yup, great sample! i was wondering about that when i first saw it, but i was thinking of something much more complicated!
  • Javier Patiño
    Hello..nice work...I have the same problem but I cant set the filter for the viweport because I dont use viewport..what can I do?..the green color now is black color.
  • Rob
    Hi All,

    Javier I had the same problem. I couldn’t get the effect because I had no viewport… I’m not a coder but I’m interested in AR so I’ve started to using and hacking templates (sorry developer dudes). So I guess you are same kind as me, and I guess you are using the same (or at least similar) template as me. And I have the solution for you:

    So basically you have a viewport just you don’t know about it. As I see now this whole thing is not working without viewport. So if you see the 3d object then you have viewport 

    Ok, where is that than? The template what I’m using is built up from different external ‘as’ files. In the main ‘as’ file there is no viewport definition, but it is defined in another as file (PV3DARApp.as for me).

    Find your other as file with the viewport definition. Check for lines like:

    import org.papervision3d.view.Viewport3D;

    and

    new Viewport3D(320, 240

    and things like that.

    If you find that file than you are almost there.

    Now you have to “hack” this file. Put this code to the “import section”:
    import flash.filters.ColorMatrixFilter;

    Then search for viewport related lines like

    this._viewport = this._base.addChild(new Viewport3D(320, 240)) as Viewport3D;
    this._viewport.scaleX = 640 / 320;

    etc.

    Put this code there:

    var myElements_array:Array = [1, 0, 0, 0, 0,
    0, 1, 0, 0, 0,
    0, 0, 1, 0, 0,
    1, -1, 1, 1, 0];
    var myColorMatrix_filter:ColorMatrixFilter = new ColorMatrixFilter(myElements_array);
    this._viewport.filters = [myColorMatrix_filter];

    And that’s it. I hope I helped the AR community with this.

    BTW thanks for all the developer dudes to put together this fantastic piece of flash!
  • Rob
    Oh one more thing.

    Just a designer solution again :D So coders skip this message ;)

    If you don’t understand this coder language, I will translate it for you:

    This whole thing is about using a specific colour as a simple green screen. This case the colour is a specific green colour (00FF00). So whatever is 00FF00 on screen will be transparent.

    Ok, why is it good for us? Hehe, ok I have a question: what if the hole is not cubic? What if it’s not a simple mesh but a complicated one? Follow this way and you won’t have a problem:

    Use your 3D modeler tool as always. In your texture file find some free space and fill it with 00FF00 colour (just a small area needed).

    Create the hole, the shape is doesn’t matter. This will be the “inside” of the hole. Texture it as you want. Than duplicate this object and turn it inside out (reverse vertex order or something like that). This will be the ”outside” of the hole. Now texture it but this case use that small green area on it. And there you go, with the code above it will be transparent even if the shape is a complicated one.
  • Rob
    Hi Guys,

    Some additional information to the “hole” effect:

    If your hole is not perfectly “transparent” but you can see an almost invisible semi transparent green box “below” your marker (around your hole)…
    I bet you used jpg format for the green texture. I’ve no idea why but if I’m exporting the green texture from photoshop to a jpg file, the 00ff00 colour is changing to 00ff01. And that’s why is that semi transparent green box is there around your hole. Just use another format (png) and that unwanted green box will disappear.
  • Lucas
    thanks, Rob. Really helped me.
  • John
    Awesome!
    Successfully implemented it in my own project.
    And the input from Timbo and ReDrUm was of great help.

    Saqoosha, your a true ActionScript hero.
  • Olivier
    Amazing work Saqoosha. Thanks again for all the examples and sources.
    Merci mille fois.
  • draven
    Hello guys, is there any way to remove the green edge around the hole?

    Thanks for the awesomeness Saqoosha!
  • dimitrios k
    Hello there!
    I have a question.
    How can i make the hole in a 3d program like 3dsmax and export it to .dae format?can i make this or only in pv3d?
    thank you and greetz from greece
  • tetsuo
    idem dimitrios k
    I have the same question.
  • HarvesteR
    @dimitrios k:
    you can, in fact, that's how I did it... it doesn't really matter if the green is from a texture or just a color material...

    What I did was create a material in Max, with full green diffuse, then I also set the auto-illumination (emmissive) color to full green, to eliminate the shadowing, thus making it a solid green color.

    then I just applied it to the model mask, exported it with OpenCollada (that's a thing, since Autodesk's Collada plugin sucks), and put it into Flash...

    one thing I also found out, is that you can apply that filter to just the object with the mask (aka, the hole), provided it's using it's own container. this is useful to prevent problems like semi-transparent objects outside the hole showing the green behind their alphas...

    the drawback is that this approach creates z-sorting problems if you have objects that should come out or go into the hole at some point... since depth-sorting will be done on a container level, your objects will either be entirely behind or entirely over the hole, but never actually inside it.

    But I imagine this could work well for most applications...

    Cheers
  • Leonidas
    Hi Saqoosha,
    A bit off topic but I saw recently your augmented reality cloth video on vimeo (http://vimeo.com/2883790) and was wondering if you can release/share the source code and files for it. Very impressive work and would definitely like to learn how to do similar things.
    Many thanks,
    Leonidas

年賀サイトのソースコードを公開したよ

Blog

あの年賀サイトのソースコードをアップしときました。お年玉あげるー。
これ→ http://09.aid-dcc.com/aid-nenga2009-source.zip

GPL はー、リクエストがあったときにソースコード出せばいいって感じなのだけど、どうやって作ってるんかつー質問がいくつかきてて何もなしに答えるのがめんどいので先に出しておこう、とか、そんな感じ。

中の README にも書いておいたですがこのアーカイブに含まれる全てのコードに GPL が適用されてるので、このソースコードを元に新しく何か作る場合、それも GPL ってことになります。ご注意を。

ああそうだ、ここだけの話、ちょっとメモリリークしてんだよねー。誰か直してくだちい。

追記(1/18 18:44):前にも問い合わせをもらってたんだけどなんかよくわからなくて放置してたヤツ。パブリッシュしても真っ白でなんにもはじまらない問題。昨日のてら子でようやく気がつきました。これ、アレです。そうでしたそうでした。ちょうどこのサイト作ってるときにエラー出まくってて、調べたのでした。家の MBP でも真っ白で意味わからなかったのだけど、メモリ増やしたら正常にパブリッシュできた。というわけで、お試しくだせい。