Comments (4)
I have the same issue.
from gltfutility.
Code:
Importer.ImportGLTFAsync(path, new ImportSettings(),
model =>
{
onModelLoaded?.Invoke(model);
});Model:
https://poly.google.com/view/eu-5IFEOh6CError:
JsonReaderException: Unexpected character encountered while parsing value: g. Path '', line 0, position 0.
Newtonsoft.Json.JsonTextReader.ParseValue () (at <97722d3abc9f4cf69f9e21e6770081b3>:0)
Newtonsoft.Json.JsonTextReader.Read () (at <97722d3abc9f4cf69f9e21e6770081b3>:0)
Newtonsoft.Json.JsonReader.ReadAndMoveToContent () (at <97722d3abc9f4cf69f9e21e6770081b3>:0)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonContract contract, System.Boolean hasConverter) (at <97722d3abc9f4cf69f9e21e6770081b3>:0)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) (at <97722d3abc9f4cf69f9e21e6770081b3>:0)
Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) (at <97722d3abc9f4cf69f9e21e6770081b3>:0)
Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) (at <97722d3abc9f4cf69f9e21e6770081b3>:0)
Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) (at <97722d3abc9f4cf69f9e21e6770081b3>:0)
Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) (at <97722d3abc9f4cf69f9e21e6770081b3>:0)
Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) (at <97722d3abc9f4cf69f9e21e6770081b3>:0)
Siccity.GLTFUtility.Importer+<>c__DisplayClass9_0.b__0 () (at Assets/GLTFUtility/Scripts/Importer.cs:154)
System.Threading.Tasks.Task1[TResult].InnerInvoke () (at <df7127ba07dc446d9f5831a0ec7b1d63>:0) System.Threading.Tasks.Task.Execute () (at <df7127ba07dc446d9f5831a0ec7b1d63>:0) Rethrow as AggregateException: One or more errors occurred. System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) (at <df7127ba07dc446d9f5831a0ec7b1d63>:0) System.Threading.Tasks.Task
1[TResult].GetResultCore (System.Boolean waitCompletionNotification) (at :0)
System.Threading.Tasks.Task`1[TResult].get_Result () (at :0)
Siccity.GLTFUtility.Importer+d__9.MoveNext () (at Assets/GLTFUtility/Scripts/Importer.cs:157)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
For all my models I get the same error.
Tried to get content of json string from LoadAsync method it is showing 'glTF' only, no json
from gltfutility.
Found it! 😃
Add this to Importer.cs:
public static void ImportGLBAsync(string filepath, ImportSettings importSettings, Action<GameObject> onFinished)
{
byte[] bytes = File.ReadAllBytes(filepath);
// 12 byte header
// 0-4 - magic = "glTF"
// 4-8 - version = 2
// 8-12 - length = total length of glb, including Header and all Chunks, in bytes.
string magic = Encoding.ASCII.GetString(bytes.SubArray(0, 4));
if (magic != "glTF")
{
Debug.LogError("File at " + filepath + " does not look like a .glb file");
onFinished(null);
}
uint version = System.BitConverter.ToUInt32(bytes, 4);
if (version != 2)
{
Debug.LogError("Importer does not support gltf version " + version);
onFinished(null);
}
// What do we even need the length for.
//uint length = System.BitConverter.ToUInt32(bytes, 8);
// Chunk 0 (json)
uint chunkLength = System.BitConverter.ToUInt32(bytes, 12);
// This prints out JSON. So predictable.
//string chunkType = Encoding.ASCII.GetString(bytes.SubArray(16, 4));
string json = Encoding.ASCII.GetString(bytes.SubArray(20, (int)chunkLength));
// Parse json
LoadAsync(json, filepath, importSettings, onFinished).RunCoroutine();
}
Then use to load GLB on runtime:
using Siccity.GLTFUtility;
void ImportGLBAsync(string filepath)
{
Importer.ImportGLBAsync(filepath, new ImportSettings(), OnFinishAsync);
}
void OnFinishAsync(GameObject result)
{
Debug.Log("Finished importing " + result.name);
}
from gltfutility.
Async GLB import is now officially supported
from gltfutility.
Related Issues (20)
- When trying to load glb file in editor, application hangs on Application.EnterPlayMode HOT 1
- Glb model fails to load on android HOT 1
- Async import in editor not suported
- No way to set individual loop settings for animation
- How can i add and Play animation file in runtime
- Not possible to update shader's materials HOT 2
- InvalidOperationException
- Error while downloading model from server at runtime in webgl
- Support for intensity of emission
- Not work at Unity2019.4.28f1 URP
- Animation doesn't work on android!
- GLTFImage.cs ToTexture2D() ERROR: Cannot connect to destination host When Importing
- Model not importing on android HOT 1
- ImportSettings.materials does nothing?
- README change
- Play animation on iphone not working
- Mesh tearing at a distance
- Build error
- error CS0117: 'ImportSettings' does not contain a definition for 'useLegacyClips'
- Plugin usage documentation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gltfutility.