本文整理汇总了C++中MeshPtr::createAnimation方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshPtr::createAnimation方法的具体用法?C++ MeshPtr::createAnimation怎么用?C++ MeshPtr::createAnimation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshPtr
的用法示例。
在下文中一共展示了MeshPtr::createAnimation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupContent
//---------------------------------------------------------------------
void PlayPen_testMorphAnimationWithoutNormals::setupContent()
{
bool testStencil = false;
if (testStencil)
mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
Vector3 dir(-1, -1, 0.5);
dir.normalise();
Light* l = mSceneMgr->createLight("light1");
l->setType(Light::LT_DIRECTIONAL);
l->setDirection(dir);
MeshPtr mesh = MeshManager::getSingleton().load("sphere.mesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
String morphName = "testmorphnonormals.mesh";
mesh = mesh->clone(morphName);
SubMesh* sm = mesh->getSubMesh(0);
// Re-organise geometry since this mesh has no animation and all
// vertex elements are packed into one buffer
VertexDeclaration* newDecl =
sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(false, true, false);
sm->vertexData->reorganiseBuffers(newDecl);
if (testStencil)
sm->vertexData->prepareForShadowVolume(); // need to re-prep since reorganised
// get the position buffer (which should now be separate);
const VertexElement* posElem =
sm->vertexData->vertexDeclaration->findElementBySemantic(VES_POSITION);
HardwareVertexBufferSharedPtr origbuf =
sm->vertexData->vertexBufferBinding->getBuffer(
posElem->getSource());
// Create a new position & normal buffer with updated values
HardwareVertexBufferSharedPtr newbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
VertexElement::getTypeSize(VET_FLOAT3),
sm->vertexData->vertexCount,
HardwareBuffer::HBU_STATIC, true);
float* pSrc = static_cast<float*>(origbuf->lock(HardwareBuffer::HBL_READ_ONLY));
float* pDst = static_cast<float*>(newbuf->lock(HardwareBuffer::HBL_DISCARD));
// Make the sphere turn into a cube
// Do this just by clamping each of the directions (we shrink it)
float cubeDimension = 0.3f * mesh->getBoundingSphereRadius();
for (size_t v = 0; v < sm->vertexData->vertexCount; ++v)
{
// x/y/z position
Vector3 pos;
for (int d = 0; d < 3; ++d)
{
if (*pSrc >= 0)
{
pos.ptr()[d] = std::min(cubeDimension, *pSrc++);
}
else
{
pos.ptr()[d] = std::max(-cubeDimension, *pSrc++);
}
*pDst++ = pos.ptr()[d];
}
}
origbuf->unlock();
newbuf->unlock();
// create a morph animation
Animation* anim = mesh->createAnimation("testAnim", 10.0f);
VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_MORPH);
// re-use start positions for frame 0
VertexMorphKeyFrame* kf = vt->createVertexMorphKeyFrame(0);
kf->setVertexBuffer(origbuf);
// Use translated buffer for mid frame
kf = vt->createVertexMorphKeyFrame(4.0f);
kf->setVertexBuffer(newbuf);
// Pause there
kf = vt->createVertexMorphKeyFrame(6.0f);
kf->setVertexBuffer(newbuf);
// re-use start positions for final frame
kf = vt->createVertexMorphKeyFrame(10.0f);
kf->setVertexBuffer(origbuf);
// Export the mesh
DataStreamPtr stream = Root::getSingleton().createFileStream(morphName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
MeshSerializer ser;
ser.exportMesh(mesh.get(), stream);
stream->close();
// Unload old mesh to force reload
MeshManager::getSingleton().remove(mesh->getHandle());
mesh->unload();
mesh.setNull();
//.........这里部分代码省略.........
示例2: merge
MeshPtr MeshMergeTool::merge(const Ogre::String& name, const Ogre::String& resourceGroupName)
{
print("Baking: New Mesh started", V_HIGH);
MeshPtr mp = MeshManager::getSingleton().createManual(name, resourceGroupName);
if (!mBaseSkeleton.isNull())
{
mp->setSkeletonName(mBaseSkeleton->getName());
}
AxisAlignedBox totalBounds = AxisAlignedBox();
for (std::vector<Ogre::MeshPtr>::iterator it = mMeshes.begin(); it != mMeshes.end(); ++it)
{
print("Baking: adding submeshes for " + (*it)->getName(), V_HIGH);
// insert all submeshes
for (Ogre::ushort sid = 0; sid < (*it)->getNumSubMeshes(); ++sid)
{
SubMesh* sub = (*it)->getSubMesh(sid);
const String name = findSubmeshName((*it), sid);
// create submesh with correct name
SubMesh* newsub;
if (name.length() == 0)
{
newsub = mp->createSubMesh();
}
else
{
/// @todo check if a submesh with this name has been created before
newsub = mp->createSubMesh(name);
}
newsub->useSharedVertices = sub->useSharedVertices;
// add index
newsub->indexData = sub->indexData->clone();
// add geometry
if (!newsub->useSharedVertices)
{
newsub->vertexData = sub->vertexData->clone();
if (!mBaseSkeleton.isNull())
{
// build bone assignments
SubMesh::BoneAssignmentIterator bit = sub->getBoneAssignmentIterator();
while (bit.hasMoreElements())
{
VertexBoneAssignment vba = bit.getNext();
newsub->addBoneAssignment(vba);
}
}
}
newsub->setMaterialName(sub->getMaterialName());
// Add vertex animations for this submesh
Animation *anim = 0;
for (unsigned short i = 0; i < (*it)->getNumAnimations(); ++i)
{
anim = (*it)->getAnimation(i);
// get or create the animation for the new mesh
Animation *newanim;
if (mp->hasAnimation(anim->getName()))
{
newanim = mp->getAnimation(anim->getName());
}
else
{
newanim = mp->createAnimation(anim->getName(), anim->getLength());
}
print("Baking: adding vertex animation "
+ anim->getName() + " for " + (*it)->getName(), V_HIGH);
Animation::VertexTrackIterator vti=anim->getVertexTrackIterator();
while (vti.hasMoreElements())
{
VertexAnimationTrack *vt = vti.getNext();
// handle=0 targets the main mesh, handle i (where i>0) targets submesh i-1.
// In this case there are only submeshes so index 0 will not be used.
unsigned short handle = mp->getNumSubMeshes();
VertexAnimationTrack* newvt = newanim->createVertexTrack(
handle,
vt->getAssociatedVertexData()->clone(),
vt->getAnimationType());
for (int keyFrameIndex = 0; keyFrameIndex < vt->getNumKeyFrames();
++keyFrameIndex)
{
switch (vt->getAnimationType())
{
case VAT_MORPH:
{
// copy the keyframe vertex buffer
VertexMorphKeyFrame *kf =
vt->getVertexMorphKeyFrame(keyFrameIndex);
//.........这里部分代码省略.........