A pure C# glTF 2.0 importer/exporter library with support for Unity integration.
VGltf is a library that simplifies the import and export of glTF 2.0 assets in your C# standard and Unity projects.
C# standard projects
and Unity
, ensuring seamless integration.hooks
.
.NET Standard 2.0
or higher
and tested on many platforms.VGltf is compatible with Unity 2019.4
or higher
and supports the following:
Tested platforms include:
WebGL
with Unity 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"
}
}
Boost Software License - Version 1.0