KhronosGroup / UnityGLTF

Runtime glTF 2.0 Loader for Unity3D
MIT License
1.77k stars 483 forks source link

Get the json from the gltf #743

Open MarcusGT076 opened 1 month ago

MarcusGT076 commented 1 month ago

Hello there,

i want to access the complete json from the gltf file. I tried to get the root, but he is not displaying the whole json from the gltf file ? This is what i see when i access the root of the GLTFSsceneImporter.

{ "ExtensionsUsed": [ "KHR_draco_mesh_compression", "KHR_materials_emissive_strength" ], "ExtensionsRequired": [ "KHR_draco_mesh_compression" ], "IsGLB": false }

I want to send the whole structure of the gltf to javascript as a json with all inside. How is this possible to get those data that i need ?

Cheers :)

pfcDorn commented 2 weeks ago

hey, when the file is a gltf (not glb), then you can just send the whole gltf file. It's all json. Or do i miss here something?

MarcusGT076 commented 2 weeks ago

hey, but in the loading process from youre plugin you dispose the complete result from the json ? I have a workaround to load the json file second time and send it to javascript. But than i have to load it twice. First to send the json to javascript and second time with youre plugin. So it would be cool maybe that you have a flag that you can set that a copy from the json will be kept ?

pfcDorn commented 2 weeks ago

Are you downloading the glb?

MarcusGT076 commented 2 weeks ago

Nope i load it with a gltf. I mean i can access the root from the plugin but all i get in return its from the first article. I did not get back the whole gltf json. So i mean the workaround its functioning but i have to load the GLTF Json twice. First for myself to send it to Javascript and than over your plugin with LoadScene.

pfcDorn commented 2 weeks ago

I don't think it would make sense to expose the loaded json string. When you need them, just load the json string with File.ReadAllText(gtlfFilePath). To read the file twice should not be a problem in any case. You just read the string without any deserialisation and send it to the javascript.

hybridherbst commented 2 weeks ago

@MarcusGT076 can you say a bit more what your goal is? Do you just want to display the JSON data somewhere else, both for files loaded as glTF and as glb?

You get the parsed JSON object (gltfroot) in an importer plugin and can do with it what you want. This is a JObject that is serializable back to readable JSON if that’s your goal.

MarcusGT076 commented 2 weeks ago

Yes in this case its not a problem to load it twice i already did that. My goal is : i create a hierarchy list in javascript on an html site that take the data with all its children and submeshes. So it was only a thought when the loader get the file to access it and send it to javascript that i dont have to load it second time, because its already there in youre loader. I mean in gltfast i could access the root after loading and it showed the gltf file in its original form. With your loader i can access also the root but it has not all the data as the original gltf. I am sending the gltf as a string through unity to javascript and parse it there back to an json.