简体   繁体   中英

Error importing .mesh file in Ogre 3D

I'm trying to import a .mesh file in my Ogre 3D project just to visualize it. The file is really simple, it just contains a triangle. I'm keeping it simple just to see if everything works fine.

Here's the section of code which load the .mesh:

Ogre::String source;
source = "C:\\path\\tri.mesh";
FILE* pFile = fopen( source.c_str(), "rb" );
if (!pFile)
    OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,"File " + source + " not found.", "OgreMeshLoaded");
struct stat tagStat;
stat( source.c_str(), &tagStat );
Ogre::MemoryDataStream* memstream = new Ogre::MemoryDataStream(source, tagStat.st_size, true);
fread( (void*)memstream->getPtr(), tagStat.st_size, 1, pFile );
fclose( pFile );
Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().createManual("LocalMesh",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
MeshSerializer meshSerializer;
DataStreamPtr stream(memstream);
meshSerializer.importMesh(stream, pMesh.getPointer());

and here the content of the tri.mesh file:

%  tri.mesh
%
%  The first line lists the number of elements, and their type.
%
%  The type code is:
%    1: 2D triangular elements (vertices can be listed in any order)
%    2: 3D tetrahedral elements (vertices can be listed in any order)
%    3: 3D hexahedral (brick) elements 
%       (vertices must be listed in a particular order)
%    4: 2D quadrilateral elements. 
%       (vertices must be listed in a particular order)
%
5  1
%
%  The following lines list the vertices making up each element.
%
1  2  3
2  4  6
2  6  3
4  5  6
5  6  3

When i compile the program i don't have any errors, but when i run it i get the following:

exception: Ogre::InvalidParametersException at memory location 0x00b2f020

and it comes from the last line of the code shown above (in the importMesh()). Does anybody know what could cause this ?

This is not a valid Ogre3D mesh file. Our mesh files are binary and therefore you will not be able to decipher its content in a text editor.

More information: http://www.ogre3d.org/tikiwiki/tiki-index.php?page=-mesh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM