When working with three.js, you may come across .json and .js files which are used for object formats. But what exactly is the difference between them?
The .js
extension signifies that the file should contain scripts following JavaScript syntax, making it human-readable.
On the other hand, the .json
extension indicates that the file should follow a tree structure using JavaScript object syntax (not related to 3D objects), also being human-readable. Additionally, any valid JSON file can also be considered as a valid JS file.
In Three.js, loaders play a crucial role in parsing these files. They do not rely on file extensions but rather on the content within the files.
Do different loaders need to be used for loading objects?
In my understanding, Three.js is capable of loading various types of structures, each having its own loader containing one or more parsers.
For instance, the JSONLoader is a basic loader that requires a file with a specific JSON structure detailing materials, normals, positions, texture coordinates, among others.
There is also the BinaryLoader that necessitates two files - one containing JSON structure with material information and the location of another binary file, while the second file holds buffer data in binary format. Notably, providing buffer data in JSON structure will not work with this loader.<
Another loader known as fbxloader exists, designed to read results created in software like Blender, although its functionality remains uncertain.
In an example where a .js file was used with the BinaryLoader, why didn't it work when I attempted the same?
It seems that the BinaryLoader expects two separate files with distinct JSON and binary structures, disregarding filenames and extensions. If correct structures are present inside the files, even named unconventionally, the loader will function properly. It's possible that only one file with the right JSON structure was provided, making it compatible only with the JSONLoader.
... (More details regarding file loaders and object creation)