参考:http://blog.csdn.net/butwang/article/details/5807707
参考:http://blog.csdn.net/pizi0475/article/details/6341726
参考:Ogre 3d 1.7 beginner Guide 中文版.doc
Ogre材质的创建可以通过脚本或代码创建:层级 Material -〉technique -> pass -> texture_unit
Ogre的材质具有动态的效果,提供有animation,rotate,scroll,mirror等效果
Ogre中的材质可以在mesh创建时指定材质,也可以在entiry创建时重新制定材质。
通过脚本创建材质:(*.material)
material MyMaterial1 { technique { pass { texture_unit { texture leaf.png } } } }
通过代码创建一个简单材质:
// 添加一种新材质 Ogre::MaterialPtr m_pManualMat = Ogre::MaterialManager::getSingletonPtr()->create("manualMaterial1", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); // 设置图片纹理 Ogre::TextureUnitState* m_pTexUnitState = m_pManualMat->getTechnique(0)->getPass(0)->createTextureUnitState("ogrelogo-small.jpg"); // 设置图片纹理旋转或其他变换 m_pTexUnitState->setTextureRotate(Ogre::Radian(Ogre::Degree(45)));
通过脚本创建动态材质:
分别为:
"MyMaterial4" - rock + clamp
"MyMaterial5" - leaf + mirror
"MyMaterial6"- leaf + border
"MyMaterial7"- leaf + border + bordercolor
"MyMaterial8"- rock + scroll + scroll animation
"MyMaterial11"- rock + rotate animation
"MyMaterial12"- "MyMaterial11" -> water = water + rotate animation
material MyMaterial4 { technique { pass { texture_unit { texture terr_rock6.jpg tex_address_mode clamp } } } } material MyMaterial5 { technique { pass { texture_unit { texture leaf.png tex_address_mode mirror } } } } material MyMaterial6 { technique { pass { texture_unit { texture leaf.png tex_address_mode border } } } } material MyMaterial7 { technique { pass { texture_unit { texture leaf.png tex_address_mode border tex_border_colour 0 0 1 } } } } material MyMaterial8 { technique { pass { texture_unit { texture terr_rock6.jpg scroll 0.8 0.8 scroll_anim 0.01 0.01 } } } } material MyMaterial11 { technique { pass { texture_unit texture1 { texture terr_rock6.jpg rotate_anim 0.1 } } } } material MyMaterial12 : MyMaterial11 { set_texture_alias texture1 Water02.jpg }
材质应用:
1. 创建ManualObject时初始指定材质: (注意:a. 三角型逆时针 b.材质左上点为0,0, 右下点为1,1)
// add a quad for material Ogre::ManualObject* pQuad = mSceneMgr->createManualObject("Quad"); pQuad->begin("<strong><span style="color:#000099;BACKGROUND-COLOR: #cccccc">manualMaterial1</span></strong>", RenderOperation::OT_TRIANGLE_LIST); pQuad->position(0, 0, 0); pQuad->textureCoord(0, 1); pQuad->position(20, 0, 0); pQuad->textureCoord(1, 1); pQuad->position(20, 20, 0); pQuad->textureCoord(1, 0); pQuad->position(0, 20, 0); pQuad->textureCoord(0, 0); pQuad->triangle(0, 1, 2); pQuad->triangle(2, 3, 0); pQuad->end(); pQuad->convertToMesh("Quad");
2. 创建entity后重新指定材质
Ogre::Entity* pQuadEnt2 = mSceneMgr->createEntity("Quad"); pQuadEnt2->setMaterialName("<strong><span style="color:#000099;BACKGROUND-COLOR: #cccccc">MyMaterial12</span></strong>"); // water + roate Ogre::SceneNode* pQuadNode2 = mSceneMgr->createSceneNode(); pQuadNode2->attachObject(pQuadEnt2);
3. 创建plane entity时指定材质
// create plane Ogre::Plane plane(Ogre::Vector3(0, 1, 0), -50); Ogre::MeshManager::getSingleton().createPlane("planeMesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME , plane, 1500.0, 1500.0, 200, 200, true, 1, 5, 5, Ogre::Vector3::UNIT_Z); Ogre::Entity* pPlaneEnt = mSceneMgr->createEntity("planeMesh"); pPlaneEnt->setMaterialName("Examples/GrassFloor");
Ogre::SceneNode* pPlaneNode = mSceneMgr->createSceneNode(); pPlaneNode->attachObject(pPlaneEnt);
时间: 2024-10-11 13:54:31