2008年11月20日
電光掲示板とかホワイトボードとか

上はJ-CASTニュースを拾ってきて右から左に表示する電光掲示板、下は各国語対応のホワイトボードです。
電光掲示板のニュース取得方法は外部サーバに置いたPHPスクリプトを使用していますので、SL内で完結したものにはできていません。もう、ほんとllHTTPRequestの使えなさって><…
ところで、電光掲示板は右から左に文字が流れていくのですが、当初のスクリプトではあちこちの文字がバラバラと切り替わるのが表示されて、結果的に非常に読みにくいものになっていました。実質読めないといってもいい感じ。下のホワイトボードみたいに静的なものならそれでもいいんですけど、動かしちゃうと、一部の文字が先に左に行き、一部は少し遅れってのがあちこち重なると、まじで読めません。表示部分の抜本的な対策が必要でした。
とりあえず表示プリム(五文字表示できるプリム)に入れたスクリプトを公開します。わたしプロじゃないし、だらだらやるのが好きなので、決して読みやすくもないし、無駄も多いですが…
なお、これはあくまで表示プリムに入れるものなので、5文字しか表示する機能を持ちません。長い文字列を分割したりするのは、親プリムの方で行う必要があります。
前にも書きましたが、これは独自に実装したもので、このジャンルでスタンダードなXyzzyTextとは全く違っています。従って10文字対応も出来ませんし、機能的には基本的なものでしかありません。ただし、表示プリムを作るためにXyzzyTextのセットアップスクリプトが必要になります。このスクリプトでfaceごとのテクスチャの拡大率やずれを設定していますが、それはXyzzyTextのセットアップスクリプトで作成したプリムにあわせ、トライアンドエラーで数値をあわせたものです。
なお、これはあくまで表示プリムに入れるものなので、5文字しか表示する機能を持ちません。長い文字列を分割したりするのは、親プリムの方で行う必要があります。
//
// UniText 1.0
// Copy this script to display prim.
// Display 5 unicode character on 1 prim.
// You have to use XyzzyText Prim Setup Script (5 Face) before use this.
// http://wiki.secondlife.com/wiki/XyzzyText
//
integer SLAVE_DISPLAY = 205003;
integer SLAVE_COLOR = 205010;
string tmpTexture;
string myText;
vector myColor=<1,1,1>;
list faces=[3,7,4,6,1];
list faceScale=[2.48,1,-14.75,1,2.48];
list faceShift=[0,-0.021,0,0.022,-0.195,0,0,0];
float tScale=0.03125;
// Get Unicode Character cord.
// Accept only 1 unicode character.
// この関数は文字を受け取って数値に変換し、それを16bitのUNICODEに変換しています。
//
integer getUnicodeChar(string m)
{
string s= llStringToBase64(m);
integer n= llBase64ToInteger(s);
//
// n contains UTF-8 character code with 'Left to Right order'.
// We accept only 2 byte unicode, so it was only 1 to 3 byte UTF-8.
//
if ((n & 0x80000000) == 0) return ((n & 0x7f000000) >>24);
if ((n & 0xe0000000) == 0xc0000000) return ((n & 0x1f000000) >>18) | ((n & 0x003f0000)>>16);
if ((n & 0xf0000000) == 0xe0000000) return ((n & 0x0f000000) >>12) | ((n & 0x003f0000) >>10) | ((n & 0x00003f00) >>8);
return 32; // else return space code.
}
//
// Get code page and base.
// If code is not in this area, return space code.
//
// この関数では、文字コードからその文字が含まれるテクスチャを
// 選び出しています。
//
integer selectTexture(integer uc){
if (uc >=0 && uc <= 0x03ff){
tmpTexture="c8a49a35-05d6-afb0-bac4-3237d922e36c";
return 0x0000;
} else if (uc >= 0x0400 && uc <= 0x07ff){
tmpTexture="dea9626e-bf08-1cbf-0702-9eaf179bdead";
return 0x0400;
}else if (uc >= 0x0800 && uc <= 0x0bff){
tmpTexture="2a45a8a8-04c6-f225-e569-28901f164bae";
return 0x0800;
}else if (uc >= 0x0c00 && uc <= 0x0fff){
tmpTexture="bfd4deb5-ff7e-eece-4faf-d558f78d1319";
return 0x0c00;
}else if (uc >= 0x1000 && uc <= 0x1000){
tmpTexture="5a998423-3ca3-ebc5-a66d-6af06a55eb7c";
return 0x1000;
}else if (uc >= 0x1e00 && uc <= 0x21ff){
tmpTexture="1a1f9308-1530-e2b1-ee9a-66e1b2488673";
return 0x1e00;
}else if (uc >= 0x2200 && uc <= 0x25ff){
tmpTexture="467f2ca2-6d46-c6d7-0b1d-e0c70c05c48b";
return 0x2200;
}else if (uc >= 0x2600 && uc <= 0x29ff){
tmpTexture="398ed4d4-3f92-50cd-b002-230a37a93140";
return 0x2600;
}else if (uc >= 0x3000 && uc <= 0x33ff){
tmpTexture="f87557d4-1c50-5975-6ffa-621440d7b1f6";
return 0x3000;
}else if (uc >= 0x4e00 && uc <= 0x51ff){
tmpTexture="27b66b9f-37b7-8713-48ca-3a1d40c7c85f";
return 0x4e00;
}else if (uc >= 0x5200 && uc <= 0x55ff){
tmpTexture="c6acbbe1-d164-a401-8711-c81d2220f885";
return 0x5200;
}else if (uc >= 0x5600 && uc <= 0x59ff){
tmpTexture="aa06212a-b373-c73f-2a83-bb1783286c83";
return 0x5600;
}else if (uc >= 0x5a00 && uc <= 0x5dff){
tmpTexture="75900dee-ab9b-33b3-3d6f-2bf2ba52fa0a";
return 0x5a00;
}else if (uc >= 0x5e00 && uc <= 0x61ff){
tmpTexture="0667302c-a52b-7726-b7df-8197ddf5610a";
return 0x5e00;
}else if (uc >= 0x6200 && uc <= 0x65ff){
tmpTexture="e32c7071-1b7f-7826-57dd-f07f5c38d56c";
return 0x6200;
}else if (uc >= 0x6600 && uc <= 0x69ff){
tmpTexture="8893f543-efb8-a728-28fc-6ba3ea0ff2c2";
return 0x6600;
}else if (uc >= 0x6a00 && uc <= 0x6dff){
tmpTexture="cd94eced-5ae6-95a9-7b3e-c7ab62b0b7fd";
return 0x6a00;
}else if (uc >= 0x6e00 && uc <= 0x71ff){
tmpTexture="0e7b6564-67d5-d39c-7300-61d87653d721";
return 0x6e00;
}else if (uc >= 0x7200 && uc <= 0x75ff){
tmpTexture="2dd1664d-47ae-f08a-f48d-8062e75fe6d5";
return 0x7200;
}else if (uc >= 0x7600 && uc <= 0x79ff){
tmpTexture="8baeffc1-8fb5-c788-6700-020465f87103";
return 0x7600;
}else if (uc >= 0x7a00 && uc <= 0x7dff){
tmpTexture="56bd32fd-37bd-bbd4-4f2b-4b2858851d18";
return 0x7a00;
}else if (uc >= 0x7e00 && uc <= 0x81ff){
tmpTexture="7dd05fe0-a82c-9dab-7d1c-193f606184f0";
return 0x7e00;
}else if (uc >= 0x8200 && uc <= 0x85ff){
tmpTexture="e73e7aa7-8086-264f-f88f-7a55b09b4d82";
return 0x8200;
}else if (uc >= 0x8600 && uc <= 0x89ff){
tmpTexture="29759934-a652-235d-53fb-24dbc89f9692";
return 0x8600;
}else if (uc >= 0x8a00 && uc <= 0x8dff){
tmpTexture="447bc9cf-ccb6-e399-f1f1-7beb55eda5d9";
return 0x8a00;
}else if (uc >= 0x8e00 && uc <= 0x91ff){
tmpTexture="a2d06ee8-d61e-eec8-db44-7e0b32ed9a79";
return 0x8e00;
}else if (uc >= 0x9200 && uc <= 0x95ff){
tmpTexture="4e5a14c7-f8bc-a9a8-0966-53c7554e61c2";
return 0x9200;
}else if (uc >= 0x9600 && uc <= 0x99ff){
tmpTexture="2e70735e-636f-2e25-197d-80753d7951d7";
return 0x9600;
}else if (uc >= 0x9a00 && uc <= 0x9dff){
tmpTexture="a4f0c405-e11b-dc8b-064f-35fd174f1d4c";
return 0x9a00;
}else if (uc >= 0x9e00 && uc <= 0xa1ff){
tmpTexture="439f4e3e-5c2d-7fd6-4df5-6b1776ba74cf";
return 0x9e00;
}else if (uc >= 0xac00 && uc <= 0xafff){
tmpTexture="565df042-44ff-80ef-de0b-f531902bbd1f";
return 0xac00;
}else if (uc >= 0xb000 && uc <= 0xb3ff){
tmpTexture="c28e5d8b-61c3-86d2-92ba-d2a91d14edc2";
return 0xb000;
}else if (uc >= 0xb400 && uc <= 0xb7ff){
tmpTexture="62f120f6-c126-dd4e-c905-3edad83a5499";
return 0xb400;
}else if (uc >= 0xb800 && uc <= 0xbbff){
tmpTexture="d048ae48-ea3b-88bd-efb5-99ad03d990b6";
return 0xb800;
}else if (uc >= 0xbc00 && uc <= 0xbfff){
tmpTexture="5c19a432-0879-131f-6a19-5963ed196788";
return 0xbc00;
}else if (uc >= 0xc000 && uc <= 0xc3ff){
tmpTexture="c06eb9aa-287a-313e-b66f-dae97a1130e0";
return 0xc000;
}else if (uc >= 0xc400 && uc <= 0xc7ff){
tmpTexture="a9ca36c7-761c-9a70-067c-24cf22cdc974";
return 0xc400;
}else if (uc >= 0xc800 && uc <= 0xcbff){
tmpTexture="8b7dedf4-0343-eefb-58ed-b21dff736519";
return 0xc800;
}else if (uc >= 0xcc00 && uc <= 0xcfff){
tmpTexture="6a360b3b-416f-5906-712d-dd12a24ffc6d";
return 0xcc00;
}else if (uc >= 0xd000 && uc <= 0xd3ff){
tmpTexture="60c5e79c-0a45-c6f0-af2a-db74977d4216";
return 0xd000;
}else if (uc >= 0xd400 && uc <= 0xd7ff){
tmpTexture="73fa910a-3051-85a3-afc3-f3e8a77d5dc3";
return 0xd400;
}else if (uc >= 0xf900 && uc <= 0xfcff){
tmpTexture="880b1f96-b487-766f-0d23-1aa80a818420";
return 0xf900;
}else if (uc >= 0xfd00 && uc <= 0xffff){
tmpTexture="f6c4f1f6-686e-1f78-a1d6-3f7d5542ff46";
return 0xfd00;
}
return 0x20;
}
//
// テクスチャの中の文字の位置を検出し、llSetPrimitiveParamsのパラメータになるよう
// リスト形式で返します。
//
//
list getPoint(integer c,integer i){
float scale=1/32.0;
integer base =selectTexture(c);
integer face=llList2Integer(faces,i);
c-=base;
float fShift=llList2Float(faceShift,face);
integer cx=c%32;
integer cy=c/32;
float xOffset=fShift+ cx*scale-0.5+scale/2;
float yOffset=(float)cy*scale-0.5+scale/2;
float pscale=llList2Float(faceScale,i);
return [PRIM_COLOR,face,myColor,1.0 ,PRIM_TEXTURE, face , tmpTexture, < tScale*pscale,tScale,1 > , < xOffset,-yOffset,0 > ,0 ];
}
//
// Show up to 5 unicode characters.
// 五文字分のパラメータを貯めて、一気にプリムの五面を設定します。
//
showText(string s)
{
integer i;
integer len;
len = llStringLength(s);
string c;
integer uc;
list data=[];
list param;
for (i=0; i<5; i++){
if (i < len ) {
c=llGetSubString(s,i,i);
}else{
c=" ";
}
uc=getUnicodeChar(c);
data+=getPoint(uc,i);
}
llSetPrimitiveParams(data);
myText=s; // store for redraw.
}
setColor(string colStr)
{
myColor = (vector)colStr;
showText(myText);
}
default
{
state_entry()
{
integer i;
for (i=0; i<5; i++){
integer face=llList2Integer(faces,i);
float scale=llList2Float(faceScale,i);
llScaleTexture(tScale*scale,tScale,face);
}
showText("①②③④⑤"); //空白だとプリムの配置がしにくいので、数字を並べます。
}
//
// リンクされた親プリムからのメッセージで動作するようになっています。
//
//
link_message(integer sender_num, integer num, string str, key id)
{
if (num ==SLAVE_DISPLAY){ //文字表示
showText(str);
}else if (num == SLAVE_COLOR){ //色変更
setColor(str); //この場合、strに"<1,1,0>"みたいな形で色のベクターを渡します。
}
}
}
前にも書きましたが、これは独自に実装したもので、このジャンルでスタンダードなXyzzyTextとは全く違っています。従って10文字対応も出来ませんし、機能的には基本的なものでしかありません。ただし、表示プリムを作るためにXyzzyTextのセットアップスクリプトが必要になります。このスクリプトでfaceごとのテクスチャの拡大率やずれを設定していますが、それはXyzzyTextのセットアップスクリプトで作成したプリムにあわせ、トライアンドエラーで数値をあわせたものです。
Posted by Hitomi Magne at 23:47│Comments(0)
│LSL