downloadJSON not define

I used GLFTExpoter to download file as a glft format but i get some error in my console that is downloadJSON is not define

code of function

 //gltf exporter
  function SaveDesign(e) {
    e.preventDefault();
    var data = blueprint3d.model.exportSerialized();
    var exporter = new THREE.GLTFExporter();
    exporter.parse(data, function (result) {
      var output = JSON.stringify(result, null, 2);
      console.log(output);
      downloadJSON(output, "scene.gltf");
    });
  }

Is downloadJSON defined somewhere in your code?

No, I just copy the code of glftexporter from following references that how to used this exporter

https://threejs.org/docs/#examples/en/exporters/GLTFExporter

Screen Shot 2020-07-19 at 17.56.16

Well, it is quite obvious that you cannot use a function that is not defined. Either define it or remove it from the code.

Edit: Just so I don’t seem too cruel, here’s a sample implementation of downloading an exported model.

1 Like

As i mentioned above i just followed the code from some resource
they include the downloadJson function because that is come from GLFTexporter.js

I understand. Still, it’s just a code snippet showing a sample use-case, not a copy-paste solution. GLTFExporter has no downloadJSON method.

1 Like

But both use downloadJSON function ,then whats that mean??

https://threejs.org/docs/#examples/en/exporters/GLTFExporter

According to my detectivistic instincts, it could only mean that Mozilla blog used a sample snippet from Three’s documentation and the owners of Three repository should now continue with a legal action against this obvious copyright infringement, become billionaires overnight due to a polite court settlement, and spend the rest of their lives sipping tequila in Bali.

(Also, read the article further, in the A-Painter exporter paragraph they virtually show a working example of downloading a model, with a full code. :’) )

But i dont know how to solve it.Can you help me with that?

You can implement it this way. I think it was just considered too much code for a simple example.

function downloadJSON( json, filename ) {

	saveString( JSON.stringify( json ), filename );  

}

var link = document.createElement( 'a' );
link.style.display = 'none';
document.body.appendChild( link ); // Firefox workaround, see #6594

function save( blob, filename ) {

	link.href = URL.createObjectURL( blob );
	link.download = filename;
	link.click();

	// URL.revokeObjectURL( url ); breaks Firefox...

}

function saveString( text, filename ) {

	save( new Blob( [ text ], { type: 'text/plain' } ), filename );

}

This is work

This download the empty glft file that have no data.why?

code

 //gltf exporter
  function SaveDesign(e) {
    e.preventDefault();
    var data = blueprint3d.model.exportSerialized();
    var exporter = new THREE.GLTFExporter();
    exporter.parse(data, function (result) {
      var output = JSON.stringify(result, null, 2);
      console.log(output);
      downloadJSON(output, "scene.gltf");
    });
  }
  function downloadJSON( json, filename ) {

	saveString( JSON.stringify( json ), filename );  

}

var link = document.createElement( 'a' );
link.style.display = 'none';
document.body.appendChild( link ); // Firefox workaround, see #6594

function save( blob, filename ) {

	link.href = URL.createObjectURL( blob );
	link.download = filename;
	link.click();

	// URL.revokeObjectURL( url ); breaks Firefox...

}

function saveString( text, filename ) {

	save( new Blob( [ text ], { type: 'text/plain' } ), filename );

}
can you check it

Two problems I see:

  1. JSON.stringify() is being called twice on the same data, that’s my mistake… instead of calling downloadJSON … try… saveString( output, 'scene.gltf' );
  2. What is the output of blueprint3d.model.exportSerialized();? Is that a three.js scene? I can’t tell you what to expect without knowing what your code does. :slight_smile:

1.I tried saveString instead of downloadJSON but result is same
2.Yes its a three.js scene.

http://furnishup.github.io/blueprint3d/example/
please visit it to check it

and i want add saveGlft button in it like save button in this above example.I hope you can better understand it

In the example you share, here’s the code I see:

Screen Shot 2020-07-20 at 9.06.28 AM

When I press “Save” It does save the file, and that file contains the same JSON that exportSerialized() returns. It’s not three.js or glTF data, so I can’t tell you if it’s correct. It’s not a glTF file.

I know but i want to download file as glft format thats why i want to add another function that download glft with glftexporter.

But not know how to make it possible.

The data coming out of exportSerialized(), at least in the link you shared, is custom JSON that nothing in three.js, including GLTFExporter, can understand. If you need help debugging custom code you will have to share enough of that for us to fully reproduce the error. The code you shared above does not attempt to create a glTF file, so I’m not sure how to help you.

ok i understand
but is there any way to convert this custom json to glft format or three.js??
i also used this

https://blackthread.io/gltf-converter/

converter to convert json into glft but thats give error like invalid json

It’s probably possible, but it’s a proprietary format — only the authors of that custom JSON know what it means, unless you manage to reverse engineer it. You probably won’t be able to find any pre-existing tool that can convert it to anything else.

What should i need to do to convert it into glft format?
any suggestion?

You are asking us how to reverse engineer someone else’s custom data format. Only the author knows, and it would take anyone else a lot of effort to learn. Sorry, but I can’t help you with that. I would suggest that you ask the author on GitHub (it looks like you already have?), or hire someone to do this, or find a way to solve your problem without using this proprietary format.