当前位置: 首页>>代码示例>>C++>>正文


C++ Geometry::setMaterial方法代码示例

本文整理汇总了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));
        }
    }
开发者ID:Himbeertoni,项目名称:OpenSGDevMaster,代码行数:65,代码来源:idbuffer.cpp


注:本文中的osg::Geometry::setMaterial方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。