PageRenderTime 48ms CodeModel.GetById 12ms app.highlight 31ms RepoModel.GetById 1ms app.codeStats 0ms

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