本文整理汇总了C++中osg::Geometry::setMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ Geometry::setMaterial方法的具体用法?C++ Geometry::setMaterial怎么用?C++ Geometry::setMaterial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::Geometry
的用法示例。
在下文中一共展示了Geometry::setMaterial方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertToColorIdentificationSwitchable
void convertToColorIdentificationSwitchable(OSG::Node * const root)
{
// This is a recursive traversal of the Scene Graph, so as to replace
// each material by a SwitchMaterial, in wich we put the normal one on one
// side, and the color identification one in other side.
OSG::UInt32 children = root->getNChildren();
if(root->getCore()->getType().isDerivedFrom(OSG::MaterialGroup::getClassType()))
{
// Need to turn off material groups, as they would override our
// geo-specific materials
// Just record them here.
OSG::MaterialGroup *mg = dynamic_cast<OSG::MaterialGroup *>(root->getCore());
_mgswitches.push_back(
MaterialGroupList::value_type(
mg,
static_cast<OSG::Material *>(NULL)));
}
if(root->getCore()->getType().isDerivedFrom(OSG::Geometry::getClassType()))
{
OSG::Geometry *geo = dynamic_cast<OSG::Geometry *>(root->getCore());
// If we get a Geometry, we replace it by a switch,
// we add this geometry a SwitchMaterial, with its original material
// in one case, and a chunkmaterial corresponding to the node ID in the other.
OSG::Color4ub c = create_new_color();
OSG::Color4f cf;
cf.setRGBA(c.getRGBA());
// We add the associated pair color/node to the map
//_node_index[c] = root;
_node_index [c] = root;
OSG::PolygonChunkRefPtr pc = OSG::PolygonChunk::create();
pc->setSmooth(false);
OSG::MaterialChunkRefPtr mc = OSG::MaterialChunk::create();
mc->setLit(false);
mc->setEmission(cf);
mc->setDiffuse(cf);
OSG::ChunkMaterialRefPtr cm = OSG::ChunkMaterial::create();
cm->addChunk(pc);
cm->addChunk(mc);
OSG::Material *mat = geo->getMaterial();
OSG::SwitchMaterialRefPtr sw = OSG::SwitchMaterial::create();
sw->addMaterial(mat); // Choice 0
sw->addMaterial(cm); // Choice 1
geo->setMaterial(sw);
_switches.push_back(sw);
}
// check all children
for (OSG::UInt32 i = 0; i < children; i++)
{
convertToColorIdentificationSwitchable(root->getChild(i));
}
}