llviewerobject.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:132k
- LLFloaterReg::hideInstance("properties", item_id);
- LLMessageSystem* msg = gMessageSystem;
- msg->newMessageFast(_PREHASH_RemoveTaskInventory);
- msg->nextBlockFast(_PREHASH_AgentData);
- msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
- msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
- msg->nextBlockFast(_PREHASH_InventoryData);
- msg->addU32Fast(_PREHASH_LocalID, mLocalID);
- msg->addUUIDFast(_PREHASH_ItemID, item_id);
- msg->sendReliable(mRegionp->getHost());
- deleteInventoryItem(item_id);
- ++mInventorySerialNum;
- }
- void LLViewerObject::updateInventory(
- LLViewerInventoryItem* item,
- U8 key,
- bool is_new)
- {
- LLMemType mt(LLMemType::MTYPE_OBJECT);
-
- // This slices the object into what we're concerned about on the
- // viewer. The simulator will take the permissions and transfer
- // ownership.
- LLPointer<LLViewerInventoryItem> task_item =
- new LLViewerInventoryItem(item->getUUID(), mID, item->getPermissions(),
- item->getAssetUUID(), item->getType(),
- item->getInventoryType(),
- item->getName(), item->getDescription(),
- item->getSaleInfo(),
- item->getFlags(),
- item->getCreationDate());
- task_item->setTransactionID(item->getTransactionID());
- LLMessageSystem* msg = gMessageSystem;
- msg->newMessageFast(_PREHASH_UpdateTaskInventory);
- msg->nextBlockFast(_PREHASH_AgentData);
- msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
- msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
- msg->nextBlockFast(_PREHASH_UpdateData);
- msg->addU32Fast(_PREHASH_LocalID, mLocalID);
- msg->addU8Fast(_PREHASH_Key, key);
- msg->nextBlockFast(_PREHASH_InventoryData);
- task_item->packMessage(msg);
- msg->sendReliable(mRegionp->getHost());
- // do the internal logic
- doUpdateInventory(task_item, key, is_new);
- }
- void LLViewerObject::updateInventoryLocal(LLInventoryItem* item, U8 key)
- {
- LLPointer<LLViewerInventoryItem> task_item =
- new LLViewerInventoryItem(item->getUUID(), mID, item->getPermissions(),
- item->getAssetUUID(), item->getType(),
- item->getInventoryType(),
- item->getName(), item->getDescription(),
- item->getSaleInfo(), item->getFlags(),
- item->getCreationDate());
- // do the internal logic
- const bool is_new = false;
- doUpdateInventory(task_item, key, is_new);
- }
- LLInventoryObject* LLViewerObject::getInventoryObject(const LLUUID& item_id)
- {
- LLInventoryObject* rv = NULL;
- if(mInventory)
- {
- InventoryObjectList::iterator it = mInventory->begin();
- InventoryObjectList::iterator end = mInventory->end();
- for ( ; it != end; ++it)
- {
- if((*it)->getUUID() == item_id)
- {
- rv = *it;
- break;
- }
- }
- }
- return rv;
- }
- void LLViewerObject::getInventoryContents(InventoryObjectList& objects)
- {
- if(mInventory)
- {
- InventoryObjectList::iterator it = mInventory->begin();
- InventoryObjectList::iterator end = mInventory->end();
- for( ; it != end; ++it)
- {
- if ((*it)->getType() != LLAssetType::AT_CATEGORY)
- {
- objects.push_back(*it);
- }
- }
- }
- }
- LLInventoryObject* LLViewerObject::getInventoryRoot()
- {
- if (!mInventory || !mInventory->size())
- {
- return NULL;
- }
- return mInventory->back();
- }
- LLViewerInventoryItem* LLViewerObject::getInventoryItemByAsset(const LLUUID& asset_id)
- {
- if (mInventoryDirty)
- llwarns << "Peforming inventory lookup for object " << mID << " that has dirty inventory!" << llendl;
- LLViewerInventoryItem* rv = NULL;
- if(mInventory)
- {
- LLViewerInventoryItem* item = NULL;
- InventoryObjectList::iterator it = mInventory->begin();
- InventoryObjectList::iterator end = mInventory->end();
- for( ; it != end; ++it)
- {
- LLInventoryObject* obj = *it;
- if(obj->getType() != LLAssetType::AT_CATEGORY)
- {
- // *FIX: gank-ass down cast!
- item = (LLViewerInventoryItem*)obj;
- if(item->getAssetUUID() == asset_id)
- {
- rv = item;
- break;
- }
- }
- }
- }
- return rv;
- }
- void LLViewerObject::updateViewerInventoryAsset(
- const LLViewerInventoryItem* item,
- const LLUUID& new_asset)
- {
- LLPointer<LLViewerInventoryItem> task_item =
- new LLViewerInventoryItem(item);
- task_item->setAssetUUID(new_asset);
- // do the internal logic
- doUpdateInventory(task_item, TASK_INVENTORY_ITEM_KEY, false);
- }
- void LLViewerObject::setPixelAreaAndAngle(LLAgent &agent)
- {
- if (getVolume())
- { //volumes calculate pixel area and angle per face
- return;
- }
-
- LLVector3 viewer_pos_agent = agent.getCameraPositionAgent();
- LLVector3 pos_agent = getRenderPosition();
- F32 dx = viewer_pos_agent.mV[VX] - pos_agent.mV[VX];
- F32 dy = viewer_pos_agent.mV[VY] - pos_agent.mV[VY];
- F32 dz = viewer_pos_agent.mV[VZ] - pos_agent.mV[VZ];
- F32 max_scale = getMaxScale();
- F32 mid_scale = getMidScale();
- F32 min_scale = getMinScale();
- // IW: estimate - when close to large objects, computing range based on distance from center is no good
- // to try to get a min distance from face, subtract min_scale/2 from the range.
- // This means we'll load too much detail sometimes, but that's better than not enough
- // I don't think there's a better way to do this without calculating distance per-poly
- F32 range = sqrt(dx*dx + dy*dy + dz*dz) - min_scale/2;
- LLViewerCamera* camera = LLViewerCamera::getInstance();
- if (range < 0.001f || isHUDAttachment()) // range == zero
- {
- mAppAngle = 180.f;
- mPixelArea = (F32)camera->getScreenPixelArea();
- }
- else
- {
- mAppAngle = (F32) atan2( max_scale, range) * RAD_TO_DEG;
- F32 pixels_per_meter = camera->getPixelMeterRatio() / range;
- mPixelArea = (pixels_per_meter * max_scale) * (pixels_per_meter * mid_scale);
- if (mPixelArea > camera->getScreenPixelArea())
- {
- mAppAngle = 180.f;
- mPixelArea = (F32)camera->getScreenPixelArea();
- }
- }
- }
- BOOL LLViewerObject::updateLOD()
- {
- return FALSE;
- }
- BOOL LLViewerObject::updateGeometry(LLDrawable *drawable)
- {
- return TRUE;
- }
- void LLViewerObject::updateGL()
- {
- }
- void LLViewerObject::updateFaceSize(S32 idx)
- {
-
- }
- LLDrawable* LLViewerObject::createDrawable(LLPipeline *pipeline)
- {
- return NULL;
- }
- void LLViewerObject::setScale(const LLVector3 &scale, BOOL damped)
- {
- LLPrimitive::setScale(scale);
- if (mDrawable.notNull())
- {
- //encompass completely sheared objects by taking
- //the most extreme point possible (<1,1,0.5>)
- mDrawable->setRadius(LLVector3(1,1,0.5f).scaleVec(scale).magVec());
- updateDrawable(damped);
- }
- if( (LL_PCODE_VOLUME == getPCode()) && !isDead() )
- {
- if (permYouOwner() || (scale.magVecSquared() > (7.5f * 7.5f)) )
- {
- if (!mOnMap)
- {
- gObjectList.addToMap(this);
- mOnMap = TRUE;
- }
- }
- else
- {
- if (mOnMap)
- {
- gObjectList.removeFromMap(this);
- mOnMap = FALSE;
- }
- }
- }
- }
- void LLViewerObject::updateSpatialExtents(LLVector3& newMin, LLVector3 &newMax)
- {
- LLVector3 center = getRenderPosition();
- LLVector3 size = getScale();
- newMin.setVec(center-size);
- newMax.setVec(center+size);
- mDrawable->setPositionGroup((newMin + newMax) * 0.5f);
- }
- F32 LLViewerObject::getBinRadius()
- {
- if (mDrawable.notNull())
- {
- const LLVector3* ext = mDrawable->getSpatialExtents();
- return (ext[1]-ext[0]).magVec();
- }
-
- return getScale().magVec();
- }
- F32 LLViewerObject::getMaxScale() const
- {
- return llmax(getScale().mV[VX],getScale().mV[VY], getScale().mV[VZ]);
- }
- F32 LLViewerObject::getMinScale() const
- {
- return llmin(getScale().mV[0],getScale().mV[1],getScale().mV[2]);
- }
- F32 LLViewerObject::getMidScale() const
- {
- if (getScale().mV[VX] < getScale().mV[VY])
- {
- if (getScale().mV[VY] < getScale().mV[VZ])
- {
- return getScale().mV[VY];
- }
- else if (getScale().mV[VX] < getScale().mV[VZ])
- {
- return getScale().mV[VZ];
- }
- else
- {
- return getScale().mV[VX];
- }
- }
- else if (getScale().mV[VX] < getScale().mV[VZ])
- {
- return getScale().mV[VX];
- }
- else if (getScale().mV[VY] < getScale().mV[VZ])
- {
- return getScale().mV[VZ];
- }
- else
- {
- return getScale().mV[VY];
- }
- }
- void LLViewerObject::updateTextures()
- {
- }
- void LLViewerObject::boostTexturePriority(BOOL boost_children /* = TRUE */)
- {
- if (isDead())
- {
- return;
- }
- S32 i;
- S32 tex_count = getNumTEs();
- for (i = 0; i < tex_count; i++)
- {
- getTEImage(i)->setBoostLevel(LLViewerTexture::BOOST_SELECTED);
- }
- if (isSculpted())
- {
- LLSculptParams *sculpt_params = (LLSculptParams *)getParameterEntry(LLNetworkData::PARAMS_SCULPT);
- LLUUID sculpt_id = sculpt_params->getSculptTexture();
- LLViewerTextureManager::getFetchedTexture(sculpt_id, TRUE, LLViewerTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE)->setBoostLevel(LLViewerTexture::BOOST_SELECTED);
- }
-
- if (boost_children)
- {
- for (child_list_t::iterator iter = mChildList.begin();
- iter != mChildList.end(); iter++)
- {
- LLViewerObject* child = *iter;
- child->boostTexturePriority();
- }
- }
- }
- void LLViewerObject::setLineWidthForWindowSize(S32 window_width)
- {
- if (window_width < 700)
- {
- LLUI::setLineWidth(2.0f);
- }
- else if (window_width < 1100)
- {
- LLUI::setLineWidth(3.0f);
- }
- else if (window_width < 2000)
- {
- LLUI::setLineWidth(4.0f);
- }
- else
- {
- // _damn_, what a nice monitor!
- LLUI::setLineWidth(5.0f);
- }
- }
- void LLViewerObject::increaseArrowLength()
- {
- /* ???
- if (mAxisArrowLength == 50)
- {
- mAxisArrowLength = 100;
- }
- else
- {
- mAxisArrowLength = 150;
- }
- */
- }
- void LLViewerObject::decreaseArrowLength()
- {
- /* ???
- if (mAxisArrowLength == 150)
- {
- mAxisArrowLength = 100;
- }
- else
- {
- mAxisArrowLength = 50;
- }
- */
- }
- // Culled from newsim LLTask::addNVPair
- void LLViewerObject::addNVPair(const std::string& data)
- {
- // cout << "LLViewerObject::addNVPair() with ---" << data << "---" << endl;
- LLNameValue *nv = new LLNameValue(data.c_str());
- // char splat[MAX_STRING];
- // temp->printNameValue(splat);
- // llinfos << "addNVPair " << splat << llendl;
- name_value_map_t::iterator iter = mNameValuePairs.find(nv->mName);
- if (iter != mNameValuePairs.end())
- {
- LLNameValue* foundnv = iter->second;
- if (foundnv->mClass != NVC_READ_ONLY)
- {
- delete foundnv;
- mNameValuePairs.erase(iter);
- }
- else
- {
- delete nv;
- // llinfos << "Trying to write to Read Only NVPair " << temp->mName << " in addNVPair()" << llendl;
- return;
- }
- }
- mNameValuePairs[nv->mName] = nv;
- }
- BOOL LLViewerObject::removeNVPair(const std::string& name)
- {
- char* canonical_name = gNVNameTable.addString(name);
- lldebugs << "LLViewerObject::removeNVPair(): " << name << llendl;
- name_value_map_t::iterator iter = mNameValuePairs.find(canonical_name);
- if (iter != mNameValuePairs.end())
- {
- if( mRegionp )
- {
- LLNameValue* nv = iter->second;
- /*
- std::string buffer = nv->printNameValue();
- gMessageSystem->newMessageFast(_PREHASH_RemoveNameValuePair);
- gMessageSystem->nextBlockFast(_PREHASH_TaskData);
- gMessageSystem->addUUIDFast(_PREHASH_ID, mID);
-
- gMessageSystem->nextBlockFast(_PREHASH_NameValueData);
- gMessageSystem->addStringFast(_PREHASH_NVPair, buffer);
- gMessageSystem->sendReliable( mRegionp->getHost() );
- */
- // Remove the NV pair from the local list.
- delete nv;
- mNameValuePairs.erase(iter);
- return TRUE;
- }
- else
- {
- lldebugs << "removeNVPair - No region for object" << llendl;
- }
- }
- return FALSE;
- }
- LLNameValue *LLViewerObject::getNVPair(const std::string& name) const
- {
- char *canonical_name;
- canonical_name = gNVNameTable.addString(name);
- // If you access a map with a name that isn't in it, it will add the name and a null pointer.
- // So first check if the data is in the map.
- name_value_map_t::const_iterator iter = mNameValuePairs.find(canonical_name);
- if (iter != mNameValuePairs.end())
- {
- return iter->second;
- }
- else
- {
- return NULL;
- }
- }
- void LLViewerObject::updatePositionCaches() const
- {
- if(mRegionp)
- {
- if (!isRoot())
- {
- mPositionRegion = ((LLViewerObject *)getParent())->getPositionRegion() + getPosition() * getParent()->getRotation();
- mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
- }
- else
- {
- mPositionRegion = getPosition();
- mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
- }
- }
- }
- const LLVector3d LLViewerObject::getPositionGlobal() const
- {
- if(mRegionp)
- {
- LLVector3d position_global = mRegionp->getPosGlobalFromRegion(getPositionRegion());
- if (isAttachment())
- {
- position_global = gAgent.getPosGlobalFromAgent(getRenderPosition());
- }
- return position_global;
- }
- else
- {
- LLVector3d position_global(getPosition());
- return position_global;
- }
- }
- const LLVector3 &LLViewerObject::getPositionAgent() const
- {
- if (mRegionp)
- {
- if (mDrawable.notNull() && (!mDrawable->isRoot() && getParent()))
- {
- // Don't return cached position if you have a parent, recalc (until all dirtying is done correctly.
- LLVector3 position_region;
- position_region = ((LLViewerObject *)getParent())->getPositionRegion() + getPosition() * getParent()->getRotation();
- mPositionAgent = mRegionp->getPosAgentFromRegion(position_region);
- }
- else
- {
- mPositionAgent = mRegionp->getPosAgentFromRegion(getPosition());
- }
- }
- return mPositionAgent;
- }
- const LLVector3 &LLViewerObject::getPositionRegion() const
- {
- if (!isRoot())
- {
- LLViewerObject *parent = (LLViewerObject *)getParent();
- mPositionRegion = parent->getPositionRegion() + (getPosition() * parent->getRotation());
- }
- else
- {
- mPositionRegion = getPosition();
- }
- return mPositionRegion;
- }
- const LLVector3 LLViewerObject::getPositionEdit() const
- {
- if (isRootEdit())
- {
- return getPosition();
- }
- else
- {
- LLViewerObject *parent = (LLViewerObject *)getParent();
- LLVector3 position_edit = parent->getPositionEdit() + getPosition() * parent->getRotationEdit();
- return position_edit;
- }
- }
- const LLVector3 LLViewerObject::getRenderPosition() const
- {
- if (mDrawable.isNull() || mDrawable->getGeneration() < 0)
- {
- return getPositionAgent();
- }
- else
- {
- return mDrawable->getPositionAgent();
- }
- }
- const LLVector3 LLViewerObject::getPivotPositionAgent() const
- {
- return getRenderPosition();
- }
- const LLQuaternion LLViewerObject::getRenderRotation() const
- {
- LLQuaternion ret;
- if (mDrawable.isNull() || mDrawable->isStatic())
- {
- ret = getRotationEdit();
- }
- else
- {
- if (!mDrawable->isRoot())
- {
- ret = getRotation() * LLQuaternion(mDrawable->getParent()->getWorldMatrix());
- }
- else
- {
- ret = LLQuaternion(mDrawable->getWorldMatrix());
- }
- }
-
- return ret;
- }
- const LLMatrix4 LLViewerObject::getRenderMatrix() const
- {
- return mDrawable->getWorldMatrix();
- }
- const LLQuaternion LLViewerObject::getRotationRegion() const
- {
- LLQuaternion global_rotation = getRotation();
- if (!((LLXform *)this)->isRoot())
- {
- global_rotation = global_rotation * getParent()->getRotation();
- }
- return global_rotation;
- }
- const LLQuaternion LLViewerObject::getRotationEdit() const
- {
- LLQuaternion global_rotation = getRotation();
- if (!((LLXform *)this)->isRootEdit())
- {
- global_rotation = global_rotation * getParent()->getRotation();
- }
- return global_rotation;
- }
- void LLViewerObject::setPositionAbsoluteGlobal( const LLVector3d &pos_global, BOOL damped )
- {
- if (isAttachment())
- {
- LLVector3 new_pos = mRegionp->getPosRegionFromGlobal(pos_global);
- if (isRootEdit())
- {
- new_pos -= mDrawable->mXform.getParent()->getWorldPosition();
- LLQuaternion world_rotation = mDrawable->mXform.getParent()->getWorldRotation();
- new_pos = new_pos * ~world_rotation;
- }
- else
- {
- LLViewerObject* parentp = (LLViewerObject*)getParent();
- new_pos -= parentp->getPositionAgent();
- new_pos = new_pos * ~parentp->getRotationRegion();
- }
- LLViewerObject::setPosition(new_pos);
-
- if (mParent && ((LLViewerObject*)mParent)->isAvatar())
- {
- // we have changed the position of an attachment, so we need to clamp it
- LLVOAvatar *avatar = (LLVOAvatar*)mParent;
- avatar->clampAttachmentPositions();
- }
- }
- else
- {
- if( isRoot() )
- {
- setPositionRegion(mRegionp->getPosRegionFromGlobal(pos_global));
- }
- else
- {
- // the relative position with the parent is not constant
- LLViewerObject* parent = (LLViewerObject *)getParent();
- //RN: this assumes we are only calling this function from the edit tools
- gPipeline.updateMoveNormalAsync(parent->mDrawable);
- LLVector3 pos_local = mRegionp->getPosRegionFromGlobal(pos_global) - parent->getPositionRegion();
- pos_local = pos_local * ~parent->getRotationRegion();
- LLViewerObject::setPosition( pos_local );
- }
- }
- //RN: assumes we always want to snap the object when calling this function
- gPipeline.updateMoveNormalAsync(mDrawable);
- }
- void LLViewerObject::setPosition(const LLVector3 &pos, BOOL damped)
- {
- if (getPosition() != pos)
- {
- setChanged(TRANSLATED | SILHOUETTE);
- }
-
- LLXform::setPosition(pos);
- updateDrawable(damped);
- if (isRoot())
- {
- // position caches need to be up to date on root objects
- updatePositionCaches();
- }
- }
- void LLViewerObject::setPositionGlobal(const LLVector3d &pos_global, BOOL damped)
- {
- if (isAttachment())
- {
- if (isRootEdit())
- {
- LLVector3 newPos = mRegionp->getPosRegionFromGlobal(pos_global);
- newPos = newPos - mDrawable->mXform.getParent()->getWorldPosition();
- LLQuaternion invWorldRotation = mDrawable->mXform.getParent()->getWorldRotation();
- invWorldRotation.transQuat();
- newPos = newPos * invWorldRotation;
- LLViewerObject::setPosition(newPos);
- }
- else
- {
- // assumes parent is root editable (root of attachment)
- LLVector3 newPos = mRegionp->getPosRegionFromGlobal(pos_global);
- newPos = newPos - mDrawable->mXform.getParent()->getWorldPosition();
- LLVector3 delta_pos = newPos - getPosition();
- LLQuaternion invRotation = mDrawable->getRotation();
- invRotation.transQuat();
-
- delta_pos = delta_pos * invRotation;
- // *FIX: is this right? Shouldn't we be calling the
- // LLViewerObject version of setPosition?
- LLVector3 old_pos = mDrawable->mXform.getParent()->getPosition();
- mDrawable->mXform.getParent()->setPosition(old_pos + delta_pos);
- setChanged(TRANSLATED | SILHOUETTE);
- }
- if (mParent && ((LLViewerObject*)mParent)->isAvatar())
- {
- // we have changed the position of an attachment, so we need to clamp it
- LLVOAvatar *avatar = (LLVOAvatar*)mParent;
- avatar->clampAttachmentPositions();
- }
- }
- else
- {
- if (isRoot())
- {
- setPositionRegion(mRegionp->getPosRegionFromGlobal(pos_global));
- }
- else
- {
- // the relative position with the parent is constant, but the parent's position needs to be changed
- LLVector3d position_offset;
- position_offset.setVec(getPosition()*getParent()->getRotation());
- LLVector3d new_pos_global = pos_global - position_offset;
- ((LLViewerObject *)getParent())->setPositionGlobal(new_pos_global);
- }
- }
- updateDrawable(damped);
- }
- void LLViewerObject::setPositionParent(const LLVector3 &pos_parent, BOOL damped)
- {
- // Set position relative to parent, if no parent, relative to region
- if (!isRoot())
- {
- LLViewerObject::setPosition(pos_parent);
- updateDrawable(damped);
- }
- else
- {
- setPositionRegion(pos_parent, damped);
- }
- }
- void LLViewerObject::setPositionRegion(const LLVector3 &pos_region, BOOL damped)
- {
- if (!isRootEdit())
- {
- LLViewerObject* parent = (LLViewerObject*) getParent();
- LLViewerObject::setPosition((pos_region-parent->getPositionRegion())*~parent->getRotationRegion());
- }
- else
- {
- LLViewerObject::setPosition(pos_region);
- mPositionRegion = pos_region;
- mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
- }
- }
- void LLViewerObject::setPositionAgent(const LLVector3 &pos_agent, BOOL damped)
- {
- LLVector3 pos_region = getRegion()->getPosRegionFromAgent(pos_agent);
- setPositionRegion(pos_region, damped);
- }
- // identical to setPositionRegion() except it checks for child-joints
- // and doesn't also move the joint-parent
- // TODO -- implement similar intelligence for joint-parents toward
- // their joint-children
- void LLViewerObject::setPositionEdit(const LLVector3 &pos_edit, BOOL damped)
- {
- if (!isRootEdit())
- {
- // the relative position with the parent is constant, but the parent's position needs to be changed
- LLVector3 position_offset = getPosition() * getParent()->getRotation();
- ((LLViewerObject *)getParent())->setPositionEdit(pos_edit - position_offset);
- }
- else if (isJointChild())
- {
- // compute new parent-relative position
- LLViewerObject *parent = (LLViewerObject *) getParent();
- LLQuaternion inv_parent_rot = parent->getRotation();
- inv_parent_rot.transQuat();
- LLVector3 pos_parent = (pos_edit - parent->getPositionRegion()) * inv_parent_rot;
- LLViewerObject::setPosition(pos_parent);
- }
- else
- {
- LLViewerObject::setPosition(pos_edit);
- mPositionRegion = pos_edit;
- mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
- }
- updateDrawable(damped);
- }
- LLViewerObject* LLViewerObject::getRootEdit() const
- {
- const LLViewerObject* root = this;
- while (root->mParent
- && !(root->mJointInfo
- || ((LLViewerObject*)root->mParent)->isAvatar()) )
- {
- root = (LLViewerObject*)root->mParent;
- }
- return (LLViewerObject*)root;
- }
- BOOL LLViewerObject::lineSegmentIntersect(const LLVector3& start, const LLVector3& end,
- S32 face,
- BOOL pick_transparent,
- S32* face_hit,
- LLVector3* intersection,
- LLVector2* tex_coord,
- LLVector3* normal,
- LLVector3* bi_normal)
- {
- return false;
- }
- BOOL LLViewerObject::lineSegmentBoundingBox(const LLVector3& start, const LLVector3& end)
- {
- if (mDrawable.isNull() || mDrawable->isDead())
- {
- return FALSE;
- }
- const LLVector3* ext = mDrawable->getSpatialExtents();
- LLVector3 center = (ext[1]+ext[0])*0.5f;
- LLVector3 size = (ext[1]-ext[0])*0.5f;
- return LLLineSegmentBoxIntersect(start, end, center, size);
- }
- U8 LLViewerObject::getMediaType() const
- {
- if (mMedia)
- {
- return mMedia->mMediaType;
- }
- else
- {
- return LLViewerObject::MEDIA_NONE;
- }
- }
- void LLViewerObject::setMediaType(U8 media_type)
- {
- if (!mMedia)
- {
- // TODO what if we don't have a media pointer?
- }
- else if (mMedia->mMediaType != media_type)
- {
- mMedia->mMediaType = media_type;
- // TODO: update materials with new image
- }
- }
- std::string LLViewerObject::getMediaURL() const
- {
- if (mMedia)
- {
- return mMedia->mMediaURL;
- }
- else
- {
- return std::string();
- }
- }
- void LLViewerObject::setMediaURL(const std::string& media_url)
- {
- LLMemType mt(LLMemType::MTYPE_OBJECT);
-
- if (!mMedia)
- {
- mMedia = new LLViewerObjectMedia;
- mMedia->mMediaURL = media_url;
- mMedia->mPassedWhitelist = FALSE;
- // TODO: update materials with new image
- }
- else if (mMedia->mMediaURL != media_url)
- {
- mMedia->mMediaURL = media_url;
- mMedia->mPassedWhitelist = FALSE;
- // TODO: update materials with new image
- }
- }
- BOOL LLViewerObject::getMediaPassedWhitelist() const
- {
- if (mMedia)
- {
- return mMedia->mPassedWhitelist;
- }
- else
- {
- return FALSE;
- }
- }
- void LLViewerObject::setMediaPassedWhitelist(BOOL passed)
- {
- if (mMedia)
- {
- mMedia->mPassedWhitelist = passed;
- }
- }
- BOOL LLViewerObject::setMaterial(const U8 material)
- {
- BOOL res = LLPrimitive::setMaterial(material);
- if (res)
- {
- setChanged(TEXTURE);
- }
- return res;
- }
- void LLViewerObject::setNumTEs(const U8 num_tes)
- {
- LLMemType mt(LLMemType::MTYPE_OBJECT);
-
- U32 i;
- if (num_tes != getNumTEs())
- {
- if (num_tes)
- {
- LLPointer<LLViewerTexture> *new_images;
- new_images = new LLPointer<LLViewerTexture>[num_tes];
- for (i = 0; i < num_tes; i++)
- {
- if (i < getNumTEs())
- {
- new_images[i] = mTEImages[i];
- }
- else if (getNumTEs())
- {
- new_images[i] = mTEImages[getNumTEs()-1];
- }
- else
- {
- new_images[i] = NULL;
- }
- }
- deleteTEImages();
-
- mTEImages = new_images;
- }
- else
- {
- deleteTEImages();
- }
- LLPrimitive::setNumTEs(num_tes);
- setChanged(TEXTURE);
- if (mDrawable.notNull())
- {
- gPipeline.markTextured(mDrawable);
- }
- }
- }
- void LLViewerObject::sendMaterialUpdate() const
- {
- LLViewerRegion* regionp = getRegion();
- if(!regionp) return;
- gMessageSystem->newMessageFast(_PREHASH_ObjectMaterial);
- gMessageSystem->nextBlockFast(_PREHASH_AgentData);
- gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
- gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
- gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
- gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, mLocalID );
- gMessageSystem->addU8Fast(_PREHASH_Material, getMaterial() );
- gMessageSystem->sendReliable( regionp->getHost() );
- }
- // formerly send_object_rotation
- void LLViewerObject::sendRotationUpdate() const
- {
- LLViewerRegion* regionp = getRegion();
- if(!regionp) return;
- gMessageSystem->newMessageFast(_PREHASH_ObjectRotation);
- gMessageSystem->nextBlockFast(_PREHASH_AgentData);
- gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
- gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
- gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
- gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, mLocalID);
- gMessageSystem->addQuatFast(_PREHASH_Rotation, getRotationEdit());
- //llinfos << "Sent rotation " << getRotationEdit() << llendl;
- gMessageSystem->sendReliable( regionp->getHost() );
- }
- /* Obsolete, we use MultipleObjectUpdate instead
- //// formerly send_object_position_global
- //void LLViewerObject::sendPositionUpdate() const
- //{
- // gMessageSystem->newMessageFast(_PREHASH_ObjectPosition);
- // gMessageSystem->nextBlockFast(_PREHASH_AgentData);
- // gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
- // gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
- // gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
- // gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, mLocalID );
- // gMessageSystem->addVector3Fast(_PREHASH_Position, getPositionRegion());
- // LLViewerRegion* regionp = getRegion();
- // gMessageSystem->sendReliable(regionp->getHost());
- //}
- */
- //formerly send_object_shape(LLViewerObject *object)
- void LLViewerObject::sendShapeUpdate()
- {
- gMessageSystem->newMessageFast(_PREHASH_ObjectShape);
- gMessageSystem->nextBlockFast(_PREHASH_AgentData);
- gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
- gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
- gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
- gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, mLocalID );
- LLVolumeMessage::packVolumeParams(&getVolume()->getParams(), gMessageSystem);
- LLViewerRegion *regionp = getRegion();
- gMessageSystem->sendReliable( regionp->getHost() );
- }
- void LLViewerObject::sendTEUpdate() const
- {
- LLMessageSystem* msg = gMessageSystem;
- msg->newMessageFast(_PREHASH_ObjectImage);
- msg->nextBlockFast(_PREHASH_AgentData);
- msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
- msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
- msg->nextBlockFast(_PREHASH_ObjectData);
- msg->addU32Fast(_PREHASH_ObjectLocalID, mLocalID );
- if (mMedia)
- {
- msg->addString("MediaURL", mMedia->mMediaURL);
- }
- else
- {
- msg->addString("MediaURL", NULL);
- }
- // TODO send media type
- packTEMessage(msg);
- LLViewerRegion *regionp = getRegion();
- msg->sendReliable( regionp->getHost() );
- }
- void LLViewerObject::setTE(const U8 te, const LLTextureEntry &texture_entry)
- {
- LLPrimitive::setTE(te, texture_entry);
- // This doesn't work, don't get any textures.
- // if (mDrawable.notNull() && mDrawable->isVisible())
- // {
- const LLUUID& image_id = getTE(te)->getID();
- mTEImages[te] = LLViewerTextureManager::getFetchedTexture(image_id, TRUE, LLViewerTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
- // }
- }
- void LLViewerObject::setTEImage(const U8 te, LLViewerTexture *imagep)
- {
- if (mTEImages[te] != imagep)
- {
- mTEImages[te] = imagep;
- LLPrimitive::setTETexture(te, imagep->getID());
- setChanged(TEXTURE);
- if (mDrawable.notNull())
- {
- gPipeline.markTextured(mDrawable);
- }
- }
- }
- S32 LLViewerObject::setTETextureCore(const U8 te, const LLUUID& uuid, LLHost host)
- {
- S32 retval = 0;
- if (uuid != getTE(te)->getID() ||
- uuid == LLUUID::null)
- {
- retval = LLPrimitive::setTETexture(te, uuid);
- mTEImages[te] = LLViewerTextureManager::getFetchedTexture(uuid, TRUE, LLViewerTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, host);
- setChanged(TEXTURE);
- if (mDrawable.notNull())
- {
- gPipeline.markTextured(mDrawable);
- }
- }
- return retval;
- }
- void LLViewerObject::changeTEImage(S32 index, LLViewerTexture* new_image)
- {
- if(index < 0 || index >= getNumTEs())
- {
- return ;
- }
- mTEImages[index] = new_image ;
- }
- S32 LLViewerObject::setTETexture(const U8 te, const LLUUID& uuid)
- {
- // Invalid host == get from the agent's sim
- return setTETextureCore(te, uuid, LLHost::invalid);
- }
- S32 LLViewerObject::setTEColor(const U8 te, const LLColor3& color)
- {
- return setTEColor(te, LLColor4(color));
- }
- S32 LLViewerObject::setTEColor(const U8 te, const LLColor4& color)
- {
- S32 retval = 0;
- const LLTextureEntry *tep = getTE(te);
- if (!tep)
- {
- llwarns << "No texture entry for te " << (S32)te << ", object " << mID << llendl;
- }
- else if (color != tep->getColor())
- {
- retval = LLPrimitive::setTEColor(te, color);
- if (mDrawable.notNull() && retval)
- {
- // These should only happen on updates which are not the initial update.
- dirtyMesh();
- }
- }
- return retval;
- }
- S32 LLViewerObject::setTEBumpmap(const U8 te, const U8 bump)
- {
- S32 retval = 0;
- const LLTextureEntry *tep = getTE(te);
- if (!tep)
- {
- llwarns << "No texture entry for te " << (S32)te << ", object " << mID << llendl;
- }
- else if (bump != tep->getBumpmap())
- {
- retval = LLPrimitive::setTEBumpmap(te, bump);
- setChanged(TEXTURE);
- if (mDrawable.notNull() && retval)
- {
- gPipeline.markTextured(mDrawable);
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY, TRUE);
- }
- }
- return retval;
- }
- S32 LLViewerObject::setTETexGen(const U8 te, const U8 texgen)
- {
- S32 retval = 0;
- const LLTextureEntry *tep = getTE(te);
- if (!tep)
- {
- llwarns << "No texture entry for te " << (S32)te << ", object " << mID << llendl;
- }
- else if (texgen != tep->getTexGen())
- {
- retval = LLPrimitive::setTETexGen(te, texgen);
- setChanged(TEXTURE);
- }
- return retval;
- }
- S32 LLViewerObject::setTEMediaTexGen(const U8 te, const U8 media)
- {
- S32 retval = 0;
- const LLTextureEntry *tep = getTE(te);
- if (!tep)
- {
- llwarns << "No texture entry for te " << (S32)te << ", object " << mID << llendl;
- }
- else if (media != tep->getMediaTexGen())
- {
- retval = LLPrimitive::setTEMediaTexGen(te, media);
- setChanged(TEXTURE);
- }
- return retval;
- }
- S32 LLViewerObject::setTEShiny(const U8 te, const U8 shiny)
- {
- S32 retval = 0;
- const LLTextureEntry *tep = getTE(te);
- if (!tep)
- {
- llwarns << "No texture entry for te " << (S32)te << ", object " << mID << llendl;
- }
- else if (shiny != tep->getShiny())
- {
- retval = LLPrimitive::setTEShiny(te, shiny);
- setChanged(TEXTURE);
- }
- return retval;
- }
- S32 LLViewerObject::setTEFullbright(const U8 te, const U8 fullbright)
- {
- S32 retval = 0;
- const LLTextureEntry *tep = getTE(te);
- if (!tep)
- {
- llwarns << "No texture entry for te " << (S32)te << ", object " << mID << llendl;
- }
- else if (fullbright != tep->getFullbright())
- {
- retval = LLPrimitive::setTEFullbright(te, fullbright);
- setChanged(TEXTURE);
- if (mDrawable.notNull() && retval)
- {
- gPipeline.markTextured(mDrawable);
- }
- }
- return retval;
- }
- S32 LLViewerObject::setTEMediaFlags(const U8 te, const U8 media_flags)
- {
- // this might need work for media type
- S32 retval = 0;
- const LLTextureEntry *tep = getTE(te);
- if (!tep)
- {
- llwarns << "No texture entry for te " << (S32)te << ", object " << mID << llendl;
- }
- else if (media_flags != tep->getMediaFlags())
- {
- retval = LLPrimitive::setTEMediaFlags(te, media_flags);
- setChanged(TEXTURE);
- if (mDrawable.notNull() && retval)
- {
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD, TRUE);
- gPipeline.markTextured(mDrawable);
- // JC - probably only need this if changes texture coords
- //gPipeline.markRebuild(mDrawable);
- }
- }
- return retval;
- }
- S32 LLViewerObject::setTEGlow(const U8 te, const F32 glow)
- {
- S32 retval = 0;
- const LLTextureEntry *tep = getTE(te);
- if (!tep)
- {
- llwarns << "No texture entry for te " << (S32)te << ", object " << mID << llendl;
- }
- else if (glow != tep->getGlow())
- {
- retval = LLPrimitive::setTEGlow(te, glow);
- setChanged(TEXTURE);
- if (mDrawable.notNull() && retval)
- {
- gPipeline.markTextured(mDrawable);
- }
- }
- return retval;
- }
- S32 LLViewerObject::setTEScale(const U8 te, const F32 s, const F32 t)
- {
- S32 retval = 0;
- retval = LLPrimitive::setTEScale(te, s, t);
- setChanged(TEXTURE);
- if (mDrawable.notNull() && retval)
- {
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
- }
- return retval;
- }
- S32 LLViewerObject::setTEScaleS(const U8 te, const F32 s)
- {
- S32 retval = LLPrimitive::setTEScaleS(te, s);
- if (mDrawable.notNull() && retval)
- {
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
- }
- return retval;
- }
- S32 LLViewerObject::setTEScaleT(const U8 te, const F32 t)
- {
- S32 retval = LLPrimitive::setTEScaleT(te, t);
- if (mDrawable.notNull() && retval)
- {
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
- }
- return retval;
- }
- S32 LLViewerObject::setTEOffset(const U8 te, const F32 s, const F32 t)
- {
- S32 retval = LLPrimitive::setTEOffset(te, s, t);
- if (mDrawable.notNull() && retval)
- {
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
- }
- return retval;
- }
- S32 LLViewerObject::setTEOffsetS(const U8 te, const F32 s)
- {
- S32 retval = LLPrimitive::setTEOffsetS(te, s);
- if (mDrawable.notNull() && retval)
- {
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
- }
- return retval;
- }
- S32 LLViewerObject::setTEOffsetT(const U8 te, const F32 t)
- {
- S32 retval = LLPrimitive::setTEOffsetT(te, t);
- if (mDrawable.notNull() && retval)
- {
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
- }
- return retval;
- }
- S32 LLViewerObject::setTERotation(const U8 te, const F32 r)
- {
- S32 retval = LLPrimitive::setTERotation(te, r);
- if (mDrawable.notNull() && retval)
- {
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
- }
- return retval;
- }
- LLViewerTexture *LLViewerObject::getTEImage(const U8 face) const
- {
- // llassert(mTEImages);
- if (face < getNumTEs())
- {
- LLViewerTexture* image = mTEImages[face];
- if (image)
- {
- return image;
- }
- else
- {
- return (LLViewerTexture*)(LLViewerFetchedTexture::sDefaultImagep);
- }
- }
- llerrs << llformat("Requested Image from invalid face: %d/%d",face,getNumTEs()) << llendl;
- return NULL;
- }
- void LLViewerObject::fitFaceTexture(const U8 face)
- {
- llinfos << "fitFaceTexture not implemented" << llendl;
- }
- LLBBox LLViewerObject::getBoundingBoxAgent() const
- {
- LLVector3 position_agent;
- LLQuaternion rot;
- LLViewerObject* avatar_parent = NULL;
- LLViewerObject* root_edit = (LLViewerObject*)getRootEdit();
- if (root_edit)
- {
- avatar_parent = (LLViewerObject*)root_edit->getParent();
- }
-
- if (avatar_parent && avatar_parent->isAvatar() && root_edit && root_edit->mDrawable.notNull())
- {
- LLXform* parent_xform = root_edit->mDrawable->getXform()->getParent();
- position_agent = (getPositionEdit() * parent_xform->getWorldRotation()) + parent_xform->getWorldPosition();
- rot = getRotationEdit() * parent_xform->getWorldRotation();
- }
- else
- {
- position_agent = getPositionAgent();
- rot = getRotationRegion();
- }
-
- return LLBBox( position_agent, rot, getScale() * -0.5f, getScale() * 0.5f );
- }
- U32 LLViewerObject::getNumVertices() const
- {
- U32 num_vertices = 0;
- if (mDrawable.notNull())
- {
- S32 i, num_faces;
- num_faces = mDrawable->getNumFaces();
- for (i = 0; i < num_faces; i++)
- {
- num_vertices += mDrawable->getFace(i)->getGeomCount();
- }
- }
- return num_vertices;
- }
- U32 LLViewerObject::getNumIndices() const
- {
- U32 num_indices = 0;
- if (mDrawable.notNull())
- {
- S32 i, num_faces;
- num_faces = mDrawable->getNumFaces();
- for (i = 0; i < num_faces; i++)
- {
- num_indices += mDrawable->getFace(i)->getIndicesCount();
- }
- }
- return num_indices;
- }
- // Find the number of instances of this object's inventory that are of the given type
- S32 LLViewerObject::countInventoryContents(LLAssetType::EType type)
- {
- S32 count = 0;
- if( mInventory )
- {
- InventoryObjectList::const_iterator it = mInventory->begin();
- InventoryObjectList::const_iterator end = mInventory->end();
- for( ; it != end ; ++it )
- {
- if( (*it)->getType() == type )
- {
- ++count;
- }
- }
- }
- return count;
- }
- void LLViewerObject::setCanSelect(BOOL canSelect)
- {
- mbCanSelect = canSelect;
- for (child_list_t::iterator iter = mChildList.begin();
- iter != mChildList.end(); iter++)
- {
- LLViewerObject* child = *iter;
- child->mbCanSelect = canSelect;
- }
- }
- void LLViewerObject::setDebugText(const std::string &utf8text)
- {
- if (utf8text.empty() && !mText)
- {
- return;
- }
- if (!mText)
- {
- mText = (LLHUDText *)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_TEXT);
- mText->setFont(LLFontGL::getFontSansSerif());
- mText->setVertAlignment(LLHUDText::ALIGN_VERT_TOP);
- mText->setMaxLines(-1);
- mText->setSourceObject(this);
- mText->setOnHUDAttachment(isHUDAttachment());
- }
- mText->setColor(LLColor4::white);
- mText->setStringUTF8(utf8text);
- mText->setZCompare(FALSE);
- mText->setDoFade(FALSE);
- updateText();
- }
- void LLViewerObject::setIcon(LLViewerTexture* icon_image)
- {
- if (!mIcon)
- {
- mIcon = (LLHUDIcon *)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_ICON);
- mIcon->setSourceObject(this);
- mIcon->setImage(icon_image);
- // *TODO: make this user configurable
- mIcon->setScale(0.03f);
- }
- else
- {
- mIcon->restartLifeTimer();
- }
- }
- void LLViewerObject::clearIcon()
- {
- if (mIcon)
- {
- mIcon = NULL;
- }
- }
- LLViewerObject* LLViewerObject::getSubParent()
- {
- if (isJointChild())
- {
- return this;
- }
- return (LLViewerObject*) getParent();
- }
- const LLViewerObject* LLViewerObject::getSubParent() const
- {
- if (isJointChild())
- {
- return this;
- }
- return (const LLViewerObject*) getParent();
- }
- BOOL LLViewerObject::isOnMap()
- {
- return mOnMap;
- }
- void LLViewerObject::updateText()
- {
- if (!isDead())
- {
- if (mText.notNull())
- {
- LLVector3 up_offset(0,0,0);
- up_offset.mV[2] = getScale().mV[VZ]*0.6f;
-
- if (mDrawable.notNull())
- {
- mText->setPositionAgent(getRenderPosition() + up_offset);
- }
- else
- {
- mText->setPositionAgent(getPositionAgent() + up_offset);
- }
- }
- }
- }
- LLVOAvatar* LLViewerObject::asAvatar()
- {
- return NULL;
- }
- BOOL LLViewerObject::isParticleSource() const
- {
- return !mPartSourcep.isNull() && !mPartSourcep->isDead();
- }
- void LLViewerObject::setParticleSource(const LLPartSysData& particle_parameters, const LLUUID& owner_id)
- {
- if (mPartSourcep)
- {
- deleteParticleSource();
- }
- LLPointer<LLViewerPartSourceScript> pss = LLViewerPartSourceScript::createPSS(this, particle_parameters);
- mPartSourcep = pss;
-
- if (mPartSourcep)
- {
- mPartSourcep->setOwnerUUID(owner_id);
- if (mPartSourcep->getImage()->getID() != mPartSourcep->mPartSysData.mPartImageID)
- {
- LLViewerTexture* image;
- if (mPartSourcep->mPartSysData.mPartImageID == LLUUID::null)
- {
- image = LLViewerTextureManager::getFetchedTextureFromFile("pixiesmall.tga");
- }
- else
- {
- image = LLViewerTextureManager::getFetchedTexture(mPartSourcep->mPartSysData.mPartImageID);
- }
- mPartSourcep->setImage(image);
- }
- }
- LLViewerPartSim::getInstance()->addPartSource(pss);
- }
- void LLViewerObject::unpackParticleSource(const S32 block_num, const LLUUID& owner_id)
- {
- if (!mPartSourcep.isNull() && mPartSourcep->isDead())
- {
- mPartSourcep = NULL;
- }
- if (mPartSourcep)
- {
- // If we've got one already, just update the existing source (or remove it)
- if (!LLViewerPartSourceScript::unpackPSS(this, mPartSourcep, block_num))
- {
- mPartSourcep->setDead();
- mPartSourcep = NULL;
- }
- }
- else
- {
- LLPointer<LLViewerPartSourceScript> pss = LLViewerPartSourceScript::unpackPSS(this, NULL, block_num);
- //If the owner is muted, don't create the system
- if(LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagParticles)) return;
- // We need to be able to deal with a particle source that hasn't changed, but still got an update!
- if (pss)
- {
- // llinfos << "Making particle system with owner " << owner_id << llendl;
- pss->setOwnerUUID(owner_id);
- mPartSourcep = pss;
- LLViewerPartSim::getInstance()->addPartSource(pss);
- }
- }
- if (mPartSourcep)
- {
- if (mPartSourcep->getImage()->getID() != mPartSourcep->mPartSysData.mPartImageID)
- {
- LLViewerTexture* image;
- if (mPartSourcep->mPartSysData.mPartImageID == LLUUID::null)
- {
- image = LLViewerTextureManager::getFetchedTextureFromFile("pixiesmall.j2c");
- }
- else
- {
- image = LLViewerTextureManager::getFetchedTexture(mPartSourcep->mPartSysData.mPartImageID);
- }
- mPartSourcep->setImage(image);
- }
- }
- }
- void LLViewerObject::unpackParticleSource(LLDataPacker &dp, const LLUUID& owner_id)
- {
- if (!mPartSourcep.isNull() && mPartSourcep->isDead())
- {
- mPartSourcep = NULL;
- }
- if (mPartSourcep)
- {
- // If we've got one already, just update the existing source (or remove it)
- if (!LLViewerPartSourceScript::unpackPSS(this, mPartSourcep, dp))
- {
- mPartSourcep->setDead();
- mPartSourcep = NULL;
- }
- }
- else
- {
- LLPointer<LLViewerPartSourceScript> pss = LLViewerPartSourceScript::unpackPSS(this, NULL, dp);
- //If the owner is muted, don't create the system
- if(LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagParticles)) return;
- // We need to be able to deal with a particle source that hasn't changed, but still got an update!
- if (pss)
- {
- // llinfos << "Making particle system with owner " << owner_id << llendl;
- pss->setOwnerUUID(owner_id);
- mPartSourcep = pss;
- LLViewerPartSim::getInstance()->addPartSource(pss);
- }
- }
- if (mPartSourcep)
- {
- if (mPartSourcep->getImage()->getID() != mPartSourcep->mPartSysData.mPartImageID)
- {
- LLViewerTexture* image;
- if (mPartSourcep->mPartSysData.mPartImageID == LLUUID::null)
- {
- image = LLViewerTextureManager::getFetchedTextureFromFile("pixiesmall.j2c");
- }
- else
- {
- image = LLViewerTextureManager::getFetchedTexture(mPartSourcep->mPartSysData.mPartImageID);
- }
- mPartSourcep->setImage(image);
- }
- }
- }
- void LLViewerObject::deleteParticleSource()
- {
- if (mPartSourcep.notNull())
- {
- mPartSourcep->setDead();
- mPartSourcep = NULL;
- }
- }
- // virtual
- void LLViewerObject::updateDrawable(BOOL force_damped)
- {
- if (mDrawable.notNull() &&
- !mDrawable->isState(LLDrawable::ON_MOVE_LIST) &&
- isChanged(MOVED))
- {
- BOOL damped_motion =
- !isChanged(SHIFTED) && // not shifted between regions this frame and...
- ( force_damped || // ...forced into damped motion by application logic or...
- ( !isSelected() && // ...not selected and...
- ( mDrawable->isRoot() || // ... is root or ...
- (getParent() && !((LLViewerObject*)getParent())->isSelected())// ... parent is not selected and ...
- ) &&
- getPCode() == LL_PCODE_VOLUME && // ...is a volume object and...
- getVelocity().isExactlyZero() && // ...is not moving physically and...
- mDrawable->getGeneration() != -1 // ...was not created this frame.
- )
- );
- gPipeline.markMoved(mDrawable, damped_motion);
- }
- clearChanged(SHIFTED);
- }
- // virtual, overridden by LLVOVolume
- F32 LLViewerObject::getVObjRadius() const
- {
- return mDrawable.notNull() ? mDrawable->getRadius() : 0.f;
- }
- void LLViewerObject::setAttachedSound(const LLUUID &audio_uuid, const LLUUID& owner_id, const F32 gain, const U8 flags)
- {
- if (!gAudiop)
- {
- return;
- }
-
- if (audio_uuid.isNull())
- {
- if (!mAudioSourcep)
- {
- return;
- }
- if (mAudioSourcep->isLoop() && !mAudioSourcep->hasPendingPreloads())
- {
- // We don't clear the sound if it's a loop, it'll go away on its own.
- // At least, this appears to be how the scripts work.
- // The attached sound ID is set to NULL to avoid it playing back when the
- // object rezzes in on non-looping sounds.
- //llinfos << "Clearing attached sound " << mAudioSourcep->getCurrentData()->getID() << llendl;
- gAudiop->cleanupAudioSource(mAudioSourcep);
- mAudioSourcep = NULL;
- }
- else if (flags & LL_SOUND_FLAG_STOP)
- {
- // Just shut off the sound
- mAudioSourcep->play(LLUUID::null);
- }
- return;
- }
- if (flags & LL_SOUND_FLAG_LOOP
- && mAudioSourcep && mAudioSourcep->isLoop() && mAudioSourcep->getCurrentData()
- && mAudioSourcep->getCurrentData()->getID() == audio_uuid)
- {
- //llinfos << "Already playing this sound on a loop, ignoring" << llendl;
- return;
- }
- // don't clean up before previous sound is done. Solves: SL-33486
- if ( mAudioSourcep && mAudioSourcep->isDone() )
- {
- gAudiop->cleanupAudioSource(mAudioSourcep);
- mAudioSourcep = NULL;
- }
- getAudioSource(owner_id);
- if (mAudioSourcep)
- {
- BOOL queue = flags & LL_SOUND_FLAG_QUEUE;
- mAudioGain = gain;
- mAudioSourcep->setGain(gain);
- mAudioSourcep->setLoop(flags & LL_SOUND_FLAG_LOOP);
- mAudioSourcep->setSyncMaster(flags & LL_SOUND_FLAG_SYNC_MASTER);
- mAudioSourcep->setSyncSlave(flags & LL_SOUND_FLAG_SYNC_SLAVE);
- mAudioSourcep->setQueueSounds(queue);
- if(!queue) // stop any current sound first to avoid "farts of doom" (SL-1541) -MG
- {
- mAudioSourcep->play(LLUUID::null);
- }
-
- // Play this sound if region maturity permits
- if( gAgent.canAccessMaturityAtGlobal(this->getPositionGlobal()) )
- {
- //llinfos << "Playing attached sound " << audio_uuid << llendl;
- mAudioSourcep->play(audio_uuid);
- }
- }
- }
- LLAudioSource *LLViewerObject::getAudioSource(const LLUUID& owner_id)
- {
- if (!mAudioSourcep)
- {
- // Arbitrary low gain for a sound that's not playing.
- // This is used for sound preloads, for example.
- LLAudioSourceVO *asvop = new LLAudioSourceVO(mID, owner_id, 0.01f, this);
- mAudioSourcep = asvop;
- if(gAudiop) gAudiop->addAudioSource(asvop);
- }
- return mAudioSourcep;
- }
- void LLViewerObject::adjustAudioGain(const F32 gain)
- {
- if (!gAudiop)
- {
- return;
- }
- if (mAudioSourcep)
- {
- mAudioGain = gain;
- mAudioSourcep->setGain(mAudioGain);
- }
- }
- //----------------------------------------------------------------------------
- bool LLViewerObject::unpackParameterEntry(U16 param_type, LLDataPacker *dp)
- {
- ExtraParameter* param = getExtraParameterEntryCreate(param_type);
- if (param)
- {
- param->data->unpack(*dp);
- param->in_use = TRUE;
- parameterChanged(param_type, param->data, TRUE, false);
- return true;
- }
- else
- {
- return false;
- }
- }
- LLViewerObject::ExtraParameter* LLViewerObject::createNewParameterEntry(U16 param_type)
- {
- LLNetworkData* new_block = NULL;
- switch (param_type)
- {
- case LLNetworkData::PARAMS_FLEXIBLE:
- {
- new_block = new LLFlexibleObjectData();
- break;
- }
- case LLNetworkData::PARAMS_LIGHT:
- {
- new_block = new LLLightParams();
- break;
- }
- case LLNetworkData::PARAMS_SCULPT:
- {
- new_block = new LLSculptParams();
- break;
- }
- case LLNetworkData::PARAMS_LIGHT_IMAGE:
- {
- new_block = new LLLightImageParams();
- break;
- }
- default:
- {
- llinfos << "Unknown param type." << llendl;
- break;
- }
- };
- if (new_block)
- {
- ExtraParameter* new_entry = new ExtraParameter;
- new_entry->data = new_block;
- new_entry->in_use = false; // not in use yet
- mExtraParameterList[param_type] = new_entry;
- return new_entry;
- }
- return NULL;
- }
- LLViewerObject::ExtraParameter* LLViewerObject::getExtraParameterEntry(U16 param_type) const
- {
- std::map<U16, ExtraParameter*>::const_iterator itor = mExtraParameterList.find(param_type);
- if (itor != mExtraParameterList.end())
- {
- return itor->second;
- }
- return NULL;
- }
- LLViewerObject::ExtraParameter* LLViewerObject::getExtraParameterEntryCreate(U16 param_type)
- {
- ExtraParameter* param = getExtraParameterEntry(param_type);
- if (!param)
- {
- param = createNewParameterEntry(param_type);
- }
- return param;
- }
- LLNetworkData* LLViewerObject::getParameterEntry(U16 param_type) const
- {
- ExtraParameter* param = getExtraParameterEntry(param_type);
- if (param)
- {
- return param->data;
- }
- else
- {
- return NULL;
- }
- }
- BOOL LLViewerObject::getParameterEntryInUse(U16 param_type) const
- {
- ExtraParameter* param = getExtraParameterEntry(param_type);
- if (param)
- {
- return param->in_use;
- }
- else
- {
- return FALSE;
- }
- }
- bool LLViewerObject::setParameterEntry(U16 param_type, const LLNetworkData& new_value, bool local_origin)
- {
- ExtraParameter* param = getExtraParameterEntryCreate(param_type);
- if (param)
- {
- if (param->in_use && new_value == *(param->data))
- {
- return false;
- }
- param->in_use = true;
- param->data->copy(new_value);
- parameterChanged(param_type, param->data, TRUE, local_origin);
- return true;
- }
- else
- {
- return false;
- }
- }
- // Assumed to be called locally
- // If in_use is TRUE, will crate a new extra parameter if none exists.
- // Should always return true.
- bool LLViewerObject::setParameterEntryInUse(U16 param_type, BOOL in_use, bool local_origin)
- {
- ExtraParameter* param = getExtraParameterEntryCreate(param_type);
- if (param && param->in_use != in_use)
- {
- param->in_use = in_use;
- parameterChanged(param_type, param->data, in_use, local_origin);
- return true;
- }
- return false;
- }
- void LLViewerObject::parameterChanged(U16 param_type, bool local_origin)
- {
- ExtraParameter* param = getExtraParameterEntry(param_type);
- if (param)
- {
- parameterChanged(param_type, param->data, param->in_use, local_origin);
- }
- }
- void LLViewerObject::parameterChanged(U16 param_type, LLNetworkData* data, BOOL in_use, bool local_origin)
- {
- if (local_origin)
- {
- LLViewerRegion* regionp = getRegion();
- if(!regionp) return;
- // Change happened on the viewer. Send the change up
- U8 tmp[MAX_OBJECT_PARAMS_SIZE];
- LLDataPackerBinaryBuffer dpb(tmp, MAX_OBJECT_PARAMS_SIZE);
- if (data->pack(dpb))
- {
- U32 datasize = (U32)dpb.getCurrentSize();
- LLMessageSystem* msg = gMessageSystem;
- msg->newMessageFast(_PREHASH_ObjectExtraParams);
- msg->nextBlockFast(_PREHASH_AgentData);
- msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
- msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
- msg->nextBlockFast(_PREHASH_ObjectData);
- msg->addU32Fast(_PREHASH_ObjectLocalID, mLocalID );
- msg->addU16Fast(_PREHASH_ParamType, param_type);
- msg->addBOOLFast(_PREHASH_ParamInUse, in_use);
- msg->addU32Fast(_PREHASH_ParamSize, datasize);
- msg->addBinaryDataFast(_PREHASH_ParamData, tmp, datasize);
- msg->sendReliable( regionp->getHost() );
- }
- else
- {
- llwarns << "Failed to send object extra parameters: " << param_type << llendl;
- }
- }
- }
- void LLViewerObject::setDrawableState(U32 state, BOOL recursive)
- {
- if (mDrawable)
- {
- mDrawable->setState(state);
- }
- if (recursive)
- {
- for (child_list_t::iterator iter = mChildList.begin();
- iter != mChildList.end(); iter++)
- {
- LLViewerObject* child = *iter;
- child->setDrawableState(state, recursive);
- }
- }
- }
- void LLViewerObject::clearDrawableState(U32 state, BOOL recursive)
- {
- if (mDrawable)
- {
- mDrawable->clearState(state);
- }
- if (recursive)
- {
- for (child_list_t::iterator iter = mChildList.begin();
- iter != mChildList.end(); iter++)
- {
- LLViewerObject* child = *iter;
- child->clearDrawableState(state, recursive);
- }
- }
- }
- //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- // RN: these functions assume a 2-level hierarchy
- //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- // Owned by anyone?
- BOOL LLViewerObject::permAnyOwner() const
- {
- if (isRootEdit())
- {
- return ((mFlags & FLAGS_OBJECT_ANY_OWNER) != 0);
- }
- else
- {
- return ((LLViewerObject*)getParent())->permAnyOwner();
- }
- }
- // Owned by this viewer?
- BOOL LLViewerObject::permYouOwner() const
- {
- if (isRootEdit())
- {
- #ifdef HACKED_GODLIKE_VIEWER
- return TRUE;
- #else
- # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
- if (!LLViewerLogin::getInstance()->isInProductionGrid()
- && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
- {
- return TRUE;
- }
- # endif
- return ((mFlags & FLAGS_OBJECT_YOU_OWNER) != 0);
- #endif
- }
- else
- {
- return ((LLViewerObject*)getParent())->permYouOwner();
- }
- }
- // Owned by a group?
- BOOL LLViewerObject::permGroupOwner() const
- {
- if (isRootEdit())
- {
- return ((mFlags & FLAGS_OBJECT_GROUP_OWNED) != 0);
- }
- else
- {
- return ((LLViewerObject*)getParent())->permGroupOwner();
- }
- }
- // Can the owner edit
- BOOL LLViewerObject::permOwnerModify() const
- {
- if (isRootEdit())
- {
- #ifdef HACKED_GODLIKE_VIEWER
- return TRUE;
- #else
- # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
- if (!LLViewerLogin::getInstance()->isInProductionGrid()
- && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
- {
- return TRUE;
- }
- # endif
- return ((mFlags & FLAGS_OBJECT_OWNER_MODIFY) != 0);
- #endif
- }
- else
- {
- return ((LLViewerObject*)getParent())->permOwnerModify();
- }
- }
- // Can edit
- BOOL LLViewerObject::permModify() const
- {
- if (isRootEdit())
- {
- #ifdef HACKED_GODLIKE_VIEWER
- return TRUE;
- #else
- # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
- if (!LLViewerLogin::getInstance()->isInProductionGrid()
- && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
- {
- return TRUE;
- }
- # endif
- return ((mFlags & FLAGS_OBJECT_MODIFY) != 0);
- #endif
- }
- else
- {
- return ((LLViewerObject*)getParent())->permModify();
- }
- }
- // Can copy
- BOOL LLViewerObject::permCopy() const
- {
- if (isRootEdit())
- {
- #ifdef HACKED_GODLIKE_VIEWER
- return TRUE;
- #else
- # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
- if (!LLViewerLogin::getInstance()->isInProductionGrid()
- && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
- {
- return TRUE;
- }
- # endif
- return ((mFlags & FLAGS_OBJECT_COPY) != 0);
- #endif
- }
- else
- {
- return ((LLViewerObject*)getParent())->permCopy();
- }
- }
- // Can move
- BOOL LLViewerObject::permMove() const
- {
- if (isRootEdit())
- {
- #ifdef HACKED_GODLIKE_VIEWER
- return TRUE;
- #else
- # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
- if (!LLViewerLogin::getInstance()->isInProductionGrid()
- && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
- {
- return TRUE;
- }
- # endif
- return ((mFlags & FLAGS_OBJECT_MOVE) != 0);
- #endif
- }
- else
- {
- return ((LLViewerObject*)getParent())->permMove();
- }
- }
- // Can be transferred
- BOOL LLViewerObject::permTransfer() const
- {
- if (isRootEdit())
- {
- #ifdef HACKED_GODLIKE_VIEWER
- return TRUE;
- #else
- # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
- if (!LLViewerLogin::getInstance()->isInProductionGrid()
- && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
- {
- return TRUE;
- }
- # endif
- return ((mFlags & FLAGS_OBJECT_TRANSFER) != 0);
- #endif
- }
- else
- {
- return ((LLViewerObject*)getParent())->permTransfer();
- }
- }
- // Can only open objects that you own, or that someone has
- // given you modify rights to. JC
- BOOL LLViewerObject::allowOpen() const
- {
- return !flagInventoryEmpty() && (permYouOwner() || permModify());
- }
- LLViewerObject::LLInventoryCallbackInfo::~LLInventoryCallbackInfo()
- {
- if (mListener)
- {
- mListener->clearVOInventoryListener();
- }
- }
- void LLViewerObject::updateVolume(const LLVolumeParams& volume_params)
- {
- if (setVolume(volume_params, 1)) // *FIX: magic number, ack!
- {
- // Transmit the update to the simulator
- sendShapeUpdate();
- markForUpdate(TRUE);
- }
- }
- void LLViewerObject::markForUpdate(BOOL priority)
- {
- if (mDrawable.notNull())
- {
- gPipeline.markTextured(mDrawable);
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY, priority);
- }
- }
- bool LLViewerObject::getIncludeInSearch() const
- {
- return ((mFlags & FLAGS_INCLUDE_IN_SEARCH) != 0);
- }
- void LLViewerObject::setIncludeInSearch(bool include_in_search)
- {
- if (include_in_search)
- {
- mFlags |= FLAGS_INCLUDE_IN_SEARCH;
- }
- else
- {
- mFlags &= ~FLAGS_INCLUDE_IN_SEARCH;
- }
- }
- void LLViewerObject::setRegion(LLViewerRegion *regionp)
- {
- llassert(regionp);
- mLatestRecvPacketID = 0;
- mRegionp = regionp;
- for (child_list_t::iterator i = mChildList.begin(); i != mChildList.end(); ++i)
- {
- LLViewerObject* child = *i;
- child->setRegion(regionp);
- }
- setChanged(MOVED | SILHOUETTE);
- updateDrawable(FALSE);
- }
- bool LLViewerObject::specialHoverCursor() const
- {
- return (mFlags & FLAGS_USE_PHYSICS)
- || (mFlags & FLAGS_HANDLE_TOUCH)
- || (mClickAction != 0);
- }
- void LLViewerObject::updateFlags()
- {
- LLViewerRegion* regionp = getRegion();
- if(!regionp) return;
- gMessageSystem->newMessage("ObjectFlagUpdate");
- gMessageSystem->nextBlockFast(_PREHASH_AgentData);
- gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
- gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
- gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, getLocalID() );
- gMessageSystem->addBOOLFast(_PREHASH_UsePhysics, usePhysics() );
- gMessageSystem->addBOOL("IsTemporary", flagTemporaryOnRez() );
- gMessageSystem->addBOOL("IsPhantom", flagPhantom() );
- gMessageSystem->addBOOL("CastsShadows", flagCastShadows() );
- gMessageSystem->sendReliable( regionp->getHost() );
- }
- BOOL LLViewerObject::setFlags(U32 flags, BOOL state)
- {
- BOOL setit = FALSE;
- if (state)
- {
- if ((mFlags & flags) != flags)
- {
- mFlags |= flags;
- setit = TRUE;
- }
- }
- else
- {
- if ((mFlags & flags) != 0)
- {
- mFlags &= ~flags;
- setit = TRUE;
- }
- }
- // BUG: Sometimes viewer physics and simulator physics get
- // out of sync. To fix this, always send update to simulator.
- // if (setit)
- {
- updateFlags();
- }
- return setit;
- }
- void LLViewerObject::applyAngularVelocity(F32 dt)
- {
- //do target omega here
- mRotTime += dt;
- LLVector3 ang_vel = getAngularVelocity();
- F32 omega = ang_vel.magVecSquared();
- F32 angle = 0.0f;
- LLQuaternion dQ;
- if (omega > 0.00001f)
- {
- omega = sqrt(omega);
- angle = omega * dt;
- ang_vel *= 1.f/omega;
-
- dQ.setQuat(angle, ang_vel);
-
- setRotation(getRotation()*dQ);
- setChanged(MOVED | SILHOUETTE);
- }
- }
- void LLViewerObject::resetRot()
- {
- mRotTime = 0.0f;
- }
- U32 LLViewerObject::getPartitionType() const
- {
- return LLViewerRegion::PARTITION_NONE;
- }
- void LLViewerObject::dirtySpatialGroup(BOOL priority) const
- {
- if (mDrawable)
- {
- LLSpatialGroup* group = mDrawable->getSpatialGroup();
- if (group)
- {
- group->dirtyGeom();
- gPipeline.markRebuild(group, priority);
- }
- }
- }
- void LLViewerObject::dirtyMesh()
- {
- if (mDrawable)
- {
- LLSpatialGroup* group = mDrawable->getSpatialGroup();
- if (group)
- {
- group->dirtyMesh();
- }
- }
- }
- F32 LLAlphaObject::getPartSize(S32 idx)
- {
- return 0.f;
- }
- // virtual
- void LLStaticViewerObject::updateDrawable(BOOL force_damped)
- {
- // Force an immediate rebuild on any update
- if (mDrawable.notNull())
- {
- mDrawable->updateXform(TRUE);
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL, TRUE);
- }
- clearChanged(SHIFTED);
- }
- void LLViewerObject::saveUnselectedChildrenPosition(std::vector<LLVector3>& positions)
- {
- if(mChildList.empty() || !positions.empty())
- {
- return ;
- }
- for (LLViewerObject::child_list_t::const_iterator iter = mChildList.begin();
- iter != mChildList.end(); iter++)
- {
- LLViewerObject* childp = *iter;
- if (!childp->isSelected() && childp->mDrawable.notNull())
- {
- positions.push_back(childp->getPositionEdit());
- }
- }
- return ;
- }
- void LLViewerObject::saveUnselectedChildrenRotation(std::vector<LLQuaternion>& rotations)
- {
- if(mChildList.empty())
- {
- return ;
- }
- for (LLViewerObject::child_list_t::const_iterator iter = mChildList.begin();
- iter != mChildList.end(); iter++)
- {
- LLViewerObject* childp = *iter;
- if (!childp->isSelected() && childp->mDrawable.notNull())
- {
- rotations.push_back(childp->getRotationEdit());
- }
- }
- return ;
- }
- //counter-rotation
- void LLViewerObject::resetChildrenRotationAndPosition(const std::vector<LLQuaternion>& rotations,
- const std::vector<LLVector3>& positions)
- {
- if(mChildList.empty())
- {
- return ;
- }
- S32 index = 0 ;
- LLQuaternion inv_rotation = ~getRotationEdit() ;
- LLVector3 offset = getPositionEdit() ;
- for (LLViewerObject::child_list_t::const_iterator iter = mChildList.begin();
- iter != mChildList.end(); iter++)
- {
- LLViewerObject* childp = *iter;
- if (!childp->isSelected() && childp->mDrawable.notNull())
- {
- if (childp->getPCode() != LL_PCODE_LEGACY_AVATAR)
- {
- childp->setRotation(rotations[index] * inv_rotation);
- childp->setPosition((positions[index] - offset) * inv_rotation);
- LLManip::rebuild(childp);
- }
- else //avatar
- {
- LLVector3 reset_pos = (positions[index] - offset) * inv_rotation ;
- LLQuaternion reset_rot = rotations[index] * inv_rotation ;
- ((LLVOAvatar*)childp)->mDrawable->mXform.setPosition(reset_pos);
- ((LLVOAvatar*)childp)->mDrawable->mXform.setRotation(reset_rot) ;
-
- ((LLVOAvatar*)childp)->mDrawable->getVObj()->setPosition(reset_pos, TRUE);
- ((LLVOAvatar*)childp)->mDrawable->getVObj()->setRotation(reset_rot, TRUE) ;
- LLManip::rebuild(childp);
- }
- index++;
- }
- }
- return ;
- }
- //counter-translation
- void LLViewerObject::resetChildrenPosition(const LLVector3& offset, BOOL simplified)
- {
- if(mChildList.empty())
- {
- return ;
- }
- LLVector3 child_offset;
- if(simplified) //translation only, rotation matrix does not change
- {
- child_offset = offset * ~getRotation();
- }
- else //rotation matrix might change too.
- {
- if (isAttachment() && mDrawable.notNull())
- {
- LLXform* attachment_point_xform = mDrawable->getXform()->getParent();
- LLQuaternion parent_rotation = getRotation() * attachment_point_xform->getWorldRotation();
- child_offset = offset * ~parent_rotation;
- }
- else
- {
- child_offset = offset * ~getRenderRotation();
- }
- }
- for (LLViewerObject::child_list_t::const_iterator iter = mChildList.begin();
- iter != mChildList.end(); iter++)
- {
- LLViewerObject* childp = *iter;
- if (!childp->isSelected() && childp->mDrawable.notNull())
- {
- if (childp->getPCode() != LL_PCODE_LEGACY_AVATAR)
- {
- childp->setPosition(childp->getPosition() + child_offset);
- LLManip::rebuild(childp);
- }
- else //avatar
- {
- LLVector3 reset_pos = ((LLVOAvatar*)childp)->mDrawable->mXform.getPosition() + child_offset ;
- ((LLVOAvatar*)childp)->mDrawable->mXform.setPosition(reset_pos);
- ((LLVOAvatar*)childp)->mDrawable->getVObj()->setPosition(reset_pos);
-
- LLManip::rebuild(childp);
- }
- }
- }
- return ;
- }