1.访问顶点索引
void printPrimitiveIndices(const std::string& name, osg::Drawable& drawable)
{
std::cout<<name<<std::endl;
osg::TemplatePrimitiveIndexFunctor<PrimitiveIndexPrint> pf;
drawable.accept(pf);
std::cout<<std::endl;
}
2.访问顶点
void printPrimitiveIndices(const std::string& name, osg::Drawable& drawable)
{
std::cout<<name<<std::endl;
osg::TemplatePrimitiveIndexFunctor<PrimitiveIndexPrint> pf;
drawable.accept(pf);
std::cout<<std::endl;
}
3. osg::Geode 为叶子节点
osg::Geometry 为几何体
setVertexArray 设置顶点数组
setColorArray 设置颜色数组
setNormalArray 设置法向量数组
addPrimitiveSet 设置几何图形形状模式,开始顶点,顶点数量
addDrawable 叶子节点添加几何图形
4.通过共享指针指向一份内存,达到共用目的节省内存
osg::ref_ptr<osg::Vec4Array> shared_colors = new osg::Vec4Array;
shared_colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
5.直接设置共享指针指向的地址
polyGeom->setColorArray(shared_colors.get(), osg::Array::BIND_OVERALL);
6.几何体中可设置多个几何图形
polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,6));
polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,6,6));
polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN,12,5));
7.状态集设置属性
stateSet>setAttributeAndModes(polygonStipple,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
8.设置节点灯光开关
geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);
9.设置节点回调函数
transform->setUpdateCallback(new MyTransformCallback(1.0f));
10.纹理坐标顺序开始我看的对不上几何体的顶点坐标,后来才明白绘制方式是osg::PrimitiveSet::TRIANGLE_STRIP
//顶点坐标
osg::Vec3 myCoords[] =
{
osg::Vec3(-1.22908f,0.0f,1.0f),
osg::Vec3(-1.22908f,0.0f,-1.0f),
osg::Vec3(1.22908f,0.0f,-1.0f),
osg::Vec3(1.22908f,0.0f,1.0f)
};
//纹理坐标
osg::Vec2 myTexCoords[] =
{
osg::Vec2(0,1),
osg::Vec2(0,0),
osg::Vec2(1,0),
osg::Vec2(1,1)
};
//几何体绘制顶点顺序
unsigned short myIndices[] =
{
0,
1,
3,
2
};
还是用osg::TexGen自动生成纹理坐标吧