首页 > 其他 > 详细

生成Geometry

时间:2015-06-19 10:09:59      阅读:291      评论:0      收藏:0      [点我收藏+]
    // 由一组点集生成一张三角面片网格Geometry
    osg::Geometry* createTRIANGLESGeometry(MyMesh &mesh)
    {
        osg::ref_ptr< osg::Geometry > triGeom = new osg::Geometry();

        // 顶点坐标数组
        int vertexNum=mesh.vertex.size();
        osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array();
        triGeom->setVertexArray(vertices);

        // 颜色数组
        osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
        colors->push_back(osg::Vec4(0.0f,1.0f,0.0f,1.0f));
        triGeom->setColorArray(colors);
        triGeom->setColorBinding(osg::Geometry::BIND_OVERALL);

        // 法向量数组
        int normalNum=mesh.normal.size();
        osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array();
        triGeom->setNormalArray(normals);
        triGeom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);// 一个顶点对应一个法向量

        triGeom->addPrimitiveSet(
            new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES,
            mesh.triangleNum*3,// 索引个数
            (unsigned short*)&mesh.index.at( 0 )));

        return triGeom.release();
    }

 

生成Geometry

原文:http://www.cnblogs.com/coolbear/p/4587754.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!