mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
Handle all meshes when inserting objects into the scene
This commit is contained in:
parent
ad75b47472
commit
a539e98274
@ -92,12 +92,19 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
|
|||||||
Ogre::SceneNode* insert = ptr.getRefData().getBaseNode();
|
Ogre::SceneNode* insert = ptr.getRefData().getBaseNode();
|
||||||
assert(insert);
|
assert(insert);
|
||||||
|
|
||||||
// FIXME: There can be more than one!
|
Ogre::AxisAlignedBox bounds = Ogre::AxisAlignedBox::BOX_NULL;
|
||||||
NifOgre::MeshPairList meshes = NifOgre::NIFLoader::load(mesh);
|
NifOgre::MeshPairList meshes = NifOgre::NIFLoader::load(mesh);
|
||||||
Ogre::Entity *ent = mRenderer.getScene()->createEntity(meshes[0].first->getName());
|
std::vector<Ogre::Entity*> entities(meshes.size());
|
||||||
|
for(size_t i = 0;i < meshes.size();i++)
|
||||||
|
{
|
||||||
|
entities[i] = mRenderer.getScene()->createEntity(meshes[i].first->getName());
|
||||||
|
|
||||||
|
const Ogre::AxisAlignedBox &tmp = entities[i]->getBoundingBox();
|
||||||
Ogre::Vector3 extents = ent->getBoundingBox().getSize();
|
bounds.merge(Ogre::AxisAlignedBox(insert->_getDerivedPosition() + tmp.getMinimum(),
|
||||||
|
insert->_getDerivedPosition() + tmp.getMaximum())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ogre::Vector3 extents = bounds.getSize();
|
||||||
extents *= insert->getScale();
|
extents *= insert->getScale();
|
||||||
float size = std::max(std::max(extents.x, extents.y), extents.z);
|
float size = std::max(std::max(extents.x, extents.y), extents.z);
|
||||||
|
|
||||||
@ -109,42 +116,42 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
|
|||||||
|
|
||||||
if (mBounds.find(ptr.getCell()) == mBounds.end())
|
if (mBounds.find(ptr.getCell()) == mBounds.end())
|
||||||
mBounds[ptr.getCell()] = Ogre::AxisAlignedBox::BOX_NULL;
|
mBounds[ptr.getCell()] = Ogre::AxisAlignedBox::BOX_NULL;
|
||||||
|
|
||||||
Ogre::AxisAlignedBox bounds = ent->getBoundingBox();
|
|
||||||
bounds = Ogre::AxisAlignedBox(
|
|
||||||
insert->_getDerivedPosition() + bounds.getMinimum(),
|
|
||||||
insert->_getDerivedPosition() + bounds.getMaximum()
|
|
||||||
);
|
|
||||||
|
|
||||||
bounds.scale(insert->getScale());
|
|
||||||
mBounds[ptr.getCell()].merge(bounds);
|
mBounds[ptr.getCell()].merge(bounds);
|
||||||
|
|
||||||
bool transparent = false;
|
bool transparent = false;
|
||||||
for (unsigned int i=0; i<ent->getNumSubEntities(); ++i)
|
for(size_t i = 0;i < entities.size();i++)
|
||||||
{
|
{
|
||||||
Ogre::MaterialPtr mat = ent->getSubEntity(i)->getMaterial();
|
Ogre::Entity *ent = entities[i];
|
||||||
Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
|
for (unsigned int i=0; i<ent->getNumSubEntities(); ++i)
|
||||||
while (techIt.hasMoreElements())
|
|
||||||
{
|
{
|
||||||
Ogre::Technique* tech = techIt.getNext();
|
Ogre::MaterialPtr mat = ent->getSubEntity(i)->getMaterial();
|
||||||
Ogre::Technique::PassIterator passIt = tech->getPassIterator();
|
Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
|
||||||
while (passIt.hasMoreElements())
|
while (techIt.hasMoreElements())
|
||||||
{
|
{
|
||||||
Ogre::Pass* pass = passIt.getNext();
|
Ogre::Technique* tech = techIt.getNext();
|
||||||
|
Ogre::Technique::PassIterator passIt = tech->getPassIterator();
|
||||||
|
while (passIt.hasMoreElements())
|
||||||
|
{
|
||||||
|
Ogre::Pass* pass = passIt.getNext();
|
||||||
|
|
||||||
if (pass->getDepthWriteEnabled() == false)
|
if (pass->getDepthWriteEnabled() == false)
|
||||||
transparent = true;
|
transparent = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mIsStatic || !Settings::Manager::getBool("use static geometry", "Objects") || transparent)
|
if(!mIsStatic || !Settings::Manager::getBool("use static geometry", "Objects") || transparent)
|
||||||
{
|
{
|
||||||
insert->attachObject(ent);
|
for(size_t i = 0;i < entities.size();i++)
|
||||||
|
{
|
||||||
|
Ogre::Entity *ent = entities[i];
|
||||||
|
insert->attachObject(ent);
|
||||||
|
|
||||||
ent->setRenderingDistance(small ? Settings::Manager::getInt("small object distance", "Viewing distance") : 0);
|
ent->setRenderingDistance(small ? Settings::Manager::getInt("small object distance", "Viewing distance") : 0);
|
||||||
ent->setVisibilityFlags(mIsStatic ? (small ? RV_StaticsSmall : RV_Statics) : RV_Misc);
|
ent->setVisibilityFlags(mIsStatic ? (small ? RV_StaticsSmall : RV_Statics) : RV_Misc);
|
||||||
ent->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
|
ent->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -184,15 +191,19 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
|
|||||||
// - there will be too many batches.
|
// - there will be too many batches.
|
||||||
sg->setRegionDimensions(Ogre::Vector3(2500,2500,2500));
|
sg->setRegionDimensions(Ogre::Vector3(2500,2500,2500));
|
||||||
|
|
||||||
sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale());
|
|
||||||
|
|
||||||
sg->setVisibilityFlags(small ? RV_StaticsSmall : RV_Statics);
|
sg->setVisibilityFlags(small ? RV_StaticsSmall : RV_Statics);
|
||||||
|
|
||||||
sg->setCastShadows(true);
|
sg->setCastShadows(true);
|
||||||
|
|
||||||
sg->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
|
sg->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
|
||||||
|
|
||||||
mRenderer.getScene()->destroyEntity(ent);
|
for(size_t i = 0;i < entities.size();i++)
|
||||||
|
{
|
||||||
|
Ogre::Entity *ent = entities[i];
|
||||||
|
sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale());
|
||||||
|
|
||||||
|
mRenderer.getScene()->destroyEntity(ent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user