[SOLVED] [1.9] ManualObject and MaterialPtr problem

Problems building or running the engine, queries about how to use features etc.
Post Reply
TombFan1996
Kobold
Posts: 29
Joined: Tue Apr 19, 2016 2:51 pm
x 1

[SOLVED] [1.9] ManualObject and MaterialPtr problem

Post by TombFan1996 »

Hi,

I am using a ManualObject to load in a .OBJ file and then trying to assign a MaterialPtr via name to the ManualObject->begin, it compiles successfully but the material is white, which i presume Ogre defaults to "BaseWhiteNoLighting". I changed the setDiffuse to take the ColorValue red as a test.

m_material refers to the data loaded in from the .MTL file, this works perfectly fine

I can't understand why the code below doesn't work:

Creating the material

Code: Select all

   m_materialPtr = Ogre::MaterialManager::getSingleton().create(ss.str(), "General", true); //create a material
	m_technique = m_materialPtr->getTechnique(0);
	m_pass = m_technique->getPass(0);

	m_materialPtr->setSceneBlending(Ogre::SceneBlendType::SBT_TRANSPARENT_ALPHA);
	m_materialPtr->setDepthWriteEnabled(false);

	//load diffuse data from MTL
	m_pass->setEmissive(Ogre::ColourValue(m_material->m_diffuse.x,
		m_material->m_diffuse.y, m_material->m_diffuse.z, 1.0f));

	m_pass->setDiffuse(Ogre::ColourValue::Red);

	//Load the ambient colour values from data from MTL
	m_pass->setAmbient(Ogre::ColourValue(m_material->m_ambient.x, 
		m_material->m_ambient.y, m_material->m_ambient.z, 1.0f));

	//set the specular colours from the MTL
	m_pass->setSpecular(Ogre::ColourValue(m_material->m_spec.x,
		m_material->m_spec.y, m_material->m_spec.z, 1.0f));

	//set the power of the specular light
	m_pass->setShininess(m_material->m_spec_focus);
	
	//Ogre::TextureUnitState* lTextureUnit = m_pass->createTextureUnitState();
        //lTextureUnit->setTextureName("TexName.jpeg", Ogre::TEX_TYPE_2D);
        //lTextureUnit->setTextureCoordSet(0);

	m_materialPtr->compile();
	m_materialPtr->load();
Assigning the material

Code: Select all

   m_sceneNode_OBJ->begin(m_material->name(), Ogre::RenderOperation::OT_TRIANGLE_LIST);
	
	// push the vertices into the OBJ
	for (unsigned int i = 0; i < _verts_indices.size(); i++)
	{
		m_sceneNode_OBJ->position(_verts_indices.at(i));
		m_sceneNode_OBJ->textureCoord(_uv_coords.at(i));
		m_sceneNode_OBJ->normal(_normals.at(i));
	}

	// end rendering phase
	m_sceneNode_OBJ->end();
Last edited by TombFan1996 on Wed May 04, 2016 8:17 pm, edited 1 time in total.
TombFan1996
Kobold
Posts: 29
Joined: Tue Apr 19, 2016 2:51 pm
x 1

Re: [1.9] ManualObject and MaterialPtr problem

Post by TombFan1996 »

Managed to fix it, turns out the Manual Object needed the vertex colours per vertex and then I inserted the diffuse colour from the MTL file and it worked unlit. To get the specular working I needed to add a directional light.

Image
Post Reply