码迷,mamicode.com
首页 > 其他好文 > 详细

生成Geometry

时间:2015-06-19 10:11:14      阅读:169      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!