Having trouble rendering the textured Collada file that was exported from Blender with Three.js

I am currently working with Three.js, specifically using version 71. For my models, I am utilizing Blender, version 2.73.

In my recent project, I have created a collada object (.dae file) in Blender that is textured, and now I want to import it into my three.js scene. However, I seem to be encountering issues as I can only load models without textures exported from Blender.

Here's the process of creating the textured collada object:
In Blender, I start by using the default cube and proceed to add a texture to it using the settings on the right. The texture applied to the cube is sized at 2048 X 2048, ensuring it's a power of 2.

To visually confirm the presence of the texture on the cube, here is an image of the cube in render mode:

The export settings used when exporting the cube as a collada from Blender are as follows:

Below is a snippet of code I tried to load the textured collada:

var loader = new THREE.ColladaLoader();
var localObject;
loader.options.convertUpAxis = true;
loader.load( './models/test_texture.dae', function ( collada ) {
  localObject = collada.scene;
  localObject.scale.x = localObject.scale.y = localObject.scale.z = 32;
  localObject.updateMatrix();
  game.scene.add(localObject);
} );

Upon attempting to load, I encountered the following error message:

[.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 2

Following this error, I researched and found a suggestion indicating the need to compute tangents. Here are my attempts along with the subsequent errors received:

var loader = new THREE.ColladaLoader();
var localObject;
loader.options.convertUpAxis = true;
loader.load( './models/test_texture.dae', function ( collada ) {
  localObject = collada.scene;
  localObject.scale.x = localObject.scale.y = localObject.scale.z = 32;
  localObject.updateMatrix();

  for (var i = collada.scene.children.length - 1; i >= 0; i--) {
    var child = collada.scene.children[i];

    // Attempted methods for computing tangents
    // Error messages follow each attempt

  };
  game.scene.add(localObject);
} );

Error from ATTEMPT 1:

Uncaught TypeError: Cannot read property '0' of undefined
// Stack trace
three.js:9935 handleTriangle
three.js:9974 THREE.Geometry.computeTangents
myCode.js:116 (anonymous function)
ColladaLoader.js:204 parse
ColladaLoader.js:84 request.onreadystatechange

Error from ATTEMPT 2:

Uncaught TypeError: Cannot read property '0' of undefined

This error stemmed from trying to access a two-dimensional geometry structure which was not applicable.

Error from ATTEMPT 3: (same as ATTEMPT 1)

Uncaught TypeError: Cannot read property '0' of undefined
// Stack trace
three.js:9935 handleTriangle
three.js:9974 THREE.Geometry.computeTangents
myCode.js:116 (anonymous function)
ColladaLoader.js:204 parse
ColladaLoader.js:84 request.onreadystatechange

Answer №1

Opting for the JSON loader proved to be the better choice for me as I struggled with getting the collada loader to function properly. To get started, I installed the JSON exporter addon in Blender by obtaining it from the .zip file included in my three.js download. The addon can be found in three.js-r71/utils/exporters/blender/addons and is named io_three. Simply copy this folder and paste it into your Blender installation directory under Blender Foundation/Blender/2.73/scripts/addons.

Next step is to enable the addon in Blender:

  1. Go to File->User Preferences...
  2. Select Add-ons
  3. In the search field, type three
  4. Enable the addon by checking the box on the right side
  5. Click Save User Settings at the bottom left to save the changes. You should now see Three.js (.json) when you go to File->Export.

I followed the instructions provided on this website to assist me with creating and exporting a model:

Here are the modified steps I followed to create and export the model:

  1. Launch Blender.
  2. Access the Properties editor (located on the right).
  3. Select the World context button. In the World panel, adjust the Ambient Color from black to middle gray.
  4. Switch to the Material context. Set Intensity to 1.0 on the Diffuse and Specular panels. Tick the Shadeless option in the Shading panel.
  5. Proceed to the Textures context. Choose Image or Movie from the Type dropdown. Browse for the image in the Image panel, ensuring its dimensions are power of 2.
  6. Switch to the UV Editing screen layout.
  7. In edit mode (Tab key), unwrap the model using Smart UV Project.
  8. In the UV Editing screen, select the image using the menu at the bottom left.
  9. Save the image by selecting Image->Save As Image. This image needs to be stored next to the JSON file for export.
  10. Export the model by clicking File->Export->Three.js (.json).
  11. Configure additional export options on the left (I used Face Materials, Materials, and Textures). Save these settings by clicking Save Settings.
  12. Include both the JSON file and saved image in your project folder.
  13. Utilize the following code snippet to load the model:

    var object;
    var loader = new THREE.JSONLoader();          
    loader.load( "./models/test_texture.json", function(geometry, materials) {
      object = new THREE.Mesh(geometry, materials[0]);
      object.scale.set(32, 32, 32);
      game.scene.add(object);
    });
    

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

What are the benefits of using Lifery Ajax URLs?

I'm currently using the Grails portlets plugin and I'm exploring how to properly route AJAX methods. It seems like <portlet:actionURL> is only able to map to methods that return models for GSPs, while <portlet:resourceURL> doesn&apos ...

Discover the seamless process of dynamically adjusting metadata to reflect current state values within the Next.js app directory

Exploring the app directory within Next.js version 13, I came across a change in the official documentation where they have replaced the old head method with metadata. Initially, I thought this feature was only available on page or layout components. Now, ...

Although the xpath simulates a click on the button, it does not actually perform any action

I've been diligently working on an automation test suite for a web application that can be quite temperamental. Following a recent UI update, I decided to run some tests to ensure the GUI, buttons, and xpaths were functioning as expected. The night b ...

Is it possible to change text dynamically with an input box using JavaScript?

Is there a way to use JavaScript to create two input boxes for text replacement? Instead of constantly editing code to replace different text, I am looking for a simple user interface with Input Box A, Input Box B, and a button. The first input box will ...

Check if the page has been loaded using Jquery

Can anyone share a helpful strategy for initiating a function in JavaScript that only begins once the entire page has finished loading? ...

What is a more efficient approach to managing the response from an asynchronous call other than using setState?

Utilizing javascript async await, I have been making service calls to the server in componentDidMount or componentDidUpdate. However, when I need to pass the response data as props to other components, I find myself updating the component's state with ...

Having trouble sending a FormData object with Axios for a user uploaded file in a React, Node.JS project

My goal is to enable users to upload images to my application, which consists of a React frontend and a Node backend. The process involves sending the uploaded file from the client to the server, followed by making a request from the server to Firebase clo ...

What's the reason behind the console showing an uncaught promise error message?

When attempting to delete some lists from my backend using a fetch request, I encountered an issue. The console is displaying an error message that reads "Uncaught (in promise)." What could be causing this problem? Here is the frontend code snippet for th ...

Using Bitly API in JavaScript to launch a popup window

I have implemented a script that dynamically generates short links for my Tweet buttons. It is working perfectly fine, but I am encountering an issue with opening the link either in a new tab or a popup window. I've tried adjusting the window.locatio ...

Creating a PHP script that retrieves data from JavaScript and stores it in MySQL can be accomplished by using AJAX to send the

Hello, I am attempting to create a PHP script that can extract coordinates from this JavaScript code (or from this link ) and store them in a MySQL database. Can someone please provide me with a tutorial on how to accomplish this? <script> var ...

"Encountered an issue with ng-annotate during processing

I'm attempting to utilize ng-annotate on my Angular application, but it seems to be not working at all. Here is the configuration part: (function () { 'use strict'; angular.module('app') .config(/*@ngInject*/ ro ...

What is the method for adjusting the time format?

Using the TIME data type, my data is currently displayed in the format hh:mm:ss (03:14:00). How can I change it to display in the format hh:mm (03:14)? The usual DATE type method does not seem to work: {{test.time | date: 'HH:mm'}} However, thi ...

Submit your document using the connect-form tool

I ran into an issue while trying to upload a file using connect-form. I found that in order to successfully upload the file, I had to disable the bodyParser() function in my app.js. If I kept bodyParser() enabled, it would result in an error: loading forev ...

What is the reason the useEffect hook does not function properly with a state variable within context?

Check out my code here. I'm trying to display the content of the array testingData, but it's not showing up. If I remove the useEffect hook, it works fine. Can you help me understand why and how to fix it? ...

Replacing text using regex results in whitespace

How can I eliminate text and spaces? For instance: http://www.exampleweb.com/myprogram.rar http://www.examplebackup.com/mybackups.rar http://www.exampleweb.com/myprogram1.rar I have used something similar to remove the second line: http://www.exampleba ...

React-Troubleshooting list items and keys: A comprehensive guide to resolving common issues

I'm facing a challenge with generating unique key ID's for my list items. Even though I thought I had a good understanding of how unique keys function, it seems that I am mistaken. In the code snippet below, using key={index} or key={item} is no ...

Retrieving the IDs of all socket connections in a Node.js Socket.IO array

I currently have a complex program utilizing socketio 0.9 where I am storing all the sockets id in arrays like so: var clients = {}; To uniquely identify and store my sockets, I assign them a serial and then set the 'socket' key with its actual ...

What could be causing my click() function to only work properly after resizing?

It's driving me crazy. The code snippet below works perfectly, but not in my project. Only the code in the resize() function seems to work. When I resize the window, everything functions as expected - I can add and remove the 'open' class by ...

The SrollToTop function is ineffective when used with a component in Ionic 6/Angular

Recently, I implemented a fabbutton feature that allows users to scroll to the top of a page with just one click. Initially, I tested this functionality without using it as a component, and everything worked perfectly. However, now I want to turn this fabb ...

What causes the data property to supersede the return false in a jQuery ajax call?

Below is a block of code that I am currently working with: $("#contact_container form, #contact_details form").live( "submit", function(event) { $.ajax({ type: this.method, url: this.action, data: this.s ...