I want make a same mesh

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
leonhong
Gnoblar
Posts: 5
Joined: Sat Jun 25, 2011 7:24 am

I want make a same mesh

Post by leonhong »

Hi all.
I'm new in Ogre3D. but I used DirectX before.

I need 100 spheres. They has a same shape. btw if I load them from resources, it wasts a memory.
so I want reuse mesh. I found a method, "createEntity(const MeshPtr& pMesh);".

so I appled that code like this.

Code: Select all

int gNumObjects = 120;//120;
int i;		

// Load Mesh from resources
Ogre::Entity* entity = m_sceneManager->createEntity( "Entity", "SphereNormal.mesh" );

for (i=0;i<gNumObjects;i++)
{

	// making node ID
	char buf[8];
	itoa( i, buf, 10 );
	string str = "Node";
	str = str + buf;

[color=#004080][b]	Ogre::Entity* entity2 = m_sceneManager->createEntity( entity->getMesh() );[/b][/color]
	Ogre::SceneNode* node = m_sceneManager->getRootSceneNode()->createChildSceneNode( str );
	node->attachObject(entity2);

	m_arrObject.push_back(node);
}

So, My Questions are these:
1. Am I right that using that code?
2. How can i check reuse mesh or not?

Thanks.
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: I want make a same mesh

Post by areay »

leonhong wrote: I need 100 spheres. They has a same shape. btw if I load them from resources, it wasts a memory.
so I want reuse mesh.
Hi Leon,

Take a look at the manual http://www.ogre3d.org/docs/manual/manua ... l#Entities creating multiple entities with the same mesh does not make additional copies of the mesh.

The standard tutorial-esque code below is fine

Code: Select all

for (i=0;i<gNumObjects;i++)
{
  Ogre::Entity *myEntity = m_sceneManager->createEntity("SphereNormal.mesh");
  Ogre::SceneNode *myNode = m_sceneManager->getRootSceneNode()->createChildSceneNode("Node_" + Ogre::StringConverter::toString(i));
  myNode->attachObject(myEntity);
  m_arrObject.push_back(myNode);
}
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: I want make a same mesh

Post by Kojack »

In fact you don't even need the name, it's optional for both entities and scene nodes.

Yep, entities share their mesh. You can move them, scale them and even change the material on them, but only one copy of the mesh will be in memory (so all of your spheres could have different textures, they would still be one mesh).
leonhong
Gnoblar
Posts: 5
Joined: Sat Jun 25, 2011 7:24 am

Re: I want make a same mesh

Post by leonhong »

Im appricate areay.

I was really new in Ogre.
U gave me a good code and Ill apply them right now ^^.

Btw. I have a question.
Its wierdo function, I think.

Code: Select all

[color=#008000]        /** Create an Entity (instance of a discrete mesh).
            @param
                entityName The name to be given to the entity (must be unique).
            @param
                meshName The name of the Mesh it is to be based on (e.g. 'knot.oof'). The
                mesh will be loaded if it is not already.
        */[/color]
        virtual Entity* createEntity(const String& entityName, const String& meshName, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
Why Ogre wants a unique entityName?
I think they can identify using meshName.
If u have a idea, let me know. ^^

Thanks.
leonhong
Gnoblar
Posts: 5
Joined: Sat Jun 25, 2011 7:24 am

Re: I want make a same mesh

Post by leonhong »

Thanks Kojack.

I understand. and i can use mesh more useful. :lol:

Have a nice-day everybody~
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: I want make a same mesh

Post by areay »

leonhong wrote: Why Ogre wants a unique entityName?
I think they can identify using meshName.
If u have a idea, let me know. ^^
If you don't create a entity with a name then Ogre will create one for you. Using this name you can do a lookup based on the name. But as Kojack mentioned, you don't actually need to name entities or the nodes yourself if you don't want to. The example code I gave above could be simplified further to look like this

Code: Select all

for (i=0;i<gNumObjects;i++)
{
  Ogre::Entity *myEntity = m_sceneManager->createEntity("SphereNormal.mesh");
  Ogre::SceneNode *myNode = m_sceneManager->getRootSceneNode()->createChildSceneNode(); //no name now
  myNode->attachObject(myEntity);
  m_arrObject.push_back(myNode); //you might not need this either, depends if you're keeping track of the spheres after creating them
}
leonhong
Gnoblar
Posts: 5
Joined: Sat Jun 25, 2011 7:24 am

Re: I want make a same mesh

Post by leonhong »

Hi .

I thought your code is very clear!

And I alreay appled^^

thanks
Post Reply