osgb的顶点,纹理,索引,UV读取与存储
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读取与存储的更多相关文章
- [原][spark]帧序列的纹理UV索引,修改spark源码,改变纹理索引方式,支持常规帧序列
spark的纹理索引方式是左下为最小值0 右上为最大值k ,遍历顺序为横向即: 3 4 5 0 1 2 而常规的纹理帧序列是这样的: 0 1 2 3 4 5 所以,为了让spark的纹理遍历顺序能按照 ...
- 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 ...
- [Slimdx]顶点和索引缓冲,绘制了2个分离的三角形
定义网格顶点和索引缓冲,绘制了2个分离的三角形. using System; using System.Drawing; using RGeos.SlimScene.Core; using SlimD ...
- MySQL数据库之索引、事务、存储引擎详细讲解
一.索引 1.1 索引的概念 索引是一个排序的列表,存储着索引值和这个值所对应的物理地址 无须对整个表进行扫描,通过物理地址就可以找到所需数据 (数据库索引类似书中的目录,通过目录就可以快速査找所需信 ...
- Pandas_数据读取与存储数据(全面但不精炼)
Pandas 读取和存储数据 目录 读取 csv数据 读取 txt数据 存储 csv 和 txt 文件 读取和存储 json数据 读取和存储 excel数据 一道练习题 参考 Numpy基础(全) P ...
- Pandas_数据读取与存储数据(精炼)
# 一,读取 CSV 文件: # 文字解析函数: # pd.read_csv() 从文件中加载带分隔符的数据,默认分隔符为逗号 # pd.read_table() 从文件中加载带分隔符的数据,默认分隔 ...
- MySQL索引、事务、存储引擎
一.MySQL 索引 1.索引的概念 ●索引是一个排序的列表,在这个列表中存储着索引的值和包含这个值的数据所在行的物理地址(类似于C语言的链表通过指针指向数据记录的内存地址).●使用索引后可以不用扫描 ...
- MySQL 索引、事务与存储引擎
MySQL 索引.事务与存储引擎 1.索引 2.事务 3.存储引擎 1.索引: 索引的概念 : 索引是一个排序的列表,在这个列表中存储着索引的值和包含这个值的数据所在行的物理地址 ...
- 27.MySQL 索引、事务与存储引擎
MySQL 索引.事务与存储引擎 目录 MySQL 索引.事务与存储引擎 MySQL 索引 索引的概念 索引的作用及副作用 索引的作用 索引的副作用 创建索引的原则依据 索引的分类和创建 普通索引 唯 ...
随机推荐
- JavaSE复习~基本数据类型
数据类型 java有两大类数据类型:基本数据类型 和 引用数据类型 基本数据类型 整数型:byte.short.int.long 浮点型:float.double 字符型:char 布尔型:boole ...
- python numpy的var std cov研究
var:表示方差, 即各项-均值的平方求和后再除以N , std:表示标准差,是var的平方根. cov:协方差 ,与var类似,但是除以(N-1) import numpy as np # 构建测试 ...
- 单播反向路径转发uRPF
uRPF将数据包的源地址和存储在转发信息库(FIB)中的信息进行对照,以判定数据包的合法性.FIB是Cisco CEF技术中的一张表,包含从路由表中复制过来的转发信息,可以将其视为路由表的镜像,FIB ...
- ASA-有关AAA用户登录的问题
问题示例:I have created a test user that is set to privilege 15 in the config: When I log in to the ASA ...
- 【原】简单shell练习(六)
1.shell获取进程号并杀掉该进程 kill - $(ps -ef | grep node| grep -v grep | awk '{print $2}') 解析: ps (processStat ...
- IDEA中常用优化设置
1.设置鼠标悬浮提示 Editor->General 这里要勾选下,后面设置的是延迟时间 默认半秒:设置后,我们鼠标移动到类上看看: 2.显示方法分隔符 Editor->General - ...
- pycharm 右键无法显示unittest框架&&解决右键只有unittest 运行如何取消右键显示进行普通run
上面是普通文件和unittest 导入的文件右键快捷键显示情况,可以看出两者快捷键都是ctr+shift+F10,如果你是右键模式想运行unitest,但是又不知道哪里配置unittest直接运行快捷 ...
- tornado框架的简单实用
一.安装模块 pip3 install tornado 二.简单的起服务的方法 import json, datetime from tornado.web import RequestHandler ...
- mac 终端连接服务器报错
今天在连接虚拟机服务器时突然报了一个 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!的错误.  会出现这个错误的原因是在第一次进行SSH连接时,会生 ...
- Swift3.0-基本运算符
一.简介 运算符是检查.改变.合并值的特殊符号或者短语.在本篇文章中只介绍基本运算符,Swift中包含的高级运算符(比如溢出运算符)不在其中.Swift中的运算符和OC中的运算法还是有比较大的区别的, ...