OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: Loading Meshes From Any Path
View page
Source of version: 7
(current)
Usually the paths of resources - including meshes - should be defined in the ''resource.cfg'' file. However, sometimes we need to load mesh files just like "open file" from any local path, which is not predefined in the resource file. The following code snippet shows to accomplish that. ''For a similar example using FileStreamDataStream see the wiki article ((Loading skeletons from any path)).'' {CODE(wrap="1", colors="c++")}// "source" should contain the pathname to your mesh file Ogre::String source; /* An alternate (better) way of doing the following would be to use the FileStreamDataStream class, which avoids having to use the more esoteric "stat" struct and stdio APIs. For more, see http://stderr.org/doc/ogre-doc/api/classOgre_1_1FileStreamDataStream.html This prevents having to create and fill a MemoryDataStream instance, as the FileStreamDataStream can be used directly in the "stream" c'tor below. */ 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 ); MemoryDataStream* memstream = new MemoryDataStream(source, tagStat.st_size, true); fread( (void*)memstream->getPtr(), tagStat.st_size, 1, pFile ); fclose( pFile ); // give the resource a name -- it can be the full pathname if you like, since it's // just going to be the key in an STL associative tree container MeshPtr pMesh = MeshManager::getSingleton().createManual("LocalMesh",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); // this part does the actual load into the live Mesh object created above MeshSerializer meshSerializer; DataStreamPtr stream(memstream); meshSerializer.importMesh(stream, pMesh.getPointer()); // and finally, now that we have a named Mesh resource, we can use it // in our createEntity() call... Entity* pF35_1 = m_pSceneMgr->createEntity("LocalMesh_Ent", "LocalMesh"); {CODE} --- Alias: (alias(Loading_Meshes_From_Any_Path))
Search by Tags
Search Wiki by Freetags
Latest Changes
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
Critter AI
Mogre Add-ons
MOGRE
Mogre MyGUI wrapper
MOGRE Editable Terrain Manager
...more
Search
Find
Advanced
Search Help
Online Users
56 online users