aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lldrawable.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/lldrawable.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/newview/lldrawable.cpp')
-rw-r--r--linden/indra/newview/lldrawable.cpp359
1 files changed, 94 insertions, 265 deletions
diff --git a/linden/indra/newview/lldrawable.cpp b/linden/indra/newview/lldrawable.cpp
index a86fc07..4b6bd7c 100644
--- a/linden/indra/newview/lldrawable.cpp
+++ b/linden/indra/newview/lldrawable.cpp
@@ -94,11 +94,7 @@ void LLDrawable::init()
94 mRenderType = 0; 94 mRenderType = 0;
95 mCurrentScale = LLVector3(1,1,1); 95 mCurrentScale = LLVector3(1,1,1);
96 mDistanceWRTCamera = 0.0f; 96 mDistanceWRTCamera = 0.0f;
97 // mUVRect 97
98 mUVZ = 0.f;
99 // mLightSet
100 // mBlockSet
101 // mSavePos
102 mQuietCount = 0; 98 mQuietCount = 0;
103 99
104 mState = 0; 100 mState = 0;
@@ -107,7 +103,6 @@ void LLDrawable::init()
107 mSpatialGroupp = NULL; 103 mSpatialGroupp = NULL;
108 mVisible = 0; 104 mVisible = 0;
109 mRadius = 0.f; 105 mRadius = 0.f;
110 mSunShadowFactor = 1.f;
111 106
112 mGeneration = -1; 107 mGeneration = -1;
113 mBinRadius = 1.f; 108 mBinRadius = 1.f;
@@ -185,21 +180,6 @@ BOOL LLDrawable::isLight() const
185 } 180 }
186} 181}
187 182
188void LLDrawable::clearLightSet()
189{
190 // Remove this object from any object which has it as a light
191 for (drawable_set_t::iterator iter = mLightSet.begin(); iter != mLightSet.end(); iter++)
192 {
193 LLDrawable *targetp = *iter;
194 if (targetp != this && !targetp->isDead())
195 {
196 targetp->mLightSet.erase(this);
197 gPipeline.markRelight(targetp);
198 }
199 }
200 mLightSet.clear();
201}
202
203void LLDrawable::cleanupReferences() 183void LLDrawable::cleanupReferences()
204{ 184{
205 LLFastTimer t(LLFastTimer::FTM_PIPELINE); 185 LLFastTimer t(LLFastTimer::FTM_PIPELINE);
@@ -207,12 +187,8 @@ void LLDrawable::cleanupReferences()
207 std::for_each(mFaces.begin(), mFaces.end(), DeletePointer()); 187 std::for_each(mFaces.begin(), mFaces.end(), DeletePointer());
208 mFaces.clear(); 188 mFaces.clear();
209 189
210 clearLightSet();
211
212 gObjectList.removeDrawable(this); 190 gObjectList.removeDrawable(this);
213 191
214 mBlockSet.clear();
215
216 gPipeline.unlinkDrawable(this); 192 gPipeline.unlinkDrawable(this);
217 193
218 // Cleanup references to other objects 194 // Cleanup references to other objects
@@ -239,16 +215,6 @@ void LLDrawable::cleanupDeadDrawables()
239S32 LLDrawable::findReferences(LLDrawable *drawablep) 215S32 LLDrawable::findReferences(LLDrawable *drawablep)
240{ 216{
241 S32 count = 0; 217 S32 count = 0;
242 if (mLightSet.count(drawablep) > 0)
243 {
244 llinfos << this << ": lightset reference" << llendl;
245 count++;
246 }
247 if (mBlockSet.count(drawablep) > 0)
248 {
249 llinfos << this << ": blockset reference" << llendl;
250 count++;
251 }
252 if (mParent == drawablep) 218 if (mParent == drawablep)
253 { 219 {
254 llinfos << this << ": parent reference" << llendl; 220 llinfos << this << ": parent reference" << llendl;
@@ -257,20 +223,6 @@ S32 LLDrawable::findReferences(LLDrawable *drawablep)
257 return count; 223 return count;
258} 224}
259 225
260#if 0
261// SJB: This is SLOW, so we don't want to allow it (we don't currently use it)
262void LLDrawable::removeFace(const S32 i)
263{
264 LLFace *face= mFaces[i];
265
266 if (face)
267 {
268 mFaces.erase(mFaces.begin() + i);
269 delete face;
270 }
271}
272#endif
273
274LLFace* LLDrawable::addFace(LLFacePool *poolp, LLViewerImage *texturep) 226LLFace* LLDrawable::addFace(LLFacePool *poolp, LLViewerImage *texturep)
275{ 227{
276 LLMemType mt(LLMemType::MTYPE_DRAWABLE); 228 LLMemType mt(LLMemType::MTYPE_DRAWABLE);
@@ -299,11 +251,13 @@ LLFace* LLDrawable::addFace(const LLTextureEntry *te, LLViewerImage *texturep)
299{ 251{
300 LLMemType mt(LLMemType::MTYPE_DRAWABLE); 252 LLMemType mt(LLMemType::MTYPE_DRAWABLE);
301 253
302 LLFace *face = new LLFace(this, mVObjp); 254 LLFace *face;
255 face = new LLFace(this, mVObjp);
303 256
304 face->setTEOffset(mFaces.size()); 257 face->setTEOffset(mFaces.size());
305 face->setTexture(texturep); 258 face->setTexture(texturep);
306 face->setPoolType(gPipeline.getPoolTypeFromTE(te, texturep)); 259 face->setPoolType(gPipeline.getPoolTypeFromTE(te, texturep));
260
307 mFaces.push_back(face); 261 mFaces.push_back(face);
308 262
309 if (isState(UNLIT)) 263 if (isState(UNLIT))
@@ -399,7 +353,6 @@ void LLDrawable::makeActive()
399 pcode == LLViewerObject::LL_VO_SURFACE_PATCH || 353 pcode == LLViewerObject::LL_VO_SURFACE_PATCH ||
400 pcode == LLViewerObject::LL_VO_PART_GROUP || 354 pcode == LLViewerObject::LL_VO_PART_GROUP ||
401 pcode == LLViewerObject::LL_VO_CLOUDS || 355 pcode == LLViewerObject::LL_VO_CLOUDS ||
402 pcode == LLViewerObject::LL_VO_STARS ||
403 pcode == LLViewerObject::LL_VO_GROUND || 356 pcode == LLViewerObject::LL_VO_GROUND ||
404 pcode == LLViewerObject::LL_VO_SKY) 357 pcode == LLViewerObject::LL_VO_SKY)
405 { 358 {
@@ -429,22 +382,22 @@ void LLDrawable::makeActive()
429 drawable->makeActive(); 382 drawable->makeActive();
430 } 383 }
431 } 384 }
432 385
433 if (mVObjp->getPCode() == LL_PCODE_VOLUME) 386 if (mVObjp->getPCode() == LL_PCODE_VOLUME)
434 { 387 {
435 if (mVObjp->getVolume()->getPathType() == LL_PCODE_PATH_FLEXIBLE) 388 if (mVObjp->isFlexible())
436 { 389 {
437 return; 390 return;
438 } 391 }
439 } 392 }
440 393
441 clearState(LLDrawable::LIGHTING_BUILT);
442 if (mVObjp->getPCode() == LL_PCODE_VOLUME) 394 if (mVObjp->getPCode() == LL_PCODE_VOLUME)
443 { 395 {
444 gPipeline.markRebuild(this, LLDrawable::REBUILD_VOLUME, TRUE); 396 gPipeline.markRebuild(this, LLDrawable::REBUILD_VOLUME, TRUE);
445 } 397 }
398 updatePartition();
446 } 399 }
447 updatePartition(); 400
448 if (isRoot()) 401 if (isRoot())
449 { 402 {
450 mQuietCount = 0; 403 mQuietCount = 0;
@@ -482,7 +435,6 @@ void LLDrawable::makeStatic()
482 } 435 }
483 } 436 }
484 437
485 gPipeline.markRelight(this);
486 if (mVObjp->getPCode() == LL_PCODE_VOLUME) 438 if (mVObjp->getPCode() == LL_PCODE_VOLUME)
487 { 439 {
488 gPipeline.markRebuild(this, LLDrawable::REBUILD_VOLUME, TRUE); 440 gPipeline.markRebuild(this, LLDrawable::REBUILD_VOLUME, TRUE);
@@ -526,8 +478,8 @@ F32 LLDrawable::updateXform(BOOL undamped)
526 478
527 // Damping 479 // Damping
528 F32 dist_squared = 0.f; 480 F32 dist_squared = 0.f;
529 F32 scaled = 0.f; 481 F32 camdist2 = (mDistanceWRTCamera * mDistanceWRTCamera);
530 482
531 if (damped && mDistanceWRTCamera > 0.0f) 483 if (damped && mDistanceWRTCamera > 0.0f)
532 { 484 {
533 F32 lerp_amt = llclamp(LLCriticalDamp::getInterpolant(OBJECT_DAMPING_TIME_CONSTANT), 0.f, 1.f); 485 F32 lerp_amt = llclamp(LLCriticalDamp::getInterpolant(OBJECT_DAMPING_TIME_CONSTANT), 0.f, 1.f);
@@ -538,10 +490,8 @@ F32 LLDrawable::updateXform(BOOL undamped)
538 dist_squared += (1.f - dot(new_rot, target_rot)) * 10.f; 490 dist_squared += (1.f - dot(new_rot, target_rot)) * 10.f;
539 491
540 LLVector3 new_scale = lerp(old_scale, target_scale, lerp_amt); 492 LLVector3 new_scale = lerp(old_scale, target_scale, lerp_amt);
541 scaled = dist_vec_squared(new_scale, target_scale); 493 dist_squared += dist_vec_squared(new_scale, target_scale);
542 494
543 dist_squared += scaled;
544 F32 camdist2 = (mDistanceWRTCamera * mDistanceWRTCamera);
545 if ((dist_squared >= MIN_INTERPOLATE_DISTANCE_SQUARED * camdist2) && 495 if ((dist_squared >= MIN_INTERPOLATE_DISTANCE_SQUARED * camdist2) &&
546 (dist_squared <= MAX_INTERPOLATE_DISTANCE_SQUARED)) 496 (dist_squared <= MAX_INTERPOLATE_DISTANCE_SQUARED))
547 { 497 {
@@ -549,12 +499,6 @@ F32 LLDrawable::updateXform(BOOL undamped)
549 target_pos = new_pos; 499 target_pos = new_pos;
550 target_rot = new_rot; 500 target_rot = new_rot;
551 target_scale = new_scale; 501 target_scale = new_scale;
552
553 if (scaled >= MIN_INTERPOLATE_DISTANCE_SQUARED)
554 {
555 //scaling requires an immediate rebuild
556 gPipeline.markRebuild(this, LLDrawable::REBUILD_POSITION, TRUE);
557 }
558 } 502 }
559 else 503 else
560 { 504 {
@@ -562,7 +506,17 @@ F32 LLDrawable::updateXform(BOOL undamped)
562 dist_squared = 0.0f; 506 dist_squared = 0.0f;
563 } 507 }
564 } 508 }
565 509
510 if ((mCurrentScale != target_scale) ||
511 (!isRoot() && (dist_squared >= MIN_INTERPOLATE_DISTANCE_SQUARED*camdist2)))
512 { //child prim moving or scale change requires immediate rebuild
513 gPipeline.markRebuild(this, LLDrawable::REBUILD_POSITION, TRUE);
514 }
515 else if (!getVOVolume() && !isAvatar())
516 {
517 movePartition();
518 }
519
566 // Update 520 // Update
567 mXform.setPosition(target_pos); 521 mXform.setPosition(target_pos);
568 mXform.setRotation(target_rot); 522 mXform.setRotation(target_rot);
@@ -571,6 +525,10 @@ F32 LLDrawable::updateXform(BOOL undamped)
571 525
572 mCurrentScale = target_scale; 526 mCurrentScale = target_scale;
573 527
528 if (mSpatialBridge)
529 {
530 gPipeline.markMoved(mSpatialBridge, FALSE);
531 }
574 return dist_squared; 532 return dist_squared;
575} 533}
576 534
@@ -591,18 +549,6 @@ void LLDrawable::moveUpdatePipeline(BOOL moved)
591 { 549 {
592 getFace(i)->updateCenterAgent(); 550 getFace(i)->updateCenterAgent();
593 } 551 }
594
595 if (moved || !isState(LLDrawable::BUILT)) // moved since last frame
596 {
597 LLVector3 tmp = mSavePos - mXform.getPositionW();
598 F32 dist = tmp.magVecSquared(); // moved since last _update_
599
600 if (dist > 1.0f || !isState(LLDrawable::BUILT) || isLight())
601 {
602 mSavePos = mXform.getPositionW();
603 gPipeline.markRelight(this);
604 }
605 }
606} 552}
607 553
608void LLDrawable::movePartition() 554void LLDrawable::movePartition()
@@ -703,17 +649,21 @@ BOOL LLDrawable::updateMoveDamped()
703void LLDrawable::updateDistance(LLCamera& camera) 649void LLDrawable::updateDistance(LLCamera& camera)
704{ 650{
705 //switch LOD with the spatial group to avoid artifacts 651 //switch LOD with the spatial group to avoid artifacts
706 LLSpatialGroup* sg = getSpatialGroup(); 652 //LLSpatialGroup* sg = getSpatialGroup();
707 653
708 LLVector3 pos; 654 LLVector3 pos;
709 655
710 if (!sg || sg->changeLOD()) 656 //if (!sg || sg->changeLOD())
711 { 657 {
712 LLVOVolume* volume = getVOVolume(); 658 LLVOVolume* volume = getVOVolume();
713 if (volume) 659 if (volume)
714 { 660 {
715 volume->updateRelativeXform(); 661 volume->updateRelativeXform();
716 pos = LLVector3(0,0,0) * volume->getRelativeXform(); 662 pos = volume->getRelativeXform().getTranslation();
663 if (isStatic())
664 {
665 pos += volume->getRegion()->getOriginAgent();
666 }
717 667
718 for (S32 i = 0; i < getNumFaces(); i++) 668 for (S32 i = 0; i < getNumFaces(); i++)
719 { 669 {
@@ -761,7 +711,7 @@ void LLDrawable::updateTexture()
761 { 711 {
762 if (!isActive()) 712 if (!isActive())
763 { 713 {
764 gPipeline.markMoved(this); 714 //gPipeline.markMoved(this);
765 } 715 }
766 else 716 else
767 { 717 {
@@ -783,18 +733,6 @@ BOOL LLDrawable::updateGeometry(BOOL priority)
783{ 733{
784 llassert(mVObjp.notNull()); 734 llassert(mVObjp.notNull());
785 BOOL res = mVObjp->updateGeometry(this); 735 BOOL res = mVObjp->updateGeometry(this);
786 if (isState(REBUILD_LIGHTING))
787 {
788 updateLighting(priority ? FALSE : TRUE); // only do actual lighting for non priority updates
789 if (priority)
790 {
791 gPipeline.markRelight(this); // schedule non priority update
792 }
793 else
794 {
795 clearState(REBUILD_LIGHTING);
796 }
797 }
798 return res; 736 return res;
799} 737}
800 738
@@ -821,7 +759,11 @@ void LLDrawable::shiftPos(const LLVector3 &shift_vector)
821 759
822 if (isStatic()) 760 if (isStatic())
823 { 761 {
824 gPipeline.markRebuild(this, LLDrawable::REBUILD_GEOMETRY, TRUE); 762 LLVOVolume* volume = getVOVolume();
763 if (!volume)
764 {
765 gPipeline.markRebuild(this, LLDrawable::REBUILD_ALL, TRUE);
766 }
825 767
826 for (S32 i = 0; i < getNumFaces(); i++) 768 for (S32 i = 0; i < getNumFaces(); i++)
827 { 769 {
@@ -830,7 +772,7 @@ void LLDrawable::shiftPos(const LLVector3 &shift_vector)
830 facep->mExtents[0] += shift_vector; 772 facep->mExtents[0] += shift_vector;
831 facep->mExtents[1] += shift_vector; 773 facep->mExtents[1] += shift_vector;
832 774
833 if (facep->hasGeometry()) 775 if (!volume && facep->hasGeometry())
834 { 776 {
835 facep->mVertexBuffer = NULL; 777 facep->mVertexBuffer = NULL;
836 facep->mLastVertexBuffer = NULL; 778 facep->mLastVertexBuffer = NULL;
@@ -845,9 +787,13 @@ void LLDrawable::shiftPos(const LLVector3 &shift_vector)
845 { 787 {
846 mSpatialBridge->shiftPos(shift_vector); 788 mSpatialBridge->shiftPos(shift_vector);
847 } 789 }
790 else if (isAvatar())
791 {
792 mExtents[0] += shift_vector;
793 mExtents[1] += shift_vector;
794 mPositionGroup += LLVector3d(shift_vector);
795 }
848 796
849 mSavePos = mXform.getPositionW();
850
851 mVObjp->onShift(shift_vector); 797 mVObjp->onShift(shift_vector);
852} 798}
853 799
@@ -894,64 +840,11 @@ void LLDrawable::updateBinRadius()
894{ 840{
895 if (mVObjp.notNull()) 841 if (mVObjp.notNull())
896 { 842 {
897 mBinRadius = mVObjp->getBinRadius(); 843 mBinRadius = llmin(mVObjp->getBinRadius(), 256.f);
898 } 844 }
899 else 845 else
900 { 846 {
901 mBinRadius = getRadius()*4.f; 847 mBinRadius = llmin(getRadius()*4.f, 256.f);
902 }
903}
904
905void LLDrawable::updateLightSet()
906{
907 if (isDead())
908 {
909 llwarns << "Updating light set for dead drawable!" << llendl;
910 return;
911 }
912
913 LLSpatialPartition* part = gPipeline.getSpatialPartition(LLPipeline::PARTITION_VOLUME);
914 LLVOVolume* light = getVOVolume();
915 if (isLight() && light)
916 {
917 // mLightSet points to lit objects
918 for (drawable_set_t::iterator iter = mLightSet.begin(); iter != mLightSet.end(); iter++)
919 {
920 gPipeline.markRelight(*iter);
921 }
922 mLightSet.clear();
923 part->getObjects(getPositionAgent(), light->getLightRadius(), mLightSet);
924 for (drawable_set_t::iterator iter = mLightSet.begin(); iter != mLightSet.end(); iter++)
925 {
926 gPipeline.markRelight(*iter);
927 }
928 }
929 else
930 {
931 // mLightSet points to nearby lights
932 mLightSet.clear();
933 part->getLights(getPositionAgent(), getRadius(), mLightSet);
934 const drawable_set_t::size_type MAX_LIGHTS = 16;
935 if (mLightSet.size() > MAX_LIGHTS)
936 {
937 typedef std::set<std::pair<F32,LLPointer<LLDrawable> > > sorted_pair_set_t;
938 sorted_pair_set_t sorted_set;
939 for (drawable_set_t::iterator iter = mLightSet.begin(); iter != mLightSet.end(); iter++)
940 {
941 LLDrawable* drawable = *iter;
942 LLVector3 dvec = drawable->getPositionAgent() - getPositionAgent();
943 F32 dist2 = dvec.magVecSquared();
944 sorted_set.insert(std::make_pair(dist2, drawable));
945 }
946 mLightSet.clear();
947 S32 count = 0;
948 for (sorted_pair_set_t::iterator iter = sorted_set.begin(); iter != sorted_set.end(); iter++)
949 {
950 if (++count > 16)
951 break;
952 mLightSet.insert((*iter).second);
953 }
954 }
955 } 848 }
956} 849}
957 850
@@ -962,72 +855,6 @@ void LLDrawable::updateSpecialHoverCursor(BOOL enabled)
962 // hover cursor selection. JC 855 // hover cursor selection. JC
963} 856}
964 857
965BOOL LLDrawable::updateLighting(BOOL do_lighting)
966{
967 if (do_lighting)
968 {
969 if (gPipeline.getLightingDetail() >= 2 && (getLit() || isLight()))
970 {
971 LLFastTimer t(LLFastTimer::FTM_UPDATE_LIGHTS);
972 updateLightSet();
973 do_lighting = isLight() ? FALSE : TRUE;
974 }
975 else
976 {
977 do_lighting = FALSE;
978 }
979 }
980 if (gPipeline.getLightingDetail() >= 2)
981 {
982 LLFastTimer t(LLFastTimer::FTM_GEO_LIGHT);
983 if (mVObjp->updateLighting(do_lighting))
984 {
985 setState(LIGHTING_BUILT);
986 }
987 }
988
989 return TRUE;
990}
991
992void LLDrawable::applyLightsAsPoint(LLColor4& result)
993{
994 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
995
996 LLVector3 point_agent(getPositionAgent());
997 LLVector3 normal(-gCamera->getXAxis()); // make point agent face camera
998
999 F32 sun_int = normal * gPipeline.mSunDir;
1000 LLColor4 color(gSky.getTotalAmbientColor());
1001 color += gPipeline.mSunDiffuse * sun_int;
1002
1003 for (drawable_set_t::iterator iter = mLightSet.begin();
1004 iter != mLightSet.end(); ++iter)
1005 {
1006 LLDrawable* drawable = *iter;
1007 LLVOVolume* light = drawable->getVOVolume();
1008 if (!light)
1009 {
1010 continue;
1011 }
1012 LLColor4 light_color;
1013 light->calcLightAtPoint(point_agent, normal, light_color);
1014 color += light_color;
1015 }
1016
1017 // Clamp the color...
1018 color.mV[0] = llmax(color.mV[0], 0.f);
1019 color.mV[1] = llmax(color.mV[1], 0.f);
1020 color.mV[2] = llmax(color.mV[2], 0.f);
1021
1022 F32 max_color = llmax(color.mV[0], color.mV[1], color.mV[2]);
1023 if (max_color > 1.f)
1024 {
1025 color *= 1.f/max_color;
1026 }
1027
1028 result = color;
1029}
1030
1031F32 LLDrawable::getVisibilityRadius() const 858F32 LLDrawable::getVisibilityRadius() const
1032{ 859{
1033 if (isDead()) 860 if (isDead())
@@ -1053,10 +880,10 @@ void LLDrawable::updateUVMinMax()
1053 880
1054void LLDrawable::setSpatialGroup(LLSpatialGroup *groupp) 881void LLDrawable::setSpatialGroup(LLSpatialGroup *groupp)
1055{ 882{
1056 if (mSpatialGroupp && (groupp != mSpatialGroupp)) 883/*if (mSpatialGroupp && (groupp != mSpatialGroupp))
1057 { 884 {
1058 mSpatialGroupp->setState(LLSpatialGroup::GEOM_DIRTY); 885 mSpatialGroupp->setState(LLSpatialGroup::GEOM_DIRTY);
1059 } 886 }*/
1060 mSpatialGroupp = groupp; 887 mSpatialGroupp = groupp;
1061} 888}
1062 889
@@ -1113,7 +940,7 @@ BOOL LLDrawable::isVisible() const
1113 { 940 {
1114 LLSpatialGroup* group = mSpatialBridge.notNull() ? mSpatialBridge->getSpatialGroup() : 941 LLSpatialGroup* group = mSpatialBridge.notNull() ? mSpatialBridge->getSpatialGroup() :
1115 getSpatialGroup(); 942 getSpatialGroup();
1116 if (!group || group->isVisible()) 943 if (group && group->isVisible())
1117 { 944 {
1118 mVisible = sCurVisible; 945 mVisible = sCurVisible;
1119 return TRUE; 946 return TRUE;
@@ -1131,7 +958,7 @@ BOOL LLDrawable::isVisible() const
1131 else 958 else
1132 { 959 {
1133 LLSpatialGroup* group = getSpatialGroup(); 960 LLSpatialGroup* group = getSpatialGroup();
1134 if (!group || group->isVisible()) 961 if (group && group->isVisible())
1135 { 962 {
1136 mVisible = sCurVisible; 963 mVisible = sCurVisible;
1137 return TRUE; 964 return TRUE;
@@ -1154,18 +981,19 @@ LLSpatialBridge::LLSpatialBridge(LLDrawable* root, U32 data_mask)
1154 mRenderType = mDrawable->mRenderType; 981 mRenderType = mDrawable->mRenderType;
1155 mDrawableType = mDrawable->mRenderType; 982 mDrawableType = mDrawable->mRenderType;
1156 983
1157 mPartitionType = LLPipeline::PARTITION_VOLUME; 984 mPartitionType = LLViewerRegion::PARTITION_VOLUME;
1158 985
1159 mOctree->balance(); 986 mOctree->balance();
1160 987
1161 gPipeline.getSpatialPartition(mPartitionType)->put(this); 988 mDrawable->getRegion()->getSpatialPartition(mPartitionType)->put(this);
1162} 989}
1163 990
1164LLSpatialBridge::~LLSpatialBridge() 991LLSpatialBridge::~LLSpatialBridge()
1165{ 992{
1166 if (getSpatialGroup()) 993 LLSpatialGroup* group = getSpatialGroup();
994 if (group)
1167 { 995 {
1168 gPipeline.getSpatialPartition(mPartitionType)->remove(this, getSpatialGroup()); 996 group->mSpatialPartition->remove(this, group);
1169 } 997 }
1170} 998}
1171 999
@@ -1252,6 +1080,11 @@ LLCamera LLSpatialBridge::transformCamera(LLCamera& camera)
1252 up_axis *= rot; 1080 up_axis *= rot;
1253 left_axis *= rot; 1081 left_axis *= rot;
1254 1082
1083 if (!delta.isFinite())
1084 {
1085 delta.clearVec();
1086 }
1087
1255 ret.setOrigin(delta); 1088 ret.setOrigin(delta);
1256 ret.setAxes(lookAt, left_axis, up_axis); 1089 ret.setAxes(lookAt, left_axis, up_axis);
1257 1090
@@ -1305,13 +1138,13 @@ public:
1305 virtual void traverse(const LLOctreeNode<LLDrawable>* node) 1138 virtual void traverse(const LLOctreeNode<LLDrawable>* node)
1306 { 1139 {
1307 LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0); 1140 LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
1308 group->clearState(LLSpatialGroup::OCCLUDED | LLSpatialGroup::CULLED); 1141 group->setVisible();
1309 LLOctreeTraveler<LLDrawable>::traverse(node); 1142 LLOctreeTraveler<LLDrawable>::traverse(node);
1310 } 1143 }
1311 1144
1312 void visit(const LLOctreeState<LLDrawable>* branch) 1145 void visit(const LLOctreeNode<LLDrawable>* branch)
1313 { 1146 {
1314 gPipeline.markNotCulled((LLSpatialGroup*) branch->getListener(0), *mCamera, TRUE); 1147 gPipeline.markNotCulled((LLSpatialGroup*) branch->getListener(0), *mCamera);
1315 } 1148 }
1316}; 1149};
1317 1150
@@ -1322,17 +1155,26 @@ void LLSpatialBridge::setVisible(LLCamera& camera_in, std::vector<LLDrawable*>*
1322 return; 1155 return;
1323 } 1156 }
1324 1157
1158
1159 //HACK don't draw attachments for avatars that haven't been visible in more than a frame
1325 LLViewerObject *vobj = mDrawable->getVObj(); 1160 LLViewerObject *vobj = mDrawable->getVObj();
1326 if (vobj && vobj->isAttachment() && !vobj->isHUDAttachment()) 1161 if (vobj && vobj->isAttachment() && !vobj->isHUDAttachment())
1327 { 1162 {
1328 LLVOAvatar* av; 1163 LLDrawable* av;
1329 LLDrawable* parent = mDrawable->getParent(); 1164 LLDrawable* parent = mDrawable->getParent();
1330 1165
1331 if (parent) 1166 if (parent)
1332 { 1167 {
1333 av = (LLVOAvatar*) parent->getVObj().get(); 1168 LLViewerObject* objparent = parent->getVObj();
1334 1169 av = objparent->mDrawable;
1335 if (!av->isVisible()) 1170 LLSpatialGroup* group = av->getSpatialGroup();
1171
1172 BOOL impostor = objparent->isAvatar() && ((LLVOAvatar*) objparent)->isImpostor();
1173
1174 if (!group ||
1175 av->getSpatialGroup()->mDistance > LLVOAvatar::sRenderDistance ||
1176 LLDrawable::getCurrentFrame() - av->mVisible > 1 ||
1177 impostor)
1336 { 1178 {
1337 return; 1179 return;
1338 } 1180 }
@@ -1346,7 +1188,8 @@ void LLSpatialBridge::setVisible(LLCamera& camera_in, std::vector<LLDrawable*>*
1346 LLVector3 center = (mExtents[0] + mExtents[1]) * 0.5f; 1188 LLVector3 center = (mExtents[0] + mExtents[1]) * 0.5f;
1347 LLVector3 size = (mExtents[1]-mExtents[0]) * 0.5f; 1189 LLVector3 size = (mExtents[1]-mExtents[0]) * 0.5f;
1348 1190
1349 if (camera_in.AABBInFrustum(center, size)) 1191 if (camera_in.AABBInFrustumNoFarClip(center, size) &&
1192 AABBSphereIntersect(mExtents[0], mExtents[1], camera_in.getOrigin(), camera_in.mFrustumCornerDist))
1350 { 1193 {
1351 if (LLPipeline::calcPixelArea(center, size, camera_in) < FORCE_INVISIBLE_AREA) 1194 if (LLPipeline::calcPixelArea(center, size, camera_in) < FORCE_INVISIBLE_AREA)
1352 { 1195 {
@@ -1392,7 +1235,11 @@ void LLSpatialBridge::updateDistance(LLCamera& camera_in)
1392 llwarns << "Corrupt drawable found while updating spatial bridge distance." << llendl; 1235 llwarns << "Corrupt drawable found while updating spatial bridge distance." << llendl;
1393 continue; 1236 continue;
1394 } 1237 }
1395 child->updateDistance(camera); 1238
1239 if (!child->isAvatar())
1240 {
1241 child->updateDistance(camera);
1242 }
1396 } 1243 }
1397} 1244}
1398 1245
@@ -1401,11 +1248,6 @@ void LLSpatialBridge::makeActive()
1401 llerrs << "makeActive called on spatial bridge" << llendl; 1248 llerrs << "makeActive called on spatial bridge" << llendl;
1402} 1249}
1403 1250
1404void LLSpatialBridge::makeStatic()
1405{
1406 llerrs << "makeStatic called on spatial bridge" << llendl;
1407}
1408
1409void LLSpatialBridge::move(LLDrawable *drawablep, LLSpatialGroup *curp, BOOL immediate) 1251void LLSpatialBridge::move(LLDrawable *drawablep, LLSpatialGroup *curp, BOOL immediate)
1410{ 1252{
1411 LLSpatialPartition::move(drawablep, curp, immediate); 1253 LLSpatialPartition::move(drawablep, curp, immediate);
@@ -1415,7 +1257,7 @@ void LLSpatialBridge::move(LLDrawable *drawablep, LLSpatialGroup *curp, BOOL imm
1415BOOL LLSpatialBridge::updateMove() 1257BOOL LLSpatialBridge::updateMove()
1416{ 1258{
1417 mOctree->balance(); 1259 mOctree->balance();
1418 gPipeline.getSpatialPartition(mPartitionType)->move(this, getSpatialGroup(), TRUE); 1260 mDrawable->getRegion()->getSpatialPartition(mPartitionType)->move(this, getSpatialGroup(), TRUE);
1419 return TRUE; 1261 return TRUE;
1420} 1262}
1421 1263
@@ -1453,14 +1295,12 @@ const LLVector3 LLDrawable::getPositionAgent() const
1453 { 1295 {
1454 if (isActive()) 1296 if (isActive())
1455 { 1297 {
1456 if (isRoot()) 1298 LLVector3 pos(0,0,0);
1457 { 1299 if (!isRoot())
1458 return LLVector3(0,0,0) * getWorldMatrix();
1459 }
1460 else
1461 { 1300 {
1462 return mVObjp->getPosition() * getParent()->getWorldMatrix(); 1301 pos = mVObjp->getPosition();
1463 } 1302 }
1303 return pos * getRenderMatrix();
1464 } 1304 }
1465 else 1305 else
1466 { 1306 {
@@ -1485,11 +1325,6 @@ BOOL LLDrawable::isAnimating() const
1485 return TRUE; 1325 return TRUE;
1486 } 1326 }
1487 1327
1488 if (mVObjp->isFlexible())
1489 {
1490 return TRUE;
1491 }
1492
1493 if (mVObjp->getPCode() == LLViewerObject::LL_VO_PART_GROUP) 1328 if (mVObjp->getPCode() == LLViewerObject::LL_VO_PART_GROUP)
1494 { 1329 {
1495 return TRUE; 1330 return TRUE;
@@ -1500,12 +1335,6 @@ BOOL LLDrawable::isAnimating() const
1500 return TRUE; 1335 return TRUE;
1501 } 1336 }
1502 1337
1503 LLVOVolume* vol = getVOVolume();
1504 if (vol && vol->mTextureAnimp)
1505 {
1506 return TRUE;
1507 }
1508
1509 if (!isRoot() && !mVObjp->getAngularVelocity().isExactlyZero()) 1338 if (!isRoot() && !mVObjp->getAngularVelocity().isExactlyZero())
1510 { 1339 {
1511 return TRUE; 1340 return TRUE;
@@ -1527,16 +1356,16 @@ LLBridgePartition::LLBridgePartition()
1527{ 1356{
1528 mRenderByGroup = FALSE; 1357 mRenderByGroup = FALSE;
1529 mDrawableType = LLPipeline::RENDER_TYPE_AVATAR; 1358 mDrawableType = LLPipeline::RENDER_TYPE_AVATAR;
1530 mPartitionType = LLPipeline::PARTITION_BRIDGE; 1359 mPartitionType = LLViewerRegion::PARTITION_BRIDGE;
1531 mLODPeriod = 1; 1360 mLODPeriod = 16;
1532 mSlopRatio = 0.f; 1361 mSlopRatio = 0.25f;
1533} 1362}
1534 1363
1535LLHUDBridge::LLHUDBridge(LLDrawable* drawablep) 1364LLHUDBridge::LLHUDBridge(LLDrawable* drawablep)
1536: LLVolumeBridge(drawablep) 1365: LLVolumeBridge(drawablep)
1537{ 1366{
1538 mDrawableType = LLPipeline::RENDER_TYPE_HUD; 1367 mDrawableType = LLPipeline::RENDER_TYPE_HUD;
1539 mPartitionType = LLPipeline::PARTITION_HUD; 1368 mPartitionType = LLViewerRegion::PARTITION_HUD;
1540 mSlopRatio = 0.0f; 1369 mSlopRatio = 0.0f;
1541} 1370}
1542 1371