1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-12 13:13:27 +00:00

For light objects without an AttachLight bone, attach the light to the center of the object instead of the origin.

This commit is contained in:
scrawl 2013-02-24 19:00:06 +01:00
parent 7e816c826b
commit 1ae2d3c6ab
3 changed files with 16 additions and 5 deletions

View File

@ -38,7 +38,7 @@ namespace MWClass
if (!model.empty()) if (!model.empty())
objects.insertMesh(ptr, "meshes\\" + model, true); objects.insertMesh(ptr, "meshes\\" + model, true);
else else
objects.insertLight(ptr, NULL); objects.insertLight(ptr, NULL, Ogre::Vector3(0,0,0));
} }
void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const

View File

@ -49,6 +49,12 @@ void Objects::clearSceneNode (Ogre::SceneNode *node)
node->detachObject (object); node->detachObject (object);
mRenderer.getScene()->destroyMovableObject (object); mRenderer.getScene()->destroyMovableObject (object);
} }
Ogre::Node::ChildNodeIterator it = node->getChildIterator ();
while (it.hasMoreElements ())
{
clearSceneNode(static_cast<Ogre::SceneNode*>(it.getNext ()));
}
} }
void Objects::setMwRoot(Ogre::SceneNode* root) void Objects::setMwRoot(Ogre::SceneNode* root)
@ -219,11 +225,11 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh, bool
if (light) if (light)
{ {
insertLight(ptr, entities.mSkelBase); insertLight(ptr, entities.mSkelBase, bounds.getCenter() - insert->_getDerivedPosition());
} }
} }
void Objects::insertLight (const MWWorld::Ptr& ptr, Ogre::Entity* skelBase) void Objects::insertLight (const MWWorld::Ptr& ptr, Ogre::Entity* skelBase, Ogre::Vector3 fallbackCenter)
{ {
Ogre::SceneNode* insert = mRenderer.getScene()->getSceneNode(ptr.getRefData().getHandle()); Ogre::SceneNode* insert = mRenderer.getScene()->getSceneNode(ptr.getRefData().getHandle());
assert(insert); assert(insert);
@ -291,9 +297,14 @@ void Objects::insertLight (const MWWorld::Ptr& ptr, Ogre::Entity* skelBase)
// If there's an AttachLight bone, attach the light to that, otherwise attach it to the base scene node // If there's an AttachLight bone, attach the light to that, otherwise attach it to the base scene node
if (skelBase && skelBase->getSkeleton ()->hasBone ("AttachLight")) if (skelBase && skelBase->getSkeleton ()->hasBone ("AttachLight"))
{
skelBase->attachObjectToBone ("AttachLight", light); skelBase->attachObjectToBone ("AttachLight", light);
}
else else
insert->attachObject(light); {
Ogre::SceneNode* childNode = insert->createChildSceneNode (fallbackCenter);
childNode->attachObject(light);
}
mLights.push_back(info); mLights.push_back(info);
} }

View File

@ -74,7 +74,7 @@ public:
~Objects(){} ~Objects(){}
void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_);
void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh, bool light=false); void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh, bool light=false);
void insertLight (const MWWorld::Ptr& ptr, Ogre::Entity* skelBase); void insertLight (const MWWorld::Ptr& ptr, Ogre::Entity* skelBase, Ogre::Vector3 fallbackCenter);
void enableLights(); void enableLights();
void disableLights(); void disableLights();