(备忘)OSGB文件转fbx obj等模型文件放到Unity里

2020-03-11  本文已影响0人  杰罗xr

项目地址和官网
https://github.com/openscenegraph/OpenSceneGraph
http://www.openscenegraph.org/

1.

去官网下载(找最新版) OpenSceneGraph-3.6.5 released

解压后进入bin文件夹 我们可以利用其中osgconv.exe文件来转换
可以先双击 这个osgconv.exe 如果提示缺少某个dll 去百度安装几个包就解决了

大概格式 就是osgconv infile.osgb outfile.obj 也可以使用多个文件合成一个 使用-h查看更多用法

注意 众多osgb文件中一块地形有多种清晰度 我发现 结尾带T的是精度比较高的 可以单独把结尾有t的文件导出 然后区分就简单点
我还不知道怎么直接导出不同的精度模型

把导出的fbx模型和贴图一起扔到Unity中就好了

C#写的批量导出脚本 可以根据自己的需求来写

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace OSGB
{
    class Program
    {
        static void Main(string[] args)
        {
            string space = " ";
            System.Diagnostics.Process exep = new System.Diagnostics.Process();
            exep.StartInfo.FileName = @"D:\Download\OpenSceneGraph-3.6.5-VC2019-64-Release\bin\osgconv.exe";
           // exep.StartInfo.Arguments = @"D:\Download\OpenSceneGraph-3.6.5-VC2019-64-Release\Tile_+253_+060_L22_0001160t2.osgb D:\Download\OpenSceneGraph-3.6.5-VC2019-64-Release\Tile_+253_+060_L22_0001160t2.fbx";
            exep.StartInfo.CreateNoWindow = false;
            exep.StartInfo.UseShellExecute = false;

            ///给到 Data文件
            string rootPath = @"E:\BaiduNetdiskDownload\实景三维\ZHZX2_OSGB\Data";

            var osgbDirs = Directory.GetDirectories(rootPath);

            foreach (var dir in osgbDirs)
            {
                string infiles = "";
                string outFile = "";
                foreach (var file in Directory.GetFiles(dir))
                {
                    infiles += file+space;
                }

                outFile = dir + ".fbx";// "\\" + Path.GetFileName(dir) + ".fbx";
                exep.StartInfo.Arguments = infiles + space + outFile;
                exep.Start();
                exep.WaitForExit();
                Console.WriteLine(outFile);
            }

            Console.WriteLine("转换结束");
            Console.Read();
        }
    }
}

上一篇 下一篇

猜你喜欢

热点阅读