hbobjectbackup.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /**
  2. * @file hbobjectbackup.h
  3. *
  4. * $LicenseInfo:firstyear=2008&license=viewergpl$
  5. *
  6. * Original implementation Copyright (c) 2008 Merkat viewer authors.
  7. * Debugged/rewritten/augmented code Copyright (c) 2008-2023 Henri Beauchamp.
  8. *
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab. Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. *
  16. * There are special exceptions to the terms and conditions of the GPL as
  17. * it is applied to this Source Code. View the full text of the exception
  18. * in the file doc/FLOSS-exception.txt in this software distribution, or
  19. * online at
  20. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21. *
  22. * By copying, modifying or distributing this software, you acknowledge
  23. * that you have read and understood your obligations described above,
  24. * and agree to abide by those obligations.
  25. *
  26. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28. * COMPLETENESS OR PERFORMANCE.
  29. * $/LicenseInfo$
  30. */
  31. #ifndef LL_HBOBJECTBACKUP_H
  32. #define LL_HBOBJECTBACKUP_H
  33. #include "hbfastmap.h"
  34. #include "hbfileselector.h"
  35. #include "llselectmgr.h"
  36. #include "llviewerinventory.h"
  37. class LLSelectNode;
  38. class LLViewerObject;
  39. enum export_states {
  40. EXPORT_INIT,
  41. EXPORT_CHECK_PERMS,
  42. EXPORT_FETCH_PHYSICS,
  43. EXPORT_STRUCTURE,
  44. EXPORT_TEXTURES,
  45. EXPORT_LLSD,
  46. EXPORT_DONE,
  47. EXPORT_FAILED,
  48. EXPORT_ABORTED
  49. };
  50. class HBObjectBackup final : public LLFloater,
  51. public LLFloaterSingleton<HBObjectBackup>
  52. {
  53. friend class LLUISingleton<HBObjectBackup, VisibilityPolicy<LLFloater> >;
  54. protected:
  55. LOG_CLASS(HBObjectBackup);
  56. public:
  57. ~HBObjectBackup() override;
  58. ///////////////////////////////////////////////////////////////////////////
  59. // LLFloater interface
  60. void onClose(bool app_quitting) override;
  61. ///////////////////////////////////////////////////////////////////////////
  62. // Public interface for invoking the object backup feature
  63. // Import entry point
  64. static void importObject(bool upload = false);
  65. // Export entry point
  66. static void exportObject();
  67. ///////////////////////////////////////////////////////////////////////////
  68. // Public methods used in callbacks, workers and responders
  69. // Update map from texture worker
  70. void updateMap(const LLUUID& uploaded_asset);
  71. // Export idle callback
  72. static void exportWorker(void* userdata);
  73. // Prim updated callback, called in llviewerobjectlist.cpp
  74. static void primUpdate(LLViewerObject* object);
  75. // New prim callback, called in llviewerobjectlist.cpp
  76. static void newPrim(LLViewerObject* object);
  77. // Folder public getter, used by the texture cache responder
  78. std::string getFolder() { return mFolder; }
  79. ///////////////////////////////////////////////////////////////////////////
  80. // Public static methods, re-used in llviewerobjectexport.cpp
  81. static void setDefaultTextures();
  82. // Permissions checking (also used for export as DAE/OBJ).
  83. static bool validatePerms(const LLPermissions* item_permissions,
  84. bool strict = false); // true for meshes
  85. static bool validateAssetPerms(const LLUUID& asset_id,
  86. bool strict = false);
  87. static bool validateNode(LLSelectNode* node);
  88. private:
  89. // Open only via the importObject() and exportObject() methods defined
  90. // above.
  91. HBObjectBackup(const LLSD&);
  92. void showFloater(bool exporting);
  93. static bool confirmCloseCallback(const LLSD& notification,
  94. const LLSD& response);
  95. // Update the floater with status numbers
  96. void updateImportNumbers();
  97. void updateExportNumbers();
  98. // Permissions stuff.
  99. LLUUID validateTextureID(const LLUUID& asset_id);
  100. // Convert a selection list of objects to LLSD
  101. LLSD primsToLLSD(LLViewerObject::child_list_t child_list,
  102. bool is_attachment);
  103. // Move to next texture upload
  104. void uploadNextAsset();
  105. static void uploadNextAssetCallback(const LLSD& result, void*);
  106. // Start the export process
  107. void doExportObject(std::string filename);
  108. static void exportCallback(HBFileSelector::ESaveFilter type,
  109. std::string& filename, void*);
  110. // Returns true if we need to register this texture id for upload.
  111. bool uploadNeeded(const LLUUID& id);
  112. // Start the import process
  113. void doImportObject(std::string filename);
  114. static void importCallback(HBFileSelector::ELoadFilter type,
  115. std::string& filename, void* data);
  116. void importFirstObject();
  117. // Move to the next import group
  118. void importNextObject();
  119. // Export the next texture in list
  120. void exportNextTexture();
  121. // Apply LLSD to object
  122. void xmlToPrim(LLSD prim_llsd, LLViewerObject* object);
  123. // Rez a prim at a given position
  124. void rezAgentOffset(LLVector3 offset);
  125. // Get an offset from the agent based on rotation and current pos
  126. LLVector3 offsetAgent(LLVector3 offset);
  127. public:
  128. // Public static constants, used in callbacks, workers and responders
  129. static constexpr U32 TEXTURE_OK = 0x00;
  130. static constexpr U32 TEXTURE_BAD_PERM = 0x01;
  131. static constexpr U32 TEXTURE_MISSING = 0x02;
  132. static constexpr U32 TEXTURE_BAD_ENCODING = 0x04;
  133. static constexpr U32 TEXTURE_IS_NULL = 0x08;
  134. static constexpr U32 TEXTURE_SAVED_FAILED = 0x10;
  135. // Export state machine
  136. enum export_states mExportState;
  137. // Export result flags for textures.
  138. U32 mNonExportedTextures;
  139. // Set when the region supports the extra physics flags
  140. bool mGotExtraPhysics;
  141. // Are we ready to check for next texture ?
  142. bool mCheckNextTexture;
  143. private:
  144. // Are we active flag
  145. bool mRunning;
  146. // True if we need to rebase the assets
  147. bool mRetexture;
  148. // Counts of import and export objects and prims
  149. U32 mObjects;
  150. U32 mCurObject;
  151. U32 mPrims;
  152. U32 mCurPrim;
  153. // Number of rezzed prims
  154. U32 mRezCount;
  155. // Root pos and rotation and central root pos for link set
  156. LLVector3 mRootPos;
  157. LLQuaternion mRootRot;
  158. LLVector3 mRootRootPos;
  159. LLVector3 mGroupOffset;
  160. // Agent inital pos and rot when starting import
  161. LLVector3 mAgentPos;
  162. LLQuaternion mAgentRot;
  163. LLUUID mCurrentAsset;
  164. LLUUID mExpectingUpdate;
  165. // Safe handle to selected objects, held throughout export.
  166. LLObjectSelectionHandle mSelectedObjects;
  167. // Working llsd iterators for objects and linksets
  168. LLSD::map_const_iterator mPrimImportIter;
  169. LLSD::array_const_iterator mGroupPrimImportIter;
  170. // File and folder name control
  171. std::string mFileName;
  172. std::string mFolder;
  173. // Export texture list
  174. uuid_list_t mTexturesList;
  175. uuid_list_t mBadPermsTexturesList;
  176. // Import object tracking
  177. std::vector<LLViewerObject*> mToSelect;
  178. std::vector<LLViewerObject*>::iterator mProcessIter;
  179. // Working LLSD holders
  180. LLSD mLLSD;
  181. LLSD mThisGroup;
  182. public:
  183. // Rebase asset map. Static to keep the memory of the assets we already
  184. // uploaded during the viewer session (avoids superfluous re-uploads).
  185. typedef fast_hmap<LLUUID, LLUUID> rebase_map_t;
  186. static rebase_map_t sAssetMap;
  187. };
  188. extern LLUUID gTextureTransparent;
  189. #endif // LL_HBOBJECTBACKUP_H