本文整理汇总了C++中MeshSerializer类的典型用法代码示例。如果您正苦于以下问题:C++ MeshSerializer类的具体用法?C++ MeshSerializer怎么用?C++ MeshSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MeshSerializer类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testMesh
void MeshSerializerTests::testMesh(MeshVersion version)
{
MeshSerializer serializer;
serializer.exportMesh(mOrigMesh.get(), mMeshFullPath, version);
mMesh->reload();
assertMeshClone(mOrigMesh.get(), mMesh.get(), version);
}
示例2: createMeshWithMaterial
void MeshWithoutIndexDataTests::testCreateMesh()
{
String fileName = "indexMix.mesh";
createMeshWithMaterial(fileName);
MeshPtr mesh = mMeshMgr->getByName(fileName);
CPPUNIT_ASSERT(mesh->getNumSubMeshes() == 4);
RenderOperation rop;
for (int i=0; i<4; ++i)
{
mesh->getSubMesh(i)->_getRenderOperation(rop);
// first submesh has indexes; the others not
CPPUNIT_ASSERT( rop.useIndexes == (i == 0) );
}
MeshSerializer meshWriter;
meshWriter.exportMesh(mesh.get(), fileName);
mMeshMgr->remove( fileName );
ResourceGroupManager::getSingleton().addResourceLocation(".", "FileSystem");
MeshPtr loadedMesh = mMeshMgr->load(fileName, "General");
remove(fileName.c_str());
CPPUNIT_ASSERT(loadedMesh->getNumSubMeshes() == 4);
mMeshMgr->remove( fileName );
}
示例3: getLODMesh
//---------------------------------------------------------------------
String PlayPen_testManualLODFromFile::getLODMesh()
{
MeshPtr msh1 = (MeshPtr)MeshManager::getSingleton().load("robot.mesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
msh1->createManualLodLevel(200, "razor.mesh");
msh1->createManualLodLevel(500, "sphere.mesh");
// this time, we save this data to a file and re-load it
MeshSerializer ser;
const ResourceGroupManager::LocationList& ll =
ResourceGroupManager::getSingleton().getResourceLocationList(ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
String prefix;
for (ResourceGroupManager::LocationList::const_iterator i = ll.begin(); i != ll.end(); ++i)
{
if (StringUtil::endsWith((*i)->archive->getName(), "media"))
{
prefix = (*i)->archive->getName();
}
}
ser.exportMesh(msh1.get(), prefix + "/testlod.mesh");
MeshManager::getSingleton().removeAll();
return "testlod.mesh";
}
示例4: testMesh
//--------------------------------------------------------------------------
void MeshSerializerTests::testMesh(MeshVersion version)
{
UnitTestSuite::getSingletonPtr()->startTestMethod(__FUNCTION__);
MeshSerializer serializer;
serializer.exportMesh(mOrigMesh.get(), mMeshFullPath, version);
mMesh->reload();
assertMeshClone(mOrigMesh.get(), mMesh.get(), version);
}
示例5: load
bool Mesh::load() {
MeshSerializer* serializer = SerializerManager::getInstance()->getMeshSerializer(mPath);
if (PlatformUtil::isZipped(mPath)) {
ZipFileDataStream data(mPath);
serializer->importMesh(data, this);
} else {
FileDataStream data(mPath);
serializer->importMesh(data, this);
}
return true;
}
示例6: ManualObject
void MeshWithoutIndexDataTests::testCreateLineWithMaterial()
{
String matName = "lineMat";
MaterialPtr matPtr = MaterialManager::getSingleton().create(matName, "General");
Pass* pass = matPtr->getTechnique(0)->getPass(0);
pass->setDiffuse(1.0, 0.1, 0.1, 0);
ManualObject* line = OGRE_NEW ManualObject("line");
line->begin(matName, RenderOperation::OT_LINE_LIST);
line->position(0, 50, 0);
line->position(50, 100, 0);
line->end();
String fileName = "lineWithMat.mesh";
MeshPtr lineMesh = line->convertToMesh(fileName);
OGRE_DELETE line;
CPPUNIT_ASSERT(lineMesh->getNumSubMeshes() == 1);
CPPUNIT_ASSERT(lineMesh->getSubMesh(0)->indexData->indexCount == 0);
RenderOperation rop;
lineMesh->getSubMesh(0)->_getRenderOperation(rop);
CPPUNIT_ASSERT(rop.useIndexes == false);
CPPUNIT_ASSERT(lineMesh->getSubMesh(0)->vertexData->vertexCount == 2);
MeshSerializer meshWriter;
meshWriter.exportMesh(lineMesh.get(), fileName);
MaterialSerializer matWriter;
matWriter.exportMaterial(
MaterialManager::getSingleton().getByName(matName),
matName + ".material"
);
mMeshMgr->remove( fileName );
ResourceGroupManager::getSingleton().addResourceLocation(".", "FileSystem");
MeshPtr loadedLine = mMeshMgr->load(fileName, "General");
remove(fileName.c_str());
remove((matName + ".material").c_str());
CPPUNIT_ASSERT(loadedLine->getNumSubMeshes() == 1);
CPPUNIT_ASSERT(loadedLine->getSubMesh(0)->indexData->indexCount == 0);
loadedLine->getSubMesh(0)->_getRenderOperation(rop);
CPPUNIT_ASSERT(rop.useIndexes == false);
CPPUNIT_ASSERT(lineMesh->getSubMesh(0)->vertexData->vertexCount == 2);
mMeshMgr->remove( fileName );
}
示例7: MergeMesh
void MeshCombiner::consoleMeshCombiner()
{
StringVector vec = m_MeshCombinerConfig->getMultiSetting( "Mesh" );
if( vec.empty() )
return;
MergeMesh* mm = new MergeMesh();
SkeletonPtr skel = SkeletonPtr();
for( StringVector::iterator it = vec.begin();
it != vec.end(); ++it )
{
log( "Loading: " + *it );
try
{
MeshPtr mesh = MeshManager::getSingleton().load(
*it, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
if( !mesh.isNull() )
mm->addMesh( mesh );
}
catch( ... )
{
}
}
// save
MeshPtr mesh = mm->bake();
MeshSerializer* meshSerializer = new MeshSerializer();
meshSerializer->exportMesh( mesh.getPointer(), "./media/merged.mesh" );
MeshManager::getSingleton().remove( mesh->getHandle() );
// try to load...
mesh = MeshManager::getSingleton().load(
"merged.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
SceneManager* sm = Root::getSingleton().createSceneManager( ST_GENERIC );
// try to place...
sm->getRootSceneNode()->attachObject( sm->createEntity( "test", "merged.mesh" ) );
delete meshSerializer;
delete mm;
}
示例8: writeEveythingToDisk
//-------------------------------------------------------------------------------------
void ScriptInterpreter::writeEveythingToDisk()
{
MeshSerializer serializer;
int meshCounter = 0;
for (std::vector<Entity*>::iterator it = mEntities.begin(); it != mEntities.end(); ++it)
{
meshCounter++;
std::string fileName;
if (mEntities.size()>1)
fileName = mCurrentScriptName.substr(0, mCurrentScriptName.find_last_of(".")) + "_" + StringConverter::toString(meshCounter);
else
fileName = mCurrentScriptName.substr(0, mCurrentScriptName.find_last_of("."));
serializer.exportMesh((*it)->getMesh().getPointer(), fileName + ".mesh", MESH_VERSION_LATEST);
}
/*MaterialSerializer matSer;
int matCounter = 0;
for (std::vector<MaterialPtr>::iterator it = mMaterials.begin(); it != mMaterials.end(); ++it)
{
matCounter++;
std::string fileName;
if (mEntities.size()>1)
fileName = mCurrentScriptName.substr(0, mCurrentScriptName.find_last_of(".")) + "_" + StringConverter::toString(meshCounter);
else
fileName = mCurrentScriptName.substr(0, mCurrentScriptName.find_last_of("."));
matSer.exportMaterial(*it, fileName + ".material");
}*/
for (std::vector<TexturePtr>::iterator it = mTextures.begin(); it!=mTextures.end(); ++it)
{
Ogre::Image im;
(*it)->convertToImage(im);
im.save(mCurrentScriptName.substr(0, mCurrentScriptName.find_last_of(".")) + ".png");
}
if (mCurrentDotFile)
mCurrentDotFile->save(".");
}
示例9: AxisAlignedBox
//.........这里部分代码省略.........
pos_next = spline->interpolate(steps_len * (float)(l - 1));
direction = (pos_cur - pos_next);
}
for (int w = 0; w<=numSeg.y; w++)
{
// build vector for the width
Vector3 wn = direction.normalisedCopy().crossProduct(Vector3::UNIT_Y);
// calculate the offset, spline in the middle
Vector3 offset = (-0.5 * wn * width) + (w/numSeg.y) * wn * width;
// push everything together
Ogre::Vector3 pos = pos_cur + offset;
// get ground height there
pos.y = hfinder->getHeightAt(pos.x, pos.z) + ground_offset;
// add the position to the mesh
mo->position(pos);
aab->merge(pos);
mo->textureCoord(l/(Ogre::Real)numSeg.x*uvSeg.x, w/(Ogre::Real)numSeg.y*uvSeg.y);
mo->normal(Vector3::UNIT_Y);
}
}
bool reverse = false;
for (int n1 = 0; n1<numSeg.x; n1++)
{
for (int n2 = 0; n2<numSeg.y; n2++)
{
if (reverse)
{
mo->index(offset+0);
mo->index(offset+(numSeg.y+1));
mo->index(offset+1);
mo->index(offset+1);
mo->index(offset+(numSeg.y+1));
mo->index(offset+(numSeg.y+1)+1);
}
else
{
mo->index(offset+0);
mo->index(offset+1);
mo->index(offset+(numSeg.y+1));
mo->index(offset+1);
mo->index(offset+(numSeg.y+1)+1);
mo->index(offset+(numSeg.y+1));
}
offset++;
}
offset++;
}
offset+=numSeg.y+1;
mo->end();
mo->setBoundingBox(*aab);
// some optimizations
mo->setCastShadows(false);
mo->setDynamic(false);
delete(aab);
MeshPtr mesh = mo->convertToMesh(oname+"_mesh");
// build edgelist
mesh->buildEdgeList();
// remove the manualobject again, since we dont need it anymore
gEnv->ogreSceneManager->destroyManualObject(mo);
unsigned short src, dest;
if (!mesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
{
mesh->buildTangentVectors(VES_TANGENT, src, dest);
}
Entity *ent = gEnv->ogreSceneManager->createEntity(oname+"_ent", oname+"_mesh");
mo_node->attachObject(ent);
mo_node->setVisible(true);
//mo_node->showBoundingBox(true);
mo_node->setPosition(Vector3::ZERO); //(position.x, 0, position.z));
if (!export_fn.empty())
{
MeshSerializer *ms = new MeshSerializer();
ms->exportMesh(mesh.get(), export_fn);
LOG("spline mesh exported as " + export_fn);
delete(ms);
}
// TBD: RTSS
//Ogre::RTShader::ShaderGenerator::getSingleton().createShaderBasedTechnique(materialname, Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
//Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, materialname);
RTSSgenerateShadersForMaterial(materialname, "");
#endif
return 0;
}
示例10: dir
//---------------------------------------------------------------------
void PlayPen_testPoseAnimationWithoutNormals::setupContent()
{
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("cube.mesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
String newName = "testposenonormals.mesh";
mesh = mesh->clone(newName);
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);
// create 2 poses
Pose* pose = mesh->createPose(1, "pose1");
// Pose1 moves vertices 0, 1, 2 and 3 upward
Vector3 offset1(0, 50, 0);
pose->addVertex(0, offset1);
pose->addVertex(1, offset1);
pose->addVertex(2, offset1);
pose->addVertex(3, offset1);
pose = mesh->createPose(1, "pose2");
// Pose2 moves vertices 3, 4, and 5 to the right
// Note 3 gets affected by both
Vector3 offset2(100, 0, 0);
pose->addVertex(3, offset2);
pose->addVertex(4, offset2);
pose->addVertex(5, offset2);
Animation* anim = mesh->createAnimation("poseanim", 20.0f);
VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_POSE);
// Frame 0 - no effect
VertexPoseKeyFrame* kf = vt->createVertexPoseKeyFrame(0);
// Frame 1 - bring in pose 1 (index 0)
kf = vt->createVertexPoseKeyFrame(3);
kf->addPoseReference(0, 1.0f);
// Frame 2 - remove all
kf = vt->createVertexPoseKeyFrame(6);
// Frame 3 - bring in pose 2 (index 1)
kf = vt->createVertexPoseKeyFrame(9);
kf->addPoseReference(1, 1.0f);
// Frame 4 - remove all
kf = vt->createVertexPoseKeyFrame(12);
// Frame 5 - bring in pose 1 at 50%, pose 2 at 100%
kf = vt->createVertexPoseKeyFrame(15);
kf->addPoseReference(0, 0.5f);
kf->addPoseReference(1, 1.0f);
// Frame 6 - bring in pose 1 at 100%, pose 2 at 50%
kf = vt->createVertexPoseKeyFrame(18);
kf->addPoseReference(0, 1.0f);
kf->addPoseReference(1, 0.5f);
// Frame 7 - reset
kf = vt->createVertexPoseKeyFrame(20);
// Export the mesh
DataStreamPtr stream = Root::getSingleton().createFileStream(newName, 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();
Entity* e;
AnimationState* animState;
// software pose
e = mSceneMgr->createEntity("test2", newName);
mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(150,0,0))->attachObject(e);
animState = e->getAnimationState("poseanim");
animState->setEnabled(true);
animState->setWeight(1.0f);
mAnimStateList.push_back(animState);
// test hardware pose
e = mSceneMgr->createEntity("test", newName);
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
//.........这里部分代码省略.........
示例11: if
void Sample_MeshLod::buttonHit( OgreBites::Button* button )
{
if(button->getName() == "btnReduceMore") {
mReductionSlider->setValue(mReductionSlider->getValue()+1);
} else if(button->getName() == "btnReduceLess") {
mReductionSlider->setValue(mReductionSlider->getValue()-1);
} else if(button->getName() == "btnAddToProfile") {
addToProfile(std::numeric_limits<Real>::max());
} else if(button->getName() == "btnRemoveFromProfile") {
if(!mLodConfig.advanced.profile.empty()){
LodProfile& profile = mLodConfig.advanced.profile;
profile.erase(profile.begin() + mProfileList->getSelectionIndex());
mProfileList->removeItem(mProfileList->getSelectionIndex());
loadUserLod();
}
} else if(button->getName() == "btnAddLodLevel") {
addLodLevel();
} else if(button->getName() == "btnRemoveSelectedLodLevel") {
removeLodLevel();
} else if(button->getName() == "btnRemoveInitialLodLevel") {
removeInitialLodLevel();
} else if(button->getName() == "btnAutoconfigure") {
mTrayMgr->destroyAllWidgetsInTray(TL_TOP);
mTrayMgr->createLabel(TL_TOP, "lblWhatYouSee", "Showing autoconfigured LOD", 300);
loadAutomaticLod();
forceLodLevel(-1); // disable Lod level forcing
} else if (button->getName() == "btnShowAll") {
loadUserLod(false);
mTrayMgr->destroyAllWidgetsInTray(TL_TOP);
mTrayMgr->createLabel(TL_TOP, "lblWhatYouSee", "Showing all LOD levels", 300);
forceLodLevel(-1); // disable Lod level forcing
} else if(button->getName() == "btnShowMesh") {
mTrayMgr->destroyAllWidgetsInTray(TL_TOP);
mTrayMgr->createLabel(TL_TOP, "lblWhatYouSee", "Showing LOD from mesh file", 300);
if(mMeshEntity){
mSceneMgr->destroyEntity(mMeshEntity);
mMeshEntity = 0;
}
mLodConfig.mesh->reload(Resource::LF_DEFAULT);
mMeshEntity = mSceneMgr->createEntity(mLodConfig.mesh->getName(), mLodConfig.mesh);
mMeshNode->attachObject(mMeshEntity);
forceLodLevel(-1); // disable Lod level forcing
//String filename("");
//getResourceFullPath(mLodConfig.mesh, filename);
//mTrayMgr->showOkDialog("Success", "Showing mesh from: " + filename);
} else if(button->getName() == "btnSaveMesh") {
if(!mTrayMgr->getTrayContainer(TL_TOP)->isVisible() && !mLodConfig.levels.empty()){
LodWorkQueueWorker::getSingleton().clearPendingLodRequests();
MeshLodGenerator& gen = MeshLodGenerator::getSingleton();
mLodConfig.advanced.useBackgroundQueue = false; // Non-threaded
gen.generateLodLevels(mLodConfig);
forceLodLevel(-1); // disable Lod level forcing
}
String filename("");
if(!getResourceFullPath(mLodConfig.mesh, filename) || filename == "") {
mTrayMgr->showOkDialog("Error", "'" + filename + "' is not a writable path!");
} else {
if(!FileSystemLayer::fileExists(filename + ".orig"))
FileSystemLayer::renameFile(filename, filename + ".orig");
MeshSerializer ms;
ms.exportMesh(mLodConfig.mesh.get(), filename);
mTrayMgr->showOkDialog("Success", "Mesh saved to: " + filename);
}
if(!mTrayMgr->getTrayContainer(TL_TOP)->isVisible()){
loadUserLod();
}
}
else if(button->getName() == "btnRestoreMesh") {
String filename("");
if(getResourceFullPath(mLodConfig.mesh, filename) && filename != "") {
if(FileSystemLayer::fileExists(filename + ".orig"))
FileSystemLayer::renameFile(filename + ".orig", filename);
}
changeSelectedMesh(mLodConfig.mesh->getName());
}
}