Several hours of work later, the class PMaterial is fully integrated to PNode. This part has been tricky: materials and textures are shared objects, managed by managers below the objects.

The approach is to create PMaterial on demand, when you call pnode.getMaterial, for instance. Once created, it stays in the pnode until you destroy it or overwrite the material with another.

This limits the memory consumption and force the coder to always retrieve the material pointer from the pnode, and not to store it.

Another cool feature of the pnode.getMaterial is that the material can be created RT if the mesh doesn’t specify one.

On the PMaterial level, it is becoming very easy to add the methods to access the different layers of the Ogre material.

For instance, here is the code used to create the 2 materials applied on the balls in the image above:

pmat_even.create( "Test", "Nice material" );
pmat_even.diffuse( 1, 0, 0 );
// activation of fog
pmat_even.fogMode( Ogre::FOG_EXP );
pmat_even.fogDensity( 0.1 );
pmat_even.fogDistance( 10, 15 );
pmat_even.fogColor( 0.4, 0.4, 0.4 ); // same as background
// cloning pmat_even in pmat_odd
pmat_odd.clone( &pmat_even );
pmat_odd.fogColor( 0.8, 0.8, 0.8 );
pmat_odd.shading( Ogre::SO_FLAT );
// adding a pass on the material
// there are now 2 passes in technique 0 of this material
uint tid = 0;
uint pid = 1;
pmat_odd.emissive( 1,0,1, tid,pid );
pmat_odd.shading( Ogre::SO_FLAT, tid,pid );
pmat_odd.polygon( Ogre::PM_WIREFRAME, tid,pid );

It’s super easy to clone a material, at creation or via the clone method. The second pass of the odd material have to be set manually. Passes are not cloneable (yet?).

As you may notice, mentioning the technique or pass to attack is optional. If your material has only one technique and one pass, the call is very short. Once you beginning to build a more complex material, adding 2 uint at the end of your arguments should not be too difficult…

The material of the cube is also created manually:

PMaterial pmat2( pmat_even );
// disabling the fog
pmat2.fogMode( Ogre::FOG_NONE );
pmat2.diffuse( 1, 1, 1 );
// checking the number of textures
if ( pmat2.getTextureUnitCount( ) == 0 ) {
	// adding one 
	pmat2.addTexture( "General", "child-computer.jpg" );
} else {
	// modifying the first one
	pmat2.setTexture( "General", "child-computer.jpg" );
cube.material( &pmat2, true );

More, soon!