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 索引 索引的概念 索引的作用及副作用 索引的作用 索引的副作用 创建索引的原则依据 索引的分类和创建 普通索引 唯 ...
随机推荐
- December 28th, Week 52nd Saturday, 2019
If you start at the bottom, pay your dues, life here can be a dream come true. 只要你从头开始,脚踏实地,梦想是可以成真的 ...
- PTA的Python练习题(十二)-第4章-7 统计学生平均成绩与及格人数
第4章-7 统计学生平均成绩与及格人数 a=eval(input()) b=list(map(int,input().split())) sum=sum(b) c=[i for i in b if i ...
- (转)__attribute__之section 分析详解
原文地址:__attribute__之section详解 前言 第一次接触 "section" 是在公司的一个STM32的项目代码中,前工程师将所有的初始化函数都使用的" ...
- 十八、sun JPA理解及使用
1.JPA理解及实现: JPA(Java Persistence API)作为Java EE 5.0平台标准的ORM规范,将得到所有Java EE服务器的支持,是SUN在充分吸收现有ORM框架的 ...
- Rect Native 使用
参见 Rect Native 中文官网. 依赖环境: Homebrew.npm.Node.js.Watchman(监测Bug和文件变化,触发指定操作).flow(JS静态类型检查仪,以方便找出代码中错 ...
- [ DLPytorch ] 文本预处理&语言模型&循环神经网络基础
文本预处理 实现步骤(处理语言模型数据集距离) 文本预处理的实现步骤 读入文本:读入zip / txt 等数据集 with zipfile.ZipFile('./jaychou_lyrics.txt. ...
- Day11 - D - Race to 1 Again LightOJ - 1038
设dp_i为所求答案,每次选择因数的概率相同,设i有x个因数,dp_i=sum(1/x*x_j)+1,(x_j表示第j个因数),那我们就预处理每个数的因数即可,T=10000,需要预处理出答案 #in ...
- Centos 下安装php
1 从php 官网下载源安装包 http://php.net/downloads.php // 安装php 扩展 2 yum install libxml2 libxml2-devel openssl ...
- 2020.02.28 Linux 命令
Cat 语法格式 cat [-AbeEnstTuv] [--help] [--version] fileName 参数说明: -n 或 --number:由 1 开始对所有输出的行数编号. -b ...
- ADO.Net实体数据模型添加DB-First/Code First报错
Authentication method 'caching_sha2_password' not supported by any of the available plugins. 解决办法: 1 ...