Displaying multiple Blender-exported objects with their corresponding meshes and materials in Three.js

I recently created two unique objects using Blender, each with their own distinct materials and textures applied through UV mapping. During the rendering process using CanvasRenderer from Three.js, I encountered an issue.

When I attempted to export the models, only one mesh was included in the resulting JSON file despite there being multiple materials present. This limitation is evident in my code snippet below:

var loader = new THREE.JSONLoader();
loader.load(myModelPath, function {

    var material = geometry.materials[0];
    material.morphTargets = true;
    material.overdraw = true;

    var mesh = new THREE.Mesh(geometry, material);

    mesh.scale.set(50, 50, 50);
    mesh.position.set(0, 0, 0);

    scene.add(mesh);

});

By utilizing only the [0] material index, I observed that the second object inherited the material from the first object. Unfortunately, I have not discovered a method to implement multiple materials on a single mesh or export separate JSON files for each object directly from Blender.

Answer №1

You know what? Dealing with a scenario like this can actually be quite straightforward.

  1. First, create your model in blender as you normally would.
  2. Save a duplicate for each object you're working with.
  3. Now, open each duplicate and remove everything except the specific object needed.
    You'll end up with files like object1.blend, object2.blend, etc.
  4. Export each of these to three.js one by one.
  5. Once exported, load them all together. In my own script, I just add the strings to an array.

If there's an easier way to tackle this task, I'm all ears too :)

Answer №2

It is likely that advancements have been made to the json exporter since the original inquiry, making it feasible now. Within the export settings located at the bottom, there is an option to deselect all meshes except for the chosen one, enabling selective export.

Answer №3

Utilize the THREE.ObjLoader to import your files. Within the export settings in Blender, remember to choose the scene and materials options located at the bottom of the export menu. Et voilà!

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

Upon initiating a second user session, NodeJS yields contrasting MySQL outcomes

As a novice in NodeJS and Express, I find myself stuck on what seems to be a trivial issue. Despite my best efforts, I have been unable to resolve the problem on my own. My aim is to create a basic web application that allows user authentication and displ ...

Node.js seems to be playing tricks on me. It's creating bizarre names and tweets by utilizing arrays

Trying to decipher a snippet of code that is tasked with generating random tweets has left me puzzled. Specifically, I find myself stumped when it comes to understanding the line: Math.floor(Math.random() * arr.length) I believe this line selects a rando ...

Implementing image rendering functionality in Vue.js

So here's what's going on: I developed a horror movie bucket list app for my bootcamp final project. The minimum viable product received positive feedback, and I obtained my certification. However, now that I've graduated, I want to enhance ...

A loopback model featuring an object as its main attribute

Good evening, I am new to loopback and decided to follow the instructions in the documentation: First, I initiated a loopback project using the command below: slc loopback Then, I used the loopback model generator to create a model with the following c ...

Inquiry about Tree Traversal in Javascript using Jquery

Consider the following scenario: <ul> <li>Item 1</li> <li>Item 2 <ul> <li>Sub Item</li> </ul> </li> <li>Item 3</li> </ul> This list is dynamically generated by another piec ...

What is the best method for adding boolean values to formdata?

Within my code, I am using this.state.word which is a boolean type with a value of either true or false. However, when attempting to append this.state.word, an error is thrown stating argument type boolean is not assignable to parameter type string | blob ...

Error: The navigation property is not defined - React Native

Utilizing Firebase in combination with react-native for user authentication. The main file is App.js which directs users to the Login component and utilizes two components for managing routes: Appnavigator.js to create a switchNavigator and DrawerNavigator ...

Enable automatic scrolling when a button on the previous page has been clicked

Imagine there are two buttons (Button 1 and Button 2) on a webpage (Page A). Clicking on either button will take you to the same external page (Page B). How can we ensure that Button 1 takes you to the top of Page B, while Button 2 automatically scrolls do ...

What is the reason for both the d3 line chart and bar chart being shown simultaneously?

On my website, I have implemented both a d3 bar chart and a line chart. You can view examples of them here: line_chart and bar_chart. However, in certain situations only one of the charts is displaying instead of both. Can anyone provide guidance on how ...

When trying to convert to JSON in node, the process fails. However, the data can still be

I am currently working on converting an array to JSON in order to send it to a client. The data I see in the console is as follows: [ NL: [ true, true, true, true, true, true, true, true, true, true, true, true ], ...

React - Issue with Input event handling when utilizing both onChange and onKeyDown functions

I was attempting to create a feature similar to a multi-select, where users could either choose a value from a list or enter a new value. The selected value should be added to an array when the user presses the enter key. To monitor changes in the input ...

Communication with child processes in node.js is not done using the child_process module

Hello Everyone, I'm currently experimenting with node.js to utilize JS plugins developed by others using the child_process API. However, I'm facing an issue where the child process is not able to communicate effectively with the parent process. ...

The browser's back-forward buttons are acting strangely and not functioning as expected. Could it be due to

Currently, I am facing an issue with a <select> tag. When the selected item is changed, AJAX is used to update certain <div>s through the functions: update_div1, update_div2, update_div3. The script for managing this process is functioning corr ...

Accessing a specific element within an array that has been nested within another array, using JavaScript

Here's what my code looks like: planets[0]= new THREE.Mesh( geometry, material ); planettexts[0]= new THREE.Mesh( textGeometry, textMaterial ); planets[0].add(planettexts[0]); Now, I am trying to hide the planettext, but every attempt results in an ...

Is there a way in JavaScript to format an array's output so that numbers are displayed with only two decimal places?

function calculateTipAmount(bill) { var tipPercent; if (bill < 50 ) { tipPercent = .20; } else if (bill >= 50 && bill < 200){ tipPercent = .15; } else { tipPercent = .10; } return tipPercent * bill; } var bills = ...

Modifying the DOM in Safari before unloading a webpage

I need a way to display a loading animation when I navigate between pages on my website. To achieve this, I have added the following HTML code for the loader: <div class="ajax-loader"><i class="icon-spin5"></i></div> And here is t ...

Checking to see if all the users mentioned in the message have been assigned a role

Hello everyone, I'm new to asking questions here so please bear with me. I am trying to retrieve all the users mentioned in a message and check if any of them have a specific role, such as the staff role. Thank you for your help! Edit: Here is the ...

Develop a unique calculator application using Javascript and showcase the calculated result

I'm currently struggling with my JavaScript basic calculator project. I can't seem to get the calculations to display on the screen when I click the buttons. Although I am new to JavaScript, I've been trying hard to make sure that clicking ...

Ways to transform a React class-based component into a functional component

I have a code snippet for a React component that implements a carousel slider using a class-based approach. I would like to refactor it into a functional component, but I'm not sure how to do so. import React from "react"; import ...

Substitute the attributes of one object with those of another

Alright, I'm revising this because it seems to be causing confusion. Imagine you have two items x and y. What I aim to do is swap all the characteristics of x with those of y. (Please note that this isn't your usual duplication process where a ...