Cesium中单个模型,可以加入的格式有gltf、glb等,在开发的过程中,需要将其他格式的模型转换成以上的格式,在github上,有一个开源的工具,可将COLLADA (.dae)文件转换成glTF文件,程序源码网址:

​https://github.com/KhronosGroup/COLLADA2GLTF         ​

DAE是一种3D模型,3Dmax 与 maya 需要安装 dae输出 插件才可 输出成后缀为.dae的文件,sketchup可以直接导出此文件。

github提供了编译完成的可运行程序,有linux版本和windows版本,下载网址为:https://github.com/KhronosGroup/COLLADA2GLTF/releases

github上有详细的参数设置:

Cesium系列:dae模型转gltf_文件路径


在windows上的使用方式:

解压下载的可执行包,在windows下打开cmd命令行窗口,输入一个最典型的使用方式: 

COLLADA2GLTF-bin.exe  -i 源文件路径(.dae) -v 版本号 -t -o  .gltf文件的输出路径

输入完成后,点击回车即可运行,成功时会生成一个gltf文件,失败会显示错误信息。

在dae文件比较多的情况,可以使用C#写一个简单的程序,将一个文件夹中的dae文件,批量转换成gltf模型,详细的开发代码如下: 

           string[]  _fileLst = Directory.GetFiles(@"文件夹路径");

            foreach (string _files in _fileLst)

            {

                FileInfo _fileInfo = new FileInfo(_files);

            //获取dae文件

                if (_fileInfo.Extension == ".dae")

                {

ProcessStartInfo startInfo = new ProcessStartInfo(string.Format(@"转换软件路径\COLLADA2GLTF-bin.exe"), string.Format(@"-i {0} -v 1.0 -t -o 输出文件路径\{1}.gltf", _fileInfo.FullName, _fileInfo.Name.Replace(".dae", string.Empty)));

//执行命令行程序的一些参数设置,具体去搜索

startInfo.CreateNoWindow = true;  

startInfo.UseShellExecute = false;

startInfo.RedirectStandardOutput = true; 

//运行程序

Process p = new Process();

p.StartInfo = startInfo; 

p.Start();

 }

}