本文整理汇总了C++中osg::Geometry::getMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ Geometry::getMaterial方法的具体用法?C++ Geometry::getMaterial怎么用?C++ Geometry::getMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::Geometry
的用法示例。
在下文中一共展示了Geometry::getMaterial方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
}
示例2: prepareSceneGraph
void prepareSceneGraph(OSG::Node * const node)
{
if(!prepared)
{
polygonChunk = OSG::PolygonChunk::create();
prepared = true;
}
OSG::NodeCore *core =node->getCore();
if(core != NULL)
{
OSG::Geometry *geo = dynamic_cast<OSG::Geometry *>(core);
if(geo != NULL)
{
OSG::Material *mat = geo->getMaterial();
if(mat != NULL)
{
OSG::ChunkMaterial *cmat =
dynamic_cast<OSG::ChunkMaterial *>(mat);
if(cmat->find(OSG::PolygonChunk::getClassType()) == NULL)
{
cmat->addChunk(polygonChunk);
}
}
// get num positions
OSG::GeoVectorProperty *positionsPtr=geo->getPositions();
if(positionsPtr != NULL)
sum_positions += positionsPtr->size32();
// get num triangles
OSG::UInt32 triangle=0;
OSG::UInt32 line=0;
OSG::UInt32 point=0;
calcPrimitiveCount(geo,triangle,line,point);
sum_triangles += triangle;
// sum of geometry nodes
++sum_geometries;
}
else
{
OSG::MaterialGroup *matGrp =
dynamic_cast<OSG::MaterialGroup *>(core);
if(matGrp != NULL)
{
OSG::Material *mat = matGrp->getMaterial();
if(mat != NULL)
{
OSG::ChunkMaterial *cmat =
dynamic_cast<OSG::ChunkMaterial *>(mat);
if(cmat->find(OSG::PolygonChunk::getClassType()) == NULL)
{
cmat->addChunk(polygonChunk);
}
}
}
else
{
OSG::ProxyGroup *proxy = dynamic_cast<OSG::ProxyGroup *>(core);
if(proxy != NULL)
{
sum_triangles += proxy->getTriangles();
sum_positions += proxy->getPositions();
sum_geometries += proxy->getGeometries();
}
}
}
}
for(OSG::MFUnrecChildNodePtr::const_iterator nI=node->getMFChildren()->begin();
nI != node->getMFChildren()->end();
++nI)
{
prepareSceneGraph(*nI);
}
}