Ogre 换装系统 shareSkeletonInstanceWith

附加模型的换装系统可以通过 shareSkeletonInstanceWith()这个函数实现把一个模型绑定到另外一个模型

voidOgre::Entity::shareSkeletonInstanceWith ( Entity* entity )
Shares the SkeletonInstance with the supplied entity.Note that in order for this to work, both entities must have the same Skeleton.

API原型+介绍可知道。其实这个函数是实现两个模型的共享骨骼!但是在调用这个函数之前必须有个前提,就是两个模型必须有共同的骨骼框架!否则这个函数会抛出一个异常,解决这个问题有两个方法:一是让美工对每个装备模型都做一套骨骼(基本不可能),另一个就是通过API实现共享骨骼:_notifySkeleton(),函数原型:

void Ogre::Mesh::_notifySkeleton ( SkeletonPtr& pSkel )

Internal notification, used to tell the Mesh which Skeleton to use without loading it.

Remarks:
This is only here for unusual situation where you want to manually set up a Skeleton. Best to let OGRE deal with this, don't call it yourself unless you really know what you're doing.

这个函数可以实现忽落自身的骨骼,共享到 SkeletonPtr的骨骼!对于参数SkeletonPtr可以这样获得:

mEntityHandle为要绑定到的模型指针

Ogre::SkeletonPtr skptr = mEntityHandle->getMesh()->getSkeleton();

上面代码总结:

Ogre::SkeletonPtr skptr = mEntityHandle->getMesh()->getSkeleton();
headMesh->getMesh()->_notifySkeleton(skptr);

headMesh->shareSkeletonInstanceWith(mEntityHandle);
mHandle->attachObject(headMesh);

你可能感兴趣的:(框架,UP)