khronosgroup / unitygltf Goto Github PK
View Code? Open in Web Editor NEWRuntime glTF 2.0 Loader for Unity3D
License: MIT License
Runtime glTF 2.0 Loader for Unity3D
License: MIT License
Allow extentions to be included as defined by Microsoft
https://github.com/sbtron/glTF/tree/MSFT_lod/extensions/Vendor/MSFT_texture_dds
https://github.com/sbtron/glTF/tree/MSFT_lod/extensions/Vendor/MSFT_packing_occlusionRoughnessMetallic
https://github.com/sbtron/glTF/tree/MSFT_lod/extensions/Vendor/MSFT_lod
The Khronos Group has a call out for open-source projects that implement the spec: KhronosGroup/glTF#867. You should consider submitting this project, you might get more help.
I am trying to open the master project in Unity 2017.2.0b11 and I am getting error with the UnityStandardCore.cginc file missing a MetalRough reference.
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.
Anthony
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.
Just curious why there's an external dependency to Newtonsoft.Json.dll
when there's a built in Json Utility in Unity?
After running a model through the GLTFExporter the Khronos GLTF Validator gives the following error:
Indices accessor format must be one of [{SCALAR, UNSIGNED_BYTE}, {SCALAR, UNSIGNED_SHORT}, {SCALAR, UNSIGNED_INT}]
. Got {SCALAR, SHORT}
.
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!
Currently #43 can't be fully tested because the sample models are invalid. Many animations are split into multiple channels and need to be merged.
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?
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)
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.
The Unity compiler generates warnings for GLTFComponent.cs
. These warnings should be fixed or explicitly suppressed with compiler directives.
Since the switch to manual JSON parsing, UnityGLTF loader does not support parsing additional properties on every object. Even though the spec says they should be allowed for future 2.x version compatibility.
Task to track creation of a Unity Package so its easier to consume.
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!
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
There is an issue in the library where a file that is deserialized, when reserialized out has round off error from double -> float.
We should update the README with the project goals, 1.0 projected release schedule, and 1.0 goals.
Currently the library works with Unity 5.6. Should we upgrade it to 2017.1?
Anyone have a requirement to support Unity 5.6 as min version?
Create a test that loads all models in a folder. Eventually this loader can be updated to pull in models from - https://github.com/bghgary/glTF-Asset-Generator/tree/generated-assets
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)
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.
When its ready, it'd be nice to include a downloadable .unitypackage in the releases section.
We should add a code of conduct to foster a positive and constructive community.
The spec lets users specify filtering and wrap settings, which are currently unimplemented in UnityGLTF. They correspond roughly to filterMode
and wrap
, but not exactly. Need to determine impact of these.
Texture2D.LoadImage is slow, can only be ran on the main thread, and blocks the renderer while loading. This is a dealbreaker for a lot of projects, especially those involving VR as dropping frames causes motion sickness.
We should add a guide for new contributors that explains our style guide, development setup, testing, and PR submission process.
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.
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)
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.
Transparent materials are defined by:
The alpha channel in material.pbrMetallicRoughness.baseColorTexture
And the alpha value in material.pbrMetallicRoughness.baseColorFactor
The opacity input needs to be hooked up in GLTFMetallicRoughness.shader. Transparency is tricky and my first attempt failed. I could probably use some help with this one.
Work item to track turning on travis build
Cameras are currently deserialized into the GLTFRoot object, but not translated into a Unity Camera. There should likely be settings to turn off creating Unity Camera objects, set a camera as the main camera, etc.
GLTF 2.0 Animation Spec
https://github.com/KhronosGroup/glTF/tree/2.0/specification/2.0#cameras
Unity Camera Component
https://docs.unity3d.com/ScriptReference/Camera.html
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);
This is the only documentation I can find on this so far: https://github.com/sbtron/glTF/tree/KHRpbrSpecGloss/extensions/Khronos/KHR_materials_pbrSpecularGlossiness#additional-maps
I'd be nice to support this workflow, but I'd like to hold off until it's finalized.
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.
Current one doesn't work on Android and was stripped out.
Need to figure out a better solution.
Notes from our meeting with @MSblgross, @stevenvergenz, and Ken Wolfe.
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.
Currently the Scifi Helmet sample model doesn't render because it has too many vertices. I wouldn't recommend procedural generation of models with over 65000 vertices, but we should support this.
Animations are currently deserialized into the GLTFRoot object, but not translated into a Unity Animation.
GLTF 2.0 Animation Spec
https://github.com/KhronosGroup/glTF/tree/2.0/specification/2.0#animations
Unity Animation Component
https://docs.unity3d.com/ScriptReference/Animation.html
The docs for sparse accessors can be found here.
Proposed 2.0 updates to the extension found here. Should support:
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
The Windows 10 Creators Update Mixed Reality Portal has requirements that glTF be used and that textures need to be in DDS format.
Adding this to the project will allow the developer to be able to export and compile Unity objects that are suitable for use in the MR portal.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.