zoukankan      html  css  js  c++  java
  • 生成Geometry

        // 由一组点集生成一张三角面片网格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();
        }
  • 相关阅读:
    PHP 单例 工厂模式 类的重载 抽象 接口
    上传文件
    ThinkPHP3.2中if标签
    JS闭包特性 运算符 DOM操作
    循环数组 连接数据库 AJAX
    ThinkPHP
    TP框架
    MVC框架
    类的自动加载,静态属性静态方法
    魔术方法__get()和set函数
  • 原文地址:https://www.cnblogs.com/coolbear/p/4587754.html
Copyright © 2011-2022 走看看