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

Folders and files

NameName
Last commit message
Last commit date
May 22, 2022
May 3, 2021
Apr 8, 2023
Apr 8, 2023
Oct 3, 2021
Mar 26, 2023
Oct 23, 2021
Jul 23, 2022
Feb 17, 2019
Oct 1, 2021
Apr 8, 2023

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