微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Unity场景导出GLTF格式的文件方法

最近需要在Unity中解析GLTF文件,以及能够导出Unity的场景信息。经过查询,最后决定使用UnitGLTF这个开源库。

1、首选下载代码,git clone https://github.com/KhronosGroup/UnityGLTF.git

2、打开UnityGLTF项目

3、打开项目之后,选择Samples下面的一个场景,在Console有超多的错误信息。

Assets\UnityGLTF\Runtime\Scripts\Extensions\SchemaExtensions.cs(229,52): error CS0246: The type or namespace name 'GLTF' Could not be found (are you missing a using directive or an assembly reference?)

Assets\UnityGLTF\Runtime\Scripts\GLTFSceneExporter.cs(54,11): error CS0246: The type or namespace name 'BufferId' Could not be found (are you missing a using directive or an assembly reference?)

Assets\UnityGLTF\Runtime\Scripts\GLTFSceneExporter.cs(55,11): error CS0246: The type or namespace name 'GLTFBuffer' Could not be found (are you missing a using directive or an assembly reference?)

看这些错误信息,看是没有引入GLTF库。

4、编译GLTFSerialization,最后生成的dll库放在了UnityGLTF\UnityGLTF\Assets\UnityGLTF\Runtime\Plugins目录下了。

 

5、关闭,再次重新打UnityGLTF,看看是否正常了呢?咦,怎么还有错误呢?

首选需要把plugins目录下的uap10.0.10586给删除掉,否则会有重复的库。

Assets\UnityGLTF\Tests\Runtime\GLTFAssetGeneratorTests.cs(3,7): error CS0246: The type or namespace name 'Newtonsoft' Could not be found (are you missing a using directive or an assembly reference?)

还有一些错误,是因为Tests引用不到GLTF库,我们也把Tests给删除掉。

这样就把所有的错误给清理掉了。

 

6、导出场景的GLTF文件,可以看到可以导出一个gltf json文件以及bin文件

GLTF相关的可以用这张图片来描述。

参考文献:

https://github.com/KhronosGroup/UnityGLTF

https://github.com/KhronosGroup/glTF/tree/master/specification/2.0

https://github.khronos.org/glTF-Sample-Viewer-Release/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐