llselectmgr.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. /**
  2. * @file llselectmgr.h
  3. * @brief A manager for selected objects and TEs.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, 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_LLSELECTMGR_H
  33. #define LL_LLSELECTMGR_H
  34. #include "boost/iterator/filter_iterator.hpp"
  35. #include "boost/signals2.hpp"
  36. #include "llbbox.h"
  37. #include "llcategory.h"
  38. #include "llcharacter.h"
  39. #include "llcontrol.h"
  40. #include "llcoord.h"
  41. #include "lleditmenuhandler.h"
  42. #include "llframetimer.h"
  43. #include "llgltfmaterial.h" // For gltf_mat_vec_t
  44. #include "llmaterial.h"
  45. #include "llpermissions.h"
  46. #include "llpointer.h"
  47. #include "llquaternion.h"
  48. #include "llrender.h"
  49. #include "llsafehandle.h"
  50. #include "llsaleinfo.h"
  51. #include "llundo.h"
  52. #include "lluuid.h"
  53. #include "llvector3d.h"
  54. #include "llviewerobject.h"
  55. class LLDrawable;
  56. class LLSelectNode;
  57. class LLViewerInventoryItem;
  58. class LLViewerTexture;
  59. class LLVOVolume;
  60. constexpr U8 UPD_NONE = 0x00;
  61. constexpr U8 UPD_POSITION = 0x01;
  62. constexpr U8 UPD_ROTATION = 0x02;
  63. constexpr U8 UPD_SCALE = 0x04;
  64. constexpr U8 UPD_LINKED_SETS = 0x08;
  65. constexpr U8 UPD_UNIFORM = 0x10; // Used with UPD_SCALE
  66. // This is used by the DeRezObject message to determine where to put derezed
  67. // objects.
  68. enum EDeRezDestination
  69. {
  70. DRD_SAVE_INTO_AGENT_INVENTORY = 0,
  71. DRD_ACQUIRE_TO_AGENT_INVENTORY = 1, // Try to leave copy in world
  72. DRD_SAVE_INTO_TASK_INVENTORY = 2,
  73. DRD_ATTACHMENT = 3,
  74. DRD_TAKE_INTO_AGENT_INVENTORY = 4, // Delete from world
  75. DRD_FORCE_TO_GOD_INVENTORY = 5, // Force take copy
  76. DRD_TRASH = 6,
  77. DRD_ATTACHMENT_TO_INV = 7,
  78. DRD_ATTACHMENT_EXISTS = 8,
  79. DRD_RETURN_TO_OWNER = 9, // Back to owner's inventory
  80. DRD_RETURN_TO_LAST_OWNER = 10, // Deeded object back to last
  81. // owner's inventory
  82. DRD_COUNT = 11
  83. };
  84. constexpr S32 SELECT_ALL_TES = -1;
  85. constexpr S32 SELECT_MAX_TES = 32;
  86. // Do something to all objects in the selection manager. The bool return value
  87. // can be used to indicate if all objects are identical (gathering information)
  88. // or if the operation was successful.
  89. struct LLSelectedObjectFunctor
  90. {
  91. virtual ~LLSelectedObjectFunctor() = default;
  92. virtual bool apply(LLViewerObject* object) = 0;
  93. };
  94. // Do something to all select nodes in the selection manager. The bool return
  95. // value can be used to indicate if all objects are identical (gathering
  96. // information) or if the operation was successful.
  97. struct LLSelectedNodeFunctor
  98. {
  99. virtual ~LLSelectedNodeFunctor() = default;
  100. virtual bool apply(LLSelectNode* node) = 0;
  101. };
  102. struct LLSelectedTEFunctor
  103. {
  104. virtual ~LLSelectedTEFunctor() = default;
  105. virtual bool apply(LLViewerObject* object, S32 face) = 0;
  106. };
  107. struct LLSelectedTEMaterialFunctor
  108. {
  109. virtual ~LLSelectedTEMaterialFunctor() = default;
  110. virtual LLMaterialPtr apply(LLViewerObject* object, S32 face,
  111. LLTextureEntry* tep,
  112. LLMaterialPtr& current_material) = 0;
  113. };
  114. template <typename T> struct LLSelectedTEGetFunctor
  115. {
  116. virtual ~LLSelectedTEGetFunctor() = default;
  117. virtual T get(LLViewerObject* object, S32 te) = 0;
  118. };
  119. typedef enum e_send_type
  120. {
  121. SEND_ONLY_ROOTS,
  122. SEND_INDIVIDUALS,
  123. SEND_ROOTS_FIRST, // Useful for serial undos on linked sets
  124. SEND_CHILDREN_FIRST // Useful for serial transforms of linked sets
  125. } ESendType;
  126. typedef enum e_grid_mode
  127. {
  128. GRID_MODE_WORLD,
  129. GRID_MODE_LOCAL,
  130. GRID_MODE_REF_OBJECT
  131. } EGridMode;
  132. typedef enum e_action_type
  133. {
  134. SELECT_ACTION_TYPE_BEGIN,
  135. SELECT_ACTION_TYPE_PICK,
  136. SELECT_ACTION_TYPE_MOVE,
  137. SELECT_ACTION_TYPE_ROTATE,
  138. SELECT_ACTION_TYPE_SCALE,
  139. NUM_ACTION_TYPES
  140. } EActionType;
  141. typedef enum e_selection_type
  142. {
  143. SELECT_TYPE_WORLD,
  144. SELECT_TYPE_ATTACHMENT,
  145. SELECT_TYPE_HUD
  146. } ESelectType;
  147. constexpr S32 TE_SELECT_MASK_ALL = 0xFFFFFFFF;
  148. // Contains information about a selected object, particularly which TEs are
  149. // selected.
  150. class LLSelectNode
  151. {
  152. protected:
  153. LOG_CLASS(LLSelectNode);
  154. public:
  155. LLSelectNode(LLViewerObject* object, bool do_glow);
  156. LLSelectNode(const LLSelectNode& nodep);
  157. ~LLSelectNode();
  158. void selectAllTEs(bool b);
  159. void selectTE(S32 te_index, bool selected);
  160. bool isTESelected(S32 te_index);
  161. S32 getLastSelectedTE();
  162. LL_INLINE S32 getLastOperatedTE() { return mLastTESelected; }
  163. S32 getTESelectMask() { return mTESelectMask; }
  164. void renderOneWireframe(const LLColor4& color);
  165. void renderOneSilhouette(const LLColor4& color, bool no_hidden = false);
  166. LL_INLINE void setTransient(bool transient) { mTransient = transient; }
  167. LL_INLINE bool isTransient() { return mTransient; }
  168. LLViewerObject* getObject();
  169. LL_INLINE void setObject(LLViewerObject* obj) { mObject = obj; }
  170. // *NOTE: invalidate stored textures and colors when # faces change
  171. void saveColors();
  172. void saveTextures(const uuid_vec_t& tex_ids);
  173. void saveTextureScaleRatios();
  174. void saveGLTFMaterials(const uuid_vec_t& mat_ids,
  175. const gltf_mat_vec_t& override_mats);
  176. bool allowOperationOnNode(PermissionBit op, U64 group_proxy_power) const;
  177. protected:
  178. LLPointer<LLViewerObject> mObject;
  179. S32 mTESelectMask;
  180. S32 mLastTESelected;
  181. public:
  182. LLPermissions* mPermissions;
  183. LLSaleInfo mSaleInfo;
  184. LLAggregatePermissions mAggregatePerm;
  185. LLAggregatePermissions mAggregateTexturePerm;
  186. LLAggregatePermissions mAggregateTexturePermOwner;
  187. LLCategory mCategory;
  188. S16 mInventorySerial;
  189. // For interactively modifying object position
  190. LLVector3 mSavedPositionLocal;
  191. LLVector3 mLastPositionLocal;
  192. // For interactively modifying object position
  193. LLVector3d mSavedPositionGlobal;
  194. // For interactively modifying object scale
  195. LLVector3 mSavedScale;
  196. LLVector3 mLastScale;
  197. // For interactively modifying object rotation
  198. LLQuaternion mSavedRotation;
  199. LLQuaternion mLastRotation;
  200. LLVector3d mDuplicatePos;
  201. LLQuaternion mDuplicateRot;
  202. LLUUID mItemID;
  203. LLUUID mFolderID;
  204. LLUUID mFromTaskID;
  205. U64 mCreationDate;
  206. std::string mName;
  207. std::string mDescription;
  208. std::string mTouchName;
  209. std::string mSitName;
  210. // Array of vertices to render silhouette of object:
  211. std::vector<LLVector3> mSilhouetteVertices;
  212. // Array of normals to render silhouette of object:
  213. std::vector<LLVector3> mSilhouetteNormals;
  214. std::vector<LLColor4> mSavedColors;
  215. uuid_vec_t mSavedTextures;
  216. uuid_vec_t mSavedGLTFMaterialIds;
  217. gltf_mat_vec_t mSavedGLTFOverrideMaterials;
  218. std::vector<LLVector3> mTextureScaleRatios;
  219. std::vector<std::vector<LLVector3> > mGLTFScaleRatios;
  220. // GLTF preview
  221. LLVector3 mLastMoveLocal;
  222. S32 mSelectedGLTFNode;
  223. S32 mSelectedGLTFPrim;
  224. // For root objects and objects individually selected
  225. bool mIndividualSelection;
  226. bool mTransient;
  227. bool mValid; // Is extra information valid ?
  228. bool mDuplicated;
  229. bool mSilhouetteGenerated; // Need to generate silhouette ?
  230. };
  231. class LLObjectSelection : public LLRefCount
  232. {
  233. friend class LLSelectMgr;
  234. friend class LLSafeHandle<LLObjectSelection>;
  235. protected:
  236. LOG_CLASS(LLObjectSelection);
  237. ~LLObjectSelection();
  238. public:
  239. typedef std::list<LLSelectNode*> list_t;
  240. public:
  241. // Iterators
  242. struct is_non_null
  243. {
  244. bool operator()(LLSelectNode* node)
  245. {
  246. return node->getObject() != NULL;
  247. }
  248. };
  249. typedef boost::filter_iterator<is_non_null, list_t::iterator > iterator;
  250. LL_INLINE iterator begin() { return iterator(mList.begin(), mList.end()); }
  251. LL_INLINE iterator end() { return iterator(mList.end(), mList.end()); }
  252. struct is_valid
  253. {
  254. bool operator()(LLSelectNode* node)
  255. {
  256. return node->getObject() != NULL && node->mValid;
  257. }
  258. };
  259. typedef boost::filter_iterator<is_valid, list_t::iterator > valid_iterator;
  260. LL_INLINE valid_iterator valid_begin() { return valid_iterator(mList.begin(), mList.end()); }
  261. LL_INLINE valid_iterator valid_end() { return valid_iterator(mList.end(), mList.end()); }
  262. struct is_root
  263. {
  264. bool operator()(LLSelectNode* node);
  265. };
  266. typedef boost::filter_iterator<is_root, list_t::iterator > root_iterator;
  267. LL_INLINE root_iterator root_begin() { return root_iterator(mList.begin(), mList.end()); }
  268. LL_INLINE root_iterator root_end() { return root_iterator(mList.end(), mList.end()); }
  269. struct is_valid_root
  270. {
  271. bool operator()(LLSelectNode* node);
  272. };
  273. typedef boost::filter_iterator<is_root, list_t::iterator > valid_root_iterator;
  274. LL_INLINE valid_root_iterator valid_root_begin()
  275. {
  276. return valid_root_iterator(mList.begin(), mList.end());
  277. }
  278. LL_INLINE valid_root_iterator valid_root_end() { return valid_root_iterator(mList.end(), mList.end()); }
  279. struct is_root_object
  280. {
  281. bool operator()(LLSelectNode* node);
  282. };
  283. typedef boost::filter_iterator<is_root_object, list_t::iterator > root_object_iterator;
  284. LL_INLINE root_object_iterator root_object_begin()
  285. {
  286. return root_object_iterator(mList.begin(), mList.end());
  287. }
  288. LL_INLINE root_object_iterator root_object_end()
  289. {
  290. return root_object_iterator(mList.end(), mList.end());
  291. }
  292. public:
  293. LLObjectSelection();
  294. LL_INLINE void updateEffects() {}
  295. LL_INLINE bool isEmpty() const { return mList.size() == 0; }
  296. LLSelectNode* getFirstNode(LLSelectedNodeFunctor* func = NULL);
  297. LLSelectNode* getFirstRootNode(LLSelectedNodeFunctor* func = NULL,
  298. bool non_root_ok = false);
  299. LLSelectNode* getFirstMoveableNode(bool get_root_first = false);
  300. LL_INLINE LLViewerObject* getFirstObject()
  301. {
  302. LLSelectNode* res = getFirstNode(NULL);
  303. return res ? res->getObject() : NULL;
  304. }
  305. LL_INLINE LLViewerObject* getFirstRootObject(bool non_root_ok = false)
  306. {
  307. LLSelectNode* res = getFirstRootNode(NULL, non_root_ok);
  308. return res ? res->getObject() : NULL;
  309. }
  310. LLViewerObject* getFirstSelectedObject(LLSelectedNodeFunctor* func,
  311. bool get_parent = false);
  312. LLViewerObject* getFirstEditableObject(bool get_parent = false);
  313. LLViewerObject* getFirstCopyableObject(bool get_parent = false);
  314. LLViewerObject* getFirstDeleteableObject();
  315. LLViewerObject* getFirstMoveableObject(bool get_parent = false);
  316. LLViewerObject* getFirstUndoEnabledObject(bool get_parent = false);
  317. // Return the object that lead to this selection, possibly a child
  318. LL_INLINE LLViewerObject* getPrimaryObject() { return mPrimaryObject; }
  319. // Methods to iterate through texture entries
  320. bool getSelectedTEValue(LLSelectedTEGetFunctor<F32>* func, F32& res,
  321. F32 tolerance);
  322. template <typename T> bool getSelectedTEValue(LLSelectedTEGetFunctor<T>* func,
  323. T& res);
  324. template <typename T> bool isMultipleTEValue(LLSelectedTEGetFunctor<T>* func,
  325. const T& ignore_value);
  326. S32 getNumNodes();
  327. LLSelectNode* findNode(LLViewerObject* objectp);
  328. // Count members
  329. LL_INLINE S32 getObjectCount() { cleanupNodes(); return (S32)mList.size(); }
  330. F32 getSelectedObjectCost();
  331. F32 getSelectedLinksetCost();
  332. F32 getSelectedPhysicsCost();
  333. F32 getSelectedLinksetPhysicsCost();
  334. F32 getSelectedObjectStreamingCost(S32* total_bytes = NULL,
  335. S32* visible_bytes = NULL);
  336. U32 getSelectedObjectTriangleCount(S32* vcount = NULL);
  337. S32 getTECount();
  338. S32 getRootObjectCount();
  339. bool isMultipleTESelected();
  340. bool contains(LLViewerObject* object);
  341. bool contains(LLViewerObject* object, S32 te);
  342. // Returns true is any node is currenly worn as an attachment
  343. bool isAttachment();
  344. // AXON: validate a potential link against limits
  345. bool checkAnimatedObjectEstTris();
  346. // Apply functors to various subsets of the selected objects. If firstonly
  347. // is false, returns the AND of all apply() calls. Else returns true
  348. // immediately if any apply() call succeeds (i.e. OR with early exit)
  349. bool applyToRootObjects(LLSelectedObjectFunctor* func,
  350. bool firstonly = false);
  351. bool applyToObjects(LLSelectedObjectFunctor* func);
  352. bool applyToTEs(LLSelectedTEFunctor* func, bool firstonly = false);
  353. bool applyToRootNodes(LLSelectedNodeFunctor* func, bool firstonly = false);
  354. bool applyToNodes(LLSelectedNodeFunctor* func, bool firstonly = false);
  355. LL_INLINE ESelectType getSelectType() const { return mSelectType; }
  356. private:
  357. void applyNoCopyTextureToTEs(LLViewerInventoryItem* itemp);
  358. // Multi-purpose method for applying PBR materials to the selected object
  359. // or faces, any combination of copy/mod/transfer permission restrictions.
  360. // This method moves the restricted material to the object's inventory and
  361. // does not make a copy of the material for each face. Then this only
  362. // material is used for all selected faces. Returns false if applying the
  363. // material failed on one or more selected faces.
  364. bool applyRestrictedPbrMatToTEs(LLViewerInventoryItem* itemp);
  365. void addNode(LLSelectNode* nodep);
  366. void addNodeAtEnd(LLSelectNode* nodep);
  367. void moveNodeToFront(LLSelectNode* nodep);
  368. void removeNode(LLSelectNode* nodep);
  369. void deleteAllNodes();
  370. void cleanupNodes();
  371. private:
  372. list_t mList;
  373. const LLObjectSelection& operator=(const LLObjectSelection&);
  374. LLPointer<LLViewerObject> mPrimaryObject;
  375. std::map<LLPointer<LLViewerObject>, LLSelectNode*> mSelectNodeMap;
  376. ESelectType mSelectType;
  377. };
  378. typedef LLSafeHandle<LLObjectSelection> LLObjectSelectionHandle;
  379. // For use with getFirstTest()
  380. struct LLSelectGetFirstTest;
  381. class LLSelectMgr : public LLEditMenuHandler
  382. {
  383. protected:
  384. LOG_CLASS(LLSelectMgr);
  385. public:
  386. LLSelectMgr();
  387. ~LLSelectMgr();
  388. void initClass(); // Called from LLAppViewer::init()
  389. // LLEditMenuHandler interface
  390. virtual bool canUndo() const;
  391. virtual void undo();
  392. virtual bool canRedo() const;
  393. virtual void redo();
  394. virtual bool canDoDelete() const;
  395. virtual void doDelete();
  396. virtual void deselect();
  397. virtual bool canDeselect() const;
  398. virtual void duplicate();
  399. virtual bool canDuplicate() const;
  400. void clearSelections();
  401. void update();
  402. void updateEffects(); // Update HUD effects
  403. void overrideObjectUpdates();
  404. // Returns the previous value of mForceSelection
  405. bool setForceSelection(bool force);
  406. ////////////////////////////////////////////////////////////////
  407. // Selection methods
  408. ////////////////////////////////////////////////////////////////
  409. static bool renderHiddenSelection();
  410. ////////////////////////////////////////////////////////////////
  411. // Add
  412. ////////////////////////////////////////////////////////////////
  413. // This method is meant to select an object, and then select all
  414. // of the ancestors and descendents. This should be the normal behavior.
  415. //
  416. // *NOTE: You must hold on to the object selection handle, otherwise
  417. // the objects will be automatically deselected in 1 frame.
  418. LLObjectSelectionHandle selectObjectAndFamily(LLViewerObject* object,
  419. bool add_to_end = false);
  420. // For when you want just a child object.
  421. LLObjectSelectionHandle selectObjectOnly(LLViewerObject* object,
  422. S32 face = SELECT_ALL_TES,
  423. S32 gltf_node = -1,
  424. S32 gltf_prim = -1);
  425. // Same as above, but takes a list of objects. Used by rectangle select.
  426. LLObjectSelectionHandle selectObjectAndFamily(const std::vector<LLViewerObject*>& object_list,
  427. bool send_to_sim = true);
  428. // converts all objects currently highlighted to a selection, and returns it
  429. LLObjectSelectionHandle selectHighlightedObjects();
  430. LLObjectSelectionHandle setHoverObject(LLViewerObject* objectp,
  431. S32 face = -1);
  432. void highlightObjectOnly(LLViewerObject* objectp);
  433. void highlightObjectAndFamily(LLViewerObject* objectp);
  434. void highlightObjectAndFamily(const std::vector<LLViewerObject*>& list);
  435. ////////////////////////////////////////////////////////////////
  436. // Remove
  437. ////////////////////////////////////////////////////////////////
  438. void deselectObjectOnly(LLViewerObject* object, bool send_to_sim = true);
  439. void deselectObjectAndFamily(LLViewerObject* object,
  440. bool send_to_sim = true,
  441. bool include_entire_object = false);
  442. // Send deselect messages to simulator, then clear the list
  443. void deselectAll();
  444. void deselectAllForStandingUp();
  445. // deselect only if nothing else currently referencing the selection
  446. void deselectUnused();
  447. // Deselect if the selection center is too far away from the agent.
  448. void deselectAllIfTooFar();
  449. // Removes all highlighted objects from current selection
  450. void deselectHighlightedObjects();
  451. void unhighlightObjectOnly(LLViewerObject* objectp);
  452. void unhighlightObjectAndFamily(LLViewerObject* objectp);
  453. void unhighlightAll();
  454. bool removeObjectFromSelections(const LLUUID& id);
  455. ////////////////////////////////////////////////////////////////
  456. // Selection editing
  457. ////////////////////////////////////////////////////////////////
  458. bool linkObjects();
  459. bool unlinkObjects();
  460. bool enableLinkObjects();
  461. bool enableUnlinkObjects();
  462. ////////////////////////////////////////////////////////////////
  463. // Selection accessors
  464. ////////////////////////////////////////////////////////////////
  465. LL_INLINE LLObjectSelectionHandle getSelection()
  466. {
  467. return mSelectedObjects;
  468. }
  469. // Right now this just renders the selection with root/child colors instead
  470. // of a single color
  471. LL_INLINE LLObjectSelectionHandle getEditSelection()
  472. {
  473. convertTransient();
  474. return mSelectedObjects;
  475. }
  476. LL_INLINE LLObjectSelectionHandle getHighlightedObjects()
  477. {
  478. return mHighlightedObjects;
  479. }
  480. LLSelectNode* getHoverNode();
  481. LLSelectNode* getPrimaryHoverNode();
  482. ////////////////////////////////////////////////////////////////
  483. // Grid manipulation
  484. ////////////////////////////////////////////////////////////////
  485. void addGridObject(LLViewerObject* objectp);
  486. void clearGridObjects();
  487. void setGridMode(EGridMode mode);
  488. LL_INLINE EGridMode getGridMode() { return mGridMode; }
  489. void getGrid(LLVector3& origin, LLQuaternion& rotation, LLVector3& scale,
  490. bool for_snap_guides = false);
  491. LL_INLINE bool getTEMode() { return mTEMode; }
  492. LL_INLINE void setTEMode(bool b) { mTEMode = b; }
  493. LL_INLINE bool shouldShowSelection() { return mShowSelection; }
  494. LLBBox getBBoxOfSelection() const;
  495. LL_INLINE LLBBox getSavedBBoxOfSelection() const
  496. {
  497. return mSavedSelectionBBox;
  498. }
  499. void dump();
  500. void cleanup();
  501. void updateSilhouettes();
  502. void renderSilhouettes(bool for_hud);
  503. LL_INLINE void enableSilhouette(bool enable) { mRenderSilhouettes = enable; }
  504. ////////////////////////////////////////////////////////////////
  505. // Utility functions that operate on the current selection
  506. ////////////////////////////////////////////////////////////////
  507. void saveSelectedObjectTransform(EActionType action_type);
  508. void saveSelectedObjectColors();
  509. void saveSelectedObjectTextures();
  510. // Sets which texture channel to query for scale and rot of display and
  511. // depends on UI state of LLPanelFace when editing
  512. LL_INLINE void setTextureChannel(LLRender::eTexIndex index)
  513. {
  514. mTextureChannel = index;
  515. }
  516. LL_INLINE LLRender::eTexIndex getTextureChannel()
  517. {
  518. return mTextureChannel;
  519. }
  520. void selectionUpdatePhysics(bool use_physics);
  521. void selectionUpdateTemporary(bool is_temporary);
  522. void selectionUpdatePhantom(bool is_ghost);
  523. void selectionDump();
  524. bool selectionAllPCode(LLPCode code); // All objects have this PCode
  525. bool selectionGetClickAction(U8* out_action);
  526. // true if all selected objects have same:
  527. bool selectionGetIncludeInSearch(bool* include_in_search_out);
  528. bool selectionGetGlow(F32* glow);
  529. void selectionSetPhysicsType(U8 type);
  530. void selectionSetGravity(F32 gravity);
  531. void selectionSetFriction(F32 friction);
  532. void selectionSetDensity(F32 density);
  533. void selectionSetRestitution(F32 restitution);
  534. void selectionSetMaterialParams(LLSelectedTEMaterialFunctor* material_func,
  535. S32 te = -1);
  536. void selectionSetMaterial(U8 material);
  537. void selectionSetTexture(const LLUUID& tex_id); // Item or asset id
  538. bool selectionSetGLTFMaterial(const LLUUID& mat_id); // Item or asset id
  539. void selectionSetColor(const LLColor4& color);
  540. void selectionSetColorOnly(const LLColor4& color); // Set only the RGB channels
  541. void selectionSetAlphaOnly(F32 alpha); // Set only the alpha channel
  542. void selectionRevertColors();
  543. bool selectionRevertTextures();
  544. void selectionRevertGLTFMaterials();
  545. void selectionSetTexGen(U8 texgen);
  546. void selectionSetBumpmap(U8 bumpmap);
  547. void selectionSetShiny(U8 shiny);
  548. void selectionSetFullbright(U8 fullbright);
  549. void selectionSetMedia(U8 media_type, const LLSD& media_data);
  550. void selectionSetClickAction(U8 action);
  551. void selectionSetIncludeInSearch(bool include_in_search);
  552. void selectionSetGlow(F32 glow);
  553. #if 1
  554. void selectionSetMaterials(LLMaterialPtr material);
  555. #endif
  556. void selectionRemoveMaterial();
  557. void selectionSetObjectPermissions(U8 perm_field, bool set, U32 perm_mask,
  558. bool do_override = false);
  559. void selectionSetObjectName(const std::string& name);
  560. void selectionSetObjectDescription(const std::string& desc);
  561. void selectionSetObjectCategory(const LLCategory& category);
  562. void selectionSetObjectSaleInfo(const LLSaleInfo& sale_info);
  563. void selectionTexScaleAutofit(F32 repeats_per_meter);
  564. void adjustTexturesByScale(bool send_to_sim, bool stretch);
  565. bool selectionMove(const LLVector3& displ, F32 rx, F32 ry, F32 rz,
  566. U32 update_type);
  567. void sendSelectionMove();
  568. void sendGodlikeRequest(const std::string& request,
  569. const std::string& parameter);
  570. // Will make sure all selected object meet current criteria, or deselect
  571. // them otherwise
  572. void validateSelection();
  573. // Returns true if it is possible to select this object
  574. bool canSelectObject(LLViewerObject* object);
  575. // Returns true when the current selection (if any) is of the avatar (not
  576. // HUD) attachment type. HB
  577. bool selectionIsAvatarAttachment();
  578. // Returns true if the viewer has information on all selected objects
  579. bool selectGetAllRootsValid();
  580. bool selectGetAllValid();
  581. // Returns true if you can modify all selected objects.
  582. bool selectGetRootsModify();
  583. bool selectGetModify();
  584. // Returns true if is all objects are non-permanent-enforced
  585. bool selectGetRootsNonPermanentEnforced();
  586. bool selectGetNonPermanentEnforced();
  587. // Returns true if is all objects are permanent
  588. bool selectGetRootsPermanent();
  589. bool selectGetPermanent();
  590. // Return true if is all objects are characters
  591. bool selectGetRootsCharacter();
  592. bool selectGetCharacter();
  593. // Returns true if is all objects are not pathfinding
  594. bool selectGetRootsNonPathfinding();
  595. bool selectGetNonPathfinding();
  596. // Returns true if is all objects are not permanent
  597. bool selectGetRootsNonPermanent();
  598. bool selectGetNonPermanent();
  599. // Returns true if is all objects are not character
  600. bool selectGetRootsNonCharacter();
  601. bool selectGetNonCharacter();
  602. bool selectGetEditableLinksets();
  603. bool selectGetViewableCharacters();
  604. std::string getPathFindingAttributeInfo(bool empty_for_none = false);
  605. // Returns true if selected objects can be transferred.
  606. bool selectGetRootsTransfer();
  607. // Returns true if selected objects can be copied.
  608. bool selectGetRootsCopy();
  609. // Returns true if all have same creator, returns id
  610. bool selectGetCreator(LLUUID& id, std::string& name);
  611. // Returns true if all objects have same owner, returns id
  612. bool selectGetOwner(LLUUID& id, std::string& name);
  613. // Returns true if all objects have same owner, returns id
  614. bool selectGetLastOwner(LLUUID& id, std::string& name);
  615. // Returns true if all are the same. id is stuffed with the value found if
  616. // available.
  617. bool selectGetGroup(LLUUID& id);
  618. // Returns true if all have data, returns two masks, each indicating which
  619. // bits are all on and all off
  620. bool selectGetPerm(U8 which_perm, U32* mask_on, U32* mask_off);
  621. // Returns true if all root objects have valid data and are group owned.
  622. bool selectIsGroupOwned();
  623. // Returns true if all the nodes are valid. Accumulates permissions in the
  624. // parameter.
  625. bool selectGetPermissions(LLPermissions& perm);
  626. // Returns true if all the nodes are valid. Depends onto "edit linked"
  627. // state. Children in linksets are a bit special: they require not only
  628. // move permission but also modify if "edit linked" is set, since you move
  629. // them relative to their parent.
  630. bool selectGetEditMoveLinksetPermissions(bool& move, bool& modify);
  631. // Get a bunch of useful sale information for the object(s) selected.
  632. // "_mixed" is true if not all objects have the same setting.
  633. void selectGetAggregateSaleInfo(U32& num_for_sale,
  634. bool& is_for_sale_mixed,
  635. bool& is_sale_price_mixed,
  636. S32& total_sale_price,
  637. S32& individual_sale_price);
  638. // Returns true if all nodes are valid. Method also stores an accumulated
  639. // sale info.
  640. bool selectGetSaleInfo(LLSaleInfo& sale_info);
  641. // Returns true if all nodes are valid. fills passed in object
  642. // with the aggregate permissions of the selection.
  643. bool selectGetAggregatePermissions(LLAggregatePermissions& ag_perm);
  644. // Returns true if all nodes are valid. fills passed in object with the
  645. // aggregate permissions for texture inventory items of the selection.
  646. bool selectGetAggregateTexturePermissions(LLAggregatePermissions& ag_perm);
  647. LLPermissions* findObjectPermissions(const LLViewerObject* object);
  648. void selectDelete(); // Delete on simulator
  649. void selectForceDelete(); // just delete, no into trash
  650. // Duplicate on simulator:
  651. void selectDuplicate(const LLVector3& offset, bool select_copy);
  652. void repeatDuplicate();
  653. void selectDuplicateOnRay(const LLVector3& ray_start_region,
  654. const LLVector3& ray_end_region,
  655. bool bypass_raycast,
  656. bool ray_end_is_intersection,
  657. const LLUUID& ray_target_id,
  658. bool copy_centers,
  659. bool copy_rotates,
  660. bool select_copy);
  661. void sendMultipleUpdate(U32 type); // Position, rotation, scale all in one
  662. void sendOwner(const LLUUID& owner_id, const LLUUID& group_id,
  663. bool do_override = false);
  664. void sendGroup(const LLUUID& group_id);
  665. // Category ID is the UUID of the folder you want to contain the purchase.
  666. // *NOTE: sale_info check doesn't work for multiple object buy, which UI
  667. // does not currently support sale info is used for verification only, if
  668. // it does not match region info then the sale is cancelled.
  669. void sendBuy(const LLUUID& buyer_id, const LLUUID& category_id,
  670. const LLSaleInfo sale_info);
  671. void sendAttach(U8 attachment_point);
  672. void sendDetach();
  673. void sendDropAttachment();
  674. void sendLink();
  675. void sendDelink();
  676. #ifdef SEND_HINGES
  677. void sendHinge(U8 type);
  678. void sendDehinge();
  679. #endif
  680. void sendSelect();
  681. static void registerObjectPropertiesFamilyRequest(const LLUUID& id);
  682. // Asks sim for creator, permissions, resources, etc.
  683. void requestObjectPropertiesFamily(LLViewerObject* object);
  684. static void processObjectProperties(LLMessageSystem* mesgsys,
  685. void** user_data);
  686. static void processObjectPropertiesFamily(LLMessageSystem* mesgsys,
  687. void**);
  688. static void processForceObjectSelect(LLMessageSystem* msg, void**);
  689. void requestGodInfo();
  690. LL_INLINE const LLVector3d& getSelectionCenterGlobal() const
  691. {
  692. return mSelectionCenterGlobal;
  693. }
  694. void updateSelectionCenter();
  695. void pauseAssociatedAvatars();
  696. void updatePointAt();
  697. // Internal list maintenance functions. TODO: Make these private!
  698. void remove(std::vector<LLViewerObject*>& objects);
  699. void remove(LLViewerObject* object, S32 te = SELECT_ALL_TES,
  700. bool undoable = true);
  701. void removeAll();
  702. void addAsIndividual(LLViewerObject* object, S32 te = SELECT_ALL_TES,
  703. bool undoable = true, S32 gltf_node = -1,
  704. S32 gltf_prim = -1);
  705. void promoteSelectionToRoot();
  706. void demoteSelectionToIndividuals();
  707. private:
  708. // Converts temporarily selected objects to full-fledged selections
  709. void convertTransient();
  710. ESelectType getSelectTypeForObject(LLViewerObject* object);
  711. void addAsFamily(std::vector<LLViewerObject*>& objects,
  712. bool add_to_end = false);
  713. void generateSilhouette(LLSelectNode* nodep, const LLVector3& view_point);
  714. void updateSelectionSilhouette(LLObjectSelectionHandle object_handle,
  715. S32& num_sils_genned,
  716. std::vector<LLViewerObject*>& changed_objects);
  717. // Send one message to each region containing an object on selection list.
  718. void sendListToRegions(const std::string& message_name,
  719. void (*pack_header)(void*),
  720. void (*pack_body)(LLSelectNode*, void*),
  721. void* user_data,
  722. ESendType send_type);
  723. static void connectRefreshCachedSettingsSafe(const char* name);
  724. static void refreshCachedSettings();
  725. static void packAgentID(void*);
  726. static void packAgentAndSessionID(void* user_data);
  727. static void packAgentAndGroupID(void* user_data);
  728. static void packAgentAndSessionAndGroupID(void* user_data);
  729. static void packAgentIDAndSessionAndAttachment(void*);
  730. static void packAgentGroupAndCatID(void*);
  731. static void packDeleteHeader(void* userdata);
  732. static void packDeRezHeader(void* user_data);
  733. static void packObjectID(LLSelectNode* node, void*);
  734. static void packObjectIDAsParam(LLSelectNode* node, void*);
  735. static void packObjectIDAndRotation(LLSelectNode* node, void*);
  736. static void packObjectLocalID(LLSelectNode* node, void*);
  737. static void packObjectClickAction(LLSelectNode* node, void* data);
  738. static void packObjectIncludeInSearch(LLSelectNode* node, void* data);
  739. static void packObjectName(LLSelectNode* node, void* user_data);
  740. static void packObjectDescription(LLSelectNode* node, void* user_data);
  741. static void packObjectCategory(LLSelectNode* node, void* user_data);
  742. static void packObjectSaleInfo(LLSelectNode* node, void* user_data);
  743. static void packBuyObjectIDs(LLSelectNode* node, void* user_data);
  744. static void packDuplicate(LLSelectNode* node, void* duplicate_data);
  745. static void packDuplicateHeader(void*);
  746. static void packDuplicateOnRayHead(void* user_data);
  747. static void packPermissions(LLSelectNode* node, void* user_data);
  748. static void packDeselect(LLSelectNode* node, void* user_data);
  749. static void packMultipleUpdate(LLSelectNode* node, void* user_data);
  750. static void packPhysics(LLSelectNode* node, void* user_data);
  751. static void packShape(LLSelectNode* node, void* user_data);
  752. static void packOwnerHead(void* user_data);
  753. #ifdef SEND_HINGES
  754. static void packHingeHead(void* user_data);
  755. #endif
  756. static void packPermissionsHead(void* user_data);
  757. static void packGodlikeHead(void* user_data);
  758. static bool confirmDelete(const LLSD& notification, const LLSD& response,
  759. LLObjectSelectionHandle handle);
  760. // Gets the first ID that matches test and whether or not all Ids are
  761. // identical in selected objects.
  762. void getFirst(LLSelectGetFirstTest* test);
  763. // Only used for PBR rendering, for now. HB
  764. void renderMeshSelection(LLSelectNode* nodep, LLViewerObject* objectp,
  765. LLDrawable* drawablep, LLVOVolume* volp,
  766. const LLColor4& color, bool no_hidden = false);
  767. public:
  768. // Observer/callback support for when object selection changes or
  769. // properties are received/updated
  770. typedef boost::signals2::signal<void()> update_signal_t;
  771. update_signal_t mUpdateSignal;
  772. // Do we need to surround an object to pick it ?
  773. static bool sRectSelectInclusive;
  774. // Do we show the radius of selected lights?
  775. static bool sRenderLightRadius;
  776. static F32 sHighlightThickness;
  777. static F32 sHighlightUScale;
  778. static F32 sHighlightVScale;
  779. static F32 sHighlightAlpha;
  780. static F32 sHighlightAlphaTest;
  781. static F32 sHighlightUAnim;
  782. static F32 sHighlightVAnim;
  783. static LLColor4 sSilhouetteParentColor;
  784. static LLColor4 sSilhouetteChildColor;
  785. static LLColor4 sHighlightParentColor;
  786. static LLColor4 sHighlightChildColor;
  787. static LLColor4 sHighlightInspectColor;
  788. static LLColor4 sContextSilhouetteColor;
  789. U32 mRenderSelectionsPolicy;
  790. bool mHideSelectedObjects;
  791. bool mAllowSelectAvatar;
  792. bool mDebugSelectMgr;
  793. bool mEditLinkedParts;
  794. bool mSelectOwnedOnly;
  795. bool mSelectMovableOnly;
  796. private:
  797. LLPointer<LLViewerTexture> mSilhouetteImagep;
  798. LLObjectSelectionHandle mSelectedObjects;
  799. LLObjectSelectionHandle mHoverObjects;
  800. LLObjectSelectionHandle mHighlightedObjects;
  801. std::set<LLPointer<LLViewerObject> > mRectSelectedObjects;
  802. LLObjectSelection mGridObjects;
  803. LLQuaternion mGridRotation;
  804. LLVector3 mGridOrigin;
  805. LLVector3 mGridScale;
  806. EGridMode mGridMode;
  807. // Diffuse, normal or specular, depending on editing mode:
  808. LLRender::eTexIndex mTextureChannel;
  809. LLVector3d mSelectionCenterGlobal;
  810. LLBBox mSelectionBBox;
  811. LLVector3d mLastSentSelectionCenterGlobal;
  812. // Camera position from last generation of selection silhouette:
  813. LLVector3d mLastCameraPos;
  814. LLBBox mSavedSelectionBBox;
  815. LLFrameTimer mEffectsTimer;
  816. std::vector<LLAnimPauseRequest> mPauseRequests;
  817. // Render TE
  818. bool mTEMode;
  819. // Do we send the selection center name value and do we animate this
  820. // selection ?
  821. bool mShowSelection;
  822. // Do we render the silhouette ?
  823. bool mRenderSilhouettes;
  824. bool mForceSelection;
  825. static uuid_list_t sObjectPropertiesFamilyRequests;
  826. };
  827. // Utilities
  828. void dialog_refresh_all(); // Update subscribers to the selection list
  829. // Templates
  830. //-----------------------------------------------------------------------------
  831. // getSelectedTEValue
  832. //-----------------------------------------------------------------------------
  833. template <typename T> bool LLObjectSelection::getSelectedTEValue(LLSelectedTEGetFunctor<T>* func,
  834. T& res)
  835. {
  836. bool have_first = false;
  837. bool have_selected = false;
  838. T selected_value = T();
  839. // Now iterate through all TEs to test for sameness
  840. bool identical = true;
  841. for (iterator iter = begin(); iter != end(); ++iter)
  842. {
  843. LLSelectNode* node = *iter;
  844. LLViewerObject* object = node->getObject();
  845. S32 selected_te = -1;
  846. if (object == getPrimaryObject())
  847. {
  848. selected_te = node->getLastSelectedTE();
  849. }
  850. for (S32 te = 0, count = object->getNumTEs(); te < count; ++te)
  851. {
  852. if (!node->isTESelected(te))
  853. {
  854. continue;
  855. }
  856. T value = func->get(object, te);
  857. if (!have_first)
  858. {
  859. have_first = true;
  860. if (!have_selected)
  861. {
  862. selected_value = value;
  863. }
  864. }
  865. else
  866. {
  867. if (value != selected_value)
  868. {
  869. identical = false;
  870. }
  871. if (te == selected_te)
  872. {
  873. selected_value = value;
  874. have_selected = true;
  875. }
  876. }
  877. }
  878. if (!identical && have_selected)
  879. {
  880. break;
  881. }
  882. }
  883. if (have_first || have_selected)
  884. {
  885. res = selected_value;
  886. }
  887. return identical;
  888. }
  889. // Templates
  890. //-----------------------------------------------------------------------------
  891. // isMultipleTEValue iterate through all TEs and test for uniqueness
  892. // with certain return value ignored when performing the test.
  893. // E.g. when testing if the selection has a unique non-empty home URL you can
  894. // set ignore_value = "" and it will only compare among the non-empty home URLs
  895. // and ignore the empty ones.
  896. //-----------------------------------------------------------------------------
  897. template <typename T> bool LLObjectSelection::isMultipleTEValue(LLSelectedTEGetFunctor<T>* func,
  898. const T& ignore_value)
  899. {
  900. bool have_first = false;
  901. T selected_value = T();
  902. // Now iterate through all TEs to test for sameness
  903. bool unique = true;
  904. for (iterator iter = begin(); iter != end(); ++iter)
  905. {
  906. LLSelectNode* node = *iter;
  907. LLViewerObject* object = node->getObject();
  908. for (S32 te = 0, count = object->getNumTEs(); te < count; ++te)
  909. {
  910. if (!node->isTESelected(te))
  911. {
  912. continue;
  913. }
  914. T value = func->get(object, te);
  915. if (value == ignore_value)
  916. {
  917. continue;
  918. }
  919. if (!have_first)
  920. {
  921. have_first = true;
  922. }
  923. else
  924. {
  925. if (value != selected_value)
  926. {
  927. unique = false;
  928. return !unique;
  929. }
  930. }
  931. }
  932. }
  933. return !unique;
  934. }
  935. extern LLSelectMgr gSelectMgr;
  936. #endif