OpenSceneGraph | OSG如何存儲帶紋理osgb格式可以節省空間

  在使用OSG(OpenSceneGraph)存儲帶紋理osgb格式的過程中,大家會遇到這樣一種情況:存儲後的osgb文件所佔用的大小遠大於原始文件的大小,幾倍至幾十倍。這是爲何呢?原因是OSG默認的存儲格式是不壓縮存儲,所以解決方案就是設置參數將存儲格式改爲壓縮存儲。方法如下:

osg::ref_ptr<osgDB::ReaderWriter::Options> options = new osgDB::ReaderWriter::Options;
options->setOptionString("WriteImageHint=IncludeFile");			// 設置壓縮
osgDB::writeNodeFile(*(node.get()), osgb_path, options);

  如下文檔可以找到解決方法的來源:

$ osgconv --format osgb 
Plugin osgPlugins-3.3.9/osgdb_osg.so 
{ 
   ReaderWriter : OSG Reader/Writer 
   { 
       features   : readObject readNode writeObject writeNode   
       extensions : .osg                           OpenSceneGraph Ascii file format 
       extensions : .osgs                          Pseudo OpenSceneGraph file loaded, with file encoded in filename string 
       options    : OutputTextureFiles             Write out the texture images to file 
       options    : includeExternalReferences      Export option 
       options    : precision                      Set the floating point precision when writing out files 
       options    : writeExternalReferenceFiles    Export option 
   } 
   ReaderWriter : OpenSceneGraph Native Format Reader/Writer 
   { 
       features   : readObject readImage readNode writeObject writeImage writeNode   
       extensions : .osg2                    OpenSceneGraph extendable format 
       extensions : .osgb                    OpenSceneGraph extendable binary format 
       extensions : .osgt                    OpenSceneGraph extendable ascii format 
       extensions : .osgx                    OpenSceneGraph extendable XML format 
       options    : Ascii                    Import/Export option: Force reading/writing ascii file 
       options    : Compressor=<name>        Export option: Use an inbuilt or user-defined compressor 
       options    : ForceReadingImage        Import option: Load an empty image instead if required file missed 
       options    : SchemaData               Export option: Record inbuilt schema data into a binary file 
       options    : SchemaFile=<file>        Import/Export option: Use/Record an ascii schema file 
       options    : WriteImageHint=<hint>    Export option: Hint of writing image to stream: <IncludeData> writes Image::data() directly; <IncludeFile> writes the image file itself to stream; <UseExternal> writes only the fi 
lename; <WriteOut> writes Image::data() to disk as external file. 
       options    : XML                      Import/Export option: Force reading/writing XML file 
   } 
} 

  上面文檔中,有關WriteImageHint的項的描述(第26行):選擇IncludeData是直接寫入數據,無壓縮,是默認選項。而includeFile則是寫入流,按我的理解,就是將原始的影像數據流原原本本的寫入osgb,原始的影像是壓縮過的,比如jpg格式,那保存出來的osgb就是壓縮過的。因此,將WriteImageHint設置爲IncludeFile可以解決OSG存儲帶紋理osgb格式數據量大的問題,節省空間。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章