Attaching entities to a OGRE3DPointRenderable

tertle

26-01-2010 04:39:15

I was wanting to attach the recently released ogre3d mascot sinbad to a character controller (cc is irrelevant though).

Now this model has 3 separate parts, the body and 2 swords attached to his back as so. This is how it was displayed with just Ogre.

// create main model
Ogre::SceneManager* sceneMgr = OgreFramework::getSingletonPtr()->m_pRoot->getSceneManager("GameSceneMgr");
mBodyNode = sceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3::UNIT_Y * CHAR_HEIGHT);
mBodyNode->setScale(0.36,0.36,0.36);
mBodyNode->setPosition(20,20,20);
mBodyEnt = sceneMgr->createEntity("SinbadBody","Sinbad.mesh");
mBodyNode->attachObject(mBodyEnt);

// create swords and attach to sheath
mSword1 = sceneMgr->createEntity("SinbadSword1", "Sword.mesh");
mSword2 = sceneMgr->createEntity("SinbadSword2", "Sword.mesh");
mBodyEnt->attachObjectToBone("Sheath.L", mSword1);
mBodyEnt->attachObjectToBone("Sheath.R", mSword2);


My problem is, I to have this model as a OGRE3DPointRenderable for the character controller and need to attach the 2 swords somehow.

I've done it by editing the OGRE3DPointRenderable constructor, to save the original entity. Then created a simple attach function (which I'll probably modify later so that I can give the entity a unique name if I need for animations.)

OGRE3DPointRenderable.cpp
OGRE3DPointRenderable::OGRE3DPointRenderable(OGRE3DRenderSystem* renderSystem, const Ogre::String& ogre_mesh_name)
: mRenderSystem(renderSystem), mNode(0)
{
mNode = mRenderSystem->getSceneManager()->getRootSceneNode()->createChildSceneNode();
mEntity = fetchEntity(ogre_mesh_name);
addEntity(mEntity);
}

void OGRE3DPointRenderable::attachObjectToBone(const Ogre::String& boneName, const Ogre::String& ogre_mesh_name)
{
Ogre::Entity* bEntity = mRenderSystem->getSceneManager()->createEntity(mRenderSystem->getUniqueName("Entity"),ogre_mesh_name);
mEntity->attachObjectToBone(boneName,bEntity);
}


then it's just setup using

OGRE3DPointRenderable* mControllerRenderable = mRenderSystem->createPointRenderable("Sinbad.mesh");
mControllerRenderable->attachObjectToBone("Sheath.L", "Sword.mesh");
mControllerRenderable->attachObjectToBone("Sheath.R", "Sword.mesh");

Ogre::SceneNode* mPlayerNode = mControllerRenderable->getNode();
mPlayerNode->setScale(0.36,0.36,0.36);

mController = mControllerManager->createBoxController(desc, NxOgre::Vec3(1,1,1), mScene, mControllerRenderable);


Only been using Ogre for a month, and I'm a pretty average programmer (100% self taught) and I'm writing/playing around with game design mainly for the learning experience (and I love games)
I just want to know if there was a better way to do this (or if there was a way I didn't think of without editing OGRE3DPointRenderable.)

Thanks in advanced!