llpuppetmodule.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * @file llpuppetmodule.h
  3. * @brief Declaration of the LLPuppetModule class.
  4. *
  5. * $LicenseInfo:firstyear=2022&license=viewergpl$
  6. *
  7. * Copyright (c) 2022, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #if LL_PUPPETRY
  33. #ifndef LL_LLPUPPETMODULE_H
  34. #define LL_LLPUPPETMODULE_H
  35. #include <memory>
  36. #include <map>
  37. #include "lleventdispatcher.h" // For LLEventAPI
  38. #include "llsingleton.h"
  39. class LLLeap;
  40. class LLPuppetMotion;
  41. // Bit mask for puppetry parts enabling
  42. enum LLPuppetPartMask
  43. {
  44. // These must match the (void*)user_data parameter used for the corresponding
  45. // LLMenuItemCheckGL() calls in llviewermenu.cpp, init_puppetry_menu()
  46. // function.
  47. PPM_NONE = 0,
  48. PPM_HEAD = 1,
  49. PPM_FACE = 2,
  50. PPM_LEFT_HAND = 4,
  51. PPM_RIGHT_HAND = 8,
  52. PPM_FINGERS = 16,
  53. PPM_ALL = 31
  54. };
  55. // Singleton to manage a pointer to the LLLeap module that provides puppetry
  56. // functions
  57. class LLPuppetModule final : public LLSingleton<LLPuppetModule>,
  58. public LLEventAPI
  59. {
  60. friend class LLSingleton<LLPuppetModule>;
  61. protected:
  62. LOG_CLASS(LLPuppetModule);
  63. public:
  64. LLPuppetModule();
  65. ~LLPuppetModule() override = default;
  66. // Used to launch a LEAP plugin/script as a puppet module. Whenever the
  67. // "PuppetryCameraOption" debug setting is not empty, the string it
  68. // contains is automatically added as an option, together with the current
  69. // camera number. This method returns true when successful or false
  70. // otherwise, and spawns an alert dialog in case of failure. HB
  71. bool launchLeapPlugin(const std::string& filename);
  72. // Used to launch a LEAP module with the provided command line (i.e. an
  73. // executable or script file name and any needed options) as a puppet
  74. // module. Returns true when successful or false otherwise, and spawns an
  75. // alert dialog in case of failure. HB
  76. bool launchLeapCommand(const std::string& command);
  77. typedef std::shared_ptr<LLLeap> puppet_module_ptr_t;
  78. void setLeapModule(std::weak_ptr<LLLeap> mod,
  79. const std::string& module_name);
  80. puppet_module_ptr_t getLeapModule() const;
  81. bool havePuppetModule() const; // Returns true when module is loaded
  82. void disableHeadMotion() const;
  83. void enableHeadMotion() const;
  84. void clearLeapModule();
  85. void sendCommand(const std::string& command,
  86. const LLSD& args = LLSD()) const;
  87. LL_INLINE const std::string& getModuleName() const { return mModuleName; }
  88. // Enable puppetry on body part - head, face, left/right hands
  89. void setEnabledPart(S32 part_num, bool enable);
  90. S32 getEnabledPart(S32 mask = PPM_ALL) const;
  91. void setCameraNumber(S32 num);
  92. S32 getCameraNumber() const;
  93. void sendCameraNumber();
  94. void sendEnabledParts();
  95. void sendSkeleton(const LLSD& sd = LLSD::emptyMap());
  96. void sendReport(const LLSD& sd = LLSD::emptyMap());
  97. LL_INLINE bool getEcho() const { return mPlayServerEcho; }
  98. void setEcho(bool play_server_echo);
  99. LL_INLINE bool isSending() const { return mIsSending; }
  100. void setSending(bool sending);
  101. LL_INLINE bool isReceiving() const { return mIsReceiving; }
  102. void setReceiving(bool receiving);
  103. LL_INLINE F32 getRange() const { return mRange; }
  104. void setRange(F32 range);
  105. // Map of used joints and last time
  106. typedef std::map<std::string, F64> active_joint_map_t;
  107. void addActiveJoint(const std::string& joint_name);
  108. bool isActiveJoint(const std::string& joint_name);
  109. LL_INLINE const active_joint_map_t& getActiveJoints() const
  110. {
  111. return mActiveJoints;
  112. }
  113. void parsePuppetryResponse(const LLSD& response);
  114. private:
  115. void processJointData(LLPuppetMotion* motionp, const std::string& key,
  116. const LLSD& data, S32 reqid = -1);
  117. void setCameraNumber_(S32 num); // LEAP caller
  118. void getCameraNumber_(const LLSD& request) const; // LEAP caller
  119. void setPuppetryOptions(LLSD options);
  120. static void setPuppetryOptionsCoro(const std::string& url, LLSD options);
  121. static void processGetRequest(const LLSD& data);
  122. static void processSetRequest(const LLSD& data);
  123. static void settingsObserver();
  124. private:
  125. mutable std::weak_ptr<LLLeap> mLeapModule; // Weak pointer to module
  126. // For event pump to send leap updates to plug-ins
  127. LLTempBoundListener mSendSkeletonAPI;
  128. LLTempBoundListener mSendReportAPI;
  129. std::string mModuleName;
  130. // Sent to the expression module on request.
  131. LLSD mSkeletonData;
  132. // Map of used joints and last time seen
  133. active_joint_map_t mActiveJoints;
  134. F32 mRange;
  135. // true to play own avatar from server data stream, not directy from leap
  136. // module.
  137. bool mPlayServerEcho;
  138. // true when streaming to simulator
  139. bool mIsSending;
  140. // true when getting stream from simulator
  141. bool mIsReceiving;
  142. };
  143. #endif // LL_LLPUPPETMODULE_H
  144. #endif // LL_PUPPETRY