2008年07月28日
Puppeteer もどき 作ってみよう(その9)
さて もらってきた 子犬を自作ので動かしてみようかなと試してみると
-----
動きがばらばら... 子犬はしかし そんなにばらばら動いていない
-----
なんで? と少し考えたら 位置と回転を渡した後 一斉にそれを設定させるようにすればよい ということに気付いたので w
-----
再び 修正... でもって ようやく子犬も自然に動かすことができた w
-----
-----
-----
まぶたが無いので 目を閉じているのは テクスチャを変えてるんじゃないのかな~ 違うかな...
-----
というわけで リストも上げときます
-----
まずルートプリム側
-----
動きがばらばら... 子犬はしかし そんなにばらばら動いていない
-----
なんで? と少し考えたら 位置と回転を渡した後 一斉にそれを設定させるようにすればよい ということに気付いたので w
-----
再び 修正... でもって ようやく子犬も自然に動かすことができた w
-----
-----
-----
まぶたが無いので 目を閉じているのは テクスチャを変えてるんじゃないのかな~ 違うかな...
-----
というわけで リストも上げときます
-----
まずルートプリム側
//次に子プリムの側
// File: Animator2.lsl
// Date Author number of nodes
// 2008/7/28 walkinglint 230
// 2008/7/27 walkinglint 202
// 2008/7/26 walkinglint 199
// 2008/7/26 walkinglint 179 (Animator->Animator2)
// 2008/7/26 walkinglint 179
// 2008/7/25 walkinglint 377
// 2008/7/21 walkinglint 374
// 2008/7/19 walkinglint 374
//
float delay_to_stop_recording = 0.5;
integer GET_POSE = 1;
integer SET_POSE = 2;
integer DO_POSE = 3;
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_num;
integer handle;
integer is_recording = FALSE;
integer play_once = FALSE;
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() {
llSay(0, "Dump Animation");
dump_body();
}
dump_body() {
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;
llSay(0, 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) {
llSay(0, line);
}
}
first() {
llSay(0, "First Animation");
num_of_seq = llGetListLength(seq0) / size_of_record;
cur_seq_num = 0;
llSetTimerEvent(1.0);
play_once = TRUE;
}
load() {
llSay(0, "Loading " + notecard_name + " ...");
read_line = 0;
query_id = llGetNotecardLine(notecard_name, read_line);
seq0 = [];
}
next() {
llSay(0, "Next Animation");
num_of_seq = llGetListLength(seq0) / size_of_record;
llSetTimerEvent(1.0);
play_once = TRUE;
}
play() {
llSay(0, "Starting Animation");
num_of_seq = llGetListLength(seq0) / size_of_record;
cur_seq_num = 0;
llSetTimerEvent(1.0);
}
publish() {
llSay(0, "Publish Animation");
dump_body();
llListenRemove(handle);
}
record() {
stop_body();
is_recording = TRUE;
llMessageLinked(LINK_ALL_CHILDREN, GET_POSE, "", NULL_KEY);
}
reset() {
llSay(0, "Reset Animation");
seq0 = [];
pose_num = 1;
}
stop() {
llSay(0, "Stop Animation");
stop_body();
}
stop_body() {
llSetTimerEvent(0.0);
}
default {
state_entry() {
llSetTimerEvent(0.0);
handle = llListen(32, "", "", "");
pose_num = 1;
}
touch_start(integer total_number) {
is_animating = !is_animating;
if (is_animating) {
play();
} else {
stop();
}
}
listen(integer channel, string name, key id, string message) {
if ((message == "dump") || (message == "print")) {
dump();
} else if (message == "first") {
first();
} else if ((message == "load") || (message == "load")) {
load();
} else if (message == "next") {
next();
} else if ((message == "play") || (message == "replay") || (message == "start")) {
play();
} else if (message == "publish") {
publish();
} else if (message == "record") {
record();
} else if ((message == "reset") || (message == "clear")) {
reset();
} else if (message == "stop") {
stop();
}
}
timer() {
if (is_recording) {
llSay(0, "Recorded snapshot: " + (string)pose_num);
pose_num++;
llSetTimerEvent(0.0);
is_recording = FALSE;
integer l = llGetListLength(seq0);
seq0 = llListReplaceList(seq0, [1.0], l - size_of_record, l - size_of_record);
} else {
integer max_count = 0;
while ((cur_duration = update_cur_seq_and_get_duration()) == 0.0) {
get_record();
if (llGetAttached()) {
llMessageLinked(cur_link_num, SET_POSE, (string)cur_rotation
+ (string)cur_position + (string)llGetLocalRot(), NULL_KEY);
} else {
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();
if (llGetAttached()) {
llMessageLinked(cur_link_num, SET_POSE, (string)cur_rotation
+ (string)cur_position + (string)llGetLocalRot(), NULL_KEY);
} else {
llMessageLinked(cur_link_num, SET_POSE, (string)cur_rotation
+ (string)cur_position, NULL_KEY);
}
llMessageLinked(LINK_ALL_CHILDREN, DO_POSE, "", NULL_KEY);
if (play_once) {
llSetTimerEvent(0.0);
play_once = FALSE;
} else {
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 {
llSay(0, "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) {
llSetTimerEvent(0.0);
float delay = 0.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];
llSetTimerEvent(delay_to_stop_recording);
}
}
}
//
// File: Animator_Probe2.lsl
// Date Author number of nodes
// 2008/7/27 walkinglint 51
// 2008/7/26 walkinglint 45
// 2008/7/26 walkinglint 39 (Animator_Probe->Animator_Probe2)
// 2008/7/26 walkinglint 38
// 2008/7/19 walkinglint 28
//
integer GET_POSE = 1;
integer SET_POSE = 2;
integer DO_POSE = 3;
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();
} else {
tmp_str = llGetSubString(str, l + 1, llStringLength(str) - 1);
l = llSubStringIndex(tmp_str, "><");
pos = (vector)(llGetSubString(tmp_str, 0, l));
root_rot = (rotation)llGetSubString(tmp_str, l + 1, llStringLength(tmp_str) - 1);
rot = rot / root_rot;
}
} else if (num == DO_POSE) {
llSetPrimitiveParams([PRIM_POSITION, pos, PRIM_ROTATION, rot]);
}
}
}
Posted by walkinglint at 20:30│Comments(0)
│walking のスクリプティング講座