本文整理汇总了C++中ogre::SubMesh::addBoneAssignment方法的典型用法代码示例。如果您正苦于以下问题:C++ SubMesh::addBoneAssignment方法的具体用法?C++ SubMesh::addBoneAssignment怎么用?C++ SubMesh::addBoneAssignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::SubMesh
的用法示例。
在下文中一共展示了SubMesh::addBoneAssignment方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createSubMesh
//.........这里部分代码省略.........
std::vector<Ogre::RGBA> colorsRGB(colors.size());
for(size_t i = 0;i < colorsRGB.size();i++)
{
Ogre::ColourValue clr(colors[i][0], colors[i][1], colors[i][2], colors[i][3]);
rs->convertColourValue(clr, &colorsRGB[i]);
}
vbuf = hwBufMgr->createVertexBuffer(Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR),
colorsRGB.size(), Ogre::HardwareBuffer::HBU_STATIC);
vbuf->writeData(0, vbuf->getSizeInBytes(), &colorsRGB[0], true);
decl->addElement(nextBuf, 0, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
bind->setBinding(nextBuf++, vbuf);
}
// Texture UV coordinates
size_t numUVs = data->uvlist.size();
if (numUVs)
{
size_t elemSize = Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
for(size_t i = 0; i < numUVs; i++)
decl->addElement(nextBuf, elemSize*i, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, i);
vbuf = hwBufMgr->createVertexBuffer(decl->getVertexSize(nextBuf), srcVerts.size(),
Ogre::HardwareBuffer::HBU_STATIC);
std::vector<Ogre::Vector2> allUVs;
allUVs.reserve(srcVerts.size()*numUVs);
for (size_t vert = 0; vert<srcVerts.size(); ++vert)
for(size_t i = 0; i < numUVs; i++)
allUVs.push_back(data->uvlist[i][vert]);
vbuf->writeData(0, elemSize*srcVerts.size()*numUVs, &allUVs[0], true);
bind->setBinding(nextBuf++, vbuf);
}
// Triangle faces
const std::vector<short> &srcIdx = data->triangles;
if(srcIdx.size())
{
ibuf = hwBufMgr->createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, srcIdx.size(),
Ogre::HardwareBuffer::HBU_STATIC);
ibuf->writeData(0, ibuf->getSizeInBytes(), &srcIdx[0], true);
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = srcIdx.size();
sub->indexData->indexStart = 0;
}
// Assign bone weights for this TriShape
if(skin != NULL)
{
Ogre::SkeletonPtr skel = Ogre::SkeletonManager::getSingleton().getByName(mName);
const Nif::NiSkinData *data = skin->data.getPtr();
const Nif::NodeList &bones = skin->bones;
for(size_t i = 0;i < bones.length();i++)
{
Ogre::VertexBoneAssignment boneInf;
boneInf.boneIndex = skel->getBone(bones[i]->name)->getHandle();
const std::vector<Nif::NiSkinData::VertWeight> &weights = data->bones[i].weights;
for(size_t j = 0;j < weights.size();j++)
{
boneInf.vertexIndex = weights[j].vertex;
boneInf.weight = weights[j].weight;
sub->addBoneAssignment(boneInf);
}
}
}
const Nif::NiTexturingProperty *texprop = NULL;
const Nif::NiMaterialProperty *matprop = NULL;
const Nif::NiAlphaProperty *alphaprop = NULL;
const Nif::NiVertexColorProperty *vertprop = NULL;
const Nif::NiZBufferProperty *zprop = NULL;
const Nif::NiSpecularProperty *specprop = NULL;
const Nif::NiWireframeProperty *wireprop = NULL;
bool needTangents = false;
shape->getProperties(texprop, matprop, alphaprop, vertprop, zprop, specprop, wireprop);
std::string matname = NIFMaterialLoader::getMaterial(data, mesh->getName(), mGroup,
texprop, matprop, alphaprop,
vertprop, zprop, specprop,
wireprop, needTangents);
if(matname.length() > 0)
sub->setMaterialName(matname);
// build tangents if the material needs them
if (needTangents)
{
unsigned short src,dest;
if (!mesh->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src,dest))
mesh->buildTangentVectors(Ogre::VES_TANGENT, src,dest);
}
// Create a dummy vertex animation track if there's a geom morpher controller
// This is required to make Ogre create the buffers we will use for software vertex animation
if (srcVerts.size() && geomMorpherController)
mesh->createAnimation("dummy", 0)->createVertexTrack(1, sub->vertexData, Ogre::VAT_MORPH);
}
示例2: EngineSetup
//.........这里部分代码省略.........
ManualObject->position(1, 1, 1);
ManualObject->triangle(18, 19, 20);
ManualObject->position(1, 0, 0);
ManualObject->position(1, 1, 1);
ManualObject->position(1, 0, 1);
ManualObject->triangle(21, 22, 23);
//face 5
ManualObject->position(0, 1, 0);
ManualObject->position(1, 1, 0);
ManualObject->position(0, 1, 1);
ManualObject->triangle(24, 25, 26);
ManualObject->position(1, 1, 0);
ManualObject->position(1, 1, 1);
ManualObject->position(0, 1, 1);
ManualObject->triangle(27, 28, 29);
//face 6
ManualObject->position(0, 0, 0);
ManualObject->position(0, 1, 1);
ManualObject->position(0, 0, 1);
ManualObject->triangle(30, 31, 32);
ManualObject->position(0, 0, 0);
ManualObject->position(0, 1, 0);
ManualObject->position(0, 1, 1);
ManualObject->triangle(33, 34, 35);
ManualObject->end();
Ogre::MeshPtr MeshPtr = ManualObject->convertToMesh("Animation");
Ogre::SubMesh* sub = MeshPtr->getSubMesh(0);
Ogre::SkeletonPtr Skeleton = Ogre::SkeletonManager::getSingleton().create("Skeleton", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
MeshPtr.getPointer()->_notifySkeleton(Skeleton);
Ogre::Bone *Root1 = NULL;
Ogre::Bone *Child1 = NULL;
Ogre::Bone *Child2 = NULL;
Root1 = Skeleton.getPointer()->createBone("Root");
Root1->setPosition(Ogre::Vector3(0.0, 0.0, 0.0));
Root1->setOrientation(Ogre::Quaternion::IDENTITY);
Child1 = Root1->createChild(1);
Child1->setPosition(Ogre::Vector3(4.0, 0.0, 0.0));
Child1->setOrientation(Ogre::Quaternion::IDENTITY);
Child2 = Root1->createChild(2);
Child2->setPosition(Ogre::Vector3(5.0, 0.0, 0.0));
Child2->setOrientation(Ogre::Quaternion::IDENTITY);
Ogre::VertexBoneAssignment Assignment;
Assignment.boneIndex = 0;
Assignment.vertexIndex = 0;
Assignment.weight = 1.0;
Skeleton->setBindingPose();
sub->addBoneAssignment(Assignment);
Assignment.vertexIndex = 1;
sub->addBoneAssignment(Assignment);
Assignment.vertexIndex = 2;
sub->addBoneAssignment(Assignment);
Ogre::Animation *Animation = MeshPtr->createAnimation("HandAnimation", 100.0);
Ogre::NodeAnimationTrack *Track = Animation->createNodeTrack(0, Root1);
Ogre::TransformKeyFrame *KeyFrame = NULL;
for (float FrameTime = 0.0; FrameTime < 100.0; FrameTime += 0.1)
{
KeyFrame = Track->createNodeKeyFrame(FrameTime);
KeyFrame->setTranslate(Ogre::Vector3(10.0, 0.0, 0.0));
}
Root1->setManuallyControlled(true);
Child1->setManuallyControlled(true);
Child2->setManuallyControlled(true);
MeshPtr->load();
MeshPtr.getPointer()->_notifySkeleton(Skeleton);
// Ogre::SkeletonSerializer skeletonSerializer;
// skeletonSerializer.exportSkeleton(Skeleton.get(), "C:\\Users\\Ilya\\Documents\\Visual Studio 2010\\Projects\\Recipes\\media\\models\\testskeleton.skeleton");
// Ogre::MeshSerializer ser;
// ser.exportMesh(MeshPtr.get(), "C:\\Users\\Ilya\\Documents\\Visual Studio 2010\\Projects\\Recipes\\media\\models\\testskeleton.mesh");
Ogre::Entity *Entity = SceneManager->createEntity("Animation", "Animation"/*"testskeleton.mesh"*/);
Ogre::SceneNode *SceneNode = SceneManager->getRootSceneNode()->createChildSceneNode();
SceneNode->attachObject(Entity);
Entity->setDisplaySkeleton(true);
m_AnimationState = Entity->getAnimationState("HandAnimation");
m_AnimationState->setEnabled(true);
m_AnimationState->setLoop(true);
m_Camera->setPolygonMode(Ogre::PolygonMode::PM_WIREFRAME);
Root->renderOneFrame();
}
开发者ID:southerlies,项目名称:OGRE-3D-1.7-Application-Development-Cookbook-Code,代码行数:101,代码来源:SceletalAnimationView.cpp
示例3: doExportMesh
//.........这里部分代码省略.........
min.makeFloor(currpos);
max.makeCeil(currpos);
maxSquaredRadius = std::max(maxSquaredRadius, currpos.squaredLength());
}
int boneIdx = msVertex_GetBoneIndex(pVertex);
if (boneIdx != -1)
{
foundBoneAssignment = true;
numbones = 1;
intbones[0] = intbones[1] = intbones[2] = -1;
intweight[0] = intweight[1] = intweight[2] = 0;
for(wh = 0; wh < 3; ++wh)
{
intbones[wh] = msVertexEx_GetBoneIndices(pVertexEx, wh);
if(intbones[wh] == -1)
break;
++numbones;
intweight[wh] = msVertexEx_GetBoneWeights(pVertexEx, wh);
} // for(k)
Ogre::VertexBoneAssignment vertAssign;
vertAssign.boneIndex = boneIdx;
vertAssign.vertexIndex = (unsigned int)j;
if(numbones == 1)
{
vertAssign.weight = 1.0;
} // single assignment
else
{
vertAssign.weight=(Ogre::Real)intweight[0]/100.0;
}
ogreSubMesh->addBoneAssignment(vertAssign);
if(numbones > 1)
{
// this somewhat contorted logic is because the first weight [0] matches to the bone assignment
// located with pVertex. The next two weights [1][2] match up to the first two bones found
// with pVertexEx [0][1]. The weight for the fourth bone, if present, is the unassigned weight
for(wh = 0; wh < 3; wh++)
{
boneIdx = intbones[wh];
if(boneIdx == -1)
break;
vertAssign.boneIndex = boneIdx;
vertAssign.vertexIndex = (unsigned int)j;
if(wh == 2)
{
// fourth weight is 1.0-(sumoffirstthreeweights)
vertAssign.weight = 1.0-(((Ogre::Real)intweight[0]/100.0)+
((Ogre::Real)intweight[1]/100.0)+((Ogre::Real)intweight[2]/100.0));
}
else
{
vertAssign.weight=(Ogre::Real)intweight[wh+1];
}
ogreSubMesh->addBoneAssignment(vertAssign);
} // for(k)
} // if(numbones)
}
}
pbuf->unlock();
float* pTex = static_cast<float*>(
tbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
示例4: createOgreSubmesh
//.........这里部分代码省略.........
bool use32BitIndexes = false;
if (m_vertices.size() > 65536 || params.useSharedGeom)
{
use32BitIndexes = true;
}
// Create a new index buffer
pSubmesh->indexData->indexBuffer =
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
use32BitIndexes ? Ogre::HardwareIndexBuffer::IT_32BIT : Ogre::HardwareIndexBuffer::IT_16BIT,
pSubmesh->indexData->indexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Fill the index buffer with faces data
if (use32BitIndexes)
{
Ogre::uint32* pIdx = static_cast<Ogre::uint32*>(
pSubmesh->indexData->indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
for (i=0; i<m_faces.size(); i++)
{
*pIdx++ = static_cast<Ogre::uint32>(m_faces[i].v[0]);
*pIdx++ = static_cast<Ogre::uint32>(m_faces[i].v[1]);
*pIdx++ = static_cast<Ogre::uint32>(m_faces[i].v[2]);
}
pSubmesh->indexData->indexBuffer->unlock();
}
else
{
Ogre::uint16* pIdx = static_cast<Ogre::uint16*>(
pSubmesh->indexData->indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
for (i=0; i<m_faces.size(); i++)
{
*pIdx++ = static_cast<Ogre::uint16>(m_faces[i].v[0]);
*pIdx++ = static_cast<Ogre::uint16>(m_faces[i].v[1]);
*pIdx++ = static_cast<Ogre::uint16>(m_faces[i].v[2]);
}
pSubmesh->indexData->indexBuffer->unlock();
}
// Define vertex declaration (only if we're not using shared geometry)
if(!params.useSharedGeom)
{
Ogre::VertexDeclaration* pDecl = pSubmesh->vertexData->vertexDeclaration;
unsigned buf = 0;
size_t offset = 0;
// Add vertex position
pDecl->addElement(buf, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
// Add vertex normal
if (params.exportVertNorm)
{
pDecl->addElement(buf, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
}
// Add vertex colour
if(params.exportVertCol)
{
pDecl->addElement(buf, offset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR);
}
// Add texture coordinates
for (i=0; i<m_vertices[0].texcoords.size(); i++)
{
Ogre::VertexElementType uvType = Ogre::VertexElement::multiplyTypeCount(Ogre::VET_FLOAT1, 2);
pDecl->addElement(buf, offset, uvType, Ogre::VES_TEXTURE_COORDINATES, static_cast<unsigned short>(i));
offset += Ogre::VertexElement::getTypeSize(uvType);
}
Ogre::VertexDeclaration* pOptimalDecl = pDecl->getAutoOrganisedDeclaration(
params.exportVBA, params.exportBlendShapes || params.exportVertAnims, false);
// Fill the vertex buffer using the newly created vertex declaration
stat = createOgreVertexBuffer(pSubmesh,pDecl,m_vertices);
// Write vertex bone assignements list
if (params.exportVBA)
{
// Create a new vertex bone assignements list
Ogre::SubMesh::VertexBoneAssignmentList vbas;
// Scan list of shared geometry vertices
for (i=0; i<m_vertices.size(); i++)
{
vertex v = m_vertices[i];
// Add all bone assignemnts for every vertex to the bone assignements list
for (j=0; j<v.vbas.size(); j++)
{
Ogre::VertexBoneAssignment vba;
vba.vertexIndex = static_cast<unsigned int>(i);
vba.boneIndex = v.vbas[j].jointIdx;
vba.weight = v.vbas[j].weight;
vbas.insert(Ogre::SubMesh::VertexBoneAssignmentList::value_type(i, vba));
}
}
// Rationalise the bone assignements list
pSubmesh->parent->_rationaliseBoneAssignments(pSubmesh->vertexData->vertexCount,vbas);
// Add bone assignements to the submesh
for (Ogre::SubMesh::VertexBoneAssignmentList::iterator bi = vbas.begin(); bi != vbas.end(); bi++)
{
pSubmesh->addBoneAssignment(bi->second);
}
pSubmesh->_compileBoneAssignments();
}
pSubmesh->vertexData->reorganiseBuffers(pOptimalDecl);
}
return true;
}