How do .mesh files load their textures

Problems building or running the engine, queries about how to use features etc.
Post Reply
Coinshot
Gnoblar
Posts: 4
Joined: Sat Sep 30, 2017 9:25 am

How do .mesh files load their textures

Post by Coinshot »

Trying to get my head around how .mesh files load their textures when an entity is loaded via createEntity(name, meshName). Currently I'm using the ninja model provided by the OGRE samples.

The .mesh file is located at

Code: Select all

C:/OgreSDK/.../media/models/ninja.mesh
and the texture is location

Code: Select all

C:/OgreSDK/.../media/textures/<somewhere>
I'm loading it with something like this:

Code: Select all

  entity = Game::getInstance().getSceneManager()->createEntity(name, mesh);

  node = Game::getInstance()
             .getSceneManager()
             ->getRootSceneNode()
             ->createChildSceneNode();
  node->attachObject(entity);
Is this something that's configured in the model itself, or are all models located at media/models and all textures media/textures?

I have a model I've created and exported to the .mesh format, and I want to load it with a particular texture. How should I do that?

Is it common for OGRE projects to use the precompiled SDK location, and put their models in the given media/ directory?
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: How do .mesh files load their textures

Post by xrgo »

.mesh files sometimes contains the name of the material used by each submesh (a default one "hardcoded"), then the materials should be specified in a .material script file (or by code), and in that material definition must be a texture unit state that specifies which texture file is using.

You can have the files in any folder you want as long as its included in the resource system (via the resources.cfg file or by code).

To use another texture in your mesh, you have to define the material in a .material file (or by code) and in that material specify a texture file, and then apply it to the subentity by doing entity->getSubEntity(0)->setMaterialName("myMaterialSpecifiedSomewhere")

That's in a few words... find .material files in the samples folder to understand more about how it works
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: How do .mesh files load their textures

Post by Kojack »

First up, we have the resource system.
Depending on how your project is working, the resource system is given a list of directories to look in for assets. Usually we use a resources.cfg file which lists directories, or you can add them manually in code.
The resource system allows you to search for an asset in any of those directories. The name doesn't mean anything (you can put textures in the mesh directory, meshes in the script directory, etc). Directories normally aren't part of the name, so looking for just a file name will find it if it's in any of the listed resource directories.

The ninja consists of 4 files:
models/ninja.mesh
models/ninja.skeleton
materials/scripts/Examples.material
materials/textures/nskingr.jpg

The ninja.mesh file contains a reference to the material name and skeleton file. Note: not the material file! Examples.material contains many materials, they are all loaded in and you don't refer to them by file name, just the name inside of the file. The part of Examples.material we want is:

Code: Select all

material Examples/Ninja
{
	technique
	{
		pass
		{

			texture_unit
			{
				texture nskingr.jpg
			}
		}
	}
}
As you can see, the texture file name is listed here.

Changing the material file's texture line will change the default texture used when you create an entity.

Note: this is for Ogre 1.x style materials. Ogre 2.x's PBS high level materials are a bit different.
Coinshot
Gnoblar
Posts: 4
Joined: Sat Sep 30, 2017 9:25 am

Re: How do .mesh files load their textures

Post by Coinshot »

Are all files in the directories included in .cfg basically in the same directory as far as Ogre is concerned?
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: How do .mesh files load their textures

Post by Kojack »

Yep. So they need to be uniquely named.
Post Reply