void LLFloaterGesture::onClickPlay() { const LLUUID& item_id = mGestureList->getCurrentID(); if(item_id.isNull()) return; LL_DEBUGS("Gesture")<<" Trying to play gesture id: "<< item_id <<LL_ENDL; if(!LLGestureMgr::instance().isGestureActive(item_id)) { // we need to inform server about gesture activating to be consistent with LLPreviewGesture and LLGestureComboList. BOOL inform_server = TRUE; BOOL deactivate_similar = FALSE; LLGestureMgr::instance().setGestureLoadedCallback(item_id, boost::bind(&LLFloaterGesture::playGesture, this, item_id)); LLViewerInventoryItem *item = gInventory.getItem(item_id); llassert(item); if (item) { LLGestureMgr::instance().activateGestureWithAsset(item_id, item->getAssetUUID(), inform_server, deactivate_similar); LL_DEBUGS("Gesture")<< "Activating gesture with inventory ID: " << item_id <<LL_ENDL; } } else { playGesture(item_id); } }
BOOL LLGestureMgr::triggerGesture(KEY key, MASK mask) { std::vector <LLMultiGesture *> matching; item_map_t::iterator it; // collect matching gestures for (it = mActive.begin(); it != mActive.end(); ++it) { LLMultiGesture* gesture = (*it).second; // asset data might not have arrived yet if (!gesture) continue; if (gesture->mKey == key && gesture->mMask == mask) { matching.push_back(gesture); } } // choose one and play it if (matching.size() > 0) { U32 random = ll_rand(matching.size()); LLMultiGesture* gesture = matching[random]; playGesture(gesture); return TRUE; } return FALSE; }
// Convenience function that looks up the item_id for you. void LLGestureManager::playGesture(const LLUUID& item_id) { item_map_t::iterator it = mActive.find(item_id); if (it == mActive.end()) return; LLMultiGesture* gesture = (*it).second; if (!gesture) return; playGesture(gesture); }
// Function: execute sit down gesture void GestureManager::sitDown() { // Activate stiffness std_srvs::Empty empty; stiffness_enable_client.call(empty); // Execute sit down motion //playGesture("stand", "gesture", "global", "sit down"); playGesture(motion_state::body_state::SIT, motion_state::motion_type::GESTURE, gesture_names::gesture_subtype::GLOBAL, gesture_names::gesture_motion_names::GLOBAL_SIT_DOWN); // Publish body status publishBodyStatus("sat down"); }
// Function: execute stand init gesture void GestureManager::standInit() { // Activate stiffness std_srvs::Empty empty; stiffness_enable_client.call(empty); // Execute stand init motion //playGesture("stand", "gesture", "global", "stand init"); playGesture(motion_state::body_state::STAND, motion_state::motion_type::GESTURE, gesture_names::gesture_subtype::GLOBAL, gesture_names::gesture_motion_names::GLOBAL_STAND_INIT); // Publish body status publishBodyStatus("woke up"); }
// Convenience function that looks up the item_id for you. void LLGestureMgr::playGesture(const LLUUID& item_id, bool local) { const LLUUID& base_item_id = get_linked_uuid(item_id); item_map_t::iterator it = mActive.find(base_item_id); if (it == mActive.end()) return; LLMultiGesture* gesture = (*it).second; if (!gesture) return; playGesture(gesture); }
// Function: execute stand up from chair gesture void GestureManager::standFromChair() { // Activate stiffness std_srvs::Empty empty; stiffness_enable_client.call(empty); // Execute stand chair motion //playGesture("stand", "gesture", "global", "stand chair"); playGesture(motion_state::body_state::STAND, motion_state::motion_type::GESTURE, gesture_names::gesture_subtype::GLOBAL, gesture_names::gesture_motion_names::GLOBAL_STAND_FROM_CHAIR); // Rest rest(); // Wakeup wakeUp(); }
// Function: execute sit down in chair gesture void GestureManager::sitChairInit() { // Activate stiffness std_srvs::Empty empty; stiffness_enable_client.call(empty); // Execute stand chair motion playGesture(motion_state::body_state::SIT, motion_state::motion_type::GESTURE, gesture_names::gesture_subtype::GLOBAL, gesture_names::gesture_motion_names::GLOBAL_SIT_CHAIR_START_POS); // Rest rest(); // Disable stiffness disableStiffness(); // Publish body status publishBodyStatus("sat chair"); }
void GestureManager::playGestureSequence(const string body_status, const string type, const string subtype) { nao_gestures::GestureSequence gesture_sequence_srv; gesture_sequence_srv.request.animation_body_status=body_status; gesture_sequence_srv.request.animation_motion_type=type; gesture_sequence_srv.request.animation_motion_subtype=subtype; //ROS_INFO("Number of gestures: %ld", (long int)gesture_generator_srv.response.num); play_gesture_sequence_client.call(gesture_sequence_srv); for (int i = 0; i < gesture_sequence_srv.response.num; i++) { const string motion_name = gesture_sequence_srv.response.gestures[i]; //ROS_INFO("%d Gesture Name: %s", i, gesture_sequence_srv.response.gestures[i].c_str()); // For each gesture generated call execute motion service playGesture(gesture_sequence_srv.request.animation_body_status, gesture_sequence_srv.request.animation_motion_type, gesture_sequence_srv.request.animation_motion_subtype, motion_name); } }
// Iterates through space delimited tokens in string, triggering any gestures found. // Generates a revised string that has the found tokens replaced by their replacement strings // and (as a minor side effect) has multiple spaces in a row replaced by single spaces. BOOL LLGestureMgr::triggerAndReviseString(const std::string &utf8str, std::string* revised_string) { std::string tokenized = utf8str; BOOL found_gestures = FALSE; BOOL first_token = TRUE; typedef boost::tokenizer<boost::char_separator<char> > tokenizer; boost::char_separator<char> sep(" "); tokenizer tokens(tokenized, sep); tokenizer::iterator token_iter; for( token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter) { const char* cur_token = token_iter->c_str(); LLMultiGesture* gesture = NULL; // Only pay attention to the first gesture in the string. if( !found_gestures ) { // collect gestures that match std::vector <LLMultiGesture *> matching; item_map_t::iterator it; for (it = mActive.begin(); it != mActive.end(); ++it) { gesture = (*it).second; // Gesture asset data might not have arrived yet if (!gesture) continue; if (LLStringUtil::compareInsensitive(gesture->mTrigger, cur_token) == 0) { matching.push_back(gesture); } gesture = NULL; } if (matching.size() > 0) { // choose one at random { S32 random = ll_rand(matching.size()); gesture = matching[random]; playGesture(gesture); if (!gesture->mReplaceText.empty()) { if( !first_token ) { if (revised_string) revised_string->append( " " ); } // Don't muck with the user's capitalization if we don't have to. if( LLStringUtil::compareInsensitive(cur_token, gesture->mReplaceText) == 0) { if (revised_string) revised_string->append( cur_token ); } else { if (revised_string) revised_string->append( gesture->mReplaceText ); } } found_gestures = TRUE; } } } if(!gesture) { // This token doesn't match a gesture. Pass it through to the output. if( !first_token ) { if (revised_string) revised_string->append( " " ); } if (revised_string) revised_string->append( cur_token ); } first_token = FALSE; gesture = NULL; } return found_gestures; }