osg(osg中文社区)-osgEarth-osgViewer-基于OpenGL-开源三维渲染引擎-图形引擎-虚拟仿真工具-osg教程-osg仿真

压缩已经生成的数据

当前位置:首页 > 学习支持 > 其他帮助 > VPB工具

OSG现在提供压缩数据的功能,使用-O "compressed"压缩选项,本文经过测试可以把22GB的数据压到13GB。


概述

这个想法源于如果已经生成过的数据集未经过压缩,可以通过osgconv对每个ive数据进行压缩(osgconv有很多压缩选项)。如果在创建数据集时已经选择了-O "commpressed“参数,则无需此步。


假定

*old_db = 是数据集的根目录。

* old_db目录可读写。

*new_db = 是新的压缩后的数据集目录。

* 在Linux上使用bash


过程

关闭优化选项

export OSG_OPTIMIZER=OFF

创建一个脚本,把所有的ive从旧目录old_db转到新目录new_db,转的时候加-O "commpressed",注意必须cd到旧目录(原因后面有述)。

cd old_db
emacs conv_all_in_dir.sh

下面是脚本

#!/bin/bash

# used with e.g.:
#find . -type d -exec ./conv_all_in_dir.sh {} ;

# the output root, edit as needed
OUT_ROOT=`pwd`/../new_db
#echo $OUT_ROOT

# 1st parameter is the directory we should process
IN_DIR=$1;
echo Changing to $IN_DIR
cd $IN_DIR

# find: find all ive files in this directory only, not subdirs
# sed: remove ./ in front of names
# xargs: run for every input file, start multiple processes (-P)
# osgconv -O "compressed": make compressed ive files

find . -maxdepth 1 -name "*.ive" | sed -e s/"./"// | xargs -P 2 -I {} osgconv {} $OUT_ROOT/$IN_DIR/{} -O "compressed"

如果机器性能好,可以把-P参数指定大一些。

把脚本的权限更改为可执行。

chmod u+x ./conv_all_in_dir.sh

在新的目录下按照旧的目录结构也创建一套, osgconv 对创建目录非常不在行。

find . -type d -exec mkdir -p ../new_db/{} ;

下一步就是找每个ive,然后转。

find . -type d -exec ./conv_all_in_dir.sh {} ;

等待完成即可...


必须cd到旧目录的原因

因为 ive都是pagedlod文件,里面包含的有文件路径,当osgconv在外层目录执行时,目标文件的路径会被修改成带外层路径的路径。这个修改是相当致使的,会导致将这堆文件考到别处就无法正确一级一级的执行了。