Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Culmination of two years of fixes, especially for export #644

Merged
merged 1,206 commits into from
Jan 23, 2024

Conversation

hybridherbst
Copy link
Collaborator

@hybridherbst hybridherbst commented Apr 8, 2022

The UnityGLTF repo has been stale for around 2 years now.
This is approximately the same time when we (prefrontal cortex) started working with glTF extensively, and thus we forked this repository and starting to improve things. There have been more than 300 commits since then, numerous features have been added, and most notably, the package has been used in many productions and battle-tested, especially for exporting glTF files from Unity. Early on, we tried to PR our changes in small chunks, but it soon became clear that the repo was abandoned.
This PR moves all of our changes over to the main repository and effectively promotes our fork, so that veryone can benefit from the changes done so far.

State of glTF in Unity

UnityGLTF hasn't received official support since early 2020. However, a number of forks have fixed issues and improved several key areas, especially animation support,export workflows, color spaces and extendibility. These forks have now been merged back into main so that everyone can benefit from then, and to enable further work.

A separate glTF implementation for Unity, glTFast, is on its path towards becoming feature complete, with import already being complete. It leverages modern Unity features such as Burst and Jobs, has better compression support (importing compressed textures and meshes), and also has wider Render Pipeline support, notably supporting URP and HDRP import (and partial export).

glTFast and UnityGLTF can coexist in the same project; you can for example use glTFast for import and UnityGLTF for export, where each of these shine. In fact, we've been contributors to both projects.

  • UnityGLTF has very good export support (runtime, editor, animations).
  • glTFast has better general import support (compression extensions supported, SRP support).
  • If you're playing with custom extensions, UnityGLTF might still be the right choice for import.

Notable changes

  • editor animation export support, originally based on a Sketchfab fork but much improved
  • runtime animation export through Timeline Recorder Tracks and also via API
  • proper colorspace export and import, for colors, vertex colors, textures, emissive, ...
  • export of arbitrary textures, readable or not, including RenderTextures
  • exporting blend shapes and blend shape animations with sparse accessors
  • numerous hooks for custom extension export (still work in progress – the goal is that what's needed for custom extensions is made public)
  • support for KHR_lights_punctual, KHR_materials_unlit
  • restructured as UPM package (proper repository restructuring and modernization can happen after this PR)
  • GLTFSerialization is now an AsmDef, not a separate sln anymore (easier cross-platform development)
  • removed embedded Newtonsoft.Json, using the one from Unity's registry now for better compatibility with other packages
  • ability for in-memory export of GLB files (relevant for WebGL and other platforms with limited filesystem access)

Notable things that haven't changed

  • still not fully spec-compliant (see Known Issues)
  • mixed bag of features that are supported on export and import
  • no URP/HDRP import support – use glTFast if you need that
  • no support for Draco, Meshopt, KTX2 import or export – use glTFast if you need that

How to test this PR

  1. Open Window > Package Manager
  2. In Package Manager, click + and select Add Package from git URL
  3. Paste the following link to the dev branch of this repository:
https://github.com/KhronosGroup/UnityGLTF.git?path=/UnityGLTF/Assets/UnityGLTF#dev
  1. Click Add.

Once the PR is approved, the package will be updated on OpenUPM as well for easier consumption (no git installation required).

Example exports

All these projects have been exported with our fork of UnityGLTF:

and many more.

Next Steps

This PR is now up for feedback. The changes that were made over the last 2 years tried to keep the repository structure the same to make eventual reviewing easier. Whoever has concerns about the general idea of promoting this fork to main: please let me know, now is the time!

Full changelog with ~35 internal releases: https://github.com/prefrontalcortex/UnityGLTF/blob/master/UnityGLTF/Assets/UnityGLTF/CHANGELOG.md

The goal is to merge this PR in ~1-2 weeks.

This PR has been made possible by prefrontal cortex and Needle.

@CLAassistant
Copy link

CLAassistant commented Apr 8, 2022

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ hybridherbst
❌ pfcDorn


pfcDorn seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hybridherbst
Copy link
Collaborator Author

hybridherbst commented Apr 28, 2022

Added a couple more commits that have fixed issues people brought up (some of them old, some of them introduced by the PR).
I'd give it another few days for public testing and then merge back to master and properly set up OpenUPM releases :)

One bigger (kind of unintended) feature that now works is WebGL platform import support (which seems to have never been working before). So now WebGL has runtime import + runtime export, including animations, same as other platforms.

@Ayfel
Copy link

Ayfel commented May 6, 2022

Amazing, so gltFast is included here as well?

P.s. just read more carefully, they are compatible. Still, amazing progress!

@hybridherbst
Copy link
Collaborator Author

Big update that actually brings UnityGLTF back to being state-of-the-art in some areas!

  • experimental support for KHR_animation_pointer export
  • upon popular request, experimental URP (2020.3+) & BiRP (2021.2+) Shader Graph for export and import, UnityGLTF/PBRGraph
  • approximated support for exporting and importing KHR_materials_transmission, KHR_materials_volume, KHR_materials_ior, KHR_materials_iridescence
  • renderer features and post effect for rough refraction / transmission (for URP and BiRP)

Additionally, some more fixes went in for camera/lights export and import, material export heuristics, and helpful things like ProfilerMarkers.

UnityGLTF/Assets/UnityGLTF/Tests/Assets/SkyboxMaterial.mat Outdated Show resolved Hide resolved
@@ -30,6 +30,7 @@ public class Skin : GLTFChildOfRootProperty

public Skin()
{
Joints = new List<NodeId>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this might have unintended consequences due to assumptions in this class and others.
This class itself specifically checks Joints != null on line 50, though it checks Joints != null && Joints.Count > 0 on line 113. Maybe line 50 just needs to be updated to also check .Count (and potentially anywhere else in the codebase that accesses Joints)?

UnityGLTF/Assets/UnityGLTF/Tests/UnityGLTFTests.asmdef Outdated Show resolved Hide resolved
hybridherbst and others added 28 commits January 16, 2024 21:52
…sor to cover more cases where a reimport might be necessary
@hybridherbst hybridherbst merged commit c82fd3b into KhronosGroup:master Jan 23, 2024
0 of 3 checks passed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did all of these get removed? Where did they go?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They have been removed for now because they were
a) in the wrong place (test assets outside the Tests folder)
b) tests didn't work even when I started working on the fork.

Some recent changes to speed up certain models by 10-100x also resulted in the GLTFSerialization assembly having a dependency on Unity, which I'm not particularly happy with – but the performance improvements were worth it I think.

We are planning to bring better test capabilities back though :)
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So no replacement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind elaborating a bit more? There are currently less test files directly in the package because it doesn’t make sense to ship test files inside a package. As in the screenshot above we’re planning to add a window that allows importing directly from the Khronos Sample Assets for tests and verification. The same mechanism is used for automated tests as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Khronos Sample Assets

Where are these located?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment