What sets apart a .json file from a .js file when incorporating them into three.js coding?

When working with three.js, both .json and .js files are utilized as object formats. What sets them apart from each other? Do they necessitate different loaders for loading the objects?

I came across this three.js demonstration: . In the example, a .js file was used for the object along with the BinaryLoader. However, when I attempted the same approach using a .js file for my object with BinaryLoader, it didn't work. It only worked with JSONLoader. This has left me pondering how to distinguish between a .js or .json file and which loader should be used for loading the corresponding object.

Answer №1

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)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a three-dimensional shape using three sets of coordinates: How to do it?

I am currently working on a feature that will allow users to choose 3 points from a point cloud, create a 3D hexahedron geometry using those points, and then calculate the volume of the shape. I'm aiming for a functionality similar to the volume meas ...

Tips for updating and transferring a variable within a callback function

I have implemented a function using the SoundCloud API that retrieves a song URL, obtains the associated sound ID from the API, and then passes that ID to a callback for streaming purposes and updating the page. The data is successfully retrieved from the ...

I need help figuring out how to showcase the following object in an Angular 5 HTML file

https://i.sstatic.net/XXm3W.png The console screenshot above shows an object with two values: users and tickers, each being an array of values. How can I display these values in an Angular 5 HTML template similar to the screenshot above? I attempted to ...

When making an Ajax call, the response returns the existing HTML page instead of the intended

Recently, I attempted to implement an AJAX call using jQuery in the following manner (the file name is BR_states.txt and it matches correctly): <script> function changeSelectedShippingCountry(select){ var countryCode = select.options[select.select ...

Utilize Array.filter to retrieve specific values based on a defined number of elements

I have a function that currently retrieves the url value for each item in an array up to a specified maximum number. Below is the code snippet: const myArray = [ { url: "example.com/1", other: "foo" }, { url: "example.com/s ...

Implementing a personalized Angular filter with an indexOf condition

As a beginner in the world of computers, I am attempting to create a customized filter for an AngularJS application. My objective is to search through a string of integers (cultivos.age) and retrieve the item if the string meets the mes.age condition. I h ...

Launching an HTML document with checkboxes already selected

I am attempting to load my HTML page with checkboxes already checked if they were selected on the previous page. The code I currently have is shown below: {% if job.activism %} checkbox logic goes here {% endif %} <br><input type="checkbox ...

Using inline SVG in a Vite production build

When utilizing Vite and Vue, my goal is to compile a single JavaScript file without creating an assets directory that includes SVG and GIF files during the build process. I want to achieve this without manually inserting the SVG code in a Vue JS file as a ...

Exploring differences: map versus concatMap

I'm struggling to grasp the distinction between concat map and map. In a particular scenario, this difference became very confusing for me: const domainsObservable = this.auth.getAuthDomains() .shareReplay() .concatMap((authDomains) => aut ...

Can you explain the functionality of dismissing a Bootstrap alert?

In this example, we can see how Bootstrap handles dismissible alerts: <div class="alert alert-warning alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidde ...

Changing JavaScript functions into jQuery functions

Currently, I have this Javascript function that I am interested in converting to jQuery: function confirm() { var http = new XMLHttpRequest(); var url = "index.php?tag=' . $dt . '"; var params = "confirm_ref=' . urlencode(encry ...

Moving an item to the top of an array in JavaScript/Vue.js: A simple guide

const a = [{ "iso2": "KH", "countryName": "Cambodia", "nationality": "Cambodian" }, { "iso2": "KI", "countryName": "Kiribati", "nationality": "I-Kiribati" }, { "iso2": "KM", "countryName": "Comoros", "nationality": "Como ...

Programmatically toggle the visibility of an ion fab button

Looking for assistance in finding a method to toggle the visibility of a particular button within the collection of buttons in an ion-fab https://i.sstatic.net/vkFrP.png ...

A guide on utilizing MongoDB command line tools in the railway environment

A current MERN stack project I am working on involves resetting two documents in my MongoDB database to default data at midnight every day to revert changes made on the live website. I achieve this by using the MongoDB CLI database tools to import .json fi ...

iOS devices experiencing issues with fixed positioning

Currently, I am in the process of implementing a few instances of , but I am encountering some issues with the CSS. When viewing the website on an iPad or iPhone, the calendar is positioned correctly as the container covers the window like a fixed position ...

Node does not recognize the $or operator

Currently, I am enrolled in an online course and facing a problem with a query issue. Interestingly, the query functions perfectly fine in the shell, however, when executing the js file, an error arises stating: unknown operator: $or. Here is the crucial c ...

AngularJS restricts the display of elements to only 4 using the limitTo filter

I'm facing an issue with my filters. I have a JSON dataset that I need to display on my website, but I only want to show 4 elements that meet a certain criteria. Here's the code snippet: <div ng-repeat="place in places | limitTo: 4 | filter: ...

Sort posts alphabetically by their first letter using jQuery

Currently, I am dealing with a collection of products sourced from WooCommerce and displayed as custom posts through the Elementor page builder at this link: My attempt to incorporate an alphabetical filter using a plugin has not been successful, most lik ...

Control the data options available in the autosuggest textbox

I have implemented an autosuggest feature in a text box with predefined values. When typing the first letter in the textbox, a dropdown displays all related values. Is there a way to limit the number of displayed related values to 20? This is what my cu ...

Having trouble retrieving the table value from an HTML document?

I am trying to retrieve specific information from this source: https://i.sstatic.net/g1wDj.png This information is crucial for fetching data from a database using a primary key. However, extracting this value has proven to be quite challenging. Upon docu ...