Problem Assigning Material To Plane

Problems building or running the engine, queries about how to use features etc.
Post Reply
Walta69
Halfling
Posts: 62
Joined: Sun May 11, 2014 5:49 pm

Problem Assigning Material To Plane

Post by Walta69 »

I am attempting to simply create a plane with a material on it (as seen in basic tutorial 2).

I have done the following:

Note:
Ogre::Entity * floor;

Code: Select all

	Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0); // Normal is the y-axis
	Ogre::MeshManager::getSingleton().createPlane("floor", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 6000, 6000, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);

	floor = mSceneMgr->createEntity("floorEntity", "floor");
	floor->setCastShadows(false);
	floor->setMaterialName("Ocean");
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(floor);
Where Ocean is Ocean.material found in materials/scripts in my ogre folder.

What am I doing wrong?
thegooseking
Gnoblar
Posts: 13
Joined: Mon Sep 29, 2008 11:40 pm

Re: Problem Assigning Material To Plane

Post by thegooseking »

One thing is you can't really assign a material from a filename. Ocean.material is not just one material, but actually several different materials, so you need to say which material in Ocean.material you want to use. The tutorial says to use Examples/Rockwall - this means use the Rockwall material in the Examples.material file.

In addition, Ocean is a very different material to the Rockwall the tutorial suggests using. Rockwall is just a texture, but Ocean is a Cg/GLSL/HLSL shader, which is a lot more complicated.
Walta69
Halfling
Posts: 62
Joined: Sun May 11, 2014 5:49 pm

Re: Problem Assigning Material To Plane

Post by Walta69 »

oh I see! So how would I view different parts of the material? (example how would I know that Examples.material had the rockwall option)

Also how would I take a texture (.png etc) and cover a plane in it? would I have to convert it to a material first?
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Problem Assigning Material To Plane

Post by Kojack »

If you look inside of ocean.material, there's the following materials defined:
OceanHLSL_GLSL
OceanCg
Ocean2_Cg
Ocean2_HLSL_GLSL
SkyBox
LightFlare

These are the names you can give to setMaterialName.
thegooseking wrote:The tutorial says to use Examples/Rockwall - this means use the Rockwall material in the Examples.material file.
Actually there's no rockwall material. The material is called "Examples/Rockwall". That doesn't mean to look in examples.material, the entire "Examples/Rockwall" is just a name, the slashes have no meaning to ogre.
Ogre will search in every .material file for the material you specify.
Walta69 wrote:(example how would I know that Examples.material had the rockwall option)
Open the examples.material file in a text editor and search for the word "material". Each material starts with that keyword.
Walta69 wrote:Also how would I take a texture (.png etc) and cover a plane in it? would I have to convert it to a material first?
You need to make a material for every texture.
Walta69
Halfling
Posts: 62
Joined: Sun May 11, 2014 5:49 pm

Re: Problem Assigning Material To Plane

Post by Walta69 »

I notice that some materials cannot be used on my plane. Why is this so? :)



Also, is there any particular plugin I need (for photoshop) to export to .material in a format that ogre will understand?
You need to make a material for every texture
RigoCL
Greenskin
Posts: 114
Joined: Mon Oct 14, 2013 1:41 am
Location: Chile
x 3

Re: Problem Assigning Material To Plane

Post by RigoCL »

Walta69 wrote:I notice that some materials cannot be used on my plane. Why is this so? :)



Also, is there any particular plugin I need (for photoshop) to export to .material in a format that ogre will understand?
You need to make a material for every texture
The problem is not between Photoshop and Ogre, is between the .material and the .mesh file. To use a PNG (or TGA or whatever file texture you like) on a mesh, the .mesh needs to define the uv coordinates to the PNG file for every vertex in the mesh, that's called "mapping", a uv coordinate is a 2D coordinate (u,v) that maps a 3D vertex (x,y,z) to a texture (PNG file), this is why you may find in a .mesh file after mapping a texture something like this (check the <textcoord> tag):

Code: Select all

<vertex>
    <position x="-2.912296" y="-2.912297" z="-2.912297"/>
    <normal x="-1.000000" y="-0.000000" z="-0.000000"/>
    <texcoord u="0.999821" v="0.999643"/>
</vertex>
To map a texture to a mesh, you need a specialized application like Blender, that is able to "unwrap" all the vertices in your mesh to a 2D file, then you export that file into a program like Photoshop to generate the texture you like for your mesh, when done, import the generated texture back into Blender and voila! you end up with a 3D mesh and a 2D texture mapped on.

Check this out:
http://en.wikibooks.org/wiki/Blender_3D ... Map_Basics

This is more advanced, but definitely what you need:
http://cgi.tutsplus.com/tutorials/model ... --cg-12763
Integrated: Ogre3D + dotScene (Blender loader) + MyGUI (UI) + RakNet (Client/Server) + Leap Motion (The future is here!) + StereoManager (3D Anaglyph red-cyan)
WIP: StereoManager (Real 3D) + CCS (Camera Control System) + Sound, experimenting with Android.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Problem Assigning Material To Plane

Post by Kojack »

Some materials may require extra vertex data (multiple texture coordinate sets, tangents, etc), shader data (pass values tot he shader to control it's effect) or may have hardware/software restrictions (like only work in opengl if it uses glsl shaders or directx 11 if it's hlsl and the shader model is 4.0 or higher).

There's no exporting to materials. They are just a simple little text file that says which texture and shaders (and other parameters) to use.
If you have a texture called "player.png" then you can use it in ogre by making a .material file containing this:

Code: Select all

material player
{
   technique
   {
      pass
      {
         texture_unit
         {
            texture player.png
         }
      }
   }
}
Post Reply