JSONLoader issues

Hallo there,

In my project I use three in react (0.98) to render some json exported by blender 2.76 in order to produce images that I can modify with images in order on top of that to save the images and show them.
The entire process is called mockuprenderer.
Everything worked fine till the day that three js doesnt use anymore the objectloader and replace it with LegacyJSONloader. Unfortunately my problem is that there are no types relative to this loader and I need them because the project is written in typescript.
Do you have some solution for that?

That’s is not entirely correct. THREE.ObjectLoader is still available and you can use it to load JSON in the Object/Scene format. THREE.JSONLoader was removed with R99 from the core. It is now THREE.LegacyJSONLoader and part of the examples.

The problem is that you work with an exporter which was removed from the project almost a year ago. Because of this, you still need to work with THREE.LegacyJSONLoader. Have you considered to switch to a glTF based workflow instead?

I don’t think there will be type definitions for deprecated classes from the official side. You might want to use the following type definitions from another project. However, a few methods are missing (.setPath(), .setResourcePath() and .setCrossOrigin()).

Hi Mugen87 thanks for the answer, you re totally right. It’s just that now redo all the project basing the thing on gtlf files is a little bit crazy. I have to review the entire project. so you think three js will not provide types in the future for LegacyJSONloader and because of this I should pass to gltf ?

Yes. But it’s not only about the types. Using glTF is the more robust and future-proof workflow. It’s also the recommended 3D format of the project. More details here:

https://threejs.org/docs/index.html#manual/en/introduction/Loading-3D-models

hello i am working with legacyJSONLoader and when i write this line of code <‘import * as THREE from’ https://threejs.org/build/three.module.js’ this error appears "Uncaught TypeError: THREE.LegacyJSONLoader is not a constructor " any suggestion please

LegacyJSONLoader was removed with r111. You can’t use the loader anymore with recent three.js versions. I highly recommend that you change your workflow towards glTF.

thanks but i don’t know how can i change legacyJSOLoader to GLTF

It depends a bit on how you originally have created your models.

  • If you still have the Blender assets, it’s probably best to export to glTF.
  • If you created the JSON files via three.js, go back to r110, load the JSON files and export to glTF via THREE.GLTFExporter.

thank u , i have a JSON file i try with three js editor but does’nt work and also i go back to r110 nothing work too , is there another method to convert JSON file to GLTF?
gym-ceiling.js (514.5 KB)

The latest editor is not able to load such a file. You have to use an older release.

And no, unfortunately there is no other way for converting.

1 Like

It seems to work fine with the editor of r98 (the last release that contained JSONLoader in core).

https://raw.githack.com/mrdoob/three.js/r98/editor/index.html

This is the resulting glTF asset: scene.glb (685.4 KB)

2 Likes

thank u a lot <3 <3

i tried to change the color of this but it doesn’t work how can i do it with this editor r98

gym-ceiling.js has 256 different materials. You have to change the color property of all materials to see the effect that you want.

BTW: This type of model design is highly inefficient especially since all 256 material seems to have the same properties. I suggest you import the glb file into Blender, merge all parts of the geometry into a single entity, adjust the color and then export to glb again.

thank u <3 everything worked fine

1 Like

Hello, have u any Idea about GltfExporter because the same problème appears with GltfExporter when i add ‘import * as …’ he don’t work, any suggestions !

For posterity, you can access this link to view an online three.js editor that has the JSONLoader and the GLTFExporter: https://raw.githack.com/mrdoob/three.js/r98/editor/index.html

Import your old json file using File > Import and then export it using File > Export GLB - nice!

However, this does not appear to work with rigging or animations - it just exports a static model so you may need to re-rig and animate your old assets

2 Likes

thanks alot for giving solution :slight_smile: