VGltf is a library that simplifies the import and export of glTF 2.0 assets in your C# standard and Unity projects.
- Broad compatibility: Designed for both
C# standard projects
andUnity
, ensuring seamless integration. - Extensibility: Easily extendable to accommodate custom glTF extensions with
hooks
. - Readability: Clean and comprehensible codebase for quick learning and adaptation.
- Stability: Focused on reliability and performance across various projects.
- Flexible support: Compatible with
.NET Standard 2.0
orhigher
and tested on many platforms.
VGltf is compatible with Unity 2019.4
or higher
and supports the following:
- ⭕ Run-time import
- ⭕ Run-time export
- 🔺 Design-time (Unity Editor) import
- Integration with AssetDatabase is not supported
- ⭕ Design-time (Unity Editor) export
Tested platforms include:
- Windows [Mono, IL2CPP]
- Linux [Mono, IL2CPP]
- MacOS [Intel and ARM] x [Mono, IL2CPP]
- iOS
- Android
- WebGL (Sample project for
WebGL
withUnity 2022.1
)
The following code demonstrates how to import a glTF file and convert it into a Unity GameObject. The input glTF data structure assumes multiple root nodes, which are combined into a single GameObject.
using UnityEngine;
using System.IO;
using VGltf.Unity;
using VGltf;
var gltfContainer = default(GltfContainer);
using (var fs = new FileStream("Lantern.glb", FileMode.Open))
{
gltfContainer = GltfContainer.FromGlb(fs);
}
var go = new GameObject();
var timeSlicer = new DefaultTimeSlicer();
var context = default(IImporterContext);
using (var gltfImporter = new Importer(gltfContainer, timeSlicer))
{
context = await gltfImporter.ImportSceneNodes(go, System.Threading.CancellationToken.None);
}
Passing Lantern.glb, you can get the following result.
For a more practical example, see Assets/Assets/VGltfExamples/glTFExample/Scripts/GltfLoader.cs.
As another topic, skinned meshes with Unity Mecanim is supported by default when using either the VRM 0.x extension or VGltf's VGLTF_unity_avatar extension.
For more details, see Assets/VGltfExamples/VRMExample/Scripts/VRMLoader.cs.
Install Nuget/VGltf.
dotnet add package VGltf
VGltf depends on VJson, so please add it to the dependencies.
Add the following VGltf Git repository URLs to your Packages/manifest.json
:
{
"dependencies": {
"net.yutopp.vgltf": "https://github.com/yutopp/VGltf.git?path=Packages/net.yutopp.vgltf",
"net.yutopp.vgltf.unity": "https://github.com/yutopp/VGltf.git?path=Packages/net.yutopp.vgltf.unity",
"net.yutopp.vjson": "https://github.com/yutopp/VJson.git?path=Packages/net.yutopp.vjson#v0.9.12",
// Optional
"net.yutopp.vgltf.ext.vrm0": "https://github.com/yutopp/VGltf.git?path=Packages/net.yutopp.vgltf.ext.vrm0",
"net.yutopp.vgltf.ext.vrm0.unity": "https://github.com/yutopp/VGltf.git?path=Packages/net.yutopp.vgltf.ext.vrm0.unity"
}
}
We recommend using the stable version by specifying the tag.
Add scoped registry information to your Packages/manifest.json
if not exists:
{
"scopedRegistries": [
{
"name": "yutopp.net",
"url": "https://registry.npmjs.com",
"scopes": [
"net.yutopp"
]
}
]
}
Then, add net.yutopp.vgltf.*
to your Packages/manifest.json
:
{
"dependencies": {
"net.yutopp.vgltf": "v0.2.25",
"net.yutopp.vgltf.unity": "v0.2.25",
"net.yutopp.vjson": "v0.9.12",
// Optional
"net.yutopp.vgltf.ext.vrm0": "v0.2.25",
"net.yutopp.vgltf.ext.vrm0.unity": "v0.2.25"
}
}
- Performance tuning