UnityGLTF icon indicating copy to clipboard operation
UnityGLTF copied to clipboard

Get the json from the gltf

Open MarcusGT076 opened this issue 1 year ago • 7 comments

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 :)

MarcusGT076 avatar Jun 24 '24 07:06 MarcusGT076

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?

robertdorn83 avatar Jul 10 '24 12:07 robertdorn83

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 ?

MarcusGT076 avatar Jul 10 '24 13:07 MarcusGT076

Are you downloading the glb?

robertdorn83 avatar Jul 11 '24 11:07 robertdorn83

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.

MarcusGT076 avatar Jul 11 '24 13:07 MarcusGT076

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.

robertdorn83 avatar Jul 12 '24 07:07 robertdorn83

@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.

hybridherbst avatar Jul 12 '24 08:07 hybridherbst

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.

MarcusGT076 avatar Jul 12 '24 15:07 MarcusGT076