Load material/texture dynamically from user defined path

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
skmCry
Gnoblar
Posts: 2
Joined: Thu Feb 12, 2015 9:48 am

Load material/texture dynamically from user defined path

Post by skmCry » Thu Feb 12, 2015 10:24 am

Hello,

i'm working with ROS/RViz (Robot Operating System) that uses Ogre3D for its rendering.
But my question is Ogre3D related, so i'm posting here in this forum.

What i want to achieve:
I have a ground plane (simple grid mesh) in the scene and want to attach different textures to it (dynamically).
In the end the user should be able to enter an arbitrary path to a material/texture in the user interface and then the defined texture in the material file
is attached to the ground plane and displayed. There is always only one texture attached to the ground plane.


So i've written some code to extract the name and path to the material file from the user input that should be used for the ground plane. The path is added
to the resourceGroupManager with "ResourceGroupManager::addResourceLocation()". Then i'm initialising and loading the resource group. Finally the
extracted material name from the user input is used to add the material to the ground plane. This all happens during runtime.

After the above process these two methods return "true":
resManager.resourceLocationExists("User defined path to the material file", "resource group");
resManager.resourceExists("resource group", "name of the material file");

So i guess the initialising of the user defined path works correctly and the material and texture should be found.
But the texture from the user defined path is not displayed.


What i've noticed:
- If the material and texture are both stored at the user defined path, there is NO texture displayed on the ground plane.
- If the material file is stored at a default resource location, that is initialised during startup, and the texture is stored at the user defined path,
the texture IS displayed on the ground plane.

Is it not possible to load a material file from a resource location that is defined during runtime? And this just works with textures?

How can i load a material file and therefore also a texture from a resource location that is defined during runtime?

I hope the above description is comprehensible enough. Otherwise feel free to ask.
Thanks a lot.
0 x

Transporter
Minaton
Posts: 933
Joined: Mon Mar 05, 2012 11:37 am
Location: Germany
x 1

Re: Load material/texture dynamically from user defined path

Post by Transporter » Thu Feb 12, 2015 11:23 am

Something like this should work

Code: Select all

	Ogre::ResourceGroupManager::getSingletonPtr()->destroyResourceGroup("UserDefinedMaterials");
	Ogre::ResourceGroupManager::getSingletonPtr()->createResourceGroup("UserDefinedMaterials");
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/home/transporter/material", "FileSystem", "UserDefinedMaterials", true);
	Ogre::ResourceGroupManager::getSingletonPtr()->initialiseResourceGroup("UserDefinedMaterials");
	Ogre::ResourceGroupManager::getSingletonPtr()->loadResourceGroup("UserDefinedMaterials");
It is working on my project.
0 x

skmCry
Gnoblar
Posts: 2
Joined: Thu Feb 12, 2015 9:48 am

Re: Load material/texture dynamically from user defined path

Post by skmCry » Fri Feb 13, 2015 9:30 am

Thanks a lot "Transporter", everything works perfect now. :)

I've used the same pieces of code, but with the default resource group of ogre. By switching to a user defined one, everythings works
fine now.
0 x

Post Reply