Is there a way to combine various Blender JSON models into a single Three.js Object3D entity?

Is there a way to combine multiple Blender JSON models into a single Three.js Object3D object? I've searched Google for answers but haven't found any solutions yet.

Answer №1

Have you considered merging them in Blender before exporting as a single object?

In Three.js, you can merge geometries and even materials if they are identical. However, if your geometries are not identical or if you have multiple materials, it can be challenging...

I've been grappling with the same issue myself and haven't found any solutions within Three.js yet. I'm thinking about trying to merge them in Blender instead. On the other hand, coding this directly in the engine might actually be easier than using Blender. It's definitely a complex piece of software to navigate through!

Answer №2

Is there a specific rationale behind needing the exported JSON objects to be grouped under a single Three.js Object3D? Would it suffice to manage both objects under one parent object instead?

You have the option to add the objects as children to an empty parent object and control them that way. Check out this gist for a demonstration.

var parent = new THREE.Object3D();
parent.add(blenderObj1);
parent.add(blenderObj2);
parent.scale.set(1,2,0.5);

Edit

Take a look at this scene, which illustrates what you mentioned in the comments. Experiment with changing the number of boxes per side (resulting in side^2 boxes) and toggling the parent functionality.

Note: As of 4/25/16, there's a known issue in Chrome that may cause texture race conditions. Reloading the page might resolve any display anomalies with the boxes.

In response to your points:

The parent object should allow users to add and remove objects from it,

Object3D provides methods like .add() and .remove() for that purpose.

.add ( object, ... )

.remove ( object, ... )

and the parent needs to be rotatable as a whole.

This is precisely how parenting functions. Simply execute something similar to:

parent.rotation.x = Math.PI / 2;

Subsequently, all child objects will rotate alongside the parent. It is important to note that they rotate relative to the world rotation (as they practically did), leaving their individual transformations unaffected.

Merging the children into a single parent would prevent choppy animations.

Not necessarily. Unless your objective involves minimizing draw calls (more details below), employing a parenting object does not noticeably impact frame rate. Based on swift tests, rendering 10k objects on an aging Macbook Air does not lead to crashes, even if it strains the system. With 10k objects, performance will inevitably suffer regardless.

By consolidating all geometry together, draw calls are reduced and processing speeds up. It's worth noting that the geometry remains completely static relative to other objects. Therefore, unless you can opt for a straightforward solution recommended by Scharnvirk (merging your objects in Blender and importing as a singular entity), you could slightly save bandwidth by dynamically cloning the geometry. In this scenario, refer to the merge() function in three.js Geometry:

.merge ( geometry, matrix, materialIndexOffset )

Merge two geometries or geometry and geometry from object (using object's transform)

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

Is there a way to make the primary button on the previous page function correctly again, just like it did before it was clicked?

Issue Description: I am facing an issue on the order page where I need to link the "Continue" button to a booking page. After reaching the booking page, I expect users to be able to navigate between the two pages seamlessly even when they use the browser& ...

Using the Parallax Effect in React

I'm currently working on implementing a parallax effect in React and I've encountered an error that's giving me trouble: Below is the snippet of JavaScript code I have for the parallax effect: export const parallax = document.getElementsBy ...

The GLSL shaders in Three.js seem to be malfunctioning

Recently, I ventured into the world of Three.js and GLSL, attempting to load my vertex and fragment shader in HTML format. Unfortunately, I encountered an error: Uncaught TypeError: Cannot read properties of null (reading 'textContent') I am p ...

Is the express.json() middleware for parsing JSON request body designed to handle synchronous calls?

According to Express.js's documentation, it is recommended to avoid using synchronous functions as much as possible. This is because in high-traffic websites, the accumulation of synchronous calls can negatively impact the performance of the applicati ...

The ViewChild instance is currently undefined

Within my component, I have the following setup: @ViewChild('PaginatedTableComponent') userTable: PaginatedTableComponent; Here is the corresponding HTML code inside the component: <pag-paginated-table #userTable [(shouldUpdate)]="sh ...

Best practice for structuring an object with multiple lengthy string elements in the GCP Datastore Node Library

My JavaScript object is structured like this: const data = { title: "short string", descriptions: [ "Really long string...", "Really long string..." ] } I need to exclude the long strings from the indexes, but I ...

Entwine words around an immovable partition

Is it possible to create an HTML element that remains fixed in place even as the content on the webpage changes, with everything else adjusting around it? I am looking to add a continuous line that spans across a dynamic webpage. No matter how much conten ...

The issue of Next.JS fetch not caching data within the same request

I am faced with a straightforward setup where a Next.JS server-side component is responsible for fetching and displaying a post. The challenge lies in setting the page title to reflect the title of the post, requiring me to call my posts API endpoint twice ...

What is the best way to sort and organize JSON data?

Upon successful ajax call, I receive JSON data structured like this: var videolist = [ { "video_id": 0, "video_name": "Guerrero Beard", "timelength": 15 }, { "video_id": 1, "video_name": "Hallie Key", "timelength": 8 }, { ...

How can I replace the unsightly "Web page not available" error in WebView on Android with a more visually pleasing alternative?

In my WebView Activity, I sometimes encounter issues with loading properly when the WIFI/DATA connection is poor or disconnected. This could potentially be a common occurrence once my app is in use. I'm curious to know how I can replace the unattracti ...

Separate string by using a regular expression pattern

Looking to parse a dynamic string with varying combinations of Code, Name, and EffectDate. It could be in the format below with all three properties or just pairs like Code-Name, Code-EffectDate, or Name-EffectDate. {"Code":{"value":"1"},"Name":{"value": ...

What could be the reason behind ejs not allowing if else statements when the variable is undefined?

I am attempting to replicate a rather simple example from this question here <div <% if (page_name === 'overview') { %> class="menu__menu-overviewPage menu" <% } %> class="menu"> However, when I try it on a ...

Unraveling the mystery: Retrieving data from various child components within a Vue parent component

Currently, I am in the process of constructing a view that includes a primary component called ContentComponent. This component acts as a container for a series of sub-components, each representing a form module. The list of forms include: EvaluationForm ...

Guide to changing the class of a particular child element when the parent element is clicked with vanilla JavaScript

Upon clicking the parent button, a class within its child element will toggle to show or hide. If the child element is selected, a loading animation will appear for a brief moment before reverting back to its original hidden state. I attempted to achieve ...

Troubleshooting VueJs and vue-i18n issues

Currently, I am utilizing the Webpack CLI Template. As a next step, I proceed to install using the command npm install --save vue-i18n Within my main.js file, I undertake the necessary importation and configuration by setting the locale to "en" import ...

customize Form Modal Bootstrap with AJAX Chained Dropdown for pre-selected options

I am facing an issue with a chained dropdown on a bootstrap modal, Here is the code snippet: function changeDetail(id) { var id = id; $('#edit').prop('hidden', true); $('#modal_form').prop('hidden', fa ...

What steps can I take to establish a simple yet secure password authentication using next.js, mongoDB, and bcrypt?

As a hobby programmer working on my project, I aim to implement a secure password authentication system in my next.js project using only my next.js backend API and MongoDB (Atlas via Data API). I understand that there are various third-party authentication ...

Is there a way to narrow down Drive API list results based on a specific domain that has write permission?

I am currently working on retrieving a list of files from the drive API using a service account, with permissions granted to a specific domain for editing. While I have successfully implemented this feature for individual emails, I am facing a challenge in ...

Tips for implementing vue.js composition api with vue-3-socket.io

Is there a way to access the socket instance within the setup function of a Vue.js component? I am utilizing vue-3-socket.io in my main.js import VueSocketIO from 'vue-3-socket.io' import SocketIO from 'socket.io-client' Vue.use(new ...

Could not locate module: The package path ./react is not exported from the package in E:NextAppportfolio_website-mainportfolio_website-main ode_modules ext-auth

I am encountering an issue while trying to import SessionProvider from Next-Auth. The error message that is being displayed is: "Module not found: Package path ./react is not exported from package E:\NextApp\portfolio_website-main\port ...