Giter Site home page Giter Site logo

unitygltf's Introduction

UnityGLTF

Great coverage of glTF 2.0. Unity 2021.3+ and URP recommended Support for 2020.3 is not actively maintained

URP supported BiRP supported with better support on 2021.3+ HDRP support is not actively maintained

Unity3D library for importing and exporting glTF 2.0 assets.

Editor Runtime
Import
Export

UnityGLTF doesn't have any native dependencies (pure C#) and thus works on all platforms that Unity supports. This includes WebGL import and export.

The library is designed to be easy to extend with additional extensions to the glTF specification. Both import and export allow attaching custom plugins and callbacks and can be heavily modified to fit into specific pipelines. Many glTF extensions are supported.

Contents

Installation

You can install this package from the Needle Package Registry with a one-click installer:

  1. Download UnityGLTF Package Installer
  2. Drop the downloaded .unitypackage into Unity and follow the steps.

You can also install this package from git, compatible with UPM (Unity Package Manager).

  1. Open Window > Package Manager
  2. Click +
  3. Select Add Package from git URL
  4. Paste
    https://github.com/KhronosGroup/UnityGLTF.git
    
  5. Click Add.

Note: If you want to target a specific version, append #release/<some-tag> or a specific commit to the URL above. Example: https://github.com/KhronosGroup/UnityGLTF.git#release/2.9.0-rc.

Unity Version and Render Pipeline Compatibility

Please use Long-Term Support versions of Unity (2021.3+, 2022.3+, 2023.3+).

Recommended:

  • Unity 2021.3+, Unity 2022.3+, Unity 2023.3+
  • Linear colorspace
  • Universal Render Pipeline (URP) and Built-In Render Pipeline (BiRP)

Tested:

  • Unity 2020.3+
  • Linear colorspace
  • Universal Render Pipeline (URP) and Built-In Render Pipeline (BiRP)

Legacy:
These configurations have been working in the past. They will not be updated with material extensions or new features. Also, issues in these configurations will most likely not be addressed if they're not also happening on later versions.

  • Unity 2018.4–2019.4
  • Gamma colorspace

HDRP:

  • Currently limited functionality.

Note: Issues on non-LTS Unity versions (not on 2020.3, 2021.3, 2022.3, ...) will most likely not be addressed. Please use LTS (Long-Term Support) versions where possible.

UnityGLTF and glTFast

A separate glTF implementation for Unity, glTFast, is available from the Unity Registry.
glTFast being supported by Unity means, in a nutshell, that it sticks to standards pretty strictly and can't easily ship non-ratified extensions or experimental features that work for the majority, but not all, of users.

  • UnityGLTF aims to be the more flexible framework, with extensive import/export plugin support and useful plugins out of the box.
  • glTFast aims to be the more performant framework, with a focus on leveraging Unity-specific features such as Burst and Jobs.
  • UnityGLTF has a versatile plugin/extension infrastructure. This allows for a lot of flexibility during import/export.
  • UnityGLTF enables the use of and ships with non-ratified extensions such as KHR_animation_pointer, KHR_audio, and KHR_materials_variants.
  • glTFast leverages Unity-specific features such as Burst and Jobs and thus can have better performance in some cases.
  • glTFast has better HDRP support.

glTFast and UnityGLTF can coexist in the same project; you can for example use glTFast for import and UnityGLTF for export.
For imported assets, you can choose which importer to use with a dropdown.
glTFast import has precedence if both are in the same project. See also Default Importer Selection.

Supported Features and Extensions

The lists below are non-conclusive and in no particular order. Note that there are gaps where features could easily be supported for im- and export but currently aren't. PRs welcome!

Import and Export

  • Animations
  • Skinned Mesh Renderers
  • Blend Shapes
    • Sparse accessors for Blend Shapes
  • Linear and Gamma colorspace support (Gamma won't be maintained anymore)
  • Vertex Colors
  • Cameras (perspective, orthographic)
  • URP and Built-In Render Pipeline Learn More
  • KHR_lights_punctual (point, spot, and directional lights)
  • KHR_texture_transform (UV offset, scale, rotation)
  • KHR_materials_unlit
  • KHR_materials_transmission (glass-like materials)
  • KHR_materials_volume (refractive materials)
  • KHR_materials_ior (for transmission and volume)
  • KHR_materials_emissive_strength (emissive values greater than 1)
  • KHR_materials_iridescence (thin-film interference, like oil on water)
  • KHR_materials_clearcoat (secondary specular layer, like a coat of varnish)
  • KHR_materials_specular (partial support)
  • KHR_materials_dispersion (refractive index dispersion)
  • MSFT_lods (level of detail)
  • KHR_animation_pointer (arbitrary property animations)

Import only

Export only

  • KHR_materials_variants
  • Timeline recorder track for exporting animations in the editor and at runtime
  • Lossless keyframe optimization on export
  • All 2D textures can be exported, RenderTextures included – they're baked at export.
  • Optional plugin: Bake TMPro 3D objects to meshes on export
  • Optional plugin: Bake Particle Systems to meshes on export
  • Optional plugin: Bake Canvas to meshes on export
  • Included plugin sample: KHR_audio

glTF Materials

To leverage the extended material model of glTF in Unity, use the UnityGLTF/PBRGraph material.
It allows the use of various glTF material extensions for import, export, and inside Unity.
This includes features that URP is missing, such as transmission, volume, and per-texture UV control.

Material Conversions

UnityGLTF contains helpers to make converting to UnityGLTF/PBRGraph easy.
When you switch a material from any shader to PBRGraph, an automatic conversion can run to bring the properties over.
Some shaders already come with automatic conversions, please see the table below.

When a shader doesn't have a converter yet, UnityGLTF will ask if you want to create a Conversion Script. These scripts contain all properties of the source shader and the target shader, but no specified mapping yet (as that depends on the intent of the shader author).
After the conversion script has been created, you can edit it to correctly map from the source shader's properties to PBRGraph properties.
When you switch such a shader to PBRGraph the next time, your conversion script will run and automatically translate the materials in the specified way.

Note: Currently, conversion scripts aren't used automatically on glTF export. Convert materials at edit time for best results.

Material and Shader Export Compatibility

If you want to design for glTF export, it's recommended to use Unity 2021.3+ with URP and the UnityGLTF/PBRGraph material. It comes with support for modern material extensions like refraction and iridescence, and allows for perfect roundtrips. Great for building glTF pipelines in and out of Unity.

Render Pipeline Shader Notes Source
URP on 2020.3+
Built-In on 2021.3+
UnityGLTF/PBRGraph
☝️ Use this if you're not sure
Perfect roundtrip, Material Extensions UnityGLTF
UnityGLTF/UnlitGraph Perfect roundtrip UnityGLTF
ShaderGraphs/glTF-pbrMetallicRoughness glTFast
ShaderGraphs/glTF-unlit glTFast
URP URP/Lit Unity
URP/Unlit Unity
Built-In Standard Unity
GLTF/PbrMetallicRoughness UnityGLTF (legacy)
GLTF/Unlit UnityGLTF (legacy)
glTF/PbrMetallicRoughness glTFast (legacy)
glTF/Unlit glTFast (legacy)
HDRP (limited support) HDRP/Lit Unity
HDRP/Unlit Unity

Configure for Refractive Materials (Transmission and Volume)

Transmission and Volume allow rendering materials like glass, that are fully transparent but still show reflections, as well as volume attenuation (e.g. colored jelly) and rough refraction (e.g. brushed glass). To use these material features, you need to do some setup on the material and your render pipeline.

Material Setup

  1. On a PBRGraph material, check "Enable Transmission" and optionally "Enable Volume"
  2. Change the Transmission, Thickness, Index of Refraction and Attenuation values as desired.

URP

To see transmissive and volume materials correctly in Unity,

  1. Select your URP Renderer Asset
  2. Under the "Renderer Features" section, add a "Opaque Texture (Rough Refraction)" feature

Built-In

To see transmissive and volume materials correctly in Unity,

  1. Add the "RoughRefraction" component to your Main Camera.

HDRP

HDRP has its own rough refraction support. There's currently no automatic import / export support to convert to that. Use glTFast if you need this.

Note: Fully metallic materials are never transparent. See the KHR_materials_transmission spec for more info.

Exporting glTF Files

To export an object from a scene or your project,

  1. Select the object
  2. Use the menu items under Assets > UnityGLTF > Export selected as GLB / Export selected as glTF to export

Tip: You can set shortcuts for quick export in Unity's Shortcut Manager. For example, Ctrl + Space for GLB export and Ctrl + Shift + Space for glTF export allow for very fast iteration.

Testing, debugging, compatibility

The various glTF viewers in existence have varying feature sets. Only a select few have full coverage of the glTF spec, most only support a subset.
Notable features with limited support:

  • setting textureCoord per texture.
  • setting textureRotation. Many viewers simply ignore it.
  • sparse accessors. Some viewers support sparse accessors only for blend shapes, others don't support it at all.
  • vertex colors.

To view your glTF files, here's a number of tools you can use:

Name Notes
Khronos glTF Sample Viewer Full support for ratified extensions
gltf.report Inspect file size, meshes, textures
model-viewer Support for KHR_materials_variants with custom code
Gestaltor Full glTF Spec Compliance
Support for KHR_animation_pointer
Support for KHR_audio
Support for KHR_materials_variants
Needle Viewer Support for KHR_animation_pointer
Inspect hierarchy, textures, cameras, lights, warnings
Babylon.js Sandbox Support for KHR_animation_pointer
UnityGLTF
(this project!)
Simply drop the exported glb file back into Unity.
glTFast Add the glTFast package to your project.
You can switch the used importer on glTF files between glTFast and UnityGLTF.

To further process files after exporting them with UnityGLTF, you can use:

Name Notes
gltf-transform Compress meshes with draco or meshopt
Compress textures to ktx2
Optimize Files
Convert between .gltf and .glb
Blender Import/export glTF files with good feature coverage

Animation Export

Animations can be exported both in the Editor and at runtime. Editor export works with Animator (multiple clips), Animation (multiple clips), and Timeline (GLTFRecorderTrack).

Animator Controller

You can export entire Animators and their clips as glTF files with multiple animations.
Animation clips will be named after each Motion State in the Animator Controller.
The "speed" property of each Motion will be baked into the exported clip. Ensure the speed is 1 when you want to export unchanged.
Any number of Animators in a hierarchy is supported, as is any number of clips in those.

Both Humanoid and Generic animations will be exported. Humanoid animations are baked onto the target rig at export time.

Note: Animator export only works in the Editor. For runtime export, use the GLTFRecorder capabilities or the Timeline Recorder.

GLTFRecorder API

For creating and/or recording animations at runtime, you can use the GLTFRecorder API. It allows to capture the state of entire hierarchies and complex animations and export them directly as glTF file, optionally with KHR_animation_pointer support for complex material and property animations.
See GLTFRecorderComponent for an example implementation.

Timeline Recorder

Timelines or sections of them can be recorded with a GltfRecorderTrack and one or more GltfRecorderClips. Timeline recording uses the GLTFRecorder API under the hood.

Legacy Animation Component

Note: Animation Component export only works in the Editor. For runtime export, use the GLTFRecorder capabilities.

Animation components and their legacy clips can also be exported.

KHR_animation_pointer support

UnityGLTF supports exporting animations with the KHR_animation_pointer extension. The core glTF spec only allows animation node transforms and blend shape weights, while this extension allows animating arbitrary properties in the glTF file – including material and object properties, even in custom extensions and script components.

Exporting with KHR_animation_pointer can be turned on in Project Settings > UnityGLTF by enabling the KHR_animation_pointer plugin.

Note: The exported files can be viewed with Gestaltor, Babylon Sandbox, and Needle Engine, but currently not with three.js / model-viewer. See mrdoob/three.js#24108. They can also not be reimported into UnityGLTF at this point.

Blend Shape Export

Morph Targets / Blend Shapes / Shape Keys are supported, including animations.
To create smaller files for complex blend shape animations (e.g. faces with dozens of shapes), export with the "Sparse Accessors" setting enabled.

Importing glTF files

Editor Import

For importing .gltf or .glb files in the editor, place them in your project as usual (Assets or Packages). Make sure to bring .bin/textures along for .gltf files with the correct relative paths;.glb is usually self-contained.

When moving .gltf files inside Unity, make sure to move their .bin/texture files as well, to not break the path references between them.

Default Importer Selection

UnityGLTF will register itself as the default importer for the .gltf and .glb extensions.
If the glTFast package is also present in a project, glTFast gets precedence and UnityGLTF is available as Importer Override, which can be selected from a dropdown on each glTF asset.

UnityGLTF uses Unity's ScriptedImporter system. For any given file format (file extension) there has to be one default importer and there can be additional, alternative importers.
You can make UnityGLTF the default importer and de-prioritize glTFast by adding the following settings to your project's Scripting Defines:

GLTFAST_FORCE_DEFAULT_IMPORTER_OFF
UNITYGLTF_FORCE_DEFAULT_IMPORTER_ON

Care has been taken to align glTFast's and UnityGLTF's importers, so that in most cases you can switch between them without breaking prefab references. That being said, switching between importers can change material references, mesh references etc., so some manual adjustments may be needed. You may have to adjust the root stripping settings of each importer (glTFast and UnityGLTF do that slightly differently).

Animation Import

Animations can be imported both in the Editor and at runtime.
On the importer, you can choose between "Legacy", "Mecanim" or "Humanoid" clips.

At runtime, if you're importing "Mecanim" clips, you need to make sure to add them to a playable graph via script (e.g. Animator Controller or Timeline) to play them back.

Extensibility

UnityGLTF has import and export plugins. These have callbacks for modifying node structures, extension data, materials and more as part of the regular export and import process. They are used both in the Editor and at runtime. You can make your own plugins and enable them in the Project Settings > UnityGLTF menu.
Plugins are ScriptableObjects that can have settings; they're serialized as part of the GLTFSettings asset. Plugins create concrete instances of import/export handlers.

To create a plugin, follow these steps:

  1. Make a class that inherits from GLTFImportPlugin or GLTFExportPlugin. This is the ScriptableObject that contains plugin settings.
  2. Also, make a class that inherits from GLTFImportPluginContext or GLTFExportPluginContext. This class has the actual callbacks.
  3. Implement CreateInstance in your plugin to return a new instance of your plugin context.
  4. Override the callbacks you want to use in your plugin context.

If your plugin reads/writes custom extension data, you need to also implement GLTF.Schema.IExtension for serialization and deserialization.

🏗️ Under construction. You can take a look at MaterialVariantsPlugin.cs for an example.

Known Issues

  • Blend shapes with in-betweens are currently not supported.
  • Support for glTF files with multiple scenes is limited.
  • Some material options (e.g. MAOS maps) are currently not exported correctly.

Contributing

Note: As of 20240129 the default branch of this repository has been renamed from master to main.

UnityGLTF is an open-source project. Well-tested PRs are welcome.

It is currently maintained by

More Details (legacy)

🏗️ Under construction. Feel free to raise an issue if you have questions.

  • Unity Version Be sure that the Unity release you have installed on your local machine is at least 2021.3.
  • Project Components The Unity project offers two main functionalities: importing and exporting GLTF assets. These functionalities are primarily implemented in GLTFSceneImporter and GLTFSceneExporter.
  • Basic Rundown: The GLTFSerializer facilitates serialization of the Unity asset model, and deserialization of GLTF assets.

  • Structure:

    • Each GLTF schemas (Buffer, Accessor, Camera, Image...) extends the basic class: GLTFChildOfRootProperty. Through this object model, each schema can have its own defined serialization/deserialization functionalities, which imitate the JSON file structure as per the GLTF specification.
    • Each schema can then be grouped under the GLTFRoot object, which represents the underlying GLTF Asset. Serializing the asset is then done by serializing the root object, which recursively serializes all individual schemas. Deserializing a GLTF asset is done similarly: instantiate a GLTFRoot, and parse the required schemas.

Tests

🏗️ Under construction. Tests are currently in a separate (private) repository due to test asset licensing reasons.

To run tests with UnityGLTF as package, you'll have to add UnityGLTF to the "testables" array in manifest.json:

"testables": [
	"org.khronos.unitygltf"
]

unitygltf's People

Contributors

adammitchell-ms avatar aidinabedi avatar amenzies avatar azakariamsft avatar botrif avatar calderarchinuk avatar d33pth0ught avatar ei2kpi-ptc avatar hybridherbst avatar jamesgk avatar jeoungjukim avatar johncopicms avatar keveleigh avatar kknsy avatar marwie avatar mhochk avatar naostranms avatar owilliamailliwo avatar pfcdorn avatar pkirsten avatar plepers avatar rferrese avatar robertlong avatar rpspicer avatar sbtron avatar sohailshafii avatar stevenvergenz avatar stjahns avatar ziedbha avatar ziugy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unitygltf's Issues

Cannot import GLB files in Unity 2020.3.11f1 (LTS) - Latest stable version

When using UnityGLTF with Unity 2020.3.11f1 LTS I can't import GLB models at compile time

Example GLB file: Avocado.glb

Reproduction steps:

  1. Create a new project using the 3D template
  2. Open the package manager and install https://github.com/prefrontalcortex/UnityGLTF.git?path=/UnityGLTF/Assets/UnityGLTF#dev
  3. Drag a GLB file into the project

Screenshot in 2019:
image

Screenshot in 2020:
image

This works using Unity 2019 LTS but not using Unity 2020 LTS

Textures missing from exported GLB when exported from WebGL Project

When exporting a GLB from runtime in a standard unity project, the GLB is exported fine with textures included.
However when exporting a GLB at runtime from a WebGL project, the GLB is missing the texture.
I get the feeling this is due to the texture being stored in the web cache rather than on the disk and it isn't being read due to the fact.
I am using SaveGLBToByteArray to export the GLB for download in the browser.

Support SRP (URP/HDRP) Material mapping on Asset Import

This is more of a feature request than a bug, but currently UnityGLTF import materials with BIRP shader, so they do not work under URP or HDRP.

Screen Shot 2022-03-14 at 18 07 57

(glb file imported with glTFast, GLTFUtility, UnityGLTF)

2 ways to address this issue:

  1. Map materials to URP and HDRP Lit shaders when they are active, or provide some compatible shader graph.
  2. Expose material replacement in the import settings.3.

Personally I prefer option (2), as it matches what Unity model importer does; but it can't hurt to also have (1).

Screen Shot 2022-03-14 at 18 02 27

Currently both glTFast and GLTFUtility offers (1) using a custom shader graph, and GLTFUtility in addition support (2).

(Hope this doesn't create too much competition between plugins, but I also don't want to switch between 3 GLTF plugins just to get work done :) )

Thx!

Could not export glb or gltf at runtime.

Hello!
I updated to version 1.18-3pre (because I want to export also animations at runtime) and the export at runtime, even if is a basic 3d model, is not working anymore. I provided a sample project (URP) and a build to debug the issue. I also tried on Standard Rendering Pipeline and it's not working either.

Test

Screenshot 2022-11-29 130645

Build: https://drive.google.com/file/d/1nxdL9-4OySHCYrqcBEet_ddQO4N9peR8/view?usp=share_link
Sample Project: https://drive.google.com/file/d/1kgk8SOyvJ1Whm0OPNCKFWoSKYvRKtrDc/view?usp=share_link

How To Reproduce:

  • Download Sample Build
  • Open the application
  • Change the export path to your desired location
  • Click Export button

Expected Result:
A File.glb should be exported at the desired path and it's size should be 35KB

Actual Result:
A File.glb should be is exported at the desired path but the size is 0KB

Notes:

  • The same issue is not reproducible in editor.
  • You can check GLTFExporter component inside sample project for the implementation logic
  • I assume it's because of the exception? But i'm using the same version on main project and i don't get any exception.

Compatibility issue across multiple glTF plugins

Drag an exported glb back into Project view and it does nothing, no warning or error, inspector is blank. What am I missing?

(I am testing interoperability between multiple glTF plugins, and this is the first time I am truly confused...)

Export GLTF embedded rather than with separated textures / bin

As per title.
Now if I export an object, it creates 3+ files: the GLTF file, the BIN file and N# files per textures.
But what if I want a single file embedding all of that which is not GLB?
Is this possible by changing the script? Would be nice to have an option to choose between "GLTF separated" and "GLTF embedded", besides the "Export GLB" (that does what I want, but in GLB format).
Thanks a lot!

Server build fails due to missing TargetCurveSet in ExporterAnimationHumanoid

In the latest dev, the following issue gets thrown:

Library/PackageCache/org.khronos.unitygltf@a88b38b642/Runtime/Scripts/SceneExporter/ExporterAnimationHumanoid.cs(14,102): error CS0246: The type or namespace name 'TargetCurveSet' could not be found (are you missing a using directive or an assembly reference?)

Looking at the code this is quite straightforward: TargetCurveSet is only defined when ANIMATION_SUPPORTED is true, which for my build (dedicated server) it isn't.
The corresponding line in ExporterAnimationHumanoid however isn't in an #if block, which then fails.

Exception when exporting in HDRP and no Materials

Hi there,

I try to export a gameobject in HDRP at runtime. First I got an exception in MaterialExtensionsConfig line 125. "profiles" was null. This happend also in the "ExportTestScene".
For some reason this doesn't happen anymore but in any case, the materials are all white.
The asset contains some custom shaders (Shader Graph) but mostly HDRP/Lit shaders. Both are white after exporting.

The validation report on gltf viewer shows two messages "UNUSED_MESH_TANGENT" and "UNSUED_OBJECT", both many times.

I'm using Unity 2022.2.0a17.

Any ideas? Thanks!

Animations are not looping anymore

Unfortunately I cannot specify the version in which this happens, but for some reason animations used to just loop. In the latest version (dev branch at this time), animations just play once and then stop.

Is this by design? If yes, do you know of a non hacky way to set the clip to loop?

Support KHR Lights Punctual Extension

@hybridherbst Thanks for merging in most of the branches I mentioned previously. Now that those easy bugfixes are merged in, might be time to go look for additional features / specifications that were added by PRs.

In particular, I have found the KHR Lights Punctual Extension to be a very useful feature to support and several people have merged in @plepers implementation.
Here is the link to create the PR: development-3...plepers:feature/KHR_lights_punctual_Serialisation

There is also this implementation of it:
CognitiveVR@76bb1cb

With lighting data supported, that should makes these exported GLTFs support most important Unity properties. Exporting lighting data would be one of the last features needed to bring up UnityGLTF to parity with FBXExporter.

There may be some other bugfixes and features from FlorentinMontiel's fork that could be useful to merge in as well.
FlorentinMonteil@c5349dd

I think that should be pretty much complete GLTF Support at least for export (I am not sure all those extensions are working for importing too).

Thoughts?

Stereo instancing shader issue

Hello,

I am currently facing an issue with the gltf shaders with the stereo instancing mode (tested on Quest PC and Hololens). The object associated with the PbrMetallicRoughness material is only visible for one eye (left).

I get the following error :

Shader error in 'GLTF/PbrMetallicRoughness': variable 'vi' used without having been completely initialized

I am using Unity 2021.3 LTS with the Oculus SDK.

Best

Edit : I did found a solution. It seems that the instance id of the VertexInput variable in "VertexColor.cginc" is not initialized. I just transfered this id from the appdata_full `structure.

WrappedVertexOutput vert_vcol(appdata_full v)
{
    // Save the color information
    WrappedVertexOutput o;
    o.color = v.color;

    // Forward this call to the default vertBase
    VertexInput vi;
    UNITY_TRANSFER_INSTANCE_ID(v, vi);
    vi.vertex = v.vertex;
    vi.normal = v.normal;
    vi.uv0 = v.texcoord;
    vi.uv1 = v.texcoord1;
#if defined(DYNAMICLIGHTMAP_ON) || defined(UNITY_PASS_META)
    vi.uv2 = v.tetcoord2;
#endif
#ifdef _TANGENT_TO_WORLD
    vi.tangent = v.tangent;
#endif
    o.innerValue = vertBase(vi);

    return o;
}

Tested on Hololens and Quest and it works

Can I export animation in windows platform?

I want to export animation in applications packaged for the Windows platform,but the functions for exporting animation are all under UnityEditor,i can not use it in windows platform.
1

IndexOutOfRangeException during Scene Export

I tried to update the GLTF Export Plugin. It did fix scenes that were broken due to empty meshes, but it broke scenes that worked perfectly before. I am trying to export GLBs of the all the scenes in AI2Thor for reproducibility.

IndexOutOfRangeException: Index was outside the bounds of the array.
UnityGLTF.GLTFSceneExporter.ExportPrimitive (UnityEngine.GameObject gameObject, GLTF.Schema.GLTFMesh mesh) (at Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs:1014)
UnityGLTF.GLTFSceneExporter.ExportMesh (System.String name, UnityEngine.GameObject[] primitives) (at Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs:947)
UnityGLTF.GLTFSceneExporter.ExportNode (UnityEngine.Transform nodeTransform) (at Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs:662)
UnityGLTF.GLTFSceneExporter.ExportNode (UnityEngine.Transform nodeTransform) (at Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs:687)
UnityGLTF.GLTFSceneExporter.ExportNode (UnityEngine.Transform nodeTransform) (at Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs:687)
UnityGLTF.GLTFSceneExporter.ExportScene (System.String name, UnityEngine.Transform[] rootObjTransforms) (at Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs:589)
UnityGLTF.GLTFSceneExporter.SaveGLBToStream (System.IO.Stream stream, System.String sceneName) (at Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs:259)
UnityGLTF.GLTFSceneExporter.SaveGLB (System.String path, System.String fileName) (at Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs:216)
GLTFExportMenu.exportSceneGLB (System.String sceneName, 

Skinned Mesh baking not working properly

Hello,
We are using your plugin for exporting avatar into glb format. We want skinned meshes to be baked when we export glb file, as we have some expressions applied via blendshapes & we want those expressions to be baked while exporting & we don't want to expose all the blendshapes we have, in exported glb. So we are using GLTFSettings as shown in following image.
BakeSkinnedMeshErrors
Let us know if we are missing something over here. It would be very helpful if someone from your team can help us out with this issue.

Provide a more convenient (slimmer) package download option

I am sorry to put more work on you, but I find UnityGLTF installation to be quite slow due to the many samples it appear to include, the actual library itself is around 2MB but my git-remote-https seems to be downloading hundreds of MB of samples.

This is absolutely due to the how bad our local ISP is, but we hope to see a way to install UnityGLTF without samples.

(note: I am not sure if installing via https://github.com/prefrontalcortex/UnityGLTF.git?path=/UnityGLTF/Assets/UnityGLTF will exclude all other directories during git remote fetch, does it work as intended?)

Unable to use UnityGLTF in 2022.2.3f1 - Calls to "AssetDatabase.Refresh" are restricted during asset importing.

I get these 3 errors always on import:

Calls to "AssetDatabase.Refresh" are restricted during asset importing. 
UnityEditor.AssetDatabase:Refresh ()
UnityGLTF.GLTFImporter:OnImportAsset (UnityEditor.AssetImporters.AssetImportContext) (at ./Library/PackageCache/org.khronos.unitygltf@dd0b8b2981/Editor/Scripts/GLTFImporter.cs:259)
UnityEditor.AssetImporters.ScriptedImporter:GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext)

Calls to "AssetDatabase.SaveAssets" are restricted during asset importing. 
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityGLTF.GLTFImporter:OnImportAsset (UnityEditor.AssetImporters.AssetImportContext) (at ./Library/PackageCache/org.khronos.unitygltf@dd0b8b2981/Editor/Scripts/GLTFImporter.cs:270)
UnityEditor.AssetImporters.ScriptedImporter:GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext)

Calls to "AssetDatabase.Refresh" are restricted during asset importing. 
UnityEditor.AssetDatabase:Refresh ()
UnityGLTF.GLTFImporter:OnImportAsset (UnityEditor.AssetImporters.AssetImportContext) (at ./Library/PackageCache/org.khronos.unitygltf@dd0b8b2981/Editor/Scripts/GLTFImporter.cs:271)
UnityEditor.AssetImporters.ScriptedImporter:GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext)

Tested in a new empty 2022.2.3f1 project using URP template, added UnityGLTF via git url in packman, tried to import this test model:

Scooter-Test-v7.glb.zip

Repro project:

Repro1.zip

End keyframes get trimmed on export

Using Needle Engine and Needle Exporter with UnityGLTF, this issue happens - Keyframes at the end of an animation get trimmed in some cases. Can be fixed manually by duplicating the end keyframes but ideally they shouldn't be cut off on export

This set of keyframes at the end gets cut off
image

Which results in the inner panel on this model not reaching the end keyframe position (see the gap between the corner frames and the inner panel in the screenshot)
image

Test model:
PANEL1-ANI.zip

No support for vertex color alpha

The current shader setup makes it difficult to add proper support for vertex color alpha.
Some engines have it (e.g. Babylon), others don't (e.g. three currently not).

Readme / Docs / Samples

Readme is missing:

  • code samples for import / export extensions
  • code sample for GLTFRecorder use
  • screenshots of PBRGraph
  • screenshots of rough refraction
  • screenshot of timeline recording
  • screenshot for animation pointer capabilities

Some basic sample scenes should help to show off UnityGltf features.

  • PBRGraph / UnlitGraph
  • material extensions
  • rough refraction
  • editor export
  • runtime export
  • timeline recording
  • runtime GLTFRecorder
  • export callbacks (e.g. material variants)
  • animation pointer

the scripts can not find namespace

I have already compile GLTFSerialization\GLTFSerialization.sln,but scripts also can not find namespace,I want to Run-time import of glTF 2.0 files,how can i fix it,please.
1
2

Namespace not found because .asmdef is not set to auto referenced.

When trying to use the package through code, the UnityGLTF namespace can not be found from application code. This is because the UnityGLTFScripts.asmdef has auto referenced set to false. I believe that to fix this properly, I would have to go through the significant effort of using .asmdefs for my own code. I patched it instead by changing the file in a text editor and setting "autoReferenced": true. This is of course not a good solution, because I can only edit cached file in the Library folder.

Are we really supposed to use .asmdefs for our own code to be able to use this plugin, or can you just set auto referenced to true in the repo?

export result is wrong

Describe the bug
Export result is wrong. First import a glb format asset with glfFast plugin into unity and add it to the scene. Then export the select game object with UnityGLTF. The exported glb asset is different from the original one.

Files
DamagedHelmet.zip

To Reproduce
Steps to reproduce the behavior:

  1. add the glb asset into unity
  2. drag the model to the scene
  3. select the game object, click menu-> Assets -> UnityGLTF -> Export selected as GLB
  4. add the exported glb file into asset folder, see the result.

Expected behavior
The exported file is exactly same with original one.

Screenshots
Original
Snipaste_2022-04-21_21-33-12
Snipaste_2022-04-21_21-33-35
Snipaste_2022-04-21_21-35-43
Snipaste_2022-04-21_23-47-03

Exported
Snipaste_2022-04-21_23-45-37
Snipaste_2022-04-21_23-51-15
Snipaste_2022-04-22_00-03-11
Snipaste_2022-04-21_23-47-19

Two textures has lost when exported and some shader keywords of the material were lost. If add the two texture to the material and the EMISSION keyword, the result is same.

Desktop (please complete the following information):

  • UnityGLTF 1.5.0-pre
  • glTFast 4.6.0 (used to import asset)
  • Unity 2020.3.30f1c1
  • Universal Render Pipeline 10.8.1
  • Windows Editor

Exporting textures with dot/period "." in their names results in invalid GLTF output

Version:
[1.0.4-preview.35] - 2022-03-11

Issue:
When trying to export a mesh that contains a material with a texture map that contains a "." in the file name (i.e. lambert1.001_specularGlossiness.png), the result is that the exported texture file is created with parts of its name missing, but the GLTF image references full name, thus leaving an invalid GLTF file since the reference is wrong.

Expected Result:
The file name should handle "." in the texture names and should be correctly referenced in the GLTF json output.

Notes:

  • The mesh was first imported by the GLTF importer in this library (i.e. GLTFSceneImporter)
  • I am using the GLTFSceneExporter.SaveGLTFandBin() method
  • Current workaround is to change the = Path.ChangeExtension(imagePath, ".png"); to = imagePath + ".png"; in GLTFSceneExporter.GetImageOutputPath() method

Example Output:
Note that the image name fields are correct, but the uri fields are incorrect.

"images": [
    {
      "uri": "lambert1_diffuse.png",
      "name": "lambert1_diffuse"
    },
    {
      "uri": "lambert1_specularGlossiness.png",
      "name": "lambert1_specularGlossiness"
    },
    {
      "uri": "lambert1.png",
      "name": "lambert1.001_specularGlossiness"
    },
    {
      "uri": "lambert1.png",
      "name": "lambert1.004_specularGlossiness"
    }
  ],

Runtime Export of Metallic map causes discrepancy between JPG file and PNG reference in GLTF

Version:
[1.0.4-preview.35] - 2022-03-11

Issue:
When trying to export a mesh that contains a metallic map, if the "Use Texture File Type Heuristic" is checked in the Project Settings, the result is that the JPG file is created but the GLTF image references a PNG file of the same name.

Expected Result:
The JPG file should be correctly referenced in the GLTF json output.

Notes:

  • I have attached the mesh that is failing
  • The mesh was first imported by the GLTF importer in this library (i.e. GLTFSceneImporter)
  • I am using the GLTFSceneExporter.SaveGLTFandBin() method
  • Current workaround is to uncheck "Use Texture File Type Heuristic" in the Project Settings

Luminaris_Test.zip

ShaderNotFoundException

Hello, I'm getting an issue when loading a project that uses imported gltfs/glbs for the first time.
The full error is as following:

ShaderNotFoundException: UnityGLTF/PBRGraph not found. Did you forget to add it to the build?
UnityGLTF.PBRGraphMap..ctor (System.String shaderName) (at Library/PackageCache/org.khronos.unitygltf@a72508a846/Runtime/Scripts/UniformMaps/PBRGraphMap.cs:33)
UnityGLTF.PBRGraphMap..ctor () (at Library/PackageCache/org.khronos.unitygltf@a72508a846/Runtime/Scripts/UniformMaps/PBRGraphMap.cs:11)
UnityGLTF.GLTFSceneImporter.ConstructMaterial (GLTF.Schema.GLTFMaterial def, System.Int32 materialIndex) (at Library/PackageCache/org.khronos.unitygltf@a72508a846/Runtime/Scripts/SceneImporter/ImporterMaterials.cs:58)
UnityGLTF.GLTFSceneImporter.ConstructMesh (GLTF.Schema.GLTFMesh mesh, System.Int32 meshIndex, System.Threading.CancellationToken cancellationToken) (at Library/PackageCache/org.khronos.unitygltf@a72508a846/Runtime/Scripts/SceneImporter/ImporterMeshes.cs:85)
UnityGLTF.GLTFSceneImporter.ConstructNode (GLTF.Schema.Node node, System.Int32 nodeIndex, System.Threading.CancellationToken cancellationToken) (at Library/PackageCache/org.khronos.unitygltf@a72508a846/Runtime/Scripts/GLTFSceneImporter.cs:729)
UnityGLTF.GLTFSceneImporter.GetNode (System.Int32 nodeId, System.Threading.CancellationToken cancellationToken) (at Library/PackageCache/org.khronos.unitygltf@a72508a846/Runtime/Scripts/GLTFSceneImporter.cs:642)
UnityGLTF.GLTFSceneImporter.ConstructScene (GLTF.Schema.GLTFScene scene, System.Boolean showSceneObj, System.Threading.CancellationToken cancellationToken) (at Library/PackageCache/org.khronos.unitygltf@a72508a846/Runtime/Scripts/GLTFSceneImporter.cs:965)
UnityGLTF.GLTFSceneImporter._LoadScene (System.Int32 sceneIndex, System.Boolean showSceneObj, System.Threading.CancellationToken cancellationToken) (at Library/PackageCache/org.khronos.unitygltf@a72508a846/Runtime/Scripts/GLTFSceneImporter.cs:528)
UnityGLTF.GLTFSceneImporter.LoadSceneAsync (System.Int32 sceneIndex, System.Boolean showSceneObj, System.Action`2[T1,T2] onLoadComplete, System.Threading.CancellationToken cancellationToken, System.IProgress`1[T] progress) (at Library/PackageCache/org.khronos.unitygltf@a72508a846/Runtime/Scripts/GLTFSceneImporter.cs:366)
Rethrow as AggregateException: One or more errors occurred. (UnityGLTF/PBRGraph not found. Did you forget to add it to the build?)
System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
System.Threading.Tasks.Task.Wait () (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
UnityGLTF.GLTFImporter.CreateGLTFScene (System.String projectFilePath) (at Library/PackageCache/org.khronos.unitygltf@a72508a846/Editor/Scripts/GLTFImporter.cs:423)
UnityGLTF.GLTFImporter.OnImportAsset (UnityEditor.AssetImporters.AssetImportContext ctx) (at Library/PackageCache/org.khronos.unitygltf@a72508a846/Editor/Scripts/GLTFImporter.cs:365)
UnityEditor.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext ctx) (at <1f0be198f5164d2489de92f22c998266>:0)

I thought the recent commits that always ensured the shaders are loaded by the asset database fixes this, but unfortunately it did not.
I'm using Unity 2021.3.5 with URP and the latest dev branch here.

Doing a reimport all (or just reimporting the broken meshes) fixes it, but every time someone clones a fresh project, the error pops up.

Unable to install package via url

I get this error trying to import this into projects in Unity 2022.2.4f1 using the instructions with Packman to install with 'https://github.com/prefrontalcortex/UnityGLTF.git?path=/UnityGLTF/Assets/UnityGLTF'

Could there be an installation package using Needle installer like the other repros that might fix this?

This is the error:

[Package Manager Window] Error adding package: https://github.com/prefrontalcortex/UnityGLTF.git?path=/UnityGLTF/Assets/UnityGLTF.
Unable to add package [https://github.com/prefrontalcortex/UnityGLTF.git?path=/UnityGLTF/Assets/UnityGLTF]:
  Could not clone [https://github.com/prefrontalcortex/UnityGLTF.git]. Make sure [HEAD] is a valid branch name, tag or full commit hash on the remote registry.
UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.