lllocalgltfmaterials.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**
  2. * @file lllocalgltfmaterials.h
  3. * @brief LLLocalGLTFMaterial and HBFloaterLocalMaterial classes declaration
  4. *
  5. * $LicenseInfo:firstyear=2022&license=viewergpl$
  6. *
  7. * Copyright (c) 2022, Linden Research, Inc. (LLLocalGLTFMaterial)
  8. * Copyright (c) 2023, Henri Beauchamp. (HBFloaterLocalMaterial)
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LOCALGLTFMATERIALS_H
  34. #define LL_LOCALGLTFMATERIALS_H
  35. #include <list>
  36. #include <time.h> // For time_t
  37. #include "lleventtimer.h"
  38. #include "hbfileselector.h"
  39. #include "llpointer.h"
  40. #include "llgltfmateriallist.h"
  41. class LLButton;
  42. class LLCheckBoxCtrl;
  43. class LLScrollListCtrl;
  44. class LLTextureEntry;
  45. class LLLocalGLTFMaterialTimer final : public LLEventTimer
  46. {
  47. public:
  48. LLLocalGLTFMaterialTimer();
  49. bool tick() override;
  50. void startTimer();
  51. void stopTimer();
  52. bool isRunning();
  53. };
  54. class LLLocalGLTFMaterial : public LLFetchedGLTFMaterial
  55. {
  56. protected:
  57. LOG_CLASS(LLLocalGLTFMaterial);
  58. public:
  59. LLLocalGLTFMaterial(const std::string& filename, S32 index);
  60. LL_INLINE const std::string& getFilename() const { return mFilename; }
  61. LL_INLINE const std::string& getShortName() const { return mShortName; }
  62. LL_INLINE const LLUUID& getTrackingID() const { return mTrackingID; }
  63. LL_INLINE const LLUUID& getWorldID() const { return mWorldID; }
  64. LL_INLINE S32 getIndexInFile() const { return mMaterialIndex; }
  65. bool updateSelf();
  66. typedef std::list<LLPointer<LLLocalGLTFMaterial> > list_t;
  67. LL_INLINE static const list_t& getMaterialList() { return sMaterialList; }
  68. static void addUnits();
  69. static void delUnit(const LLUUID& tracking_id);
  70. static const LLUUID& getWorldID(const LLUUID& tracking_id);
  71. static bool isLocal(const LLUUID& world_id);
  72. static const std::string& getFilenameAndIndex(const LLUUID& tracking_id,
  73. S32& index);
  74. static void associate(const LLUUID& tracking_id, LLGLTFMaterial* matp);
  75. static void doUpdates();
  76. // To be called on viewer shutdown in LLAppViewer::cleanup(). HB
  77. static void cleanupClass();
  78. LL_INLINE static S32 getMaterialListVersion() { return sMaterialsListVersion; }
  79. private:
  80. bool loadMaterial();
  81. static S32 addUnit(const std::string& filename);
  82. static void addUnitsCallback(HBFileSelector::ELoadFilter type,
  83. std::deque<std::string>& files, void*);
  84. private:
  85. LLUUID mTrackingID;
  86. LLUUID mWorldID;
  87. std::string mFilename;
  88. std::string mShortName;
  89. time_t mLastModified;
  90. // A single file can have more than one material, so we use an index
  91. S32 mMaterialIndex;
  92. U32 mUpdateRetries;
  93. enum EExtension
  94. {
  95. ET_MATERIAL_GLTF,
  96. ET_MATERIAL_GLB,
  97. };
  98. EExtension mExtension;
  99. enum ELinkStatus
  100. {
  101. LS_ON,
  102. LS_BROKEN,
  103. };
  104. ELinkStatus mLinkStatus;
  105. private:
  106. static list_t sMaterialList;
  107. static LLLocalGLTFMaterialTimer sTimer;
  108. static S32 sMaterialsListVersion;
  109. };
  110. ///////////////////////////////////////////////////////////////////////////////
  111. // HBFloaterLocalMaterial class
  112. //
  113. // Implements the user interface to LLLocalGLTFMaterial as a floater allowing
  114. // to select/add/remove/upload local materials.
  115. ///////////////////////////////////////////////////////////////////////////////
  116. class HBFloaterLocalMaterial final : public LLFloater
  117. {
  118. protected:
  119. LOG_CLASS(HBFloaterLocalMaterial);
  120. public:
  121. typedef void(*callback_t)(const LLUUID&, void*);
  122. // Call this to create a local GLTF material floater. The callback function
  123. // will be passed the selected material UUID, if any, or a null UUID on
  124. // Cancel action.
  125. // The material picker floater will automatically become dependent on the
  126. // parent floater of 'ownerp', if there is one (and if owner is not NULL,
  127. // of course), else it will stay independent.
  128. HBFloaterLocalMaterial(LLView* ownerp, callback_t cb, void* userdata);
  129. ~HBFloaterLocalMaterial() override;
  130. private:
  131. bool postBuild() override;
  132. void draw() override;
  133. static void onBtnAdd(void*);
  134. static void onBtnRemove(void* userdata);
  135. static void onBtnUpload(void* userdata);
  136. static void onBtnSelect(void* userdata);
  137. static void onBtnCancel(void* userdata);
  138. static void onMaterialListCommit(LLUICtrl*, void* userdata);
  139. private:
  140. LLScrollListCtrl* mMaterialsList;
  141. LLCheckBoxCtrl* mApplyImmediatelyCheck;
  142. LLButton* mSelectButton;
  143. LLButton* mRemoveButton;
  144. LLButton* mUploadButton;
  145. void (*mCallback)(const LLUUID& world_id, void* userdata);
  146. void* mCallbackUserdata;
  147. S32 mLastListVersion;
  148. };
  149. #endif // LL_LOCALGLTFMATERIALS_H