/indra/newview/llvovolume.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 379 lines · 261 code · 70 blank · 48 comment · 0 complexity · af4b6311397ceabc07c91036589fcc40 MD5 · raw file

  1. /**
  2. * @file llvovolume.h
  3. * @brief LLVOVolume class header file
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLVOVOLUME_H
  27. #define LL_LLVOVOLUME_H
  28. #include "llviewerobject.h"
  29. #include "llviewertexture.h"
  30. #include "llviewermedia.h"
  31. #include "llframetimer.h"
  32. #include "m3math.h" // LLMatrix3
  33. #include "m4math.h" // LLMatrix4
  34. #include <map>
  35. class LLViewerTextureAnim;
  36. class LLDrawPool;
  37. class LLSelectNode;
  38. class LLObjectMediaDataClient;
  39. class LLObjectMediaNavigateClient;
  40. class LLVOAvatar;
  41. class LLMeshSkinInfo;
  42. typedef std::vector<viewer_media_t> media_list_t;
  43. enum LLVolumeInterfaceType
  44. {
  45. INTERFACE_FLEXIBLE = 1,
  46. };
  47. class LLRiggedVolume : public LLVolume
  48. {
  49. public:
  50. LLRiggedVolume(const LLVolumeParams& params)
  51. : LLVolume(params, 0.f)
  52. {
  53. }
  54. void update(const LLMeshSkinInfo* skin, LLVOAvatar* avatar, const LLVolume* src_volume);
  55. };
  56. // Base class for implementations of the volume - Primitive, Flexible Object, etc.
  57. class LLVolumeInterface
  58. {
  59. public:
  60. virtual ~LLVolumeInterface() { }
  61. virtual LLVolumeInterfaceType getInterfaceType() const = 0;
  62. virtual BOOL doIdleUpdate(LLAgent &agent, LLWorld &world, const F64 &time) = 0;
  63. virtual BOOL doUpdateGeometry(LLDrawable *drawable) = 0;
  64. virtual LLVector3 getPivotPosition() const = 0;
  65. virtual void onSetVolume(const LLVolumeParams &volume_params, const S32 detail) = 0;
  66. virtual void onSetScale(const LLVector3 &scale, BOOL damped) = 0;
  67. virtual void onParameterChanged(U16 param_type, LLNetworkData *data, BOOL in_use, bool local_origin) = 0;
  68. virtual void onShift(const LLVector4a &shift_vector) = 0;
  69. virtual bool isVolumeUnique() const = 0; // Do we need a unique LLVolume instance?
  70. virtual bool isVolumeGlobal() const = 0; // Are we in global space?
  71. virtual bool isActive() const = 0; // Is this object currently active?
  72. virtual const LLMatrix4& getWorldMatrix(LLXformMatrix* xform) const = 0;
  73. virtual void updateRelativeXform() = 0;
  74. virtual U32 getID() const = 0;
  75. virtual void preRebuild() = 0;
  76. };
  77. // Class which embodies all Volume objects (with pcode LL_PCODE_VOLUME)
  78. class LLVOVolume : public LLViewerObject
  79. {
  80. LOG_CLASS(LLVOVolume);
  81. protected:
  82. virtual ~LLVOVolume();
  83. public:
  84. static void initClass();
  85. static void cleanupClass();
  86. static void preUpdateGeom();
  87. enum
  88. {
  89. VERTEX_DATA_MASK = (1 << LLVertexBuffer::TYPE_VERTEX) |
  90. (1 << LLVertexBuffer::TYPE_NORMAL) |
  91. (1 << LLVertexBuffer::TYPE_TEXCOORD0) |
  92. (1 << LLVertexBuffer::TYPE_TEXCOORD1) |
  93. (1 << LLVertexBuffer::TYPE_COLOR)
  94. };
  95. public:
  96. LLVOVolume(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
  97. /*virtual*/ void markDead(); // Override (and call through to parent) to clean up media references
  98. /*virtual*/ LLDrawable* createDrawable(LLPipeline *pipeline);
  99. void deleteFaces();
  100. void animateTextures();
  101. /*virtual*/ BOOL idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time);
  102. BOOL isVisible() const ;
  103. /*virtual*/ BOOL isActive() const;
  104. /*virtual*/ BOOL isAttachment() const;
  105. /*virtual*/ BOOL isRootEdit() const; // overridden for sake of attachments treating themselves as a root object
  106. /*virtual*/ BOOL isHUDAttachment() const;
  107. void generateSilhouette(LLSelectNode* nodep, const LLVector3& view_point);
  108. /*virtual*/ BOOL setParent(LLViewerObject* parent);
  109. S32 getLOD() const { return mLOD; }
  110. const LLVector3 getPivotPositionAgent() const;
  111. const LLMatrix4& getRelativeXform() const { return mRelativeXform; }
  112. const LLMatrix3& getRelativeXformInvTrans() const { return mRelativeXformInvTrans; }
  113. /*virtual*/ const LLMatrix4 getRenderMatrix() const;
  114. typedef std::map<LLUUID, S32> texture_cost_t;
  115. U32 getRenderCost(texture_cost_t &textures) const;
  116. F32 getStreamingCost(S32* bytes, S32* visible_bytes, F32* unscaled_value) const;
  117. /*virtual*/ F32 getStreamingCost(S32* bytes = NULL, S32* visible_bytes = NULL) { return getStreamingCost(bytes, visible_bytes, NULL); }
  118. /*virtual*/ U32 getTriangleCount(S32* vcount = NULL) const;
  119. /*virtual*/ U32 getHighLODTriangleCount();
  120. /*virtual*/ BOOL lineSegmentIntersect(const LLVector3& start, const LLVector3& end,
  121. S32 face = -1, // which face to check, -1 = ALL_SIDES
  122. BOOL pick_transparent = FALSE,
  123. S32* face_hit = NULL, // which face was hit
  124. LLVector3* intersection = NULL, // return the intersection point
  125. LLVector2* tex_coord = NULL, // return the texture coordinates of the intersection point
  126. LLVector3* normal = NULL, // return the surface normal at the intersection point
  127. LLVector3* bi_normal = NULL // return the surface bi-normal at the intersection point
  128. );
  129. LLVector3 agentPositionToVolume(const LLVector3& pos) const;
  130. LLVector3 agentDirectionToVolume(const LLVector3& dir) const;
  131. LLVector3 volumePositionToAgent(const LLVector3& dir) const;
  132. LLVector3 volumeDirectionToAgent(const LLVector3& dir) const;
  133. BOOL getVolumeChanged() const { return mVolumeChanged; }
  134. /*virtual*/ F32 getRadius() const { return mVObjRadius; };
  135. const LLMatrix4& getWorldMatrix(LLXformMatrix* xform) const;
  136. void markForUpdate(BOOL priority) { LLViewerObject::markForUpdate(priority); mVolumeChanged = TRUE; }
  137. /*virtual*/ void onShift(const LLVector4a &shift_vector); // Called when the drawable shifts
  138. /*virtual*/ void parameterChanged(U16 param_type, bool local_origin);
  139. /*virtual*/ void parameterChanged(U16 param_type, LLNetworkData* data, BOOL in_use, bool local_origin);
  140. /*virtual*/ U32 processUpdateMessage(LLMessageSystem *mesgsys,
  141. void **user_data,
  142. U32 block_num, const EObjectUpdateType update_type,
  143. LLDataPacker *dp);
  144. /*virtual*/ void setSelected(BOOL sel);
  145. /*virtual*/ BOOL setDrawableParent(LLDrawable* parentp);
  146. /*virtual*/ void setScale(const LLVector3 &scale, BOOL damped);
  147. /*virtual*/ void setNumTEs(const U8 num_tes);
  148. /*virtual*/ void setTEImage(const U8 te, LLViewerTexture *imagep);
  149. /*virtual*/ S32 setTETexture(const U8 te, const LLUUID &uuid);
  150. /*virtual*/ S32 setTEColor(const U8 te, const LLColor3 &color);
  151. /*virtual*/ S32 setTEColor(const U8 te, const LLColor4 &color);
  152. /*virtual*/ S32 setTEBumpmap(const U8 te, const U8 bump);
  153. /*virtual*/ S32 setTEShiny(const U8 te, const U8 shiny);
  154. /*virtual*/ S32 setTEFullbright(const U8 te, const U8 fullbright);
  155. /*virtual*/ S32 setTEBumpShinyFullbright(const U8 te, const U8 bump);
  156. /*virtual*/ S32 setTEMediaFlags(const U8 te, const U8 media_flags);
  157. /*virtual*/ S32 setTEGlow(const U8 te, const F32 glow);
  158. /*virtual*/ S32 setTEScale(const U8 te, const F32 s, const F32 t);
  159. /*virtual*/ S32 setTEScaleS(const U8 te, const F32 s);
  160. /*virtual*/ S32 setTEScaleT(const U8 te, const F32 t);
  161. /*virtual*/ S32 setTETexGen(const U8 te, const U8 texgen);
  162. /*virtual*/ S32 setTEMediaTexGen(const U8 te, const U8 media);
  163. /*virtual*/ BOOL setMaterial(const U8 material);
  164. void setTexture(const S32 face);
  165. S32 getIndexInTex() const {return mIndexInTex ;}
  166. /*virtual*/ BOOL setVolume(const LLVolumeParams &volume_params, const S32 detail, bool unique_volume = false);
  167. void updateSculptTexture();
  168. void setIndexInTex(S32 index) { mIndexInTex = index ;}
  169. void sculpt();
  170. static void rebuildMeshAssetCallback(LLVFS *vfs,
  171. const LLUUID& asset_uuid,
  172. LLAssetType::EType type,
  173. void* user_data, S32 status, LLExtStat ext_status);
  174. void updateRelativeXform();
  175. /*virtual*/ BOOL updateGeometry(LLDrawable *drawable);
  176. /*virtual*/ void updateFaceSize(S32 idx);
  177. /*virtual*/ BOOL updateLOD();
  178. void updateRadius();
  179. /*virtual*/ void updateTextures();
  180. void updateTextureVirtualSize(bool forced = false);
  181. void updateFaceFlags();
  182. void regenFaces();
  183. BOOL genBBoxes(BOOL force_global);
  184. void preRebuild();
  185. virtual void updateSpatialExtents(LLVector4a& min, LLVector4a& max);
  186. virtual F32 getBinRadius();
  187. virtual U32 getPartitionType() const;
  188. // For Lights
  189. void setIsLight(BOOL is_light);
  190. void setLightColor(const LLColor3& color);
  191. void setLightIntensity(F32 intensity);
  192. void setLightRadius(F32 radius);
  193. void setLightFalloff(F32 falloff);
  194. void setLightCutoff(F32 cutoff);
  195. void setLightTextureID(LLUUID id);
  196. void setSpotLightParams(LLVector3 params);
  197. BOOL getIsLight() const;
  198. LLColor3 getLightBaseColor() const; // not scaled by intensity
  199. LLColor3 getLightColor() const; // scaled by intensity
  200. LLUUID getLightTextureID() const;
  201. bool isLightSpotlight() const;
  202. LLVector3 getSpotLightParams() const;
  203. void updateSpotLightPriority();
  204. F32 getSpotLightPriority() const;
  205. LLViewerTexture* getLightTexture();
  206. F32 getLightIntensity() const;
  207. F32 getLightRadius() const;
  208. F32 getLightFalloff() const;
  209. F32 getLightCutoff() const;
  210. // Flexible Objects
  211. U32 getVolumeInterfaceID() const;
  212. virtual BOOL isFlexible() const;
  213. virtual BOOL isSculpted() const;
  214. virtual BOOL isMesh() const;
  215. virtual BOOL hasLightTexture() const;
  216. BOOL isVolumeGlobal() const;
  217. BOOL canBeFlexible() const;
  218. BOOL setIsFlexible(BOOL is_flexible);
  219. // Functions that deal with media, or media navigation
  220. // Update this object's media data with the given media data array
  221. // (typically this is only called upon a response from a server request)
  222. void updateObjectMediaData(const LLSD &media_data_array, const std::string &media_version);
  223. // Bounce back media at the given index to its current URL (or home URL, if current URL is empty)
  224. void mediaNavigateBounceBack(U8 texture_index);
  225. // Returns whether or not this object has permission to navigate or control
  226. // the given media entry
  227. enum MediaPermType {
  228. MEDIA_PERM_INTERACT, MEDIA_PERM_CONTROL
  229. };
  230. bool hasMediaPermission(const LLMediaEntry* media_entry, MediaPermType perm_type);
  231. void mediaNavigated(LLViewerMediaImpl *impl, LLPluginClassMedia* plugin, std::string new_location);
  232. void mediaEvent(LLViewerMediaImpl *impl, LLPluginClassMedia* plugin, LLViewerMediaObserver::EMediaEvent event);
  233. // Sync the given media data with the impl and the given te
  234. void syncMediaData(S32 te, const LLSD &media_data, bool merge, bool ignore_agent);
  235. // Send media data update to the simulator.
  236. void sendMediaDataUpdate();
  237. viewer_media_t getMediaImpl(U8 face_id) const;
  238. S32 getFaceIndexWithMediaImpl(const LLViewerMediaImpl* media_impl, S32 start_face_id);
  239. F64 getTotalMediaInterest() const;
  240. bool hasMedia() const;
  241. LLVector3 getApproximateFaceNormal(U8 face_id);
  242. void notifyMeshLoaded();
  243. // Returns 'true' iff the media data for this object is in flight
  244. bool isMediaDataBeingFetched() const;
  245. // Returns the "last fetched" media version, or -1 if not fetched yet
  246. S32 getLastFetchedMediaVersion() const { return mLastFetchedMediaVersion; }
  247. void addMDCImpl() { ++mMDCImplCount; }
  248. void removeMDCImpl() { --mMDCImplCount; }
  249. S32 getMDCImplCount() { return mMDCImplCount; }
  250. //rigged volume update (for raycasting)
  251. void updateRiggedVolume();
  252. LLRiggedVolume* getRiggedVolume();
  253. //returns true if volume should be treated as a rigged volume
  254. // - Build tools are open
  255. // - object is an attachment
  256. // - object is attached to self
  257. // - object is rendered as rigged
  258. bool treatAsRigged();
  259. //clear out rigged volume and revert back to non-rigged state for picking/LOD/distance updates
  260. void clearRiggedVolume();
  261. protected:
  262. S32 computeLODDetail(F32 distance, F32 radius);
  263. BOOL calcLOD();
  264. LLFace* addFace(S32 face_index);
  265. void updateTEData();
  266. // stats tracking for render complexity
  267. static S32 mRenderComplexity_last;
  268. static S32 mRenderComplexity_current;
  269. void requestMediaDataUpdate(bool isNew);
  270. void cleanUpMediaImpls();
  271. void addMediaImpl(LLViewerMediaImpl* media_impl, S32 texture_index) ;
  272. void removeMediaImpl(S32 texture_index) ;
  273. public:
  274. static S32 getRenderComplexityMax() {return mRenderComplexity_last;}
  275. static void updateRenderComplexity();
  276. LLViewerTextureAnim *mTextureAnimp;
  277. U8 mTexAnimMode;
  278. private:
  279. friend class LLDrawable;
  280. BOOL mFaceMappingChanged;
  281. LLFrameTimer mTextureUpdateTimer;
  282. S32 mLOD;
  283. BOOL mLODChanged;
  284. BOOL mSculptChanged;
  285. F32 mSpotLightPriority;
  286. LLMatrix4 mRelativeXform;
  287. LLMatrix3 mRelativeXformInvTrans;
  288. BOOL mVolumeChanged;
  289. F32 mVObjRadius;
  290. LLVolumeInterface *mVolumeImpl;
  291. LLPointer<LLViewerFetchedTexture> mSculptTexture;
  292. LLPointer<LLViewerFetchedTexture> mLightTexture;
  293. media_list_t mMediaImplList;
  294. S32 mLastFetchedMediaVersion; // as fetched from the server, starts as -1
  295. S32 mIndexInTex;
  296. S32 mMDCImplCount;
  297. LLPointer<LLRiggedVolume> mRiggedVolume;
  298. // statics
  299. public:
  300. static F32 sLODSlopDistanceFactor;// Changing this to zero, effectively disables the LOD transition slop
  301. static F32 sLODFactor; // LOD scale factor
  302. static F32 sDistanceFactor; // LOD distance factor
  303. static LLPointer<LLObjectMediaDataClient> sObjectMediaClient;
  304. static LLPointer<LLObjectMediaNavigateClient> sObjectMediaNavigateClient;
  305. protected:
  306. static S32 sNumLODChanges;
  307. friend class LLVolumeImplFlexible;
  308. };
  309. #endif // LL_LLVOVOLUME_H