summaryrefslogtreecommitdiff
path: root/indra/newview/llfloatermodelpreview.h
blob: 08ac3873db77e7414d83f7cbf8aa46cfd6cb6f90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/**
 * @file llfloatermodelpreview.h
 * @brief LLFloaterModelPreview class definition
 *
 * $LicenseInfo:firstyear=2004&license=viewergpl$
 * 
 * Copyright (c) 2004-2007, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlife.com/developers/opensource/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at http://secondlife.com/developers/opensource/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#ifndef LL_LLFLOATERMODELPREVIEW_H
#define LL_LLFLOATERMODELPREVIEW_H

#include "llfloaternamedesc.h"

#include "lldynamictexture.h"
#include "llquaternion.h"
#include "llmeshrepository.h"
#include "llmodel.h"
#include "llthread.h"

class LLComboBox;
class LLJoint;
class LLViewerJointMesh;
class LLVOAvatar;
class LLTextBox;
class LLVertexBuffer;
class LLModelPreview;
class LLFloaterModelPreview;
class daeElement;
class domProfile_COMMON;
class domInstance_geometry;

class LLPhysicsDecompFloater : public LLFloater
{
public:

	LLPhysicsDecompFloater(LLSD& key);
	~LLPhysicsDecompFloater();
};

class LLModelLoader : public LLThread
{
public:
	typedef enum
	{
		STARTING = 0,
		READING_FILE,
		CREATING_FACES,
		GENERATING_VERTEX_BUFFERS,
		GENERATING_LOD,
		DONE,
	} eLoadState;

	U32 mState;
	std::string mFilename;
	S32 mLod;
	LLModelPreview* mPreview;
	LLMatrix4 mTransform;
	BOOL mFirstTransform;
	LLVector3 mExtents[2];

	std::map<daeElement*, LLPointer<LLModel> > mModel;
	
	typedef std::vector<LLPointer<LLModel> > model_list;
	model_list mModelList;

	typedef std::vector<LLModelInstance> model_instance_list;
	
	typedef std::map<LLMatrix4, model_instance_list > scene;

	scene mScene;

	LLModelLoader(std::string filename, S32 lod, LLModelPreview* preview);

	virtual void run();
	
	void processElement(daeElement* element);
	std::vector<LLImportMaterial> getMaterials(LLModel* model, domInstance_geometry* instance_geo);
	LLImportMaterial profileToMaterial(domProfile_COMMON* material);
	std::string getElementLabel(daeElement *element);
	LLColor4 getDaeColor(daeElement* element);

	//map of avatar joints as named in COLLADA assets to internal joint names
	std::map<std::string, std::string> mJointMap;
};

class LLModelPreview : public LLViewerDynamicTexture, public LLMutex
{
 public:
	
	 LLModelPreview(S32 width, S32 height, LLFloaterModelPreview* fmp);
	virtual ~LLModelPreview();

	void resetPreviewTarget();
	void setPreviewTarget(F32 distance);
	void setTexture(U32 name) { mTextureName = name; }

	BOOL render();
	void update();
	void genBuffers(S32 lod, bool skinned);
	void clearBuffers();
	void refresh();
	void rotate(F32 yaw_radians, F32 pitch_radians);
	void zoom(F32 zoom_amt);
	void pan(F32 right, F32 up);
	virtual BOOL needsRender() { return mNeedsUpdate; }
	void setPreviewLOD(S32 lod);
	void loadModel(std::string filename, S32 lod);
	void loadModelCallback(S32 lod);
	void genLODs(S32 which_lod = -1);
	void smoothNormals();
	void consolidate();
	void scrubMaterials();
	U32 calcResourceCost();
	void rebuildUploadData();
	void clearIncompatible(S32 lod);
	void updateStatusMessages();
	bool containsRiggedAsset( void );

	static void	textureLoadedCallback( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata );

 protected:
	friend class LLFloaterModelPreview;
	friend class LLPhysicsDecomp;

	LLFloaterModelPreview* mFMP;

	BOOL        mNeedsUpdate;
	bool		mDirty;
	U32         mTextureName;
	F32			mCameraDistance;
	F32			mCameraYaw;
	F32			mCameraPitch;
	F32			mCameraZoom;
	LLVector3	mCameraOffset;
	LLVector3	mPreviewTarget;
	LLVector3	mPreviewScale;
	S32			mPreviewLOD;
	U32			mResourceCost;
	S32			mLODMode[LLModel::NUM_LODS];
	S32			mLimit[LLModel::NUM_LODS];
	
	LLModelLoader* mModelLoader;


	LLModelLoader::scene mScene[LLModel::NUM_LODS];
	LLModelLoader::scene mBaseScene;

	LLModelLoader::model_list mModel[LLModel::NUM_LODS];
	LLModelLoader::model_list mBaseModel;

	std::map<LLPointer<LLModel>, U32> mGroup;
	std::map<LLPointer<LLModel>, U32> mObject;
	std::map<LLPointer<LLModel>, std::vector<U32> > mPatch;
	std::map<LLPointer<LLModel>, F32> mPercentage;

	std::map<LLPointer<LLModel>, std::vector<LLPointer<LLVertexBuffer> > > mPhysicsMesh;

	LLMeshUploadThread::instance_list mUploadData;
	std::set<LLPointer<LLViewerFetchedTexture> > mTextureSet;

	//map of vertex buffers to models (one vertex buffer in vector per face in model
	std::map<LLModel*, std::vector<LLPointer<LLVertexBuffer> > > mVertexBuffer[6];
};

class LLFloaterModelPreview : public LLFloater
{
public:
	static LLFloaterModelPreview* sInstance;

	LLFloaterModelPreview(const LLSD& key);
	virtual ~LLFloaterModelPreview();

	virtual BOOL postBuild();
	
	BOOL handleMouseDown(S32 x, S32 y, MASK mask);
	BOOL handleMouseUp(S32 x, S32 y, MASK mask);
	BOOL handleHover(S32 x, S32 y, MASK mask);
	BOOL handleScrollWheel(S32 x, S32 y, S32 clicks); 

	static void onMouseCaptureLostModelPreview(LLMouseHandler*);
	static void setUploadAmount(S32 amount) { sUploadAmount = amount; }

	static void onBrowseHighLOD(void* data);
	static void onBrowseMediumLOD(void* data); 
	static void onBrowseLowLOD(void* data);
	static void onBrowseLowestLOD(void* data);

	static void onUpload(void* data);

	static void onConsolidate(void* data);
	static void onScrubMaterials(void* data);
	static void onDecompose(void* data);
	static void onModelDecompositionComplete(LLModel* model, std::vector<LLPointer<LLVertexBuffer> >& physics_mesh);

	static void refresh(LLUICtrl* ctrl, void* data);

	void updateResourceCost();

	void			loadModel(S32 lod);

protected:
	friend class LLModelPreview;
	friend class LLMeshFilePicker;
	friend class LLPhysicsDecomp;
	friend class LLPhysicsDecompFloater;
	
	static void		onUploadJointsCommit(LLUICtrl*,void*);
	static void		onUploadSkinCommit(LLUICtrl*,void*);
	
	static void		onPreviewLODCommit(LLUICtrl*,void*);
	
	static void		onHighLODCommit(LLUICtrl*,void*);
	static void		onMediumLODCommit(LLUICtrl*,void*);
	static void		onLowLODCommit(LLUICtrl*,void*);
	static void		onLowestLODCommit(LLUICtrl*,void*);
	static void		onPhysicsLODCommit(LLUICtrl*,void*);

	static void		onHighLimitCommit(LLUICtrl*,void*);
	static void		onMediumLimitCommit(LLUICtrl*,void*);
	static void		onLowLimitCommit(LLUICtrl*,void*);
	static void		onLowestLimitCommit(LLUICtrl*,void*);
	static void		onPhysicsLimitCommit(LLUICtrl*,void*);
	
	static void		onSmoothNormalsCommit(LLUICtrl*,void*);

	static void		onAutoFillCommit(LLUICtrl*,void*);
	static void		onShowEdgesCommit(LLUICtrl*,void*);

	static void		onExplodeCommit(LLUICtrl*, void*);

	static void onPhysicsParamCommit(LLUICtrl* ctrl, void* userdata);
	static void onPhysicsStageExecute(LLUICtrl* ctrl, void* userdata);
	static void onPhysicsStageCancel(LLUICtrl* ctrl, void* userdata);
	static void onClosePhysicsFloater(LLUICtrl* ctrl, void* userdata);

	void			draw();
	static void		setLODMode(S32 lod, void* userdata);
	void			setLODMode(S32 lod, S32 which_mode);

	static void		setLimit(S32 lod, void* userdata);
	void			setLimit(S32 lod, S32 limit);

	void showDecompFloater();
	
	LLModelPreview*	mModelPreview;

	LLFloater* mDecompFloater;
	
	S32				mLastMouseX;
	S32				mLastMouseY;
	LLRect			mPreviewRect;
	U32				mGLName;
	BOOL			mLoading;
	static S32		sUploadAmount;
};

#endif  // LL_LLFLOATERMODELPREVIEW_H