how to use progressive mesh?

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
gabriyel
Kobold
Posts: 31
Joined: Tue May 31, 2005 7:10 am

how to use progressive mesh?

Post by gabriyel »

hi,

is there an example on how i can make use of ogre::progressivemesh class?

i'd like to try it out. please help.

gab
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Read the implementation of Mesh::generateLodLevels. Really you shouldn't need to use ProgressiveMesh direct, unless you plan to use it for your own custom geometry.
gabriyel
Kobold
Posts: 31
Joined: Tue May 31, 2005 7:10 am

attempt

Post by gabriyel »

hi,

thanks. i read the documentation. i tried with the following code but when i run the envmap sample, it crashed after a long wait. what code be wrong?

Entity *ent = mSceneMgr->createEntity("head", "ogrehead.mesh");

MeshPtr mesh = ent->getMesh();
Mesh::LodDistanceList lodDList;
lodDList.push_back(50);
lodDList.push_back(100);
lodDList.push_back(150);

mesh->generateLodLevels(lodDList, ProgressiveMesh::VertexReductionQuota::VRQ_PROPORTIONAL, 100);
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

You just asked it to reduce 10000% every level. Please read the API.
gabriyel
Kobold
Posts: 31
Joined: Tue May 31, 2005 7:10 am

discrete lod

Post by gabriyel »

hi,

it worked now. but when i tried manually creating lod, there's an exception error saying something like "did you build you manual lod after creating the entity?"

what could be wrong? thanks for your help.



here's my code:

// Discrete LOD
Entity *ent1 = mSceneMgr->createEntity("MLOD", "hires.mesh");
MeshPtr mesh1 = ent1->getMesh();
mesh1->createManualLodLevel(50, "hires.mesh");
mesh1->createManualLodLevel(150, "lowres.mesh");
gabriyel
Kobold
Posts: 31
Joined: Tue May 31, 2005 7:10 am

help on manual LOD

Post by gabriyel »

hi,

can anyone offer any advice on what's wrong with my code that the engine complains "did you build you manual lod after creating the entity?"

appreciate your help very much!

// Discrete LOD
Entity *ent1 = mSceneMgr->createEntity("MLOD", "hires.mesh");
MeshPtr mesh1 = ent1->getMesh();
mesh1->createManualLodLevel(50, "hires.mesh");
mesh1->createManualLodLevel(150, "lowres.mesh");

// anything else to be done other than adding it to the root node?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Umm, did you even read that error message? The message says:
"did you build you manual lod after creating the entity?"
If you read your code, that's exactly what you did. So don't - create the LOD before creating an entity. Please take the time to read the error messages raised, most of the time they're pretty self-explanatory.
gabriyel
Kobold
Posts: 31
Joined: Tue May 31, 2005 7:10 am

Post by gabriyel »

i encountered this problem because i followed the exact logic flow for creating automatic/progressive LOD.

i can create manual LODs before creating the entity as suggested but the question i have is how do i "associate" these manual LODs thereafter to the entity i've created. i did read up mesh, entity class information, there doesn't seem to be a public function that does that.


// automatic LOD
Entity *ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
MeshPtr mesh = ent->getMesh();
Mesh::LodDistanceList lodDList;
lodDList.push_back(50);
lodDList.push_back(100);
lodDList.push_back(150);
mesh->generateLodLevels(lodDList, ProgressiveMesh::VertexReductionQuota::VRQ_PROPORTIONAL, 0.2);

// discrete/manual LOD
... // creates a mesh
mesh->createManualLodLevel(50, "hires.mesh");
mesh->createManualLodLevel(150, "lowres.mesh");
...// how to add this mesh to an entity??
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Code: Select all

Entity *ent = mSceneMgr->createEntity("head", mesh); 
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
gabriyel
Kobold
Posts: 31
Joined: Tue May 31, 2005 7:10 am

Post by gabriyel »

Code: Select all

Entity *ent = mSceneMgr->createEntity("head", mesh);


this won't work because if you read from the class info, createEntity doesn't take "mesh" as argument. it takes the name of the mesh, a string. according to the info, it needs a meshname, but from many examples, i see that it means a mesh's filename rather.

can anyone else offer advice on this? i'm sure using LOD is a common practice in most games. once this gets through i'll post a tutorial on manual and automatic LOD for the newbies... *sigh* :?

Code: Select all

// the code again
MeshPtr mesh1;
mesh1->createManualLodLevel(50, "ogrehead.mesh"); // it crashes here, anything i need to initialize the pointer with?
mesh1->createManualLodLevel(150, "fish.mesh");

// still unknown how to associate this mesh to an entity
Entity *ent1 = mSceneMgr->createEntity("MLOD", ???);

[/code]
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Sorry, I gave you bad advice.
You should load your mesh using Meshmanager::load - do the LOD - and then load it again with mSceneMgr->createEntity("name", "mesh.name");
If the resource exsists, the instance will be returned and all is well.
I think. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
gabriyel
Kobold
Posts: 31
Joined: Tue May 31, 2005 7:10 am

Post by gabriyel »

i tried this:

Code: Select all

// Discrete LOD
MeshPtr mesh1 =	MeshManager::getSingleton().load("ogrehead.mesh", "group", HardwareBuffer::HBU_STATIC_WRITE_ONLY, HardwareBuffer::HBU_STATIC_WRITE_ONLY, true, true);
// crashes here - execption complains of unknown "group"

mesh1->createManualLodLevel(50, "ogrehead.mesh");
mesh1->createManualLodLevel(150, "fish.mesh");
Entity *ent1 = mSceneMgr->createEntity("MLOD", "ogrehead.mesh");

question: i have only 1 mesh to start with, how can this "group" be created and associated with my mesh?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

The Ogre head already has LOD (generated), so you can't add manual LOD to it without removing all the existing LOD. It's also entirely pointless adding the ogre head to itself as a manual LOD level!!

I don't understand your question. What group? The mesh holds LOD information, and an Entity just points at that definition. You don't need anything else.
gabriyel
Kobold
Posts: 31
Joined: Tue May 31, 2005 7:10 am

Post by gabriyel »

The ogrehead is just a dummy file acting as one of LOD level. How would one know beforehand that the ogrehand has generated LODs?

In simple, I'm trying to create a model that can be loaded with multiple discrete LODs at different view distances. For example, intuitively I could code something like this in another scenegraph:

Code: Select all

// ...
lod1.load( "hi-res.model");
lod2.load( "low-res.model");

sg::LOD lodNode = new sg::LOD;
lodNode.addChild(lod1, 1, 50);
lodNode.addChild(lod2, 51, 100);

// ... then attach the LOD node to the root/scene node
But how can this be done in ogre?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

The ogrehead is just a dummy file acting as one of LOD level. How would one know beforehand that the ogrehand has generated LODs?
It's quite simple - just call Mesh::getNumLodLevels. But you shouldn't need to anyway - LOD is something that you typically prepare ahead of time as part of content creation, that's why LOD information is stored in the .mesh file and is already part of several meshes that come with OGRE. Clearly if you planned to use LOD another way you would set up your own meshes appropriately.


It's very easy to use manual LODs in OGRE, using the same code you used above, provided the mesh doesn't already have LOD of a different type. You can even use the MeshSerializer to write the setup out to an updated .mesh so you don't have to set it up in code more than once.

You seem to have preconceptions as to the way this should work (perhaps based on your previous engine) which is why you're having problems. It really isn't very difficult - just read the API spec once in a while. You're getting exceptions because you're using a resource group which doesn't exist. ResourceGroupManager controls resource groups; but really, stick to the general resource group until you know what you're doing - you don't need multiple resource groups for most things.

Code: Select all

// Discrete LOD
MeshPtr mesh1 =   MeshManager::getSingleton().load("something.mesh"); // level 0

mesh1->createManualLodLevel(50, "level1.mesh");
mesh1->createManualLodLevel(150, "level2.mesh");
Entity *ent1 = mSceneMgr->createEntity("MLOD", "something.mesh");

// or, if you want to save it for next time
MeshSerializer ser;
ser.exportMesh(mesh1.get(), "something_withlod.mesh");
// then you can just createEntity("MLOD", "something_withlod.mesh"); and skip all the setup next time
gabriyel
Kobold
Posts: 31
Joined: Tue May 31, 2005 7:10 am

thanks

Post by gabriyel »

thanks sinbad! appreciate your help.

yes, usually preconceptions we have due to past experiences with other engines can obscure our understanding of new things.

since trying out ogre a few days back, i grow to like it very much because of its OO and clean/neat nature. however, in my opinion, having elaborately documented classes may not be able to help newbies in using the engine. see, they only help to describe the functionalities but not how the workflow should be. the wiki tutorials are doing a job in some areas.

at the same time i understand open-source engines that can come such a long way like ogre need a lot of resources to have very nice and understandable documentation. perhaps you can look into a publisher to support the efforts of an ogre programming manual/engine book.

i'll continue to fiddle with ogre and perhaps use it for some of my bigger projects. keep up the good work!!

:D
gabriyel
Kobold
Posts: 31
Joined: Tue May 31, 2005 7:10 am

Post by gabriyel »

hi,

the MeshManager's load method does not take 1 argument. so i tried with this:

Code: Select all

MeshPtr mesh1 =   MeshManager::getSingleton().load("something.mesh", "group", HardwareBuffer::HBU_STATIC_WRITE_ONLY, HardwareBuffer::HBU_STATIC_WRITE_ONLY, true, true); 
but then there's an exception error thrown, telling me that "resource with name 01_-_ already exits"... i believe there's some resource which is duplicated and caused the conflict.

strange thing is thereafter, when i reverted the code back to its original state (which is environmap.h), rebuilt it from scratch, the same exception is being thrown.

any advice?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

You can get away with 2 parameters, sorry I forgot the group name wasn't defaulted. The standard group is ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME.

I think you have other issues in whatever code you're using to test this, or in the environment you're testing it in (scripts etc). There's no way you should get "resource with name 01_-_ already exits" if you were trying to load "something.mesh". Where is "01_-_" coming from? Unless you know, I suggest clearing down everything, including any changes you've made to any code or scripts, before testing again. You have dodgy things knocking about in your test environment which is clouding this issue I'm sure - and if you don't know what they are, I sure as hell don't ;).
Pyromaniac
Gnoblar
Posts: 1
Joined: Wed Oct 04, 2006 12:10 pm
Location: Russia
Contact:

Strange behaviour

Post by Pyromaniac »

Code: Select all

// blah-blah-blah
MeshPtr base=MeshManager::getSingleton().load(bodyData->Mesh,ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
for(LodsList::iterator it=bodyData->Lods.begin(),end=bodyData->Lods.end();it!=end;++it) {
  base->createManualLodLevel(it->dist,it->mesh);
}
shipEntity=EmperiumEngine::getSingleton().getSceneManager().createEntity(StringConverter::toString(shipID)+"_ship",bodyData->Mesh);
shipSceneNode->attachObject(shipEntity);
// blah-blah-blah
I've got quite strange behaviour of Ogre with this code. Posted code doesn't cause any errors itsself. But in release version Ogre just crashing somewhere without any information not in messagebox nor in the log file. In debug version it also crashes somewhere in depths of msvcr80.dll.

However, after commenting that code, everything works well.

HEELP! Please! What i'm doing wrong?
Post Reply