llvovolume.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /**
  2. * @file llvovolume.h
  3. * @brief LLVOVolume class header file
  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_LLVOVOLUME_H
  33. #define LL_LLVOVOLUME_H
  34. #include "hbfastmap.h"
  35. #include "llframetimer.h"
  36. #include "llmatrix3.h"
  37. #include "llmatrix4.h"
  38. #include "llpointer.h"
  39. #include "llmeshrepository.h"
  40. #include "llviewermedia.h"
  41. #include "llviewerobject.h"
  42. #include "llviewertexture.h"
  43. class LLDrawPool;
  44. class LLMaterialID;
  45. class LLMeshSkinInfo;
  46. class LLObjectMediaDataClient;
  47. class LLObjectMediaNavigateClient;
  48. class LLSelectNode;
  49. class LLViewerTextureAnim;
  50. class LLVOAvatar;
  51. typedef std::vector<viewer_media_t> media_list_t;
  52. enum LLVolumeInterfaceType
  53. {
  54. INTERFACE_FLEXIBLE = 1,
  55. };
  56. class LLRiggedVolume : public LLVolume
  57. {
  58. public:
  59. LLRiggedVolume(const LLVolumeParams& params)
  60. : LLVolume(params, 0.f)
  61. {
  62. }
  63. enum
  64. {
  65. UPDATE_ALL_FACES = -1,
  66. DO_NOT_UPDATE_FACES = -2
  67. };
  68. void update(const LLMeshSkinInfo* skin, LLVOAvatar* avatar,
  69. const LLVolume* src_volume, S32 face_index = UPDATE_ALL_FACES,
  70. bool rebuild_face_octrees = true);
  71. };
  72. // Base class for implementations of the volume - Primitive, Flexible Object,
  73. // etc.
  74. class LLVolumeInterface
  75. {
  76. public:
  77. virtual ~LLVolumeInterface() = default;
  78. virtual LLVolumeInterfaceType getInterfaceType() const = 0;
  79. virtual void doIdleUpdate() = 0;
  80. virtual bool doUpdateGeometry(LLDrawable* drawable) = 0;
  81. virtual LLVector3 getPivotPosition() const = 0;
  82. virtual void onSetVolume(const LLVolumeParams& volume_params,
  83. S32 detail) = 0;
  84. virtual void onSetScale(const LLVector3& scale, bool damped) = 0;
  85. virtual void onParameterChanged(U16 param_type, LLNetworkData* data,
  86. bool in_use, bool local_origin) = 0;
  87. virtual void onShift(const LLVector4a& shift_vector) = 0;
  88. // Do we need a unique LLVolume instance ?
  89. virtual bool isVolumeUnique() const = 0;
  90. // Are we in global space ?
  91. virtual bool isVolumeGlobal() const = 0;
  92. // Is this object currently active ?
  93. virtual bool isActive() const = 0;
  94. virtual const LLMatrix4& getWorldMatrix(LLXformMatrix* xform) const = 0;
  95. virtual void updateRelativeXform(bool force_identity = false) = 0;
  96. virtual U32 getID() const = 0;
  97. virtual void preRebuild() = 0;
  98. };
  99. // Class which embodies all Volume objects (with pcode LL_PCODE_VOLUME)
  100. class LLVOVolume : public LLViewerObject
  101. {
  102. friend class LLDrawable;
  103. friend class LLFace;
  104. friend class LLVolumeImplFlexible;
  105. protected:
  106. LOG_CLASS(LLVOVolume);
  107. ~LLVOVolume() override;
  108. public:
  109. static void initClass();
  110. static void updateSettings();
  111. static void initSharedMedia();
  112. static void cleanupClass();
  113. LL_INLINE static void preUpdateGeom() { sNumLODChanges = 0; }
  114. enum
  115. {
  116. VERTEX_DATA_MASK = (1 << LLVertexBuffer::TYPE_VERTEX) |
  117. (1 << LLVertexBuffer::TYPE_NORMAL) |
  118. (1 << LLVertexBuffer::TYPE_TEXCOORD0) |
  119. (1 << LLVertexBuffer::TYPE_TEXCOORD1) |
  120. (1 << LLVertexBuffer::TYPE_COLOR)
  121. };
  122. LLVOVolume(const LLUUID& id, LLViewerRegion* regionp);
  123. LL_INLINE LLVOVolume* asVolume() override { return this; }
  124. // Override (and call through to parent) to clean up media references
  125. void markDead() override;
  126. LLDrawable* createDrawable() override;
  127. void deleteFaces();
  128. void animateTextures();
  129. bool isVisible() const;
  130. LL_INLINE bool isActive() const override { return !mStatic; }
  131. bool isAttachment() const override;
  132. bool isHUDAttachment() const override;
  133. // Overridden for sake of attachments treating themselves as a root object
  134. LL_INLINE bool isRootEdit() const override { return !mParent || ((LLViewerObject*)mParent)->isAvatar(); }
  135. void generateSilhouette(LLSelectNode* nodep, const LLVector3& view_point);
  136. bool setParent(LLViewerObject* parent) override;
  137. LL_INLINE S32 getLOD() const override { return mLOD; }
  138. LL_INLINE const LLVector3 getPivotPositionAgent() const override;
  139. LL_INLINE const LLMatrix4& getRelativeXform() const { return mRelativeXform; }
  140. LL_INLINE const LLMatrix3& getRelativeXformInvTrans() const
  141. {
  142. return mRelativeXformInvTrans;
  143. }
  144. const LLMatrix4& getRenderMatrix() const override;
  145. typedef fast_hmap<LLUUID, S32> texture_cost_t;
  146. U32 getRenderCost(texture_cost_t& textures) const;
  147. F32 getEstTrianglesMax() const override;
  148. F32 getEstTrianglesStreamingCost() const override;
  149. F32 getStreamingCost(S32* bytes = NULL, S32* visible_bytes = NULL,
  150. F32* unscaled_value = NULL) const override;
  151. U32 getTriangleCount(S32* vcount = NULL) const override;
  152. U32 getHighLODTriangleCount() override;
  153. LLMeshCostData* getCostData() const;
  154. bool lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
  155. // Which face to check (-1=ALL_SIDES)
  156. S32 face = -1,
  157. bool pick_transparent = false,
  158. bool pick_rigged = false,
  159. // Which face was hit
  160. S32* face_hit = NULL,
  161. // Intersection point
  162. LLVector4a* intersection = NULL,
  163. // Tex coord of the intersection
  164. LLVector2* tex_coord = NULL,
  165. // Surface normal at intersection
  166. LLVector4a* normal = NULL,
  167. // Surface tangent at intersection
  168. LLVector4a* tangent = NULL) override;
  169. LLVector3 agentPositionToVolume(const LLVector3& pos) const;
  170. LLVector3 agentDirectionToVolume(const LLVector3& dir) const;
  171. LLVector3 volumePositionToAgent(const LLVector3& dir) const;
  172. LLVector3 volumeDirectionToAgent(const LLVector3& dir) const;
  173. LL_INLINE bool getVolumeChanged() const { return mVolumeChanged; }
  174. LL_INLINE F32 getRadius() const { return mVObjRadius; }
  175. const LLMatrix4& getWorldMatrix(LLXformMatrix* xform) const override;
  176. void markForUpdate(bool rebuild_all = false) override;
  177. LL_INLINE void faceMappingChanged() override { mFaceMappingChanged = true; }
  178. // Called when the drawable shifts
  179. void onShift(const LLVector4a& shift_vector) override;
  180. void parameterChanged(U16 param_type, bool local_origin) override;
  181. void parameterChanged(U16 param_type, LLNetworkData* data, bool in_use,
  182. bool local_origin) override;
  183. // Call with recreate = true to force a rebuild of the reflection probe. HB
  184. void updateReflectionProbePtr(bool recreate = false);
  185. U32 processUpdateMessage(LLMessageSystem* mesgsys, void** user_data,
  186. U32 block_num, EObjectUpdateType upd_type,
  187. LLDataPacker* dp) override;
  188. void setSelected(bool sel) override;
  189. bool setDrawableParent(LLDrawable* parentp) override;
  190. void setScale(const LLVector3& scale, bool damped) override;
  191. void setNumTEs(U8 num_tes) override;
  192. void setTEImage(U8 te, LLViewerTexture* imagep) override;
  193. S32 setTETexture(U8 te, const LLUUID& uuid) override;
  194. S32 setTEColor(U8 te, const LLColor3& color) override;
  195. S32 setTEColor(U8 te, const LLColor4& color) override;
  196. S32 setTEBumpmap(U8 te, U8 bump) override;
  197. S32 setTEShiny(U8 te, U8 shiny) override;
  198. S32 setTEFullbright(U8 te, U8 fullbright) override;
  199. S32 setTEBumpShinyFullbright(U8 te, U8 bump) override;
  200. S32 setTEMediaFlags(U8 te, U8 media_flags) override;
  201. S32 setTEGlow(U8 te, F32 glow) override;
  202. S32 setTEMaterialID(U8 te, const LLMaterialID& matidp) override;
  203. static void setTEMaterialParamsCallbackTE(const LLUUID& objid,
  204. const LLMaterialID& matidp,
  205. const LLMaterialPtr paramsp,
  206. U32 te);
  207. S32 setTEMaterialParams(U8 te, const LLMaterialPtr paramsp) override;
  208. S32 setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* mat) override;
  209. S32 setTEScale(U8 te, F32 s, F32 t) override;
  210. S32 setTEScaleS(U8 te, F32 s) override;
  211. S32 setTEScaleT(U8 te, F32 t) override;
  212. S32 setTETexGen(U8 te, U8 texgen) override;
  213. S32 setTEMediaTexGen(U8 te, U8 media) override;
  214. void setTexture(S32 face);
  215. LL_INLINE S32 getIndexInTex(U32 ch) const { return mIndexInTex[ch]; }
  216. LL_INLINE void setIndexInTex(U32 ch, S32 index) { mIndexInTex[ch] = index; }
  217. #if LL_FIX_MAT_TRANSPARENCY
  218. bool notifyAboutCreatingTexture(LLViewerTexture* texture);
  219. bool notifyAboutMissingAsset(LLViewerTexture* texture);
  220. #endif
  221. bool setVolume(const LLVolumeParams& vol_params, S32 detail,
  222. bool unique_volume = false) override;
  223. void updateSculptTexture();
  224. void sculpt();
  225. void updateRelativeXform(bool force_identity = false);
  226. bool updateGeometry(LLDrawable* drawable) override;
  227. void updateFaceSize(S32 idx) override;
  228. bool updateLOD() override;
  229. // LOD set with this method will only last till next updateLOD() call:
  230. void tempSetLOD(S32 lod);
  231. // With this method, you may force an object to render always at full LOD
  232. LL_INLINE void setMaxLOD(bool b = true) { mLockMaxLOD = b; mLODChanged = true; }
  233. LL_INLINE bool getMaxLOD() const { return mLockMaxLOD; }
  234. void updateRadius() override;
  235. void updateTextures() override;
  236. void updateTextureVirtualSize(bool forced = false);
  237. void updateFaceFlags();
  238. void regenFaces();
  239. bool genBBoxes(bool force_global, bool update_bounds = true);
  240. void preRebuild();
  241. void updateSpatialExtents(LLVector4a&, LLVector4a&) override;
  242. F32 getBinRadius() override;
  243. U32 getPartitionType() const override;
  244. // For lights
  245. void setIsLight(bool is_light);
  246. void setLightLinearColor(const LLColor3& color);
  247. void setLightIntensity(F32 intensity);
  248. void setLightRadius(F32 radius);
  249. void setLightFalloff(F32 falloff);
  250. void setLightCutoff(F32 cutoff);
  251. void setLightTextureID(const LLUUID& id);
  252. void setSpotLightParams(const LLVector3& params);
  253. LL_INLINE void setLightSRGBColor(const LLColor3& c) { setLightLinearColor(linearColor3(c)); }
  254. bool getIsLight() const;
  255. LLColor3 getLightLinearBaseColor() const; // Not scaled by intensity
  256. LLColor3 getLightLinearColor() const; // Scaled by intensity
  257. const LLUUID& getLightTextureID() const;
  258. bool isLightSpotlight() const;
  259. LLVector3 getSpotLightParams() const;
  260. void updateSpotLightPriority();
  261. LL_INLINE F32 getSpotLightPriority() const { return mSpotLightPriority; }
  262. // Gets the light color in sRGB color space not scaled by intensity.
  263. LL_INLINE LLColor3 getLightSRGBBaseColor() const { return srgbColor3(getLightLinearBaseColor()); }
  264. // Gets the light color in sRGB color space scaled by intensity.
  265. LLColor3 getLightSRGBColor() const;
  266. LLViewerTexture* getLightTexture();
  267. F32 getLightIntensity() const;
  268. F32 getLightRadius() const;
  269. F32 getLightFalloff(F32 fudge_factor = 1.f) const;
  270. F32 getLightCutoff() const;
  271. // Reflection Probes
  272. bool setIsReflectionProbe(bool is_probe);
  273. bool setReflectionProbeAmbiance(F32 ambiance);
  274. bool setReflectionProbeNearClip(F32 near_clip);
  275. bool setReflectionProbeIsBox(bool is_box);
  276. bool setReflectionProbeIsDynamic(bool is_dynamic);
  277. bool setReflectionProbeIsMirror(bool is_mirror);
  278. bool isReflectionProbe() const override;
  279. F32 getReflectionProbeAmbiance() const;
  280. F32 getReflectionProbeNearClip() const;
  281. bool getReflectionProbeIsBox() const;
  282. bool getReflectionProbeIsDynamic() const;
  283. bool getReflectionProbeIsMirror() const;
  284. U32 getVolumeInterfaceID() const;
  285. bool isVolumeGlobal() const;
  286. bool isSculpted() const override;
  287. bool isMesh() const override;
  288. bool isRiggedMesh() const override;
  289. bool hasLightTexture() const override;
  290. // Flexible Objects
  291. bool isFlexible() const override;
  292. bool canBeFlexible() const;
  293. bool setIsFlexible(bool is_flexible);
  294. const LLMeshSkinInfo* getSkinInfo() const;
  295. // Extended mesh properties
  296. U32 getExtendedMeshFlags() const;
  297. void setExtendedMeshFlags(U32 flags);
  298. bool canBeAnimatedObject() const;
  299. bool isAnimatedObject() const override;
  300. void onReparent(LLViewerObject* old_parent,
  301. LLViewerObject* new_parent) override;
  302. void afterReparent() override;
  303. void updateRiggingInfo() override;
  304. // Functions that deal with media, or media navigation
  305. // Update this object's media data with the given media data array
  306. // (typically this is only called upon a response from a server request)
  307. void updateObjectMediaData(const LLSD& media_data_array,
  308. const std::string& media_version);
  309. // Bounce back media at the given index to its current URL (or home URL, if
  310. // current URL is empty)
  311. void mediaNavigateBounceBack(U8 texture_index);
  312. // Returns whether or not this object has permission to navigate or control
  313. // the given media entry
  314. enum MediaPermType
  315. {
  316. MEDIA_PERM_INTERACT, MEDIA_PERM_CONTROL
  317. };
  318. bool hasMediaPermission(const LLMediaEntry* media_entry,
  319. MediaPermType perm_type);
  320. void mediaNavigated(LLViewerMediaImpl* impl, LLPluginClassMedia* plugin,
  321. std::string new_location);
  322. void mediaEvent(LLViewerMediaImpl* impl, LLPluginClassMedia* plugin,
  323. LLViewerMediaObserver::EMediaEvent event);
  324. // Sync the given media data with the impl and the given te
  325. void syncMediaData(S32 te, const LLSD& media_data, bool merge,
  326. bool ignore_agent);
  327. // Send media data update to the simulator.
  328. void sendMediaDataUpdate();
  329. viewer_media_t getMediaImpl(U8 face_id) const;
  330. S32 getFaceIndexWithMediaImpl(const LLViewerMediaImpl* media_impl,
  331. S32 start_face_id);
  332. F64 getTotalMediaInterest() const;
  333. bool hasMedia() const;
  334. LLVector3 getApproximateFaceNormal(U8 face_id);
  335. // Returns 'true' iff the media data for this object is in flight
  336. bool isMediaDataBeingFetched() const;
  337. // Returns the "last fetched" media version, or -1 if not fetched yet
  338. LL_INLINE S32 getLastFetchedMediaVersion() const { return mLastFetchedMediaVersion; }
  339. LL_INLINE void addMDCImpl() { ++mMDCImplCount; }
  340. LL_INLINE void removeMDCImpl() { --mMDCImplCount; }
  341. // Flags any corresponding avatar as needing update
  342. void updateVisualComplexity();
  343. void notifyMeshLoaded();
  344. void notifySkinInfoLoaded(LLMeshSkinInfo* skin);
  345. void notifySkinInfoUnavailable();
  346. // Rigged volume update (for raycasting)
  347. // By default, this updates the bounding boxes of all the faces and builds
  348. // an octree for precise per-triangle raycasting.
  349. void updateRiggedVolume(bool force_treat_as_rigged,
  350. S32 face_index = LLRiggedVolume::UPDATE_ALL_FACES,
  351. bool rebuild_face_octrees = true);
  352. LL_INLINE LLRiggedVolume* getRiggedVolume() { return mRiggedVolume.get(); }
  353. // Returns true if volume should be treated as a rigged volume, i.e. if:
  354. // - object is selected
  355. // - object is an attachment
  356. // - object is rendered as rigged
  357. bool treatAsRigged();
  358. // Clear out rigged volume and revert back to non-rigged state for
  359. // picking/LOD/distance updates
  360. void clearRiggedVolume();
  361. // Used by the mesh repository. HB
  362. LL_INLINE void setInMeshCache() { mInMeshCache = true; }
  363. LL_INLINE void setInSkinCache() { mInSkinCache = true; }
  364. protected:
  365. void onDrawableUpdateFromServer();
  366. S32 computeLODDetail(F32 distance, F32 radius, F32 lod_factor);
  367. bool calcLOD();
  368. LLFace* addFace(S32 face_index);
  369. void requestMediaDataUpdate(bool isNew);
  370. void cleanUpMediaImpls();
  371. void addMediaImpl(LLViewerMediaImpl* media_impl, S32 texture_index);
  372. void removeMediaImpl(S32 texture_index);
  373. private:
  374. bool lodOrSculptChanged(LLDrawable* drawable, bool& update_bounds);
  375. void onSetExtendedMeshFlags(U32 flags);
  376. private:
  377. LLMatrix4 mRelativeXform;
  378. LLMatrix3 mRelativeXformInvTrans;
  379. LLVolumeInterface* mVolumeImpl;
  380. LLPointer<LLViewerFetchedTexture> mSculptTexture;
  381. LLPointer<LLViewerFetchedTexture> mLightTexture;
  382. LLPointer<LLRiggedVolume> mRiggedVolume;
  383. LLPointer<LLMeshSkinInfo> mSkinInfo;
  384. mutable LLPointer<LLMeshCostData> mCostData;
  385. F32 mSpotLightPriority;
  386. F32 mVObjRadius;
  387. F32 mLastDistance;
  388. S32 mLOD;
  389. U32 mServerDrawableUpdateCount;
  390. F32 mLastServerDrawableUpdate;
  391. S32 mIndexInTex[LLRender::NUM_VOLUME_TEXTURE_CHANNELS];
  392. S32 mMDCImplCount;
  393. // As fetched from server, starts as -1:
  394. S32 mLastFetchedMediaVersion;
  395. bool mLockMaxLOD;
  396. bool mLODChanged;
  397. bool mSculptChanged;
  398. bool mColorChanged;
  399. bool mFaceMappingChanged;
  400. bool mVolumeChanged;
  401. bool mSkinInfoFailed;
  402. // NOTE: these booleans mark this volume address as registered in the mesh
  403. // repository; they are *never* reset to false, and when set, must cause
  404. // markDead() to call the mesh repository unregisterVolume() method. HB
  405. bool mInMeshCache;
  406. bool mInSkinCache;
  407. LLFrameTimer mTextureUpdateTimer;
  408. media_list_t mMediaImplList;
  409. #if LL_FIX_MAT_TRANSPARENCY
  410. struct material_info
  411. {
  412. LLRender::eTexIndex map;
  413. U8 te;
  414. material_info(LLRender::eTexIndex map_, U8 te_)
  415. : map(map_),
  416. te(te_)
  417. {
  418. }
  419. };
  420. typedef std::multimap<LLUUID, material_info> mmap_uuid_map_t;
  421. mmap_uuid_map_t mWaitingTextureInfo;
  422. #endif
  423. protected:
  424. static S32 sNumLODChanges;
  425. public:
  426. LLViewerTextureAnim* mTextureAnimp;
  427. U8 mTexAnimMode;
  428. S32 mLastRiggingInfoLOD;
  429. static LLPointer<LLObjectMediaDataClient> sObjectMediaClient;
  430. static LLPointer<LLObjectMediaNavigateClient> sObjectMediaNavigateClient;
  431. static uuid_list_t sObjectMediaPending;
  432. // Also used in llvowlsky.cpp:
  433. static U32 sRenderMaxVBOSize;
  434. // LOD scale factor:
  435. static F32 sLODFactor;
  436. // LOD distance factor:
  437. static F32 sDistanceFactor;
  438. static bool sAnimateTextures;
  439. };
  440. #endif // LL_LLVOVOLUME_H