forked from teamnwah/openmw-tes3coop
Support lights that do not have a model (Fixes #1361)
This commit is contained in:
parent
95b3026c7e
commit
a6788cfb0e
3 changed files with 87 additions and 76 deletions
|
@ -50,9 +50,9 @@ namespace MWClass
|
|||
void Light::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
||||
{
|
||||
const std::string model = getModel(ptr);
|
||||
if(!model.empty()) {
|
||||
renderingInterface.getObjects().insertModel(ptr, model);
|
||||
}
|
||||
|
||||
// Insert even if model is empty, so that the light is added
|
||||
renderingInterface.getObjects().insertModel(ptr, model);
|
||||
}
|
||||
|
||||
void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
|
||||
|
|
|
@ -1257,22 +1257,30 @@ Ogre::Vector3 Animation::getEnchantmentColor(MWWorld::Ptr item)
|
|||
ObjectAnimation::ObjectAnimation(const MWWorld::Ptr& ptr, const std::string &model)
|
||||
: Animation(ptr, ptr.getRefData().getBaseNode())
|
||||
{
|
||||
setObjectRoot(model, false);
|
||||
if (!model.empty())
|
||||
{
|
||||
setObjectRoot(model, false);
|
||||
|
||||
Ogre::Vector3 extents = getWorldBounds().getSize();
|
||||
float size = std::max(std::max(extents.x, extents.y), extents.z);
|
||||
Ogre::Vector3 extents = getWorldBounds().getSize();
|
||||
float size = std::max(std::max(extents.x, extents.y), extents.z);
|
||||
|
||||
bool small = (size < Settings::Manager::getInt("small object size", "Viewing distance")) &&
|
||||
Settings::Manager::getBool("limit small object distance", "Viewing distance");
|
||||
// do not fade out doors. that will cause holes and look stupid
|
||||
if(ptr.getTypeName().find("Door") != std::string::npos)
|
||||
small = false;
|
||||
bool small = (size < Settings::Manager::getInt("small object size", "Viewing distance")) &&
|
||||
Settings::Manager::getBool("limit small object distance", "Viewing distance");
|
||||
// do not fade out doors. that will cause holes and look stupid
|
||||
if(ptr.getTypeName().find("Door") != std::string::npos)
|
||||
small = false;
|
||||
|
||||
float dist = small ? Settings::Manager::getInt("small object distance", "Viewing distance") : 0.0f;
|
||||
Ogre::Vector3 col = getEnchantmentColor(ptr);
|
||||
setRenderProperties(mObjectRoot, (mPtr.getTypeName() == typeid(ESM::Static).name()) ?
|
||||
(small ? RV_StaticsSmall : RV_Statics) : RV_Misc,
|
||||
RQG_Main, RQG_Alpha, dist, !ptr.getClass().getEnchantment(ptr).empty(), &col);
|
||||
float dist = small ? Settings::Manager::getInt("small object distance", "Viewing distance") : 0.0f;
|
||||
Ogre::Vector3 col = getEnchantmentColor(ptr);
|
||||
setRenderProperties(mObjectRoot, (mPtr.getTypeName() == typeid(ESM::Static).name()) ?
|
||||
(small ? RV_StaticsSmall : RV_Statics) : RV_Misc,
|
||||
RQG_Main, RQG_Alpha, dist, !ptr.getClass().getEnchantment(ptr).empty(), &col);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No model given. Create an object root anyway, so that lights can be added to it if needed.
|
||||
mObjectRoot = NifOgre::ObjectScenePtr (new NifOgre::ObjectScene(mInsert->getCreator()));
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectAnimation::addLight(const ESM::Light *light)
|
||||
|
|
|
@ -79,79 +79,82 @@ void Objects::insertModel(const MWWorld::Ptr &ptr, const std::string &mesh)
|
|||
|
||||
std::auto_ptr<ObjectAnimation> anim(new ObjectAnimation(ptr, mesh));
|
||||
|
||||
Ogre::AxisAlignedBox bounds = anim->getWorldBounds();
|
||||
Ogre::Vector3 extents = bounds.getSize();
|
||||
extents *= ptr.getRefData().getBaseNode()->getScale();
|
||||
float size = std::max(std::max(extents.x, extents.y), extents.z);
|
||||
|
||||
bool small = (size < Settings::Manager::getInt("small object size", "Viewing distance")) &&
|
||||
Settings::Manager::getBool("limit small object distance", "Viewing distance");
|
||||
// do not fade out doors. that will cause holes and look stupid
|
||||
if(ptr.getTypeName().find("Door") != std::string::npos)
|
||||
small = false;
|
||||
|
||||
if (mBounds.find(ptr.getCell()) == mBounds.end())
|
||||
mBounds[ptr.getCell()] = Ogre::AxisAlignedBox::BOX_NULL;
|
||||
mBounds[ptr.getCell()].merge(bounds);
|
||||
|
||||
if(ptr.getTypeName() == typeid(ESM::Light).name())
|
||||
anim->addLight(ptr.get<ESM::Light>()->mBase);
|
||||
|
||||
if(ptr.getTypeName() == typeid(ESM::Static).name() &&
|
||||
Settings::Manager::getBool("use static geometry", "Objects") &&
|
||||
anim->canBatch())
|
||||
if (!mesh.empty())
|
||||
{
|
||||
Ogre::StaticGeometry* sg = 0;
|
||||
Ogre::AxisAlignedBox bounds = anim->getWorldBounds();
|
||||
Ogre::Vector3 extents = bounds.getSize();
|
||||
extents *= ptr.getRefData().getBaseNode()->getScale();
|
||||
float size = std::max(std::max(extents.x, extents.y), extents.z);
|
||||
|
||||
if (small)
|
||||
bool small = (size < Settings::Manager::getInt("small object size", "Viewing distance")) &&
|
||||
Settings::Manager::getBool("limit small object distance", "Viewing distance");
|
||||
// do not fade out doors. that will cause holes and look stupid
|
||||
if(ptr.getTypeName().find("Door") != std::string::npos)
|
||||
small = false;
|
||||
|
||||
if (mBounds.find(ptr.getCell()) == mBounds.end())
|
||||
mBounds[ptr.getCell()] = Ogre::AxisAlignedBox::BOX_NULL;
|
||||
mBounds[ptr.getCell()].merge(bounds);
|
||||
|
||||
if(ptr.getTypeName() == typeid(ESM::Static).name() &&
|
||||
Settings::Manager::getBool("use static geometry", "Objects") &&
|
||||
anim->canBatch())
|
||||
{
|
||||
if(mStaticGeometrySmall.find(ptr.getCell()) == mStaticGeometrySmall.end())
|
||||
{
|
||||
uniqueID = uniqueID+1;
|
||||
sg = mRenderer.getScene()->createStaticGeometry("sg" + Ogre::StringConverter::toString(uniqueID));
|
||||
sg->setOrigin(ptr.getRefData().getBaseNode()->getPosition());
|
||||
mStaticGeometrySmall[ptr.getCell()] = sg;
|
||||
Ogre::StaticGeometry* sg = 0;
|
||||
|
||||
sg->setRenderingDistance(Settings::Manager::getInt("small object distance", "Viewing distance"));
|
||||
if (small)
|
||||
{
|
||||
if(mStaticGeometrySmall.find(ptr.getCell()) == mStaticGeometrySmall.end())
|
||||
{
|
||||
uniqueID = uniqueID+1;
|
||||
sg = mRenderer.getScene()->createStaticGeometry("sg" + Ogre::StringConverter::toString(uniqueID));
|
||||
sg->setOrigin(ptr.getRefData().getBaseNode()->getPosition());
|
||||
mStaticGeometrySmall[ptr.getCell()] = sg;
|
||||
|
||||
sg->setRenderingDistance(Settings::Manager::getInt("small object distance", "Viewing distance"));
|
||||
}
|
||||
else
|
||||
sg = mStaticGeometrySmall[ptr.getCell()];
|
||||
}
|
||||
else
|
||||
sg = mStaticGeometrySmall[ptr.getCell()];
|
||||
}
|
||||
else
|
||||
{
|
||||
if(mStaticGeometry.find(ptr.getCell()) == mStaticGeometry.end())
|
||||
{
|
||||
uniqueID = uniqueID+1;
|
||||
sg = mRenderer.getScene()->createStaticGeometry("sg" + Ogre::StringConverter::toString(uniqueID));
|
||||
sg->setOrigin(ptr.getRefData().getBaseNode()->getPosition());
|
||||
mStaticGeometry[ptr.getCell()] = sg;
|
||||
if(mStaticGeometry.find(ptr.getCell()) == mStaticGeometry.end())
|
||||
{
|
||||
uniqueID = uniqueID+1;
|
||||
sg = mRenderer.getScene()->createStaticGeometry("sg" + Ogre::StringConverter::toString(uniqueID));
|
||||
sg->setOrigin(ptr.getRefData().getBaseNode()->getPosition());
|
||||
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.
|
||||
if(ptr.getCell()->isExterior())
|
||||
sg->setRegionDimensions(Ogre::Vector3(2048,2048,2048));
|
||||
else
|
||||
sg = mStaticGeometry[ptr.getCell()];
|
||||
sg->setRegionDimensions(Ogre::Vector3(1024,1024,1024));
|
||||
|
||||
sg->setVisibilityFlags(small ? RV_StaticsSmall : RV_Statics);
|
||||
|
||||
sg->setCastShadows(true);
|
||||
|
||||
sg->setRenderQueueGroup(RQG_Main);
|
||||
|
||||
anim->fillBatch(sg);
|
||||
/* TODO: We could hold on to this and just detach it from the scene graph, so if the Ptr
|
||||
* ever needs to modify we can reattach it and rebuild the StaticGeometry object without
|
||||
* it. Would require associating the Ptr with the StaticGeometry. */
|
||||
anim.reset();
|
||||
}
|
||||
|
||||
// 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.
|
||||
if(ptr.getCell()->isExterior())
|
||||
sg->setRegionDimensions(Ogre::Vector3(2048,2048,2048));
|
||||
else
|
||||
sg->setRegionDimensions(Ogre::Vector3(1024,1024,1024));
|
||||
|
||||
sg->setVisibilityFlags(small ? RV_StaticsSmall : RV_Statics);
|
||||
|
||||
sg->setCastShadows(true);
|
||||
|
||||
sg->setRenderQueueGroup(RQG_Main);
|
||||
|
||||
anim->fillBatch(sg);
|
||||
/* TODO: We could hold on to this and just detach it from the scene graph, so if the Ptr
|
||||
* ever needs to modify we can reattach it and rebuild the StaticGeometry object without
|
||||
* it. Would require associating the Ptr with the StaticGeometry. */
|
||||
anim.reset();
|
||||
}
|
||||
|
||||
if(anim.get() != NULL)
|
||||
|
|
Loading…
Reference in a new issue