Newer
Older
Nyx (Neal Orman)
committed
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
/**
* @file llavatarjoint.cpp
* @brief Implementation of LLAvatarJoint class
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
//-----------------------------------------------------------------------------
// Header Files
//-----------------------------------------------------------------------------
#include "llavatarjoint.h"
#include "llgl.h"
#include "llrender.h"
#include "llmath.h"
#include "llglheaders.h"
#include "llavatarappearance.h"
const F32 DEFAULT_AVATAR_JOINT_LOD = 0.0f;
Nyx (Neal Orman)
committed
//-----------------------------------------------------------------------------
// Static Data
//-----------------------------------------------------------------------------
BOOL LLAvatarJoint::sDisableLOD = FALSE;
//-----------------------------------------------------------------------------
// LLAvatarJoint()
// Class Constructors
Nyx (Neal Orman)
committed
//-----------------------------------------------------------------------------
LLAvatarJoint::LLAvatarJoint() :
LLJoint()
Nyx (Neal Orman)
committed
{
init();
}
Brad Payne (Vir Linden)
committed
LLAvatarJoint::LLAvatarJoint(S32 joint_num) :
LLJoint(joint_num)
{
init();
}
LLAvatarJoint::LLAvatarJoint(const std::string &name, LLJoint *parent) :
LLJoint(name, parent)
{
init();
}
Nyx (Neal Orman)
committed
void LLAvatarJoint::init()
{
mValid = FALSE;
mComponents = SC_JOINT | SC_BONE | SC_AXES;
mMinPixelArea = DEFAULT_AVATAR_JOINT_LOD;
Nyx (Neal Orman)
committed
mPickName = PN_DEFAULT;
mVisible = TRUE;
mMeshID = 0;
mIsTransparent = FALSE;
Nyx (Neal Orman)
committed
}
//-----------------------------------------------------------------------------
// ~LLAvatarJoint()
// Class Destructor
//-----------------------------------------------------------------------------
LLAvatarJoint::~LLAvatarJoint()
{
}
//--------------------------------------------------------------------
// setValid()
//--------------------------------------------------------------------
void LLAvatarJoint::setValid( BOOL valid, BOOL recursive )
{
//----------------------------------------------------------------
// set visibility for this joint
//----------------------------------------------------------------
mValid = valid;
//----------------------------------------------------------------
// set visibility for children
//----------------------------------------------------------------
if (recursive)
{
Graham Linden
committed
for (joints_t::iterator iter = mChildren.begin();
Nyx (Neal Orman)
committed
iter != mChildren.end(); ++iter)
{
LLAvatarJoint* joint = (LLAvatarJoint*)(*iter);
joint->setValid(valid, TRUE);
}
}
}
//--------------------------------------------------------------------
// setSkeletonComponents()
//--------------------------------------------------------------------
void LLAvatarJoint::setSkeletonComponents( U32 comp, BOOL recursive )
{
mComponents = comp;
if (recursive)
{
Graham Linden
committed
for (joints_t::iterator iter = mChildren.begin();
Nyx (Neal Orman)
committed
iter != mChildren.end(); ++iter)
{
Graham Linden
committed
LLAvatarJoint* joint = static_cast<LLAvatarJoint*>(*iter);
Nyx (Neal Orman)
committed
joint->setSkeletonComponents(comp, recursive);
}
}
}
void LLAvatarJoint::setVisible(BOOL visible, BOOL recursive)
{
mVisible = visible;
if (recursive)
{
Graham Linden
committed
for (joints_t::iterator iter = mChildren.begin();
Nyx (Neal Orman)
committed
iter != mChildren.end(); ++iter)
{
LLAvatarJoint* joint = (LLAvatarJoint*)(*iter);
joint->setVisible(visible, recursive);
}
}
}
void LLAvatarJoint::updateFaceSizes(U32 &num_vertices, U32& num_indices, F32 pixel_area)
{
Graham Linden
committed
for (joints_t::iterator iter = mChildren.begin();
iter != mChildren.end(); ++iter)
{
Graham Linden
committed
LLAvatarJoint* joint = static_cast<LLAvatarJoint*>(*iter);
joint->updateFaceSizes(num_vertices, num_indices, pixel_area);
}
}
void LLAvatarJoint::updateFaceData(LLFace *face, F32 pixel_area, BOOL damp_wind, bool terse_update)
{
Graham Linden
committed
for (joints_t::iterator iter = mChildren.begin();
iter != mChildren.end(); ++iter)
{
Graham Linden
committed
LLAvatarJoint* joint = static_cast<LLAvatarJoint*>(*iter);
joint->updateFaceData(face, pixel_area, damp_wind, terse_update);
}
}
void LLAvatarJoint::updateJointGeometry()
{
Graham Linden
committed
for (joints_t::iterator iter = mChildren.begin();
iter != mChildren.end(); ++iter)
{
LLAvatarJoint* joint = dynamic_cast<LLAvatarJoint*>(*iter);
joint->updateJointGeometry();
}
}
BOOL LLAvatarJoint::updateLOD(F32 pixel_area, BOOL activate)
{
BOOL lod_changed = FALSE;
BOOL found_lod = FALSE;
Graham Linden
committed
for (joints_t::iterator iter = mChildren.begin();
iter != mChildren.end(); ++iter)
{
Graham Linden
committed
LLAvatarJoint* joint = static_cast<LLAvatarJoint*>(*iter);
F32 jointLOD = joint->getLOD();
if (found_lod || jointLOD == DEFAULT_AVATAR_JOINT_LOD)
{
// we've already found a joint to enable, so enable the rest as alternatives
lod_changed |= joint->updateLOD(pixel_area, TRUE);
}
else
{
if (pixel_area >= jointLOD || sDisableLOD)
{
lod_changed |= joint->updateLOD(pixel_area, TRUE);
found_lod = TRUE;
}
else
{
lod_changed |= joint->updateLOD(pixel_area, FALSE);
}
}
}
return lod_changed;
}
void LLAvatarJoint::dump()
{
Graham Linden
committed
for (joints_t::iterator iter = mChildren.begin();
iter != mChildren.end(); ++iter)
{
Graham Linden
committed
LLAvatarJoint* joint = static_cast<LLAvatarJoint*>(*iter);
joint->dump();
}
}
Nyx (Neal Orman)
committed
void LLAvatarJoint::setMeshesToChildren()
{
removeAllChildren();
for (avatar_joint_mesh_list_t::iterator iter = mMeshParts.begin();
Nyx (Neal Orman)
committed
iter != mMeshParts.end(); iter++)
{
addChild((*iter));
Nyx (Neal Orman)
committed
}
}
//-----------------------------------------------------------------------------
// LLAvatarJointCollisionVolume()
//-----------------------------------------------------------------------------
LLAvatarJointCollisionVolume::LLAvatarJointCollisionVolume()
{
mUpdateXform = FALSE;
}
/*virtual*/
U32 LLAvatarJointCollisionVolume::render( F32 pixelArea, BOOL first_pass, BOOL is_dummy )
Nyx (Neal Orman)
committed
{
LL_ERRS() << "Cannot call render() on LLAvatarJointCollisionVolume" << LL_ENDL;
return 0;
Nyx (Neal Orman)
committed
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
}
LLVector3 LLAvatarJointCollisionVolume::getVolumePos(LLVector3 &offset)
{
mUpdateXform = TRUE;
LLVector3 result = offset;
result.scaleVec(getScale());
result.rotVec(getWorldRotation());
result += getWorldPosition();
return result;
}
void LLAvatarJointCollisionVolume::renderCollision()
{
updateWorldMatrix();
gGL.pushMatrix();
gGL.multMatrix( &mXform.getWorldMatrix().mMatrix[0][0] );
gGL.diffuseColor3f( 0.f, 0.f, 1.f );
gGL.begin(LLRender::LINES);
LLVector3 v[] =
{
LLVector3(1,0,0),
LLVector3(-1,0,0),
LLVector3(0,1,0),
LLVector3(0,-1,0),
LLVector3(0,0,-1),
LLVector3(0,0,1),
};
//sides
gGL.vertex3fv(v[0].mV);
gGL.vertex3fv(v[2].mV);
gGL.vertex3fv(v[0].mV);
gGL.vertex3fv(v[3].mV);
gGL.vertex3fv(v[1].mV);
gGL.vertex3fv(v[2].mV);
gGL.vertex3fv(v[1].mV);
gGL.vertex3fv(v[3].mV);
//top
gGL.vertex3fv(v[0].mV);
gGL.vertex3fv(v[4].mV);
gGL.vertex3fv(v[1].mV);
gGL.vertex3fv(v[4].mV);
gGL.vertex3fv(v[2].mV);
gGL.vertex3fv(v[4].mV);
gGL.vertex3fv(v[3].mV);
gGL.vertex3fv(v[4].mV);
//bottom
gGL.vertex3fv(v[0].mV);
gGL.vertex3fv(v[5].mV);
gGL.vertex3fv(v[1].mV);
gGL.vertex3fv(v[5].mV);
gGL.vertex3fv(v[2].mV);
gGL.vertex3fv(v[5].mV);
gGL.vertex3fv(v[3].mV);
gGL.vertex3fv(v[5].mV);
gGL.end();
gGL.popMatrix();
}
// End