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 索引 索引的概念 索引的作用及副作用 索引的作用 索引的副作用 创建索引的原则依据 索引的分类和创建 普通索引 唯 ...
随机推荐
- 利用 systemd 实现 Clash 开机自启
利用 systemd 实现 Clash 开机自启 首先准备 Clash 的服务脚本,并保存为/etc/systemd/system/clash.service.内容如下: [Unit] Descrip ...
- 这里是常见的HTTP状态码
遇到过的HTTP状态码 200(Ok):请求成功,服务器成功返回网页. 403(Forbidden):服务器已经理解请求,但是拒绝执行它. 404(Not Found):请求失败,请求所希望得到的资源 ...
- POJ1797 Heavy Transportation (堆优化的Dijkstra变形)
Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand bus ...
- Nginx笔试题!
1.Nginx实现HTTP及TCP负载均衡的模块?HTTP就是工作在七层协议TCP工作在四层协议 Nginx七层负载:七层通过虚拟的URL或主机名接收请求在server里面配置location反向代理 ...
- ArrayQueue(队列)
code1: #include <stdio.h> #include <conio.h> #include <stdlib.h> #define MAXSIZE 6 ...
- 【Javaweb】Servlet的xml和注解配置
1.xml <%@ page language="java" contentType="text/html;" %> <!DOCTYPE ht ...
- Java自学-集合框架 ArrayList和LinkedList的区别
ArrayList和LinkedList的区别 步骤 1 : ArrayList和LinkedList的区别 ArrayList ,插入,删除数据慢 LinkedList, 插入,删除数据快 Arra ...
- Java 笔试题
有一些还是存在问题,欢迎大家一起探讨. 在Java类中,使用以下( )声明语句来定义公有的int型常量MAX. A. public int MAX = 100; B. final int MAX = ...
- Navicat Premium 12安装及激活
一.安装 百度云下载地址:https://pan.baidu.com/s/1T5BjpBqLtwCy26szcKSdKw 提取码:ujzx 二.激活步骤 ①将navicat-keygen-for-x6 ...
- 条件语句(if语句)的用法
if语句是实现分支结构的常用分支语句之一,另外还有条件运算符.switch语句等. if语句的功能是:根据给定条件,选择程序执行方向. if语句的基本格式 “if语句”又称条件语句,其基本格式为: ...