Obtaining JSON data with Three.js

Is it possible to create a JSON file from a model built with Three.js in Webgl, similar to exporting a JSON model from Blender and loading it with THREE.JSONLoader().load? I would like to know if anyone has experience or information on this.

Answer №1

Before we proceed, I want to make sure I understand your query correctly. Are you looking to package your object3D in a JSON format similar to an .obj file? Essentially, creating a file that can be read and used to generate the geometry in another location at a different time?

It appears that you are aiming to establish a reverse route of "blender -> json -> three.js", is my assumption correct?

In my viewpoint, it is crucial to grasp the coding structure of a model when transforming it into a JSON file. This way, you can mimic the process as though you were working within blender. Subsequently, you would need to develop a serialization method to compile the relevant data into a JSON format.

If your goal is to construct a JSON file that serves as a custom template or alternative to the .obj or .blend formats, then you should also devise a de-serialization approach.

Allow me to clarify further.

Your geometry encompasses vertices, faces, uvs, normals, among other elements. When serializing, you must meticulously outline each of these components in a specific sequence to complete the process successfully. Once you comprehend this paradigm, you will be proficient in reading and de-serializing the data.

If there has been any misunderstanding on my part, please do not hesitate to inform me.

Farewell

Answer №2

Absolutely, it is indeed possible. To achieve this, you will need to have a specific plugin installed in your Blender software in order to export to Three.js.

Get the Plugin from Git: Blender exporter to Three.js

After downloading the plugin, place the io_three folder into your ~/.config/blender/2.69/scripts/addons/ directory.

Next step is to navigate to File > User preferences and move on to the Addons section. Look up Three.js and activate the plugin that appears in the search results. This should give you access to a new option under File menu - Export > Three.js. Make sure to check the Face Materials box on this panel to ensure materials are included, as without them, Three.js may not successfully import your mesh.

Implementation with Three.js

var mesh = null;
function initMesh() {
    var loader = new THREE.JSONLoader();
    loader.load('./marmelab-logo.json', function(geometry) {
        mesh = new THREE.Mesh(geometry);
        scene.add(mesh);
    });
}

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

Can a YouTube video be triggered to play when a specific CSS style is selected?

I am searching for a method to display and play different YouTube videos based on a selected CSS style from a drop-down menu. I believe JavaScript can be utilized to detect the chosen CSS. Include the following in the html header of the page. <script ...

How can I use JavaScript to collapse a node list from Bootstrap 4.6.x using the .collapse('show') method?

I'm currently attempting to implement the Bootstrap method .collapse('show') on a node list of elements, but I've run into an issue in the console.log that reads: (Uncaught TypeError: findEl[i].collapse is not a function). Because I am ...

What is the method for changing the Uint8Array object into a string?

I am encountering a similar issue as the one discussed in this post. I have read the solution provided, but I am having trouble grasping how to implement it. Are there any alternative suggestions? Here is my code snippet: var eccrypto = require("eccrypto ...

The element is inferred to have the 'any' type. No index signature matching the parameter type 'string' was found on the 'User1' type

I have been experimenting with computed properties in TypeScript, but I've encountered a specific issue: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'User1'. ...

What could be causing Jest to prevent me from using the node testing environment, especially when they have made changes to it?

I am currently working on testing a React component within Next.js using Jest. Jest made an official announcement regarding the change of default test environment to Node: Due to this update, the default test environment has been switched from "jsd ...

Replace the term "controlled" with "unleashed" when utilizing the file type input

In my app, I have defined multiple states like this: const [state,setstate]=React.useState({headerpic:'',Headerfontfamily:'',Subheaderfontfamilty:''}) And to get an image from my device, I am using the following input: &l ...

Reactjs: Prop Type Error - Issue with retrieving the values from props during data submission

Currently, I am developing a social app where users can post screams, like posts, and add comments. The issue I'm encountering is that I am not receiving the props value when posting a new scream initially, but after refreshing the page, everything wo ...

Implementing react-table version 7 to display dynamic columns and rows fetched from a JSON dataset via an API

Just starting out with react and I have a json api that needs to be displayed as a table on the client side. My plan is to use react-table v7. This is my approach: Use the keys from the data as column Headers and Accessor The json data will be the rows I ...

Is it possible to set auto height for Jquery Fancybox when using within an Iframe?

Currently, I am utilizing Fancybox iframe form which has a fixed height of 350px. However, upon submitting the form, the resulting window only displays two lines of content. Is there a way to make the window adjust its height automatically based on the fo ...

Utilize TypeScript to re-export lodash modules for enhanced functionality

In my TypeScript project, I am utilizing lodash along with typings for it. Additionally, I have a private npm module containing utilities that are utilized in various projects. This module exports methods such as: export * from './src/stringStuff&apo ...

Avoid navigating to the subscribe block when the server sends a response in Angular

When trying to send a request to the server and check the response, I am not seeing any results. The code for sending the request is below: SendVerificationInfo(item: SendVerificationModel): Observable < any > { return this.httpClient.post < any ...

Ensuring typescript req.user in Passport JS is always defined: Best practices

When utilizing Passport JS, the req.user within the route is considered potentially undefined. However, the middleware prior to my route method ensures that this scenario does not occur. How can I convey this information to TypeScript? Object may be &apos ...

Run a chunk of HTML with dynamic PHP elements using JavaScript

Within a single .php file, there is a combination of HTML, PHP, and JavaScript. The JavaScript section is crucial for detecting the browser; if the browser is not Internet Explorer, JavaScript will trigger the HTML block containing PHP. Here is the JavaS ...

What is the best way to transfer data from an AJAX GET request to a Node.js GET route?

Here is an example of an ajax request being made $.ajax({ url: '/reload', type: 'GET', contentType: "application/json", data: { Name: $("#inputName").val(), Link: $("#inputLink").val() }, succe ...

How can information be exchanged between PHP and JavaScript?

I am working on a concept to display a graph of someone's scores within a div element. The process involves a button that triggers the graph drawing function upon clicking. Additionally, there is a data retrieval function that retrieves information fr ...

What are the necessary steps for incorporating Payment/Bank transactions into an e-commerce platform?

Right now, I'm utilizing HTML, CSS, jQuery, and some JavaScript to develop a website. As I work on creating the store section, I find myself unsure of how to incorporate payment methods and all related features. Are there any free "pre-built" systems ...

How can I utilize JavaScript to retrieve the background color of a table cell upon clicking?

I am trying to create a function where an alert pops up displaying the background color of a table cell whenever it is clicked. Unfortunately, I am having trouble accessing and retrieving the background color value. The table cell in question is defined a ...

Issue with Checkbox Filtering Function [ReactJS]

I'm working on setting up a checkbox filtering feature in React. Here's what I want to achieve: User goes to the products page where all products are displayed initially. User checks a checkbox and only filtered products should be shown. If use ...

Using jQuery to add a checkbox to a list that is not ordered

My HTML structure includes an unordered list with nested lists. Here is a snippet of the code: <div id="checklist"> <ul> <li>On Page SEO <ul> <li>My work <i>And note.</i>< ...

Ways to prevent label rotation in Ant Design's Donut Chart

How can I adjust the labels in the ant design donut chart to be parallel to the X-axis instead of rotating? const config = { legend: { position: labelPosition }, appendPadding: 10, data, angleField: "value", colorField: " ...