llgltfmateriallist.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. * @file llgltfmateriallist.h
  3. * @brief The LLGLTFMaterialList class declaration
  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. #ifndef LL_LLGLTFMATERIALLIST_H
  33. #define LL_LLGLTFMATERIALLIST_H
  34. #include <list>
  35. #include "llassettype.h"
  36. #include "llextendedstatus.h"
  37. #include "hbfastmap.h"
  38. #include "hbfastset.h"
  39. #include "llfetchedgltfmaterial.h"
  40. class LLGLTFOverrideCacheEntry;
  41. class LLMessageSystem;
  42. class LLViewerObject;
  43. struct GLTFAssetLoadUserData;
  44. class LLGLTFMaterialList
  45. {
  46. friend class LLGLTFMaterialOverrideDispatchHandler;
  47. protected:
  48. LOG_CLASS(LLGLTFMaterialList);
  49. public:
  50. typedef void (*done_cb_t)(bool success);
  51. typedef void (*update_cb_t)(const LLUUID& object_id, S32 side);
  52. LLGLTFMaterialList() = default;
  53. LLFetchedGLTFMaterial* getMaterial(const LLUUID& id);
  54. LL_INLINE void addMaterial(const LLUUID& id, LLFetchedGLTFMaterial* matp)
  55. {
  56. mList[id] = matp;
  57. }
  58. LL_INLINE void removeMaterial(const LLUUID& id)
  59. {
  60. mList.erase(id);
  61. }
  62. void flushMaterials();
  63. // Queues a modification of a material that we want to send to the simulator.
  64. // Calls flushUpdates() to flush pending updates.
  65. // id: ID of object to modify
  66. // side: texure entry index to modify, or -1 for all sides
  67. // mat: material to apply as override, or nullptr to remove existing
  68. // overrides and revert to asset
  69. //
  70. // NOTE: do not use to revert to asset when applying a new asset id, use
  71. // queueApply below.
  72. static void queueModify(const LLViewerObject* objp, S32 side,
  73. const LLGLTFMaterial* matp);
  74. // Queues an application of a material asset we want to send to the simulator.
  75. // Calls flushUpdates() to flush pending updates.
  76. // object_id: Id of object to apply material asset to
  77. // side: texure entry index to apply material to, or -1 for all sides
  78. // asset_id: Id of material asset to apply, or LLUUID::null to
  79. // disassociate current material asset
  80. //
  81. // NOTE: Implicitly clears most override data if present
  82. static void queueApply(const LLViewerObject* objp, S32 side,
  83. const LLUUID& asset_id);
  84. // Queues an application of a material asset we want to send to the simulator.
  85. // Calls flushUpdates() to flush pending updates.
  86. // object_id: Id of object to apply material asset to
  87. // side: texure entry index to apply material to, or -1 for all sides
  88. // asset_id: Id of material asset to apply, or LLUUID::null to
  89. // disassociate current material asset
  90. // matp: override material, if NULL, will clear most override data.
  91. static void queueApply(const LLViewerObject* objp, S32 side,
  92. const LLUUID& asset_id, const LLGLTFMaterial* matp);
  93. // Flushes pending material updates to the simulator. Automatically called
  94. // once per frame, but may be called explicitly for cases that care about
  95. // the done_callback forwarded to gCoros.launch()
  96. static void flushUpdates(done_cb_t callback = NULL);
  97. static void addSelectionUpdateCallback(update_cb_t callback);
  98. // Queues an explicit LLSD ModifyMaterialParams update apply given override
  99. // data overrides LLSD map (or array of maps) in the format:
  100. // object_id: UUID(required) Id of object
  101. // side: integer(required) TE index of face to set, or -1 for all
  102. // gltf_json: string(optional) override data to set, empty string nulls
  103. // out override data, omissions of this
  104. // parameter keeps existing data.
  105. // asset_id: UUID(optional) Id of material asset to set: omission of
  106. // this parameter keeps existing material
  107. // asset Id
  108. //
  109. // NOTE: Unless you already have a gltf_json string you want to send,
  110. // strongly prefer using queueModify. If the queue/flush API is
  111. // insufficient, extend it.
  112. static void queueUpdate(const LLSD& data);
  113. void applyOverrideMessage(LLMessageSystem* msg, const std::string& data);
  114. // Called by batch builder to give LLGLTMaterialList an opportunity to
  115. // apply any override data that arrived before the object was ready to
  116. // receive it
  117. void applyQueuedOverrides(LLViewerObject* objp);
  118. static void doSelectionCallbacks(const LLUUID& object_id, S32 side);
  119. private:
  120. static void modifyMaterialCoro(const std::string& url, LLSD overrides,
  121. done_cb_t callback);
  122. // Called on onAssetLoadComplete() via the general queue thread pool.
  123. static bool decodeAsset(const LLUUID& id,
  124. GLTFAssetLoadUserData* asset_data);
  125. // Called on onAssetLoadComplete() on the main thread via the main loop
  126. // work queue.
  127. static void decodeAssetCallback(const LLUUID& id,
  128. GLTFAssetLoadUserData* asset_data,
  129. bool result);
  130. protected:
  131. static void onAssetLoadComplete(const LLUUID& asset_uuid,
  132. LLAssetType::EType type,
  133. void* user_data,
  134. S32 status, LLExtStat ext_status);
  135. protected:
  136. typedef fast_hmap<LLUUID, LLPointer<LLFetchedGLTFMaterial> > id_mat_map_t;
  137. id_mat_map_t mList;
  138. LLUUID mLastUpdateKey;
  139. struct ModifyMaterialData
  140. {
  141. LL_INLINE ModifyMaterialData()
  142. : side(-1),
  143. has_override(false)
  144. {
  145. }
  146. LL_INLINE ModifyMaterialData(const LLUUID& id,
  147. const LLGLTFMaterial& data,
  148. S32 s, bool overridden)
  149. : object_id(id),
  150. override_data(data),
  151. side(s),
  152. has_override(overridden)
  153. {
  154. }
  155. LLUUID object_id;
  156. LLGLTFMaterial override_data;
  157. S32 side;
  158. bool has_override;
  159. };
  160. typedef std::list<ModifyMaterialData> modify_queue_t;
  161. static modify_queue_t sModifyQueue;
  162. struct ApplyMaterialAssetData
  163. {
  164. LL_INLINE ApplyMaterialAssetData()
  165. : side(-1)
  166. {
  167. }
  168. LL_INLINE ApplyMaterialAssetData(const LLUUID& oid,const LLUUID& aid,
  169. LLGLTFMaterial* datap, S32 s)
  170. : object_id(oid),
  171. asset_id(aid),
  172. override_data(datap),
  173. side(s)
  174. {
  175. }
  176. LLUUID object_id;
  177. LLUUID asset_id;
  178. LLPointer<LLGLTFMaterial> override_data;
  179. S32 side;
  180. };
  181. typedef std::list<ApplyMaterialAssetData> apply_queue_t;
  182. static apply_queue_t sApplyQueue;
  183. // Data to be flushed to ModifyMaterialParams capability
  184. static LLSD sUpdates;
  185. typedef fast_hset<update_cb_t> selection_cb_list_t;
  186. static selection_cb_list_t sSelectionCallbacks;
  187. };
  188. extern LLGLTFMaterialList gGLTFMaterialList;
  189. #endif // LL_LLGLTFMATERIALLIST_H