diff options
Diffstat (limited to 'linden/indra/newview/lltoolmorph.cpp')
-rw-r--r-- | linden/indra/newview/lltoolmorph.cpp | 298 |
1 files changed, 298 insertions, 0 deletions
diff --git a/linden/indra/newview/lltoolmorph.cpp b/linden/indra/newview/lltoolmorph.cpp new file mode 100644 index 0000000..ca3d0e7 --- /dev/null +++ b/linden/indra/newview/lltoolmorph.cpp | |||
@@ -0,0 +1,298 @@ | |||
1 | /** | ||
2 | * @file lltoolmorph.cpp | ||
3 | * @brief A tool to manipulate faces.. | ||
4 | * | ||
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | // File includes | ||
31 | #include "lltoolmorph.h" | ||
32 | |||
33 | // Library includes | ||
34 | #include "audioengine.h" | ||
35 | #include "llviewercontrol.h" | ||
36 | #include "llfontgl.h" | ||
37 | #include "sound_ids.h" | ||
38 | #include "v3math.h" | ||
39 | #include "v3color.h" | ||
40 | |||
41 | // Viewer includes | ||
42 | #include "llagent.h" | ||
43 | #include "lldrawable.h" | ||
44 | #include "lldrawpoolavatar.h" | ||
45 | #include "llface.h" | ||
46 | #include "llfloatercustomize.h" | ||
47 | #include "llmorphview.h" | ||
48 | #include "llresmgr.h" | ||
49 | #include "llselectmgr.h" | ||
50 | #include "llsky.h" | ||
51 | #include "lltexlayer.h" | ||
52 | #include "lltoolmgr.h" | ||
53 | #include "lltoolview.h" | ||
54 | #include "llui.h" | ||
55 | #include "llviewercamera.h" | ||
56 | #include "llviewerimagelist.h" | ||
57 | #include "llviewerobject.h" | ||
58 | #include "llviewerwindow.h" | ||
59 | #include "llvoavatar.h" | ||
60 | #include "pipeline.h" | ||
61 | #include "viewer.h" | ||
62 | |||
63 | //LLToolMorph *gToolMorph = NULL; | ||
64 | |||
65 | //static | ||
66 | LLLinkedList<LLVisualParamHint> LLVisualParamHint::sInstances; | ||
67 | BOOL LLVisualParamReset::sDirty = FALSE; | ||
68 | |||
69 | //----------------------------------------------------------------------------- | ||
70 | // LLVisualParamHint() | ||
71 | //----------------------------------------------------------------------------- | ||
72 | |||
73 | // static | ||
74 | LLVisualParamHint::LLVisualParamHint( | ||
75 | S32 pos_x, S32 pos_y, | ||
76 | S32 width, S32 height, | ||
77 | LLViewerJointMesh *mesh, | ||
78 | LLViewerVisualParam *param, | ||
79 | F32 param_weight) | ||
80 | : | ||
81 | LLDynamicTexture(width, height, 3, LLDynamicTexture::ORDER_MIDDLE, TRUE ), | ||
82 | mNeedsUpdate( TRUE ), | ||
83 | mIsVisible( FALSE ), | ||
84 | mJointMesh( mesh ), | ||
85 | mVisualParam( param ), | ||
86 | mVisualParamWeight( param_weight ), | ||
87 | mAllowsUpdates( TRUE ), | ||
88 | mDelayFrames( 0 ), | ||
89 | mRect( pos_x, pos_y + height, pos_x + width, pos_y ), | ||
90 | mLastParamWeight(0.f) | ||
91 | { | ||
92 | LLVisualParamHint::sInstances.addData( this ); | ||
93 | LLUUID id; | ||
94 | id.set( gViewerArt.getString("avatar_thumb_bkgrnd.tga") ); | ||
95 | mBackgroundp = gImageList.getImage(id, FALSE, TRUE); | ||
96 | |||
97 | |||
98 | llassert(width != 0); | ||
99 | llassert(height != 0); | ||
100 | } | ||
101 | |||
102 | //----------------------------------------------------------------------------- | ||
103 | // ~LLVisualParamHint() | ||
104 | //----------------------------------------------------------------------------- | ||
105 | LLVisualParamHint::~LLVisualParamHint() | ||
106 | { | ||
107 | LLVisualParamHint::sInstances.removeData( this ); | ||
108 | } | ||
109 | |||
110 | //----------------------------------------------------------------------------- | ||
111 | // static | ||
112 | // requestHintUpdates() | ||
113 | // Requests updates for all instances (excluding two possible exceptions) Grungy but efficient. | ||
114 | //----------------------------------------------------------------------------- | ||
115 | void LLVisualParamHint::requestHintUpdates( LLVisualParamHint* exception1, LLVisualParamHint* exception2 ) | ||
116 | { | ||
117 | S32 delay_frames = 0; | ||
118 | for(LLVisualParamHint* instance = sInstances.getFirstData(); | ||
119 | instance; | ||
120 | instance = sInstances.getNextData()) | ||
121 | { | ||
122 | if( (instance != exception1) && (instance != exception2) ) | ||
123 | { | ||
124 | if( instance->mAllowsUpdates ) | ||
125 | { | ||
126 | instance->mNeedsUpdate = TRUE; | ||
127 | instance->mDelayFrames = delay_frames; | ||
128 | delay_frames++; | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | instance->mNeedsUpdate = TRUE; | ||
133 | instance->mDelayFrames = 0; | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | } | ||
138 | |||
139 | BOOL LLVisualParamHint::needsRender() | ||
140 | { | ||
141 | return mNeedsUpdate && mDelayFrames-- <= 0 && !gAgent.getAvatarObject()->mAppearanceAnimating && mAllowsUpdates; | ||
142 | } | ||
143 | |||
144 | void LLVisualParamHint::preRender(BOOL clear_depth) | ||
145 | { | ||
146 | LLVOAvatar* avatarp = gAgent.getAvatarObject(); | ||
147 | |||
148 | mLastParamWeight = avatarp->getVisualParamWeight(mVisualParam); | ||
149 | avatarp->setVisualParamWeight(mVisualParam, mVisualParamWeight); | ||
150 | avatarp->setVisualParamWeight("Blink_Left", 0.f); | ||
151 | avatarp->setVisualParamWeight("Blink_Right", 0.f); | ||
152 | avatarp->updateComposites(); | ||
153 | avatarp->updateVisualParams(); | ||
154 | avatarp->updateGeometry(avatarp->mDrawable); | ||
155 | LLDynamicTexture::preRender(clear_depth); | ||
156 | } | ||
157 | |||
158 | //----------------------------------------------------------------------------- | ||
159 | // render() | ||
160 | //----------------------------------------------------------------------------- | ||
161 | BOOL LLVisualParamHint::render() | ||
162 | { | ||
163 | LLVisualParamReset::sDirty = TRUE; | ||
164 | LLVOAvatar* avatarp = gAgent.getAvatarObject(); | ||
165 | |||
166 | glMatrixMode(GL_PROJECTION); | ||
167 | glPushMatrix(); | ||
168 | glLoadIdentity(); | ||
169 | glOrtho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f); | ||
170 | |||
171 | glMatrixMode(GL_MODELVIEW); | ||
172 | glPushMatrix(); | ||
173 | glLoadIdentity(); | ||
174 | |||
175 | LLGLSUIDefault gls_ui; | ||
176 | //LLGLState::verify(TRUE); | ||
177 | LLViewerImage::bindTexture(mBackgroundp); | ||
178 | glColor4f(1.f, 1.f, 1.f, 1.f); | ||
179 | gl_rect_2d_simple_tex( mWidth, mHeight ); | ||
180 | mBackgroundp->unbindTexture(0, GL_TEXTURE_2D); | ||
181 | |||
182 | glMatrixMode(GL_PROJECTION); | ||
183 | glPopMatrix(); | ||
184 | |||
185 | glMatrixMode(GL_MODELVIEW); | ||
186 | glPopMatrix(); | ||
187 | |||
188 | mNeedsUpdate = FALSE; | ||
189 | mIsVisible = TRUE; | ||
190 | |||
191 | LLViewerJointMesh* cam_target_joint = NULL; | ||
192 | const std::string& cam_target_mesh_name = mVisualParam->getCameraTargetName(); | ||
193 | if( !cam_target_mesh_name.empty() ) | ||
194 | { | ||
195 | cam_target_joint = (LLViewerJointMesh*)avatarp->getJoint( cam_target_mesh_name ); | ||
196 | } | ||
197 | if( !cam_target_joint ) | ||
198 | { | ||
199 | cam_target_joint = (LLViewerJointMesh*)gMorphView->getCameraTargetJoint(); | ||
200 | } | ||
201 | if( !cam_target_joint ) | ||
202 | { | ||
203 | cam_target_joint = (LLViewerJointMesh*)avatarp->getJoint("mHead"); | ||
204 | } | ||
205 | |||
206 | LLQuaternion avatar_rotation; | ||
207 | LLJoint* root_joint = avatarp->getRootJoint(); | ||
208 | if( root_joint ) | ||
209 | { | ||
210 | avatar_rotation = root_joint->getWorldRotation(); | ||
211 | } | ||
212 | |||
213 | LLVector3 target_joint_pos = cam_target_joint->getWorldPosition(); | ||
214 | |||
215 | LLVector3 target_offset( 0, 0, mVisualParam->getCameraElevation() ); | ||
216 | LLVector3 target_pos = target_joint_pos + (target_offset * avatar_rotation); | ||
217 | |||
218 | F32 cam_angle_radians = mVisualParam->getCameraAngle() * DEG_TO_RAD; | ||
219 | LLVector3 camera_snapshot_offset( | ||
220 | mVisualParam->getCameraDistance() * cosf( cam_angle_radians ), | ||
221 | mVisualParam->getCameraDistance() * sinf( cam_angle_radians ), | ||
222 | mVisualParam->getCameraElevation() ); | ||
223 | LLVector3 camera_pos = target_joint_pos + (camera_snapshot_offset * avatar_rotation); | ||
224 | |||
225 | gCamera->setAspect((F32)mWidth / (F32)mHeight); | ||
226 | gCamera->setOriginAndLookAt( | ||
227 | camera_pos, // camera | ||
228 | LLVector3(0.f, 0.f, 1.f), // up | ||
229 | target_pos ); // point of interest | ||
230 | |||
231 | gCamera->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mWidth, mHeight, FALSE); | ||
232 | |||
233 | if (avatarp->mDrawable.notNull()) | ||
234 | { | ||
235 | LLDrawPoolAvatar *avatarPoolp = (LLDrawPoolAvatar *)avatarp->mDrawable->getFace(0)->getPool(); | ||
236 | LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE); | ||
237 | gPipeline.unbindAGP(); | ||
238 | avatarPoolp->syncAGP(); | ||
239 | gPipeline.bindAGP(); | ||
240 | avatarPoolp->renderAvatars(avatarp, TRUE); // renders only one avatar (no shaders) | ||
241 | } | ||
242 | avatarp->setVisualParamWeight(mVisualParam, mLastParamWeight); | ||
243 | |||
244 | return TRUE; | ||
245 | } | ||
246 | |||
247 | |||
248 | //----------------------------------------------------------------------------- | ||
249 | // draw() | ||
250 | //----------------------------------------------------------------------------- | ||
251 | void LLVisualParamHint::draw() | ||
252 | { | ||
253 | if (!mIsVisible) return; | ||
254 | |||
255 | bindTexture(); | ||
256 | |||
257 | glColor4f(1.f, 1.f, 1.f, 1.f); | ||
258 | |||
259 | LLGLSUIDefault gls_ui; | ||
260 | glBegin(GL_QUADS); | ||
261 | { | ||
262 | glTexCoord2i(0, 1); | ||
263 | glVertex2i(0, mHeight); | ||
264 | glTexCoord2i(0, 0); | ||
265 | glVertex2i(0, 0); | ||
266 | glTexCoord2i(1, 0); | ||
267 | glVertex2i(mWidth, 0); | ||
268 | glTexCoord2i(1, 1); | ||
269 | glVertex2i(mWidth, mHeight); | ||
270 | } | ||
271 | glEnd(); | ||
272 | |||
273 | LLImageGL::unbindTexture(0, GL_TEXTURE_2D); | ||
274 | } | ||
275 | |||
276 | //----------------------------------------------------------------------------- | ||
277 | // LLVisualParamReset() | ||
278 | //----------------------------------------------------------------------------- | ||
279 | LLVisualParamReset::LLVisualParamReset() : LLDynamicTexture(1, 1, 1, ORDER_RESET, FALSE) | ||
280 | { | ||
281 | } | ||
282 | |||
283 | //----------------------------------------------------------------------------- | ||
284 | // render() | ||
285 | //----------------------------------------------------------------------------- | ||
286 | BOOL LLVisualParamReset::render() | ||
287 | { | ||
288 | if (sDirty) | ||
289 | { | ||
290 | LLVOAvatar* avatarp = gAgent.getAvatarObject(); | ||
291 | avatarp->updateComposites(); | ||
292 | avatarp->updateVisualParams(); | ||
293 | avatarp->updateGeometry(avatarp->mDrawable); | ||
294 | sDirty = FALSE; | ||
295 | } | ||
296 | |||
297 | return FALSE; | ||
298 | } | ||