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

walkinglint

2008年07月19日 07:31


できた~
-----
というわけで とりあえず リストあげときます(未テストだったり 使ってないので機能的に不十分だと思うけど プロトタイプということで 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, ">
walking のスクリプティング講座