Code Monkey home page Code Monkey 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)
  • MSFT_lods (level of detail)

Import only

Export only

  • KHR_animation_pointer
  • 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  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

unitygltf's Issues

Fix Animation Channel Parsing

The AnimatedCube integration test currently fails with the following exception:

Exception: Animation channel must be an object.
GLTF.GLTFAnimationChannel.Deserialize (GLTF.GLTFRoot root, Newtonsoft.Json.JsonTextReader reader) (at Assets/GLTF/Scripts/Schema/GLTFAnimationChannel.cs:28)
GLTF.GLTFAnimation+<Deserialize>c__AnonStoreyA.<>m__3 () (at Assets/GLTF/Scripts/Schema/GLTFAnimation.cs:36)
GLTF.JsonExtensions.JsonTextReaderExtensions.ReadList[GLTFAnimationChannel] (Newtonsoft.Json.JsonTextReader reader, System.Func`1 deserializerFunc) (at Assets/GLTF/Scripts/GLTFJsonExtensions.cs:55)
GLTF.GLTFAnimation.Deserialize (GLTF.GLTFRoot root, Newtonsoft.Json.JsonTextReader reader) (at Assets/GLTF/Scripts/Schema/GLTFAnimation.cs:36)
GLTF.GLTFRoot+<Deserialize>c__AnonStoreyE.<>m__B () (at Assets/GLTF/Scripts/Schema/GLTFRoot.cs:143)
GLTF.JsonExtensions.JsonTextReaderExtensions.ReadList[GLTFAnimation] (Newtonsoft.Json.JsonTextReader reader, System.Func`1 deserializerFunc) (at Assets/GLTF/Scripts/GLTFJsonExtensions.cs:55)
GLTF.GLTFRoot.Deserialize (Newtonsoft.Json.JsonTextReader reader) (at Assets/GLTF/Scripts/Schema/GLTFRoot.cs:143)
GLTF.GLTFParser.ParseString (System.String gltfContent) (at Assets/GLTF/Scripts/GLTFParser.cs:81)
GLTF.GLTFParser.ParseBinary (System.Byte[] gltfBinary, System.Byte[]& glbBuffer) (at Assets/GLTF/Scripts/GLTFParser.cs:75)
GLTF.GLTFLoader.ParseGLTF (System.Byte[] gltfData) (at Assets/GLTF/Scripts/GLTFLoader.cs:95)
GLTF.GLTFLoader+<Load>c__Iterator3.<>m__1 () (at Assets/GLTF/Scripts/GLTFLoader.cs:49)
GLTF.AsyncAction+<RunOnWorkerThread>c__Iterator0.<>m__0 (System.Object _) (at Assets/GLTF/Scripts/AsyncAction.cs:20)

Tangent vector problem

Hi,

I'm one of developers of glTF pipeline for CAD / Unity integration. I've used UnityGLTF project as a reference code for our Unity importer which generates meshes, materials, prefabs etc during glTF import. I found one problematic place in your code / math.

The problem is that your tangent vector looks incorrect. Code first (part of Accessor.cs):

	public Vector3[] AsVertexArray(ref NumericArray contents, byte[] bufferData)
	{
		if (contents.AsVertices != null) return contents.AsVertices;

		var arr = AsVector3Array(ref contents, bufferData);
		for (var i = 0; i < arr.Length; i++)
		{
			arr[i].Z *= -1;
		}
	...
	public Vector3[] AsNormalArray(ref NumericArray contents, byte[] bufferData)
	{
		if (contents.AsNormals != null) return contents.AsNormals;

		var arr = AsVector3Array(ref contents, bufferData);
		for (var i = 0; i < arr.Length; i++)
		{
			arr[i].Z *= -1;
		}
	...
	public Vector4[] AsTangentArray(ref NumericArray contents, byte[] bufferData)
	{
		if (contents.AsTangents != null) return contents.AsTangents;

		var arr = AsVector4Array(ref contents, bufferData);
		for (var i = 0; i < arr.Length; i++)
		{
			arr[i].W *= -1;
		}
	...

Here you may see that you're flipping Z coordinate for position and normal vectors, but not for tangent. If tangent vector is supposed to be orthogonal to normal, this orthogonality will be lost after this math. Inverting tangent's W flips handedness of the coordinate system - inverts binormal vector, but does nothing with tangent (vec3) itself. I think this is wrong.

I used special script which visualizes normal and tangent vectors (I can provide one for debugging purposes, but it works only in editor, not at runtime). I've played with all models from Kronos's glTF samples repository - with those who have tangents. Tangent vectors are good with some meshes, and bad with others. In fact, only models which has

"generator": "glTF Tools for Unity"

are "good" after importing with your math, other models are bad. I.e. "good" are models generated with your code.

I've reviewed glTF specification for tangent space and didn't find any reference that tangent's Z should be negated, i.e. glTF uses "classic" orthogonal tangent space. Could you please review your code for possible problems?

Thanks,
Konstantin

Provide UnityWebRequest Headers options and Post method

Hello there,

First of all, thanks so much for this loader, it is a great contribution!

Can you provide a HTTP headers dictionary as argumento to the Loader object?

I need to provide authentication token to the Web Server:

`

var www = UnityWebRequest.Get(_gltfUrl);

 foreach(KeyValuePair<string, string> entry in headersDictionary)
 {
    www.SetRequestHeader(entry.Key,entry.Value);
 }

`

Also, can be there an option to use Post instead of Get?

var www = UnityWebRequest.Post(_gltfUrl, postData);

Thanks in advanced!

Runtime texture color space settings

glTF's PBR material definition specifies the color spaces that its various textures should be in: sRGB for baseColor, linear for metallicTexture, etc. However, Unity's DownloadHandlerTexture class used by UnityWebRequest always assumes the texture is sRGB, and does not provide an option to specify. So an alternative loader/handler will probably need to be created to properly import these textures.

^ @tparisi

Update README

We should update the README with the project goals, 1.0 projected release schedule, and 1.0 goals.

Improve JSON Deserialization Performance

Currently JSON deserialization is a bit slow and not concurrent. It blocks the renderer and causes dropped frames. I'd like to move it to another thread or at least make it concurrent. There's also likely a lot of room for improvement in overall parsing speed.

Problem loading examples Scenes: ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

All works in Unity 2017.01f3 for Windows 10 x64.

Unity Version:
Unity 2017.01f3

Operating System:
OSX ElCapitan
10.11.6

Commit repo used:
06c9988

Unity Error:
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: startIndex
System.BitConverter.PutBytes (System.Byte* dst, System.Byte[] src, Int32 start_index, Int32 count) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/BitConverter.cs:176)
System.BitConverter.ToUInt32 (System.Byte[] value, Int32 startIndex) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/BitConverter.cs:257)
GLTF.GLTFParser.ParseBinary (System.Byte[] gltfBinary, System.Byte[]& glbBuffer) (at Assets/GLTF/Scripts/GLTFParser.cs:24)
GLTF.GLTFLoader.ParseGLTF (System.Byte[] gltfData) (at Assets/GLTF/Scripts/GLTFLoader.cs:132)
GLTF.GLTFLoader+c__Iterator0+c__AnonStorey3.<>m__0 () (at Assets/GLTF/Scripts/GLTFLoader.cs:71)
GLTF.AsyncAction+c__Iterator0+c__AnonStorey2.<>m__0 (System.Object _) (at Assets/GLTF/Scripts/AsyncAction.cs:20)

Interpretation of bytestride parameters

I believe there may be a mistake in how bytestride is interpreted inside Accessors. The reference:

https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#floating-point-data

implies (it doesn't appear to be explicit) that the bytestride is the total stride between values, not the unused bytes.

In Accesor.cs:

https://github.com/AltspaceVR/UnityGLTF/blob/master/Assets/GLTF/Scripts/Schema/Accessor.cs

It appears that if ByteStride is set, then it is added onto a calculation of the component width. (E.G. line 312).

Most densely packed objects don't set byteStride, but collada2gltf does, see attached object. In this case the bytestride is only indicating that the data is tightly packed.

test2.zip

Anthony

Accessor Flips Z Components in GLTFSerialization

The accessor currently flips z component when parsing it out of the binary data. This is needed for Unity due to differing coordinate space. This should be done in the UnityGLTF layer and not GLTFSerialization layer.

How to export skin animation to gltf model?

Sorry, My English is so bad.

I drag the "dude.fbx " that it is a  model with the mesh skin animation in unity and export it.  the tools can't export the skin animation to gltf model.

Please help me. thanks!

Publish to Unity Asset Store

I'd like to make this package as easy as possible for people to include in their projects. I'll publish it for free as soon as it's ready.

Building for Mac?

I realize this project is pre-1.0 so you may not be expecting people to be trying to build it, but I tried anyway.

I tried the steps described in the readme:
Open GLTFSerialization\GLTFSerialization.sln and compile for release. This will put the binaries in UnityGLTF\Assets\UnityGLTF\Plugins

From within both Rider and Monodevelop without success.

In monodevelop I get a project error with GLTFSerialization "Unknown ToolsVersion 15.0" and GLTFSerializationUWP failed to load.

In Rider GLTFSerializationUWP failed to load.
MSBuild targets were not found: Make sure that all SDKs required for projects in this solution are installed, or specify a different MSBuild version in settings.

Just a heads up since I'm guessing you have larger fish to fry.

Thanks.

Integration Tests Not Working

The integration tests are not running properly. I am on version 2017.1.0f3 of Unity. The error I get is:

NullReferenceException: Object reference not set to an instance of an object
UnityTest.GuiHelper.GetConsoleErrorPause () (at Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/GuiHelper.cs:13)
UnityTest.IntegrationTestsRunnerWindow+RunnerCallback..ctor (UnityTest.IntegrationTestsRunnerWindow window) (at Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/IntegrationTestsRunnerWindow.cs:499)
UnityTest.IntegrationTestsRunnerWindow.Update () (at Assets/UnityTestTools/IntegrationTestsFramework/TestRunner/Editor/IntegrationTestsRunnerWindow.cs:229)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:305)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:313)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/reflection/methodbase.cs:229)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:272)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:265)
UnityEditor.HostView.SendUpdate () (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:341)
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:109)

Error when playing a scene that tried to load a binary

Works fine for non-binary glTF, however all of the binary scenes print this error:

ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
System.Buffer.BlockCopy (System.Array src, Int32 srcOffset, System.Array dst, Int32 dstOffset, Int32 count) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Buffer.cs:112)
GLTF.GLTFLoader+<LoadImage>c__Iterator4.MoveNext () (at Assets/GLTF/Scripts/GLTFLoader.cs:574)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

Am I doing something wrong?

Putting 'extras' property into a JSON block early-exits parsing

The call to JToken.ReadFrom leaves the Value of the reader pointing to the next property, rather than an endObject - so when the caller attempts the next loop iteration (such as in Asset.cs::Deserialize) it will skip the next property and leave the reader in a weird state, thus skipping reading the rest of the glTF file.

Sample file:

{
	"asset": {
		"generator": "Unity 5.6",
		"extras": {
			"exporterVersion" : "2.1.1"
		},
		"version": "2.0"
	}
}

The version property will never be read.

Add Contributor Guide

We should add a guide for new contributors that explains our style guide, development setup, testing, and PR submission process.

Project Architecture

Notes from our meeting with @MSblgross, @stevenvergenz, and Ken Wolfe.

  • Blake will be splitting his pull request into separate parts so that it is easier to review.
  • glTF Serialization/Deserialization will be split out into a separate project within this repo and moved to a separate Khronos repo when ready.
  • We'll be keeping the "UnityGLTF" name for the Unity project and using "GLTFSerialization" for the external serialization/deserialization project.
    • Note: Capitalization of GLTF will be kept this way for the sake of C#'s Pascal case for class names.
    • In the future we may try to generate the serialization code from the glTF JSON Schema, but there is additional work needed to add manual deserialization using JSON.NET.
  • Once Blake's architecture changes have landed we'll be breaking the importer/exporter code into classes for importing/exporting specific sets of Unity components.
    • An example would be MeshImporter which would generate Unity Mesh objects, cache them, and add the correct components (MeshFilter and MeshRenderer) to a node.
    • The importer/exporter will hold fields for the component importer/exporters to be used and can be extended as necessary.
    • I'll be working on a PR for these changes and have more details to discuss with the community soon.
  • Once the architecture changes are made the focus will be on supporting the full glTF 2.0 spec for runtime import.
    • @PlutoVR has been working on animation support, we'd really like to work with you to get that merged into the repository. Let us know what we can do to help.

If there are other changes you'd like to see to the architecture of the project please let us know. Ideally after making these large architectural changes we can get to a versioned, pre-alpha release and a more stable place for anyone trying to use UnityGLTF.

Split GLTF folder into submodule

It would be much easier to include this in your project and keep it up to date if there were a separate repository for the package itself as well as this repo for the project, tests, etc.

Add Code of Conduct

We should add a code of conduct to foster a positive and constructive community.

GLTF external assets URI needs to be enconded

Hello,

All GLTF Uri must be enconded otherwise it won't find the correct path in the webserver.

For example:
model.gltf
model.bin
textures/model's texture.jpeg

The loader will fail to find 'model's texture.jpeg'

The GLTFLoader.cs file must enconde al URIs:

For example:
image.Uri = WWW.EscapeURL (image.Uri);

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.