summaryrefslogtreecommitdiff
path: root/indra/newview/llviewerjointattachment.cpp
diff options
context:
space:
mode:
authorLoren Shih <seraph@lindenlab.com>2009-10-16 21:41:31 +0000
committerLoren Shih <seraph@lindenlab.com>2009-10-16 21:41:31 +0000
commit89d92267e233bc34fe600a07f485266e7edb2879 (patch)
tree6b70df4f746b15024f3956c0dc9cb5fa5233f606 /indra/newview/llviewerjointattachment.cpp
parentfbddb3163824d44cfb2ceee7127ac9ed2874acab (diff)
svn merge -r134817:136516 svn+ssh://svn.lindenlab.com/svn/linden/branches/avatar-pipeline/avatar-pipeline-multiattachments-3 into svn+ssh://svn.lindenlab.com/svn/linden/branches/viewer/viewer-2.0.0-3
For DEV-32867 : Avatar Pipeline Project - Multi-Attachments This is a viewer-side-only, infrastructure-only merge for multi-attachments. This should not lead to any new functionality; it simply provides backwards compatibility for when multi-attachments are enabled in viewer2.1, so that viewer2.0 users can see viewer2.1 avatars correctly. Reviewed by: Vir.
Diffstat (limited to 'indra/newview/llviewerjointattachment.cpp')
-rw-r--r--indra/newview/llviewerjointattachment.cpp247
1 files changed, 156 insertions, 91 deletions
diff --git a/indra/newview/llviewerjointattachment.cpp b/indra/newview/llviewerjointattachment.cpp
index 63c63e5546..2b4b78d82d 100644
--- a/indra/newview/llviewerjointattachment.cpp
+++ b/indra/newview/llviewerjointattachment.cpp
@@ -57,14 +57,14 @@ extern LLPipeline gPipeline;
// LLViewerJointAttachment()
//-----------------------------------------------------------------------------
LLViewerJointAttachment::LLViewerJointAttachment() :
-mAttachedObject(NULL),
-mVisibleInFirst(FALSE),
-mGroup(0),
-mIsHUDAttachment(FALSE),
-mPieSlice(-1)
+ mVisibleInFirst(FALSE),
+ mGroup(0),
+ mIsHUDAttachment(FALSE),
+ mPieSlice(-1)
{
mValid = FALSE;
mUpdateXform = FALSE;
+ mAttachedObjects.clear();
}
//-----------------------------------------------------------------------------
@@ -103,36 +103,43 @@ U32 LLViewerJointAttachment::drawShape( F32 pixelArea, BOOL first_pass, BOOL is_
return 0;
}
-void LLViewerJointAttachment::setupDrawable(LLDrawable* drawablep)
+void LLViewerJointAttachment::setupDrawable(LLViewerObject *object)
{
- drawablep->mXform.setParent(&mXform); // LLViewerJointAttachment::lazyAttach
- drawablep->makeActive();
- LLVector3 current_pos = mAttachedObject->getRenderPosition();
- LLQuaternion current_rot = mAttachedObject->getRenderRotation();
- LLQuaternion attachment_pt_inv_rot = ~getWorldRotation();
+ if (!object->mDrawable)
+ return;
+ if (object->mDrawable->isActive())
+ {
+ object->mDrawable->makeStatic(FALSE);
+ }
+
+ object->mDrawable->mXform.setParent(getXform()); // LLViewerJointAttachment::lazyAttach
+ object->mDrawable->makeActive();
+ LLVector3 current_pos = object->getRenderPosition();
+ LLQuaternion current_rot = object->getRenderRotation();
+ LLQuaternion attachment_pt_inv_rot = ~(getWorldRotation());
current_pos -= getWorldPosition();
current_pos.rotVec(attachment_pt_inv_rot);
current_rot = current_rot * attachment_pt_inv_rot;
- drawablep->mXform.setPosition(current_pos);
- drawablep->mXform.setRotation(current_rot);
- gPipeline.markMoved(drawablep);
- gPipeline.markTextured(drawablep); // face may need to change draw pool to/from POOL_HUD
- drawablep->setState(LLDrawable::USE_BACKLIGHT);
+ object->mDrawable->mXform.setPosition(current_pos);
+ object->mDrawable->mXform.setRotation(current_rot);
+ gPipeline.markMoved(object->mDrawable);
+ gPipeline.markTextured(object->mDrawable); // face may need to change draw pool to/from POOL_HUD
+ object->mDrawable->setState(LLDrawable::USE_BACKLIGHT);
if(mIsHUDAttachment)
{
- for (S32 face_num = 0; face_num < drawablep->getNumFaces(); face_num++)
+ for (S32 face_num = 0; face_num < object->mDrawable->getNumFaces(); face_num++)
{
- drawablep->getFace(face_num)->setState(LLFace::HUD_RENDER);
+ object->mDrawable->getFace(face_num)->setState(LLFace::HUD_RENDER);
}
}
- LLViewerObject::const_child_list_t& child_list = mAttachedObject->getChildren();
+ LLViewerObject::const_child_list_t& child_list = object->getChildren();
for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
- iter != child_list.end(); iter++)
+ iter != child_list.end(); ++iter)
{
LLViewerObject* childp = *iter;
if (childp && childp->mDrawable.notNull())
@@ -157,27 +164,13 @@ void LLViewerJointAttachment::setupDrawable(LLDrawable* drawablep)
//-----------------------------------------------------------------------------
BOOL LLViewerJointAttachment::addObject(LLViewerObject* object)
{
- if (mAttachedObject)
+ if (isObjectAttached(object))
{
- llwarns << "Attempted to attach object where an attachment already exists!" << llendl;
-
- if (mAttachedObject == object) {
- llinfos << "(same object re-attached)" << llendl;
- removeObject(mAttachedObject);
- // Pass through anyway to let setupDrawable()
- // re-connect object to the joint correctly
- }
- else {
- llinfos << "(objects differ, removing existing object)" << llendl;
- // Rather hacky, but no-one can think of something
- // better to do for this case.
- gObjectList.killObject(mAttachedObject);
- // Proceed with new object attachment
- }
+ llinfos << "(same object re-attached)" << llendl;
+ removeObject(object);
+ // Pass through anyway to let setupDrawable()
+ // re-connect object to the joint correctly
}
- mAttachedObject = object;
-
- LLUUID item_id;
// Find the inventory item ID of the attached object
LLNameValue* item_id_nv = object->getNVPair("AttachItemID");
@@ -186,26 +179,15 @@ BOOL LLViewerJointAttachment::addObject(LLViewerObject* object)
const char* s = item_id_nv->getString();
if( s )
{
- item_id.set( s );
+ LLUUID item_id;
+ item_id.set(s);
+ object->setItemID(item_id);
lldebugs << "getNVPair( AttachItemID ) = " << item_id << llendl;
}
}
-
- mItemID = item_id;
-
- LLDrawable* drawablep = object->mDrawable;
-
- if (drawablep)
- {
- //if object is active, make it static
- if(drawablep->isActive())
- {
- drawablep->makeStatic(FALSE) ;
- }
-
- setupDrawable(drawablep);
- }
-
+ mAttachedObjects.push_back(object);
+ setupDrawable(object);
+
if (mIsHUDAttachment)
{
if (object->mText.notNull())
@@ -214,7 +196,7 @@ BOOL LLViewerJointAttachment::addObject(LLViewerObject* object)
}
LLViewerObject::const_child_list_t& child_list = object->getChildren();
for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
- iter != child_list.end(); iter++)
+ iter != child_list.end(); ++iter)
{
LLViewerObject* childp = *iter;
if (childp && childp->mText.notNull())
@@ -234,15 +216,33 @@ BOOL LLViewerJointAttachment::addObject(LLViewerObject* object)
//-----------------------------------------------------------------------------
void LLViewerJointAttachment::removeObject(LLViewerObject *object)
{
+ attachedobjs_vec_t::iterator iter;
+ for (iter = mAttachedObjects.begin();
+ iter != mAttachedObjects.end();
+ ++iter)
+ {
+ LLViewerObject *attached_object = (*iter);
+ if (attached_object == object)
+ {
+ break;
+ }
+ }
+ if (iter == mAttachedObjects.end())
+ {
+ llwarns << "Could not find object to detach" << llendl;
+ return;
+ }
+
// force object visibile
setAttachmentVisibility(TRUE);
+ mAttachedObjects.erase(iter);
if (object->mDrawable.notNull())
{
//if object is active, make it static
if(object->mDrawable->isActive())
{
- object->mDrawable->makeStatic(FALSE) ;
+ object->mDrawable->makeStatic(FALSE);
}
LLVector3 cur_position = object->getRenderPosition();
@@ -265,7 +265,7 @@ void LLViewerJointAttachment::removeObject(LLViewerObject *object)
LLViewerObject::const_child_list_t& child_list = object->getChildren();
for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
- iter != child_list.end(); iter++)
+ iter != child_list.end(); ++iter)
{
LLViewerObject* childp = *iter;
if (childp && childp->mDrawable.notNull())
@@ -290,7 +290,7 @@ void LLViewerJointAttachment::removeObject(LLViewerObject *object)
}
LLViewerObject::const_child_list_t& child_list = object->getChildren();
for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
- iter != child_list.end(); iter++)
+ iter != child_list.end(); ++iter)
{
LLViewerObject* childp = *iter;
if (childp->mText.notNull())
@@ -299,10 +299,11 @@ void LLViewerJointAttachment::removeObject(LLViewerObject *object)
}
}
}
-
- mAttachedObject = NULL;
- mUpdateXform = FALSE;
- mItemID.setNull();
+ if (mAttachedObjects.size() == 0)
+ {
+ mUpdateXform = FALSE;
+ }
+ object->setItemID(LLUUID::null);
}
//-----------------------------------------------------------------------------
@@ -310,20 +311,26 @@ void LLViewerJointAttachment::removeObject(LLViewerObject *object)
//-----------------------------------------------------------------------------
void LLViewerJointAttachment::setAttachmentVisibility(BOOL visible)
{
- if (!mAttachedObject || mAttachedObject->mDrawable.isNull() ||
- !(mAttachedObject->mDrawable->getSpatialBridge()))
- return;
-
- if (visible)
- {
- // Hack to make attachments not visible by disabling their type mask!
- // This will break if you can ever attach non-volumes! - djs 02/14/03
- mAttachedObject->mDrawable->getSpatialBridge()->mDrawableType =
- mAttachedObject->isHUDAttachment() ? LLPipeline::RENDER_TYPE_HUD : LLPipeline::RENDER_TYPE_VOLUME;
- }
- else
+ for (attachedobjs_vec_t::const_iterator iter = mAttachedObjects.begin();
+ iter != mAttachedObjects.end();
+ ++iter)
{
- mAttachedObject->mDrawable->getSpatialBridge()->mDrawableType = 0;
+ LLViewerObject *attached_obj = (*iter);
+ if (!attached_obj || attached_obj->mDrawable.isNull() ||
+ !(attached_obj->mDrawable->getSpatialBridge()))
+ continue;
+
+ if (visible)
+ {
+ // Hack to make attachments not visible by disabling their type mask!
+ // This will break if you can ever attach non-volumes! - djs 02/14/03
+ attached_obj->mDrawable->getSpatialBridge()->mDrawableType =
+ attached_obj->isHUDAttachment() ? LLPipeline::RENDER_TYPE_HUD : LLPipeline::RENDER_TYPE_VOLUME;
+ }
+ else
+ {
+ attached_obj->mDrawable->getSpatialBridge()->mDrawableType = 0;
+ }
}
}
@@ -341,14 +348,19 @@ void LLViewerJointAttachment::setOriginalPosition(LLVector3& position)
//-----------------------------------------------------------------------------
void LLViewerJointAttachment::clampObjectPosition()
{
- if (mAttachedObject)
+ for (attachedobjs_vec_t::const_iterator iter = mAttachedObjects.begin();
+ iter != mAttachedObjects.end();
+ ++iter)
{
- // *NOTE: object can drift when hitting maximum radius
- LLVector3 attachmentPos = mAttachedObject->getPosition();
- F32 dist = attachmentPos.normVec();
- dist = llmin(dist, MAX_ATTACHMENT_DIST);
- attachmentPos *= dist;
- mAttachedObject->setPosition(attachmentPos);
+ if (LLViewerObject *attached_object = (*iter))
+ {
+ // *NOTE: object can drift when hitting maximum radius
+ LLVector3 attachmentPos = attached_object->getPosition();
+ F32 dist = attachmentPos.normVec();
+ dist = llmin(dist, MAX_ATTACHMENT_DIST);
+ attachmentPos *= dist;
+ attached_object->setPosition(attachmentPos);
+ }
}
}
@@ -357,14 +369,23 @@ void LLViewerJointAttachment::clampObjectPosition()
//-----------------------------------------------------------------------------
void LLViewerJointAttachment::calcLOD()
{
- F32 maxarea = mAttachedObject->getMaxScale() * mAttachedObject->getMidScale();
- LLViewerObject::const_child_list_t& child_list = mAttachedObject->getChildren();
- for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
- iter != child_list.end(); iter++)
+ F32 maxarea = 0;
+ for (attachedobjs_vec_t::const_iterator iter = mAttachedObjects.begin();
+ iter != mAttachedObjects.end();
+ ++iter)
{
- LLViewerObject* childp = *iter;
- F32 area = childp->getMaxScale() * childp->getMidScale();
- maxarea = llmax(maxarea, area);
+ if (LLViewerObject *attached_object = (*iter))
+ {
+ maxarea = llmax(maxarea,attached_object->getMaxScale() * attached_object->getMidScale());
+ LLViewerObject::const_child_list_t& child_list = attached_object->getChildren();
+ for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
+ iter != child_list.end(); ++iter)
+ {
+ LLViewerObject* childp = *iter;
+ F32 area = childp->getMaxScale() * childp->getMidScale();
+ maxarea = llmax(maxarea, area);
+ }
+ }
}
maxarea = llclamp(maxarea, .01f*.01f, 1.f);
F32 avatar_area = (4.f * 4.f); // pixels for an avatar sized attachment
@@ -386,3 +407,47 @@ BOOL LLViewerJointAttachment::updateLOD(F32 pixel_area, BOOL activate)
return res;
}
+BOOL LLViewerJointAttachment::isObjectAttached(const LLViewerObject *viewer_object) const
+{
+ for (attachedobjs_vec_t::const_iterator iter = mAttachedObjects.begin();
+ iter != mAttachedObjects.end();
+ ++iter)
+ {
+ const LLViewerObject* attached_object = (*iter);
+ if (attached_object == viewer_object)
+ {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+const LLViewerObject *LLViewerJointAttachment::getAttachedObject(const LLUUID &object_id) const
+{
+ for (attachedobjs_vec_t::const_iterator iter = mAttachedObjects.begin();
+ iter != mAttachedObjects.end();
+ ++iter)
+ {
+ const LLViewerObject* attached_object = (*iter);
+ if (attached_object->getItemID() == object_id)
+ {
+ return attached_object;
+ }
+ }
+ return NULL;
+}
+
+LLViewerObject *LLViewerJointAttachment::getAttachedObject(const LLUUID &object_id)
+{
+ for (attachedobjs_vec_t::iterator iter = mAttachedObjects.begin();
+ iter != mAttachedObjects.end();
+ ++iter)
+ {
+ LLViewerObject* attached_object = (*iter);
+ if (attached_object->getItemID() == object_id)
+ {
+ return attached_object;
+ }
+ }
+ return NULL;
+}