Skip to content
/ VGltf Public

A pure C# glTF 2.0 importer/exporter library with support for Unity integration.

License

Notifications You must be signed in to change notification settings

yutopp/VGltf

Repository files navigation

VGltf 🗿

ci NuGet Badge codecov license gltf-2.0 unity

VGltf is a library that simplifies the import and export of glTF 2.0 assets in your C# standard and Unity projects.

VGltf package structure

Key Features

  • Broad compatibility: Designed for both C# standard projects and Unity, 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 or higher and tested on many platforms.

Unity Compatibility

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 with Unity 2022.1)

Getting Started

Import glTF file

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.

Lantern

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.

VroidAvatarSample_A

For more details, see Assets/VGltfExamples/VRMExample/Scripts/VRMLoader.cs.

Installation

For standard C# projects

Using NuGet

Install Nuget/VGltf.

dotnet add package VGltf

For Unity projects

VGltf depends on VJson, so please add it to the dependencies.

Using Git

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.

Using npm repository

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"
  }
}

TODO

  • Performance tuning

License

Boost Software License - Version 1.0

References

Author

About

A pure C# glTF 2.0 importer/exporter library with support for Unity integration.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •