Message Panels : Aide Technique : // script pour meuble v1 / script for furniture v1 / script für Möbel v1 |
<< | <First | < | <prev. | > | next.> | >> | Last> | Rep | Reply | ^ | Discussion ^ | v | Discussion v | Del | Delete the discussion |
Samuro | Samuro | 25/08 | Sent: 25/08/2024 14:50:34 | 1 / 3 | Message 1 from 3 |
// script pour meuble v1 / script for furniture v1 / script für Möbel v1 // s'asseoir, changer de texture ou couleur. // sitting, choose texture or color. // sitzen, Textur und Farbe wählen. //----------------------------------------------------------------- // nombre de places assises sur le meuble // number of sit places on the furniture // Anzahl der Sitzplätze auf dem Möbelstück const int MAX_PLACES = 4; //----------------------------------------------------------------- // nombre de places assises changeant d'animation ensembles (1 pour solo, 2 pour couples) // number of seats changing animation together (1 for alone, 2 for couples) // Anzahl der Sitzplätze wo sich die Animation gemeinsam ändert (1 für Solo, 2 für Paare) // MAX_PLACES doit être divisible par A_SET // MAX_PLACES must be divisible by A_SET // MAX_PLACES muss durch A_SET teilbar sein const int A_SET = 1; //----------------------------------------------------------------- // nombre d'animations pour chaque place assise // number of animations for each sit place // Anzahl der Animationen für jeden Sitzplatz const int MAX_ANIMS = 2; //----------------------------------------------------------------- // afficher un menu // display a menu // ein menu anzeigen const bool WANT_SIT_MENU = false; // true (oui,yes,ja) or false (non,no,nein) //----------------------------------------------------------------- // afficher un menu SWAP pour échanger les places (si A_SET > 1) // display a SWAP menu to exchange positions (if A_SET > 1) // ein SWAP menu anzeigen um die positionen zu wechseln (falls A_SET > 1) const bool SWAP = true; // true (oui,yes,ja) or false (non,no,nein) //----------------------------------------------------------------- // forcer hommes sur les places impaires et les femmes sur places paires // force men to sit on odd-numbered places and women to sit on even-numbered places // zwingt Männer auf ungeraden Plätzen und Frauen auf geraden Plätzen const bool FORCE_MALE_ON_ODD = false; // true (oui,yes,ja) or false (non,no,nein) //----------------------------------------------------------------- //----------------------------------------------------------------- // menu de changement de texture // texture change menu // textur änderungsmenu const bool WANT_TEXTURE_MENU = false; // true (oui,yes,ja) or false (non,no,nein) // numéro de mesh impacté // impacted mesh number // zu ändernde mesh nummer const int TEXTURE_MENU_MESH_NR = 1; // pour propriétaire seulement // for owner only // nur für besitzer const bool TEXTURE_MENU_FOR_OWNER_ONLY = false; // true (oui,yes,ja) or false (non,no,nein) //----------------------------------------------------------------- //----------------------------------------------------------------- // menu de changement de couleur // color change menu // farbe änderungsmenu const bool WANT_COLOR_MENU = false; // true (oui,yes,ja) or false (non,no,nein) // numéro de mesh impacté // impacted mesh number // zu ändernde mesh nummer const int COLOR_MENU_MESH_NR = 1; // pour propriétaire seulement // for owner only // nur für besitzer const bool COLOR_MENU_FOR_OWNER_ONLY = false; // true (oui,yes,ja) or false (non,no,nein) struct COLOR_INFO { string(10) name[3]; int hex; } const int MAX_COLORS = 4; // maximum 20 colors const COLOR_INFO g_colors[MAX_COLORS] = { {{ "blanc", "white", "weiss" }, 0xFFFFFF}, {{ "rouge", "red", "rot" }, 0x0000FF}, {{ "vert", "green", "grün" }, 0x00FF00}, {{ "bleu", "blue", "blau" }, 0xFF0000}, }; //----------------------------------------------------------------- //----------------------------------------------------------------- struct SIT { vector pos; vector rot; string(20) anim; } type ROW is SIT[MAX_PLACES]; //----------------------------------------------------------------- const ROW g_sit[MAX_ANIMS] = { // animation 1 { {pos => {0.4, -1.4, 1.4}, // sit place 1 rot => {0.0, 0.0, 0.0}, anim => "hommeallongé"}, {pos => {0.35, 0.80, 0.60}, // sit place 2 rot => {0.0, 0.0, 0.0}, anim => "femmeallongée"}, {pos => {0.45, -0.70, 0.60}, // sit place 3 rot => {0.0, 0.0, 0.0}, anim => "Dormir"}, {pos => {0.25, 1.8, 1.40}, // sit place 4 rot => {0.0, 0.0, 0.0}, anim => "Dormir"}, }, // animation 2 { {pos => {0.4, -1.4, 1.4}, // sit place 1 rot => {0.0, 0.0, 0.0}, anim => "Dormir"}, {pos => {0.35, 0.80, 0.60}, // sit place 2 rot => {0.0, 0.0, 0.0}, anim => "Dormir"}, {pos => {0.45, -0.70, 0.60}, // sit place 3 rot => {0.0, 0.0, 0.0}, anim => "hommeallongé"}, {pos => {0.25, 1.8, 1.40}, // sit place 4 rot => {0.0, 0.0, 0.0}, anim => "femmeallongée"}, }, }; //----------------------------------------------------------------- //----------------------------------------------------------------- // ne rien changer ci-dessous // do not change script under this // nichts im skript hierunter ändern //------------------------------------------------------- const int NB_SETS = MAX_PLACES / A_SET; bool g_valid; key[MAX_PLACES] g_avatar; int[NB_SETS] g_anim_set; // anim set (0 to MAX_ANIMS-1) //------------------------------------------------------- // return sit index of key, or -1 if not sitting int avatar_place (key k) { int ava; for (ava=0; ava<MAX_PLACES; ava++) { if (same_key (k, g_avatar[ava])) return ava; } return -1; } //------------------------------------------------------- // update the table g_avatar : remove any avatar key that is not sitting anymore void update_avatars () { sitter s; int i; bool valid[MAX_PLACES]; clear valid; while (get_sitter (out s)) { int idx = avatar_place (s.avatar); if (idx >= 0) valid[idx] = true; } for (i=0; i<MAX_PLACES; i++) { if (!valid[i]) clear g_avatar[i]; } } //------------------------------------------------------- void sit_avatar (int anim, int ava, key k) { if (sit (mesh_nr => 1, position => g_sit[anim][ava].pos, rotation => g_sit[anim][ava].rot, avatar => k)) { start_animation (g_sit[anim][ava].anim, k); g_avatar[ava] = k; } } //------------------------------------------------------- // must return seat from 0 to MAX_PLACES-1, // or -1 if no seat is free. int find_place (key k, vector pos) { int seat, i, pass, max_passes; float best_dist, dist; float dx, dy, dz; max_passes = 1; if (FORCE_MALE_ON_ODD) max_passes = 2; seat = -1; best_dist = 999999999.0; for (pass=1; pass<=max_passes; pass++) { for (i=0; i<MAX_PLACES; i++) { if (pass == 1 && FORCE_MALE_ON_ODD) { int idx; if (avatar_gender(k) == 0) // male idx = 0; else // female idx = 1; if ((i & 1) != idx) continue; } if (!is_null_key (g_avatar[i])) // occupied place continue; dx = pos.x - g_sit[0][i].pos.x; dy = pos.y - g_sit[0][i].pos.y; dz = pos.z - g_sit[0][i].pos.z; dist = dx*dx + dy*dy + dz*dz; if (dist < best_dist) { seat = i; best_dist = dist; } } if (seat >= 0) return seat; } return -1; } //------------------------------------------------------- void simple_sit (key k, vector pos) { int ava; update_avatars (); ava = find_place (k, pos); if (ava >= 0) { sit_avatar (anim => g_anim_set[ava/A_SET], ava => ava, k => k); } } //------------------------------------------------------- void advance_anim_for_avatar (key k) { int ava, h; update_avatars(); ava = avatar_place (k); if (ava < 0) // clicking avatar does not sit return; h = ava/A_SET; // "set" number // advance anim g_anim_set[h]++; if (g_anim_set[h] == MAX_ANIMS) g_anim_set[h] = 0; // update all the set for (ava=h*A_SET; ava<(h+1)*A_SET; ava++) { if (!is_null_key (g_avatar[ava])) sit_avatar (anim => g_anim_set[h], ava => ava, k => g_avatar[ava]); } } //------------------------------------------------------- void set_my_texture (string texture_name) { set_mesh_texture (TEXTURE_MENU_MESH_NR, texture_name); } //------------------------------------------------------- void set_my_color (int color) { set_mesh_color (COLOR_MENU_MESH_NR, color); } //------------------------------------------------------- string texture_menu (key k) { string(1024) s; string(32) name; int lang, index; const string(7) TEXTURE[3] = {"Texture", "Textur", "Textur"}; if (TEXTURE_MENU_FOR_OWNER_ONLY && !same_key (object_owner(), k)) return ""; lang = avatar_language (k); s = "," + TEXTURE[lang] + ":["; clear name, index; for (;;) { name = item_name (name); if (name == "") break; if (item_type (name) == "TEX") { if (index > 0) s = s + ","; s = s + name + ":" + itos(100 + index++); if (index == 20) break; } } if (index == 0) return ""; return s + "]"; } //------------------------------------------------------- string color_menu (key k) { string(1024) s; int lang, i; const string(7) COLOR[3] = {"Couleur", "Color", "Farbe"}; if (COLOR_MENU_FOR_OWNER_ONLY && !same_key (object_owner(), k)) return ""; lang = avatar_language (k); s = "," + COLOR[lang] + ":["; for (i=0; i<MAX_COLORS; i++) { s = s + g_colors[i].name[lang] + ":" + itos(200 + g_colors[i].hex); if (i < MAX_COLORS-1) s = s + ","; } return s + "]"; } //------------------------------------------------------- void click_for_the_menu (key k) { int anim, ava, lang; string(1024) s; update_avatars(); ava = avatar_place (k); if (ava < 0) { unsit (k); return; } lang = avatar_language (k); { const string(10) UNSIT_TXT[3] = {"SE LEVER", "UNSIT", "AUFSTEHEN"}; s = UNSIT_TXT[lang] + ":-1"; } for (anim=0; anim<MAX_ANIMS; anim++) s = s + "," + g_sit[anim][ava].anim + ":" + itos(anim); if (SWAP & A_SET > 1) s = s + ",Swap:-2"; if (WANT_TEXTURE_MENU) s = s + texture_menu (k); if (WANT_COLOR_MENU) s = s + color_menu (k); display_menu (k, s); } //------------------------------------------------------- string get_texture_name (int idx) { string(32) name; int index; clear name, index; for (;;) { name = item_name (name); if (name == "") break; if (item_type (name) == "TEX") { if (index == idx) return name; index++; } } return ""; } //------------------------------------------------------- event menu_selected (key k, int menu_id) { if (menu_id >= 200) // color { set_my_color (menu_id - 200); return; } if (menu_id >= 100) // texture { string(32) name = get_texture_name (menu_id - 100); set_my_texture (name); return; } if (!is_sitting (k)) return; if (menu_id == -1) // unsit { unsit (k); } else { int ava, h, i, first, last; update_avatars(); ava = avatar_place (k); if (ava < 0) return; h = ava/A_SET; // "set" number first = h*A_SET; last = first + A_SET - 1; if (menu_id == -2) // swap { key kk = g_avatar[first]; for (i=first; i<last; i++) g_avatar[i] = g_avatar[i+1]; g_avatar[last] = kk; } else { g_anim_set[h] = menu_id; } for (ava=first; ava<=last; ava++) { if (!is_null_key (g_avatar[ava])) sit_avatar (anim => g_anim_set[h], ava => ava, k => g_avatar[ava]); } } } //------------------------------------------------------- bool show_menu (key k) { bool b = false; bool owner = same_key (object_owner(), k); if (WANT_SIT_MENU) b = true; if (WANT_TEXTURE_MENU) { if (owner | !TEXTURE_MENU_FOR_OWNER_ONLY) b = true; } if (WANT_COLOR_MENU) { if (owner | !COLOR_MENU_FOR_OWNER_ONLY) b = true; } return b; } //------------------------------------------------------- event touch() // click on furniture { key k; if (!g_valid) return; k = touched_avatar(); if (is_sitting (k)) { if (show_menu (k)) click_for_the_menu (k); else unsit (k); } else // not sitting { simple_sit (k, touched_mesh_position()); } } //------------------------------------------------------- event click_avatar() // click on sitting avatar { key k; if (!g_valid) return; k = clicking_avatar(); if (show_menu (k)) click_for_the_menu (k); else advance_anim_for_avatar (clicked_avatar()); } //------------------------------------------------------- event start() { if (MAX_PLACES < 1) say ("error: bad MAX_PLACES"); else if (A_SET < 1 || A_SET > MAX_PLACES || MAX_PLACES % A_SET != 0) say ("error: bad A_SET"); else { g_valid = true; if (WANT_TEXTURE_MENU) { string(32) name = get_texture_name (0); set_my_texture (name); } else { set_my_texture (""); } if (WANT_COLOR_MENU) { set_my_color (g_colors[0].hex); } } } //------------------------------------------------------- |
Samuro | Samuro | 26/08 | Sent: 26/08/2024 03:30:00 | 2 / 3 | Message 2 from 3 |
Pour ceux/celles qui comptent refaire des animations Surveillez une chose : dans le script, on spécifie des positions, genre pos => {0.25, 1.8, 1.40}, Il ne faut pas mettre un Z de position trop bas (ici 1.40 ça va mais pas 0.0 par exemple !), car sinon quand quand on se relève on est dans le sol ! Donc ça veut dire, quand on crée une animation, dans l'éditeur d'animation, l'os POSITION doit avoir un Z à 0, et surtout pas un Z plus grand que 0 ! Für diejenigen, die vorhaben, Animationen erneut zu erstellen. Achten Sie auf eine Sache: Im Skript werden Positionen angegeben, z.B. pos => {0.25, 1.8, 1.40}, Man darf das Positions-Z nicht zu niedrig ansetzen (hier ist 1.40 in Ordnung, aber nicht 0.0 zum Beispiel!) Denn sonst ist man beim Aufstehen im Boden! Das heißt also, wenn man eine Animation erstellt, im Animationseditor, muss der Knochen POSITION ein Z von 0 haben, und vor allem kein Z, das größer als 0 ist! |
Samuro | Samuro | 26/08 | Sent: 26/08/2024 03:31:15 | 3 / 3 | Message 3 from 3 |
Donc en clair, la position où on s'assied (commande sit() du script) ne doit pas être trop basse, sinon on est enfoncé dans le sol quand on se relève. Et il ne faut pas "remonter" la position dans l'animation bvh pour corriger ça. Also im Klartext: Die Position, in der man sitzt (Befehl sit() im Skript), darf nicht zu niedrig sein, sonst ist man beim Aufstehen im Boden versunken. Und man darf die Position in der bvh-Animation nicht "hochziehen", um das zu korrigieren. |
<< | <First | < | <prev. | > | next.> | >> | Last> | Rep | Reply | ^ | Discussion ^ | v | Discussion v | Del | Delete the discussion |