参考:php
osgPlugins相关node
当使用osgDB读取文件时,会自动根据文件的扩展名来到插件目录中寻找相应的插件,来实现。设计模式
好比:网络
osgviewer cow.osg
调用了osgdb_osg插件去读*.osg文件。 curl
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插件是用户无需过度关心的事情,机制已经创建,当读某文件时,它会本身去寻找相应的插件,当你须要读定特文件的时候,就要确认这个文件的插件是否存在,若是不存在须要编译。ui
Plugin nameurl |
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内部如何实现文件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等函数方法便可
在创建插件读写类时须要注意: