Loading a Blender model exported with Three.js

I recently created a basic 3D model in Blender and exported it as an .obj file. I'm now trying to load it using three.js and have the objects with 'clickable' in their name move along the Y-axis when clicked.

You can view the project here:

However, I've encountered an issue where the object names parsed from Blender don't match up correctly with the actual objects in the scene.

Loading and parsing:

var loader = new THREE.OBJMTLLoader();
loader.addEventListener('load', function(event) {
  object = event.content;
  object.name = 'CustomObjects';
  for(var i = 0; i < object.children.length; i++) {      

    //console.log(object.children[i]);
    var properties = object.children[i].name.split('_');
    if(properties[1] == 'clickable') {
      object.children[i].clickable = true; 
    } else object.children[i].clickable = false;

  }
  object.rotation.x = 0.5;
  object.rotation.y = 0.5;                                  
  scene.add(object);
});
loader.load('shop.obj', 'shop.mtl');

For example, two cubes in the center ('005_kiosek' and '010_kiosek2') should not be clickable, but they are. Upon inspection, the console reveals that their names are mistakenly labeled as '004_clickable' and '009_clickable'!

Here is my Blender file for reference:

I'm unsure if the issue lies with the JavaScript implementation or if Blender's export process is to blame. Any insights would be greatly appreciated!

Thank you,

Martin

P.S: Additionally, any ideas why the simple green and blue meshes aren't rendering properly?

Answer №1

The issue with the incorrect rendering of the green and blue mesh is due to the obj loader only supporting triangles as faces, not polygons. Therefore, these meshes are not displayed properly.

To ensure the accuracy of names in the blender file, a suggested approach would be to print the name and its clickable attribute when loading the model. This verification step will help confirm that the names are correct instead of assuming them to be accurate.

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 it possible for a Vue component to contain both data and props simultaneously?

How does a standard Vue component look? Vue.component('blog-post', { // camelCase in JavaScript props: ['postTitle'], template: '<h3>{{ postTitle }}</h3>' }) The basic documentation on components does not us ...

Is there a way to successfully integrate a JavaScript file that has been downloaded from `npm` or `yarn` into a web client or

Currently, I am following a guide titled "Headless Drupal with React" on Medium. The tutorial itself does not address my specific questions. In the tutorial, it demonstrates importing React and ReactDOM directly from CDN in the .html file. My query revolv ...

Exploring search filters using KnockoutJS

I'm currently working on incorporating a search filter into my web application. After reading some informative articles and exploring various Jsfiddles, I've attempted to enable searching by TypeName to display the corresponding row with that spe ...

Issue with scrolling feature in div

I am currently facing an issue with scrolling on my website. Visit this site to see the problem. When scrolling down, it causes the "hidden" part of the site to slide up. I want to achieve a similar sliding effect, but it needs to be smooth. I have attempt ...

Stop the click event from firing on child elements of a parent element that is currently being dragged

Below is the structure of a UL tag in my code: <ul ondrop="drop(event)" ondragover="allowDrop(event)"> <li class="item" draggable="true" ondragstart="dragStart(event)" ondrag="dragging(event)"> <div class="product-infos"> ...

Is it possible for me to utilize a validation function to display error messages within a specific span id tag?

document.getElementById("button1").addEventListener("click", mouseOver1); function mouseOver1(){ document.getElementById("button1").style.color = "red"; } document.getElementById("button2").addEventListener("click", mouseOver); function mous ...

Adjust the height of Fullcalendar when the window is resized to maintain the aspect ratio as it shrinks

I am having trouble adjusting the height of an FC (fullcalendar) within a div. My goal is to have the FC completely fill the div without overflowing. Despite setting the height attribute during initialization, the FC's height does not resize properly, ...

The presence of asynchronous JavaScript can lead to errors due to missing functions in JavaScript

I've encountered an issue with a jQuery script that I modified by adding an ASYNC attribute. Surprisingly, it functions correctly in Firefox but encounters intermittent failures in both Chrome and IE browsers. Here's the PHP code snippet respons ...

In the realm of Bootstrap 4, the nav collapsing animation briefly hesitates when opening but smoothly closes without any interruptions

The menu expands smoothly when opened but has a slight pause before continuing to slide down. Closing the menu seems to be smoother compared to opening it. .navbar { padding: 0; float: right; } .navbar.fixed-top { left: auto; } .navbar-menu { ...

Utilizing JavaScript for simulating key presses on a webpage

Is it possible for a website to detect keystrokes and mouse movements? Can JavaScript be used to simulate actions, like clicking a mouse button, without physically doing so? If my question is unclear, please let me know. I'm new to this and feeling a ...

Troubleshooting why content set to a <div> element with JavaScript / jQuery is not persisting after a

This is the current code snippet I am working with: <asp:Button ID="btnSave" runat="server" OnClick="Save" CssClass="StylizedButton" resourcekey="btnSave" /> <div id="lbltot"></div> Below is the JavaScript portion of the code: $(do ...

Oops! Looks like there's a type error in module "*.mdx" - it seems that it doesn't have the exported member "metadata". Maybe try using "import metadata from "*.mdx"" instead?

I am attempting to extract metadata from an mdx file. I have followed the guidelines outlined in NextJS Markdown Frontmatter, but encountered build errors. It is important to note that I am unable to utilize fs. Code Section Page.tsx File import Conte ...

What are the benefits of using CSS to convert text to uppercase?

Today, I came across an intriguing observation. While browsing through code, I noticed that text was being transformed to uppercase using CSS instead of the common JavaScript method toUpperCase(). Surprisingly, this approach caused a test to fail. The test ...

The data-src tags are functioning properly in the index.html file, but they are not working correctly in angular

I'm still learning about Angular and JavaScript, so please bear with me if my questions seem silly. I've been trying to add a theme to my Angular project. When I include the entire code in index.html, everything works fine. However, when I move ...

What is the proper method for implementing a scrollable effect to the <v-bottom-sheet> element within the Vuetify framework?

Within my Vue.js project, I am utilizing the v-bottom-sheet component from Vuetify framework (version 2.1.12). Upon reviewing my code, you can observe that the v-card is enclosed within the v-bottom-sheet. The issue arises with the scrollable parameter of ...

Responsive design in Android does not function as intended

My goal is to create a responsive design for my website, but I am encountering issues with importing the CSS files into the HTML. When I try to view the site in both the Windows version of Chrome and the Android version, all I see is a white screen. I am c ...

Issue encountered with PUT method; update all tables in ReactJs framework

Let me describe the issue I'm facing today. The code below is functioning correctly. However, when I perform a PUT request, it modifies all tables in my database instead of just the intended one. I wish for the PUT request to only impact the specif ...

Is there a way to execute WebGL and JavaScript on the server side?

In the midst of my current project involving Three.js based WebGL, I find myself in need of quickly capturing a screenshot of a specific model. My approach so far has been to write some JavaScript code that renders the 3D model and then provides me with an ...

infinite loop issue with beforeRouteEnter

I'm experiencing an issue with Vue Router. The scenario is to load / initially, retrieve data from there, and then navigate to the /chat/:chatId route to display the interface using the :chatId parameter obtained from an API. The routes configured a ...

Why do I keep encountering a null window object issue while using my iPhone?

Hey there! I've got a React game and whenever the user loses, a new window pops up. const lossWindow = window.open( "", "", "width=500, height=300, top=200, left = 200" ); lossWindow.document.write( & ...