最近需要在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/

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐