diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index e4e721227..5594d623e 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -88,38 +88,71 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) NifOgre::NIFLoader::load(mesh); Ogre::Entity *ent = mRenderer.getScene()->createEntity(mesh); + Ogre::Vector3 extents = ent->getBoundingBox().getSize(); + extents *= insert->getScale(); + float size = std::max(std::max(extents.x, extents.y), extents.z); + +/* + bool small = (size < 250); /// \todo config value + + // do not fade out doors. that will cause holes and look stupid + if (ptr.getTypeName().find("Door") != std::string::npos) + small = false; +*/ + const bool small = false; + + if (mBounds.find(ptr.getCell()) == mBounds.end()) + mBounds[ptr.getCell()] = Ogre::AxisAlignedBox::BOX_NULL; + + Ogre::AxisAlignedBox bounds = ent->getBoundingBox(); + bounds.scale(insert->getScale()); + mBounds[ptr.getCell()].merge(bounds); + if(!mIsStatic) { insert->attachObject(ent); + + ent->setRenderingDistance(small ? 2500 : 0); /// \todo config value } else { Ogre::StaticGeometry* sg = 0; - if(mStaticGeometry.find(ptr.getCell()) == mStaticGeometry.end()) + + if (small) { - uniqueID = uniqueID +1; - sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); - //Create the scenenode and put it in the map - mStaticGeometry[ptr.getCell()] = sg; - - // This specifies the size of a single batch region. - // If it is set too high: - // - there will be problems choosing the correct lights - // - the culling will be more inefficient - // If it is set too low: - // - there will be too many batches. - sg->setRegionDimensions(Ogre::Vector3(2500,2500,2500)); - - mBounds[ptr.getCell()] = Ogre::AxisAlignedBox::BOX_NULL; - mBounds[ptr.getCell()].merge(ent->getBoundingBox()); + if( mStaticGeometrySmall.find(ptr.getCell()) == mStaticGeometrySmall.end()) + { + uniqueID = uniqueID +1; + sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); + mStaticGeometrySmall[ptr.getCell()] = sg; + + sg->setRenderingDistance(2500); /// \todo config value + } + else + sg = mStaticGeometrySmall[ptr.getCell()]; } else { - sg = mStaticGeometry[ptr.getCell()]; + if( mStaticGeometry.find(ptr.getCell()) == mStaticGeometry.end()) + { + + uniqueID = uniqueID +1; + sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); + mStaticGeometry[ptr.getCell()] = sg; + } + else + sg = mStaticGeometry[ptr.getCell()]; } + + // This specifies the size of a single batch region. + // If it is set too high: + // - there will be problems choosing the correct lights + // - the culling will be more inefficient + // If it is set too low: + // - there will be too many batches. + sg->setRegionDimensions(Ogre::Vector3(2500,2500,2500)); sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale()); - mBounds[ptr.getCell()].merge(insert->_getDerivedPosition()); mRenderer.getScene()->destroyEntity(ent); } @@ -206,6 +239,13 @@ void Objects::removeCell(MWWorld::Ptr::CellStore* store) mRenderer.getScene()->destroyStaticGeometry (sg); sg = 0; } + if(mStaticGeometrySmall.find(store) != mStaticGeometrySmall.end()) + { + Ogre::StaticGeometry* sg = mStaticGeometrySmall[store]; + mStaticGeometrySmall.erase(store); + mRenderer.getScene()->destroyStaticGeometry (sg); + sg = 0; + } if(mBounds.find(store) != mBounds.end()) mBounds.erase(store); @@ -218,6 +258,11 @@ void Objects::buildStaticGeometry(ESMS::CellStore& cell) Ogre::StaticGeometry* sg = mStaticGeometry[&cell]; sg->build(); } + if(mStaticGeometrySmall.find(&cell) != mStaticGeometrySmall.end()) + { + Ogre::StaticGeometry* sg = mStaticGeometrySmall[&cell]; + sg->build(); + } } Ogre::AxisAlignedBox Objects::getDimensions(MWWorld::Ptr::CellStore* cell) diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 1ca81331d..265de875b 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -14,6 +14,7 @@ class Objects{ OEngine::Render::OgreRenderer &mRenderer; std::map mCellSceneNodes; std::map mStaticGeometry; + std::map mStaticGeometrySmall; std::map mBounds; Ogre::SceneNode* mMwRoot; bool mIsStatic;