Ogre annoyances and issues

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
User avatar
Thoran
Halfling
Posts: 94
Joined: Mon Dec 01, 2008 2:04 pm
Location: Germany
x 1

Ogre annoyances and issues

Post by Thoran »

Hi everyone,

I am currently in the process of writing a scene serialisation for me engine which sits on top of Ogre. This means I am going to serialise all scenenodes, skysystem (skybox, skydome, sykx), lights, cameras and so on. However I had to realise that Ogre's interface really gives me a hard time extracting information which is existing in the depths of Ogre, but which I can not access without interface changes. Some examples:
  • Camera name - it is impossible to extract the name of a camera, however when trying to retrieve a camera from the scenemanager I should be aware of it as a reference . Strange. (I know that there is also the list of cameras). Furthermore I can't rename a camera once it is created. Maybe this is due to implementation issues in Ogre's internals? (if so would be dissapointing). From a users POV working with a scene editor I would very much like to have the possibility to rename a camera once it is created.
  • Lights - There is no way of getting a list of lights used in the scene from the scene manager. Maybe that is due to me using the default scene manager and I should change that.
  • SceneNode name - it is not possible to retrieve the name of a scene node. Why, what harm would this do?
  • Entity material - Why is it not possible to determine the name of the material used in an entity? I am allowed to set it with setMaterial(string), but I can't determine afterwards what materials is actually assigned.
So a common problem for me here is that all the information I need is existing in Ogre, I just can't access it, which is totally incomprehensible for me. I don't see any sense in storing this information as a duplicate in my engine, probably even introducing situations where there are inconsistencies due to this.

I would be happy if someone here knows if these issues are due to internal design of Ogre. If this is not case I am going to add the methods I need to Ogre (unfortunately forking Ogre, unless the changes go into the official repo).
TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin
x 65

Re: Ogre annoyances and issues

Post by TheSHEEEP »

Thoran wrote:Camera name - it is impossible to extract the name of a camera.
Camera::getName()
Actually, all MoveableObjects have this.
Thoran wrote:SceneNode name - it is not possible to retrieve the name of a scene node. Why, what harm would this do?
SceneNode::getName()
Thoran wrote:Entity material - Why is it not possible to determine the name of the material used in an entity? I am allowed to set it with setMaterial(string), but I can't determine afterwards what materials is actually assigned.
The "problem" here is that the entity does not use a material. A mesh of the entity uses a material, or more precisely submeshes of that mesh.
So a getMaterial() function of an entity could not really know what it should actually return.
What you can do here is entity->getMesh() to get the mesh, then iterate over all sub meshes and get the material of each of those.
My site! - Have a look :)
Also on Twitter - extra fluffy
User avatar
Thoran
Halfling
Posts: 94
Joined: Mon Dec 01, 2008 2:04 pm
Location: Germany
x 1

Re: Ogre annoyances and issues

Post by Thoran »

Hmm, interesting. It seems I was to quick with my complaints. I relied on my code completition which didn't seem to find the getName() methods, however a closer look in the documentation would have revealed it. Mea culpa.
I can see the problem with the meshes. Assuming a skybox only has submeshes with the same material, it might be easy to get the skybox material. Well at least this solves some of my issues. I got a round the light list problem anyways, just thought it might be nice to have that in the scenemanager (still this might be scenemanager-dependent). Having a method to rename the camera still would be nice.
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Ogre annoyances and issues

Post by bstone »

entity->getSubEntity( ... )->getMaterialName() would be more adequate because you can reassign the default sub-mesh materials.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 535

Re: Ogre annoyances and issues

Post by Kojack »

Lights - There is no way of getting a list of lights used in the scene from the scene manager.

Code: Select all

Ogre::SceneManager::MovableObjectIterator it = m_sceneManager->getMovableObjectIterator("Light");
while(it.hasMoreElements())
{
	Ogre::Light *light = (Ogre::Light *)it.getNext();
	// do stuff with the lights here
}
Same code works for all movableobject types, just use their factory name. Such as "Light", "ParticleSystem", "Entity", "BillboardSet", etc. Search for FACTORY_TYPE_NAME to find them all (for example, LightFactory::FACTORY_TYPE_NAME contains "Light").

Assuming a skybox only has submeshes with the same material, it might be easy to get the skybox material.
You can get info on the sky using:
SceneManager::isSkyPlaneEnabled
SceneManager::isSkyBoxEnabled
SceneManager::isSkyDomeEnabled
SceneManager::getSkyPlaneNode
SceneManager::getSkyBoxNode
SceneManager::getSkyDomeNode
SceneManager::getSkyPlaneGenParameters
SceneManager::getSkyBoxGenParameters
SceneManager::getSkyDomeGenParameters

For skybox(plane/dome) the material isn't stored as a parameter. But you can get it by looking at the object inside of the matching node (such as from getSkyBoxNode). A skydome has a scenenode containing 5 plane entities, each with the same material. Just grab any one of them:

Code: Select all

matName = ((Ogre::Entity *)node->getAttachedObject(0))->getSubEntity(0)->getMaterialName();
A skyplane is like a skydome but with only 1 plane. Same method should work.
Skyboxes are trickier. Their scenenode contains a single manualobject which has either one or six sections. If the skybox material contains a cubic environment map texture, then the manualobject has one section. You can get the material with:

Code: Select all

matName = ((Ogre::ManualObject *)node->getAttachedObject(0))->getSection(0)->getMaterialName();
But if the material doesn't use a cubic texture, then the manualobject has 6 sections. Each section gets a cloned material. If the original material name was "Cloudy", then the first section would have a material name "CloudySkyBoxPlane0", the second would be "CloudySkyBoxPlane1", and so on. You could grab the material name of the first section and remove the end to get the original name.
User avatar
Thoran
Halfling
Posts: 94
Joined: Mon Dec 01, 2008 2:04 pm
Location: Germany
x 1

Re: Ogre annoyances and issues

Post by Thoran »

Hi Kojack,

thanks for your detailed post. The thing about the factory names was really new to me. Together with your expanations about the skybox, skydome, etc. it will help me alot finishing my scene serialisation.

Thanks,
Thoran