Merge Mesh with position and orientation

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
Bitod
Gnoblar
Posts: 2
Joined: Fri Jul 22, 2016 2:51 pm

Merge Mesh with position and orientation

Post by Bitod »

Hello,

I need to create a lot (10000+) same objects in a scene. It seems that it works much faster if I join all meshes in one with different position and orientation of every single object. I found the technique how to merge all meshes but I cannot understand how can I use different position and orientation this way.

Code: Select all

void Utility::MergeMesh(Ogre::MeshPtr &aSourceMesh, Ogre::MeshPtr &aTargetMesh, Ogre::String aMaterialName
{
	Ogre::Mesh::SubMeshIterator mesh_itr = aSourceMesh->getSubMeshIterator();
	Ogre::SubMesh *in = 0, *out = 0;
	Ogre::VertexBoneAssignment vbass;
	while (mesh_itr.hasMoreElements())
	{
		in = mesh_itr.getNext();
		out = aTargetMesh->createSubMesh();
		out->indexData = in->indexData->clone();
		out->mLodFaceList = in->mLodFaceList;
		out->operationType = in->operationType;
		out->parent = aTargetMesh.get();
		out->useSharedVertices = false;
		out->vertexData = in->vertexData->clone();
		out->setMaterialName(aMaterialName;
		out->clearBoneAssignments();
		for (size_t i = 0; i < in->vertexData->vertexCount; ++i)
		{
			vbass.vertexIndex = i;
			vbass.weight = 1.0f;
			out->addBoneAssignment(vbass);
		}
	}
}
User avatar
TheOnlyJoey
Halfling
Posts: 53
Joined: Sun Apr 10, 2011 12:05 pm
Location: The Netherlands
x 6
Contact:

Re: Merge Mesh with position and orientation

Post by TheOnlyJoey »

You probably want to look into static geometry, which does exactly that!
It merges objects which are the same into one big batch which get pushed as single object to the GPU which increases performance dramatically!
http://www.ogre3d.org/tikiwiki/Intermediate+Tutorial+5 had a part in it how to set it up.
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Merge Mesh with position and orientation

Post by frostbyte »

dont think you can set pos/orient with subMesh...only material...
if you are using ogre 1.x ....
ogre 1.x can't realy handle scenes with lot of objects, beside the slow scene traversing and culling it's also very much cpu-bounded...
you can use some tricks like instancing, page streaming, static geometry etc
but moving to ogre 2.x may solve your issues, ogre2.0 has fast scene traversing/culling and ogre2.1 is considered to be gpu-bounded( azdo optimization )

Edit: but he said he wants to move stuff... (-:
don't know enough about static geometry...
is it possible to move/orient individual parts of the static geometry? is there any additional cost for doing so?

edit2: ok i've read again your post..."same object"...use instancing...or move to ogre 2.1 (-:
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
User avatar
TheOnlyJoey
Halfling
Posts: 53
Joined: Sun Apr 10, 2011 12:05 pm
Location: The Netherlands
x 6
Contact:

Re: Merge Mesh with position and orientation

Post by TheOnlyJoey »

frostbyte wrote: ogre 1.x can't realy handle scenes with lot of objects, beside the slow scene traversing and culling it's also very much cpu-bounded...

Edit: but he said he wants to move stuff... (-:
don't know enough about static geometry...
is it possible to move/orient individual parts of the static geometry? is there any additional cost for doing so?
Ogre 1.9/1.10 can handle lots of objects perfectly fine depending on your setup.
If the objects are non moving, static geometry is the way to go (16000 cubes in 1 static batch can run perfectly 60fps+ on a Intel HD4600), I have not been able to replicate that performance on 2.1 yet (among other issues).

Moving individual objects part of static geom is not possible though, since you will have to rebuild the entire static geom batch due to the way it is setup.
We mostly don't add dynamic objects or objects with dynamic properties to the batch upon load, or detach objects when scene(re)loading happens.
Bitod
Gnoblar
Posts: 2
Joined: Fri Jul 22, 2016 2:51 pm

Re: Merge Mesh with position and orientation

Post by Bitod »

In my case 'Static Geometry' is notthe solution. I also cannot use OGRE 2.X since there is no stable release. I started working with Instance and now I have some questions.
1. Can I add several Ogre::InstancedEntity to one Ogre::SceneNode and change position/orientation of Ogre::InstancedEntity? Or should I create a Ogre::SceneNode for every Ogre::InstancedEntity?
2. How can I release memory correctly?

I need to add approximately 30K cubes to a scene. I tried to add 2 cubes and change position of the second cube but withou success:

Code: Select all

	Ogre::InstanceManager *testInstanceManager = GetSceneManager()->createInstanceManager("testInstanceManager", "cube.mesh", "General", Ogre::InstanceManager::InstancingTechnique::HWInstancingBasic,2);
	
	Ogre::InstancedEntity *testEntity = testInstanceManager->createInstancedEntity("__UM_TRANS_GREEN_MATERIAL__");
	testEntity->setPosition(Ogre::Vector3(0, 0, 1));
	
	
	Ogre::InstancedEntity *testEntity1 = testInstanceManager->createInstancedEntity("__UM_TRANS_BLUE_MATERIAL__");
	testEntity1->setPosition(Ogre::Vector3(5, 0, 3));
	testEntity1->shareTransformWith(testEntity);
	

	Ogre::SceneNode* testNode =GetSceneManager()->getRootSceneNode()->createChildSceneNode();
	testNode->attachObject(testEntity);
	testNode->_update(true, true);
	testNode->attachObject(testEntity1);
	testNode->_update(true, true);
Post Reply