[原][资料整理][osg]osgDB文件读取插件,工作机制,支持格式,自定义插件
参考:
当使用osgDB读取文件时,会自动根据文件的扩展名来到插件目录中寻找相应的插件,来实现。
比如:
osgviewer cow.osg
调用了osgdb_osg插件去读*.osg文件。
osgviewer model.flt
调用了osgdb_flt插件去读*.flt文件。
使用代码我们是使用如下代码读取写入模型:
//读取
#include <osgDB/ReadFile> osg::ref_ptr<Node> node = osgDB::readNodeFile("cow.osg");
osg::ref_ptr<Image> image = osgDB::readImageFile("lz.rgb"); //保存
#include <osgDB/WriteFile>
osgDB::writeNodeFile(*node, "saved.osg");
使用OSG插件是用户无需过分关心的事情,机制已经建立,当读某文件时,它会自己去寻找相应的插件,当你需要读定特文件的时候,就要确认这个文件的插件是否存在,如果不存在需要编译。
OSG支持的模型类型
|
Plugin name |
Description |
Extensions |
Read |
Write |
Notes |
|
3dc |
3DC point cloud reader |
.3dc .asc |
yes |
no |
|
|
3ds |
3D Studio |
.3ds |
yes |
yes |
|
|
ac3d |
AC3D modeler |
.ac |
yes |
yes |
|
|
bsp |
Quake3 BSP |
.bsp |
yes |
no |
|
|
dae |
COLLADA 1.4.x |
.dae |
yes |
yes |
Requires Collada DOM library. See Collada plugin details |
|
dw |
Design Workshop Database |
.dw |
yes |
no |
|
|
dxf |
Autodesk DXF Reader |
.dxf |
yes |
no |
|
|
fbx |
Autodesk FBX |
.fbx |
yes |
yes |
Requires Autodesk's FBX SDK. If using OpenSceneGraph 2.8.x you'll need version 2010.2 of the SDK. Otherwise checkReaderWriterFBX.h to see which version of the SDK is required (currently 2012.1). If you have problems loading an FBX model please check that it works in Autodesk's FBX QuickTime Viewer first to see if the model was correctly exported. |
|
geo |
Geo |
.gem .geo |
yes |
no |
|
|
Inventor |
Open Inventor format |
.iv .wrl |
yes |
yes |
.wrl Only VRML1.0 |
|
ive |
Native osg binary |
.ive |
yes |
yes |
May also read/write (internal) images |
|
logo |
Logo database |
.logo |
yes |
no |
|
|
lwo |
Lightwave Object |
.lwo .lw .geo |
yes |
no |
|
|
lws |
Lightwave Scene |
.lws |
yes |
no |
|
|
md2 |
Quake MD2 |
.md2 |
yes |
no |
|
|
obj |
Alias Wavefront |
.obj |
yes |
yes |
Also writes materials to .mtl |
|
ogr |
.ogr |
yes |
no |
||
|
Openflight |
Multigen Openflight |
.flt |
yes |
yes |
See OpenFlight plugin details |
|
osg |
Native osg ascii |
.osg |
yes |
yes |
Currently the writer supports OVERRIDE/PROTECTED flags in "StateSets" only for "Modes" and not for "StateAttributes". |
|
pfb |
Performer loader |
All extensions supported by Performer loaders |
yes |
no |
Requires Performer library |
|
shp |
ESRI Shapefile |
.shp |
yes |
no |
|
|
stl |
Stereolithography file |
.stl .sta |
yes |
no |
|
|
vrml |
VRML2 |
.wrl |
yes |
no |
Requires OpenVRML library |
|
x |
DirectX 3D model |
.x |
yes |
no |
图片和视频
|
Plugin name |
Description |
Extensions |
Read |
Write |
Notes |
|
bmp |
Window bitmap |
.bmp |
yes |
yes |
|
|
dds |
DirectX image format |
.dds |
yes |
yes |
|
|
gdal |
GDAL image loaders |
All extensions supported by GDAL |
yes |
no |
|
|
gif |
GIF Image |
.gif |
yes |
no |
|
|
hdr |
High Dynamic Range image |
.hdr |
yes |
yes |
|
|
jp2 |
.jps .jpc |
yes |
yes |
||
|
jpeg |
Jpeg image |
.jpeg .jpg |
yes |
yes |
|
|
Openflight |
Image attribute files |
.attr |
yes |
yes |
Stores additional attributes that are not stored in .rgb files |
|
pic |
PIC image |
.pic |
yes |
no |
|
|
png |
Portable Network Graphics |
.png |
yes |
yes |
|
|
pnm |
.pnm. ppm .pgm .pbm |
yes |
yes |
||
|
rgb |
.rgb .sgi .rgba .int .inta .bw |
yes |
yes |
||
|
tga |
Targa image |
.tga |
yes |
no |
|
|
tiff |
Tiff image |
.tiff .tif |
yes |
yes |
|
|
quicktime |
Quicktime movie loader |
.mov .mpg .mpv .mp4 .m4v .dc .avi .flv .swf |
yes |
yes |
|
|
Quicktime image loader |
rgb. rgba .jpg .jpeg .tif .tiff .gif .png .pict .pct .tga .psd |
yes |
yes |
||
|
xine |
Xine image stream |
.mpg .mpv .db .flv .mov .avi .wmv. xine |
yes |
no |
压缩以及网络传输类型
|
Plugin name |
Description |
Extensions |
Read |
Write |
Notes |
|
curl |
HTTP Protocol Model |
.curl |
yes |
no |
|
|
osga |
|||||
|
txp |
Terrapage file |
.txp |
yes |
no |
Produced by Terra Vista terrain building tools |
|
net |
|||||
|
zip |
|||||
|
tgz |
|||||
|
osgtgz |
字体类型
|
Plugin name |
Description |
Extensions |
Read |
Write |
Notes |
|
freetype |
Freetype font loader |
.ttf .ttc .pfb .pfa .cid .cff .cef .fon .fnt |
yes |
no |
|
|
txf |
GLU texture font |
.txf |
yes |
no |
加载时可以显式加的矩阵操作
|
Plugin name |
Description |
Extensions |
Read |
Write |
Notes |
|
rot |
Rotates to the loaded model |
.rot |
|||
|
scale |
Scales the loaded model |
.scale |
|||
|
trans |
Translates the loaded model |
.trans |
|||
|
normals |
Shows normals of the loaded model |
.normals |
以下来源:图形码农
osgDB负责维护插件的信息注册表,并负责检查将要被载入的OSG插件接口的合法性。
应用程序从文件中读取各部分数据库信息时,需要在不干扰当前渲染的前提下以后台线程的方式进行。
osgDB::DatabaseParger提供了这样的功能。
插件的工作机制
osg插件是一组动态链接库,其中实现了osgDB头文件ReaderWriter定义的接口。OSG不可能查找并加载所有的插件以获取它们支持的文件格式,这样,在程序启动时将会是一个很大的开销。因此,OSG使用职责链(Chain of Responsibility)的设计模式,以加载尽量少的插件。当用户程序尝试使用osgDB读取或写入文件时,OSG将按照如下步骤来查找合适的插件。
- OSG搜索已注册的插件列表,查找支持文件格式的插件。开始时已注册插件列表仅包含了Registry类构造函数中注册的插件。如果OSG找到了可以支持此文件格式的插件,并成功执行了I/O操作,那么它将返回相应的数据。
- 如果没有发现可以支持此格式的已注册插件,或者I/0操作失败,那么OSG将根据前面所述的文件命名规则创建插件文件的名称,并尝试读取相应的插件库。如果读取成功,OSG将添加此插件到已注册插件列表中。
- OSG将重复步骤(1),如果文件I/O的操作再次失败,OSG将返回失败信息。
总的来说,用户不必了解OSG内部如何实现文件I/O操作,就可以使用插件顺利工作。反之,如果文件I/O操作失败,用户也可以根据给出的错误信息跟踪插件源代码中的相关内容。其在程序中代码的实现顺序如下图所示:

主要的实现的代码是在ReaderWriter::ReadResult Registry::read(const ReadFunctor& readFunctor)函数中
ReaderWriter::ReadResult Registry::read(const ReadFunctor& readFunctor)
{
// first attempt to load the file from existing ReaderWriter's
//看是否有可用的ReaderWriter,对当前的数据进行解析,如果解析成功,就返回结果
AvailableReaderWriterIterator itr(_rwList, _pluginMutex);
for(;itr.valid();++itr)
{
ReaderWriter::ReadResult rr = readFunctor.doRead(*itr);
if (readFunctor.isValid(rr)) return rr;
else results.push_back(rr);
} // now look for a plug-in to load the file.
//根据文件名称创建新的动态库名称,然后加载动态库,增加_rwList对象个数
std::string libraryName = createLibraryNameForFile(readFunctor._filename);
if (loadLibrary(libraryName)!=NOT_LOADED)
{
//重新遍历一下,使用新的ReaderWriter进行数据的解析
for(;itr.valid();++itr)
{
ReaderWriter::ReadResult rr = readFunctor.doRead(*itr);
if (readFunctor.isValid(rr)) return rr;
else results.push_back(rr);
}
}
}
自定义文件插件:
自定义文件插件主要是自定义一个插件读写类,继承osgDB::ReaderWriter类,然后根据需求重写如readNode等函数方法即可
在建立插件读写类时需要注意:
- 需要建立一个dll项目工程,输出的dll必须为osgdb_扩展名.dll或osgdb_扩展名d.dll的形式
- 为了实现插件注册,需要定义全局变量,方法如下REGISTER_OSGPLUGIN(VR, ReaderWriterVR),在该全局变量的初始化过程中,会使用Registery::addReaderWriter函数自动注册插件所对应的扩展名。
- 在应用程序使用中,需要注册插件,方法如下 osgDB::Registry::instance->addFileExtensionAlias("VR", "VR")
[原][资料整理][osg]osgDB文件读取插件,工作机制,支持格式,自定义插件的更多相关文章
- Cordova与现有框架的结合,Cordova插件使用教程,Cordova自定义插件,框架集成Cordova,将Cordova集成到现有框架中
一.框架集成cordova 将cordova集成到现有框架中 一般cordova工程是通过CMD命令来创建一个工程并添加Android.ios等平台,这样的创建方式可以完整的下载开发过程中所需要的的插 ...
- 浅析一个lua文件窥slua工作机制
slua的东西不是几句话能讲得完,这里只说结论不说原因,原因有空写个Little Slua工程来解释,下面注释中有几个关键点:LuaVar系列类:LuaFunction,LuaTable,LuaDel ...
- wordpress必装的插件 wp最常用的十个插件
wordpress是世界上著名的博客系统,简称wp.一般新安装完wordpress以后,往往需要首先安装一些插件,这样才可以使用wordpress的更多功能.wp最常用的十个插件有哪些呢,可能根据每个 ...
- Android插件化(三)载入插件apk中的Resource资源
Android载入插件apk中的Resource资源 简单介绍 怎样载入未安装apk中的资源文件呢?我们从android.content.res.AssetManager.java的源代码中发现,它有 ...
- [osg]osgDB的加载机制,使用3DS插件做参考(转,整理现有osgDB资料)
参考:http://blog.sina.com.cn/s/blog_7cdaf8b60102uzu3.html http://blog.csdn.net/wang15061955806/article ...
- jt格式文件读取,osg显示插件更新
osgdb_jt 最近还是更新了一下 osgdb_jt 插件.解码jt格式核心库jt_toolkit,通过静态链接到Plugin jt产生osgdb_jt插件,使得osg可以可视化jt格式文件. 用法 ...
- [原][osgearth]osgearthviewer读取earth文件,代码解析(earth文件读取的一帧)
跑osgearthviewer程序 使用一个earth文件做参数传入 跟进代码. 首先osgearthviewer程序加载earth的方式分为两种: 1.根据earth文件(load方式) 2.使用S ...
- osg osgDB::Options noTexturesInIVEFile ForceReadingImage dds_flip
osgDB::writeNodeFile(node, path, new osgDB::Options("noTexturesInIVEFile")); noTexturesInI ...
- Java资料整理
Java资料整理 原创 2017年08月25日 17:20:44 14211 1.LocalThread的应用场景,数据传输适合用LocalThread么 2.linux的基本命令 软链接.更 ...
随机推荐
- 介绍一个二次排序的小技巧(best coder27期1001jump jump jump)
先来描述一下问题: 问题描述 有n小孩在比赛跳远,看谁跳的最远.每个小孩可以跳3次,这个小孩的成绩就是三次距离里面的最大值.例如,一个小孩跳3次的距离分别时10, 30和20,那么这个小孩的成绩就是3 ...
- java基础(9)---静态方法和成员方法
一.方法: 方法的区别: 静态方法:有static方法 成员方法:没有static方法 方法的定义: 方法的调用:类.静态方法,对象.成员方法 一个MyClass类包含静态方法和成员方法: 静态方 ...
- 2019-2020-1 20199301《Linux内核原理与分析》第五周作业
第四章·系统调用的三层机制(上) 本章的重点在于用户态程序如何触发系统调用? 一.用户.内核.中断 IntelX86有四种不同的执行级别.Linux操作系统中只采用了其中的0和3两个特权级别,分别对应 ...
- LG2662 牛场围栏 和 test20181107 数学题
P2662 牛场围栏 题目背景 小L通过泥萌的帮助,成功解决了二叉树的修改问题,并因此写了一篇论文, 成功报送了叉院(羡慕不?).勤奋又勤思的他在研究生时期成功转系,考入了北京大学光华管理学院!毕业后 ...
- 1-html基本结构与编写规范
<!DOCTYPE html> <html> <!-- #前端开发系统化学习教程, #包括html.css.pc端及移动端布局技巧.javascript. #jquery ...
- Docker 安装mysql、oracle
来源:唐山网站优化 Docker 安装mysql.oracle 使用ssh工具登录docker docker 的ip一般默认为192.168.99.100可以通过安装docker-machine之后, ...
- nginx 超时配置、根据域名、端口、链接 配置不同跳转
Location正则表达式location的作用 location指令的作用是根据用户请求的URI来执行不同的应用,也就是根据用户请求的网站URL进行匹配,匹配成功即进行相关的操作. locatio ...
- http和https 握手过程
这几天测试打印机一直出现打印延迟或者不打印的BUG.找了几天也没有发现为啥没有打印或者打印延迟.然后今天公司的研发大佬过来找问题,并开个会,瞬间所有的问题都找出了并且知道怎么解决了.大佬果然还是大佬. ...
- linux ps命令查看最消耗CPU、内存的进程
1.CPU占用最多的前10个进程: ps auxw|head -1;ps auxw|sort -rn -k3|head -10 2.内存消耗最多的前10个进程 ps auxw|head -1;ps a ...
- Kylin 架构模块简介
Apache Kylin™是一个开源的分布式分析引擎,提供Hadoop/Spark之上的SQL查询接口及多维分析(OLAP)能力以支持超大规模数据,最初由eBay Inc. 开发并贡献至开源社区.它能 ...