ソラマメブログ

2008年07月19日

Puppeteer もどき 作ってみよう(その3)

できた~
-----
というわけで とりあえず リストあげときます(未テストだったり 使ってないので機能的に不十分だと思うけど プロトタイプということで w)
-----
まずはルートのプリムに入れる方
//
// File: Animator.lsl
// Date Author number of nodes
// 2008/7/19 walkinglint 357
//
integer GET_POSE = 1;
integer SET_POSE = 2;
integer size_of_record = 4; // duration, link_num, rot, pos
list seq0 = [];
integer num_of_seq;
list cur_seq;
integer cur_seq_num;
float cur_duration;
integer cur_link_num;
rotation cur_rotation;
vector cur_position;
string notecard_name = "anim_seq";
integer read_line;
key query_id;
integer is_animating = FALSE;
integer i;
integer num_of_prim;
integer pose_count;
integer pose_num;
get_record() {
cur_link_num = llList2Integer(cur_seq, 1);
cur_rotation = llList2Rot(cur_seq, 2);
cur_position = llList2Vector(cur_seq, 3);
}
float update_cur_seq_and_get_duration() {
cur_seq = llList2List(seq0, cur_seq_num * size_of_record, (cur_seq_num + 1) * size_of_record - 1);
if (++cur_seq_num > num_of_seq) {
cur_seq_num = 0;
}
return llList2Float(cur_seq, 0);
}
dump() {
string line = "";
integer l = llGetListLength(seq0);
integer line_per_chat = 10;
integer cnt = 0;
for (i = 0; i < l; i += size_of_record) {
integer link = llList2Integer(seq0, i + 1);
string comment = " // " + llGetLinkName(link);
cnt++;
if (cnt >= line_per_chat) {
line += (string)llList2Float(seq0, i) + ":" + (string)link + ":" + (string)llList2Rot(seq0, i + 2)
+ ":" + (string)llList2Vector(seq0, i + 3) + comment;
llOwnerSay(line);
cnt = 0;
line = "";
} else {
line += (string)llList2Float(seq0, i) + ":" + (string)link + ":" + (string)llList2Rot(seq0, i + 2)
+ ":" + (string)llList2Vector(seq0, i + 3) + comment + "\n";
}
}
if (llStringLength(line) != 0) {
llOwnerSay(line);
}
}
load() {
llOwnerSay("Loading " + notecard_name + " ...");
read_line = 0;
query_id = llGetNotecardLine(notecard_name, read_line);
seq0 = [];
}
play() {
llOwnerSay("Starting Animation");
num_of_seq = llGetListLength(seq0) / size_of_record;
cur_seq_num = 0;
llSetTimerEvent(1.0);
}
record() {
num_of_prim = llGetNumberOfPrims();
pose_count = 0;
llMessageLinked(LINK_ALL_CHILDREN, GET_POSE, "", NULL_KEY);
}
reset() {
seq0 = [];
pose_num = 1;
}
default {
state_entry() {
llSetTimerEvent(0.0);
llListen(32, "", llGetOwner(), "");
pose_num = 1;
}
touch_start(integer total_number) {
is_animating = !is_animating;
if (is_animating) {
num_of_seq = llGetListLength(seq0) / size_of_record;
cur_seq_num = 0;
llSetTimerEvent(1.0);
} else {
llSetTimerEvent(0.0);
}
}
listen(integer channel, string name, key id, string message) {
if ((message == "dump") || (message == "print")) {
dump();
} else if ((message == "load") || (message == "load")) {
load();
} else if ((message == "play") || (message == "replay") || (message == "start")) {
play();
} else if (message == "record") {
record();
} else if ((message == "reset") || (message == "clear")) {
reset();
} else if (message == "stop") {
llSetTimerEvent(0.0);
}
}
timer() {
integer max_count = 0;
while ((cur_duration = update_cur_seq_and_get_duration()) == 0.0) {
get_record();
llMessageLinked(cur_link_num, SET_POSE, (string)cur_rotation + (string)cur_position, NULL_KEY);
if (++max_count > num_of_seq) {
llSetTimerEvent(0.0);
return ;
}
}
get_record();
llMessageLinked(cur_link_num, SET_POSE, (string)cur_rotation + (string)cur_position, NULL_KEY);
llSetTimerEvent(cur_duration);
}
dataserver(key queryid, string data) {
if (queryid == query_id) {
if (data != EOF) {
// process data
integer l = llSubStringIndex(data, "//");
if (l == 0) {
data = "";
} else if (l != -1) {
data = llGetSubString(data, 0, l - 1);
}
if (llStringLength(data) != 0) {
integer l = llSubStringIndex(data, ":");
seq0 += (float)llGetSubString(data, 0, l - 1);
data = llGetSubString(data, l + 1, llStringLength(data) - 1);
l = llSubStringIndex(data, ":");
seq0 += (integer)llGetSubString(data, 0, l - 1);
data = llGetSubString(data, l + 1, llStringLength(data) - 1);
l = llSubStringIndex(data, ":");
seq0 += (rotation)llGetSubString(data, 0, l - 1);
data = llGetSubString(data, l + 1, llStringLength(data) - 1);
seq0 += (vector)data;
}
read_line++;
query_id = llGetNotecardLine(notecard_name, read_line);
} else {
llOwnerSay("Loading " + notecard_name + " complete.");
num_of_seq = llGetListLength(seq0) / size_of_record;
cur_seq_num = 0;
}
}
}
link_message(integer sender_num, integer num, string str, key id) {
if (num == GET_POSE) {
float delay = 0.0;
if (pose_count == 0) {
delay = 1.0;
}
integer l = llSubStringIndex(str, "><");
string rot_str = llGetSubString(str, 0, l);
string pos_str = llGetSubString(str, l + 1, llStringLength(str) - 1);
seq0 += [delay, sender_num, (rotation)rot_str, (vector)pos_str];
pose_count++;
if (pose_count >= num_of_prim - 1) {
llOwnerSay("Recorded snapshot: " + (string)pose_num);
pose_num++;
}
}
}
}
ざっと作った後 結構デバッグしてたんだけれど
-----
痛かったのが llParseString2List が どうも rotation はちゃんとやっているのに vector でバグってるみたいだったこと...
-----
後 3番目のパラメタでも要素が区切られてしまってるような気が... いまいちわからないので llSubStringIndex と llGetSubString でベタでコーディングしてしまった w
-----
引っかかったのはそこぐらいかな~ programmable fountain をベースに作ってたんだが かえって ごちゃごちゃしちゃってるかも w
-----
次に 子プリムに入れる方
//
// File: Animator_Probe.lsl
// Date Author number of nodes
// 2008/7/26 walkinglint 37
// 2008/7/19 walkinglint 28
//
integer GET_POSE = 1;
integer SET_POSE = 2;
rotation rot;
string tmp_str;
rotation root_rot;
vector pos;
default {
link_message(integer sender_num, integer num, string str, key id) {
if (num == GET_POSE) {
rot = llGetLocalRot();
pos = llGetLocalPos();
llMessageLinked(1, GET_POSE, (string)rot + (string)pos, NULL_KEY);
} else if (num == SET_POSE) {
integer l = llSubStringIndex(str, "><");
rot = (rotation)(llGetSubString(str, 0, l));
if (llGetAttached() == 0) {
pos = (vector)llGetSubString(str, l + 1, llStringLength(str) - 1);
rot = rot / llGetRootRotation();
llSetPrimitiveParams([PRIM_POSITION, pos, PRIM_ROTATION, rot]);
} else {
pos = (vector)llGetSubString(str, l + 1, llStringLength(str) - 1);
llSetLocalRot(rot);
llSetPrimitiveParams([PRIM_POSITION, pos]);
}
}
}
}

同じカテゴリー(walking のスクリプティング講座)の記事
 プロフィール写真の表示に問題 (2009-11-30 20:55)
 ミニ太陽系 (2009-03-21 06:03)
 関数から文字列を返したら何か問題になる? (2009-03-18 18:02)
 llListFindList って型って関係ないんだったっけ (2009-03-18 14:02)
 夏時間(PDT)の実験 (2009-03-08 22:04)
 15パズルの作り方(その3) (2009-03-08 06:03)
上の画像に書かれている文字を入力して下さい
 
<ご注意>
書き込まれた内容は公開され、ブログの持ち主だけが削除できます。