virtual void apply(osg::Geode& node)
{
for (int i = ; i < node.getNumDrawables(); i++)
{
osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(node.getDrawable(i));
if (geometry)
{
//apply(*g);
//***********************************************
//解析顶点
osg::Array* vertexArray = geometry->getVertexArray();
if (vertexArray == NULL)
return; //顶点数组
osg::Vec3Array* verts = dynamic_cast<osg::Vec3Array*>(vertexArray);
long lVertNum = verts->size();
std::vector<osg::Vec3 >::iterator iter_ver = verts->begin(); //遍历顶点值
for (; iter_ver != verts->end(); iter_ver++)
{
double x = iter_ver->x();
double y = iter_ver->y();
double z = iter_ver->z();
} //纹理
osg::Texture2D* tex2D = dynamic_cast<osg::Texture2D*>(geometry->getStateSet()->getTextureAttribute(, osg::StateAttribute::TEXTURE));
osg::Image* image = tex2D->getImage();
osgDB::writeImageFile(*image, "abc.jpg");
int width = image->s();
int height = image->t();
/*osg::Vec2 color;
osg::Vec4 c = image->getColor(color);*/ //UV
osg::Array* uvArry = geometry->getTexCoordArray();
osg::Vec2Array* vertsUV = dynamic_cast<osg::Vec2Array*>(uvArry);
std::vector<osg::Vec2 >::iterator iter_verUV = vertsUV->begin(); std::vector<int> greenPointIndices;
int i = ;
for (; iter_verUV != vertsUV->end(); iter_verUV++)
{
double u = iter_verUV->x();
double v = iter_verUV->y();
osg::Vec2 color(u, v);
osg::Vec4 c = image->getColor(color);
float r = c.r() * ;
float g = c.g() * ;
float b = c.b() * ;
if (r < && g < && b < )
greenPointIndices.push_back(i);
i++;
} //索引
int numP = geometry->getNumPrimitiveSets();
osg::ref_ptr<osg::DrawElementsUInt> drawElemUInt = new osg::DrawElementsUInt(GL_TRIANGLES);
for (unsigned int ipr = ; ipr < numP; ipr++)
{
osg::PrimitiveSet* prset = geometry->getPrimitiveSet(ipr);
unsigned int ncnt = prset->getNumIndices();
for (unsigned int ic = ; ic * < prset->getNumIndices(); ic++)
{
unsigned int iIndex0 = prset->index(ic * );
unsigned int iIndex1 = prset->index(ic * + );
unsigned int iIndex2 = prset->index(ic * + );
bool find = false;
for (int i = ; i < greenPointIndices.size(); i++)
{
if (greenPointIndices[i] == iIndex0 || greenPointIndices[i] == iIndex1 || greenPointIndices[i] == iIndex2)
{
find = true;
break;
}
}
if (find)
continue;
else
{
drawElemUInt->push_back(prset->index(ic * ));
drawElemUInt->push_back(prset->index(ic * + ));
drawElemUInt->push_back(prset->index(ic * + ));
}
}
} osg::ref_ptr<osg::Geometry> geometry_new = new osg::Geometry();
geometry_new->setVertexArray(verts);
geometry_new->getOrCreateStateSet()->setTextureAttributeAndModes(, tex2D, osg::StateAttribute::ON);
geometry_new->setTexCoordArray(, uvArry);
geometry_new->addPrimitiveSet(drawElemUInt); osg::Geode* pGeode_new = new osg::Geode;
pGeode_new->removeDrawables(, pGeode_new->getNumDrawables());
pGeode_new->addDrawable(geometry_new);
osgDB::writeNodeFile(*pGeode_new, "test.osgb", new osgDB::Options("WriteImageHint=IncludeData Compressor=zlib")); //***********************************************
}
}
}

geode中顶点对应UV色彩在阈值范围内的三角形删除,并生成新的geode保存成osgb文件输出

osgb的顶点,纹理,索引,UV读取与存储的更多相关文章

  1. [原][spark]帧序列的纹理UV索引,修改spark源码,改变纹理索引方式,支持常规帧序列

    spark的纹理索引方式是左下为最小值0 右上为最大值k ,遍历顺序为横向即: 3 4 5 0 1 2 而常规的纹理帧序列是这样的: 0 1 2 3 4 5 所以,为了让spark的纹理遍历顺序能按照 ...

  2. Shader Model 3.0:Using Vertex Textures SM3:使用顶点纹理 (NVIDIA spec, 6800支持使用D3DFMT_R32F and D3DFMT_A32B32G32R32F的纹理格式实现Vertex Texture。)

    翻译者 周波 zhoubo22@hotmail.com 版权所有 Philipp Gerasimov Randima (Randy) Fernando Simon Green NVIDIA Corpo ...

  3. [Slimdx]顶点和索引缓冲,绘制了2个分离的三角形

    定义网格顶点和索引缓冲,绘制了2个分离的三角形. using System; using System.Drawing; using RGeos.SlimScene.Core; using SlimD ...

  4. MySQL数据库之索引、事务、存储引擎详细讲解

    一.索引 1.1 索引的概念 索引是一个排序的列表,存储着索引值和这个值所对应的物理地址 无须对整个表进行扫描,通过物理地址就可以找到所需数据 (数据库索引类似书中的目录,通过目录就可以快速査找所需信 ...

  5. Pandas_数据读取与存储数据(全面但不精炼)

    Pandas 读取和存储数据 目录 读取 csv数据 读取 txt数据 存储 csv 和 txt 文件 读取和存储 json数据 读取和存储 excel数据 一道练习题 参考 Numpy基础(全) P ...

  6. Pandas_数据读取与存储数据(精炼)

    # 一,读取 CSV 文件: # 文字解析函数: # pd.read_csv() 从文件中加载带分隔符的数据,默认分隔符为逗号 # pd.read_table() 从文件中加载带分隔符的数据,默认分隔 ...

  7. MySQL索引、事务、存储引擎

    一.MySQL 索引 1.索引的概念 ●索引是一个排序的列表,在这个列表中存储着索引的值和包含这个值的数据所在行的物理地址(类似于C语言的链表通过指针指向数据记录的内存地址).●使用索引后可以不用扫描 ...

  8. MySQL 索引、事务与存储引擎

               MySQL 索引.事务与存储引擎 1.索引 2.事务 3.存储引擎 1.索引: 索引的概念 : 索引是一个排序的列表,在这个列表中存储着索引的值和包含这个值的数据所在行的物理地址 ...

  9. 27.MySQL 索引、事务与存储引擎

    MySQL 索引.事务与存储引擎 目录 MySQL 索引.事务与存储引擎 MySQL 索引 索引的概念 索引的作用及副作用 索引的作用 索引的副作用 创建索引的原则依据 索引的分类和创建 普通索引 唯 ...

随机推荐

  1. web渗透(转)

    某天比较无聊,听一个朋友推荐httpscan这款工具,于是就下载下来试试. 首先对某学校网段开始进行测试. 1   python httpscan.py **.**.**.0/24 测试时发现有个比较 ...

  2. Web Storage API:localStorage 和 SessionStorage

    Web Storage API 提供了存储机制,通过该机制,浏览器可以安全地存储键值对,比使用 cookie 更加直观. 参考:https://developer.mozilla.org/zh-CN/ ...

  3. 快速创建vue 项目

    随着VUE 技术的不断更新,越来越多的开发者开始使用vue编写前端界面,今天我就和大家分享一下 ,如何快速创建一个vue项目. 前提: 安装了node.js 首先: 全局安装vue-cli 使用命令: ...

  4. JavaScript 深度遍历对象的两种方式,递归与非递归

    递归遍历: 基本问题: 当前属性值不为对象时,打印键和值 递归过程:当前属性值为对象时,打印键,继续递归 var o = { a: { b: { c: { d: { e: { f: 1, g:{ h: ...

  5. 23 JavaScript规范与最佳实践&性能&箭头函数

    大多数web服务器(Apache等)对大小写敏感,因此命名注意大小写 不要声明字符串.数字和布尔值,始终把他们看做原始值而非对象,如果把这些声明为对象,会拖慢执行速度 对象是无法比较的,原始值可以 不 ...

  6. vPC配置

    1.vPC概述 如下图所示,在传统网络中,出于冗余考虑,汇聚层往往由2台设备构成,一台接入层交换机使用2根上联链路,分别连接汇聚层2台设备. 这种拓扑所带来的问题是:受制于STP,对于同一个VLAN的 ...

  7. 洛谷P1073最优贸易(跑两遍dij)

    题目描述 CC C国有n n n个大城市和m mm 条道路,每条道路连接这 nnn个城市中的某两个城市.任意两个城市之间最多只有一条道路直接相连.这 mmm 条道路中有一部分为单向通行的道路,一部分为 ...

  8. Codeforces Round #611 (Div. 3) C

    There are nn friends who want to give gifts for the New Year to each other. Each friend should give ...

  9. 标准类 (Java Bean)

    一个标准类通常包括四个部分: 1.所有成员变量都要用 private 关键字修饰 2.为每一个成员变量编写一对 Getter/Setter 方法 3.编写一个无参数的构造方法 4.编写一个全参数的构造 ...

  10. Python与线性代数——Numpy中的matrix()和array()的区别

    Numpy中matrix必须是2维的,但是 numpy中array可以是多维的(1D,2D,3D····ND).matrix是array的一个小的分支,包含于array.所以matrix 拥有arra ...