inline osg::Geometry* createLine(const std::vector<osg::Vec3>& allPTs, osg::Vec4 color,
osg::PrimitiveSet::Mode model = osg::PrimitiveSet::LINE_STRIP, float nWidth = 2)
{
int nCount = allPTs.size();
osg::ref_ptr<osg::Geometry> pGeometry = new osg::Geometry();
osg::ref_ptr<osg::Vec3Array> pyramidVertices = new osg::Vec3Array;
pGeometry->setVertexArray(pyramidVertices.get());
for (int i = 0; i < allPTs.size(); i++)
{
pyramidVertices->push_back(allPTs[i]);
}
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
colors->push_back(color);
pGeometry->setColorArray(colors.get());
pGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
osg::ref_ptr<osg::DrawArrays> pyramidBase = NULL;
pyramidBase = new osg::DrawArrays(model, 0, allPTs.size());
pGeometry->addPrimitiveSet(pyramidBase.get());
//osgUtil::SmoothingVisitor::smooth(*pGeometry);
pGeometry->setUseVertexBufferObjects(true);
{
osg::StateSet* stateset = pGeometry->getOrCreateStateSet();
stateset->setAttributeAndModes(new osg::LineWidth(nWidth), osg::StateAttribute::ON);
stateset->setAttributeAndModes(new osg::Point(3));
stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);
}
return pGeometry.release();
}
osg create line
最新推荐文章于 2024-05-31 14:22:03 发布