Difficulty loading .mtl and .obj files in Three.js causes object to remain white

I recently attempted to load an object with different textures in various places, inspired by the examples on three.js website. Despite successfully loading the object, I encountered an issue where the textures were not displaying as expected.

Here is the code snippet I used:

   // LOAD TREE Example
    var mtlLoader = new THREE.MTLLoader();
    mtlLoader.setPath("Assets/Objects/Tree_V9_OBJ/");
    mtlLoader.load("Tree_V9_Final.mtl", function(materials){
        materials.preload();
        console.log(materials);
        var objLoader = new THREE.OBJLoader();
        objLoader.setMaterials(materials);
        objLoader.setPath('Assets/Objects/Tree_V9_OBJ/');
        objLoader.load('Tree_V9_Final.obj', function(object){
            console.log(object);
            object.scale.x = 10;
            object.scale.y = 10;
            object.scale.z = 10;
            scene.add(object);
        });
    });

In reviewing my folder structure:

https://i.sstatic.net/FCsfg.png

The visual outcome:

https://i.sstatic.net/9ILAC.png

Reviewing the console output:

https://i.sstatic.net/sC1Ym.png

This was the original source of the object:

Being new to utilizing three.js, I'm unsure of how to address this issue. Strangely, no errors are being displayed in the console. Can anyone provide insight into resolving this so that the object loads correctly with its textures?

Answer №1

Well done on your code being correct! However, it seems like the model is broken due to textures not being referenced in the material file .mtl.

To fix this issue, simply include the texture paths in Tree_V9_Final.mtl:

# Blender MTL File: 'Tree_V9_Final.blend'
# Material Count: 4

newmtl bark_tree
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd bark_tree.jpg

newmtl leaves_01
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd leaves_01.jpg

newmtl leaves_02
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd leaves_02.jpg

newmtl leaves_03
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd leaves_03.jpg

Important Note:

In addition to adding texture paths, your model may also require normal maps and alpha maps for the leaves. It is recommended to familiarize yourself with the .mtl specification to properly incorporate these elements into the .mtl file.

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

Using Mongoose to insert a JavaScript object directly into the database

Recently, I've been working on POSTing a JS object through AJAX to the nodejs backend. My goal is to seamlessly insert this js object into my mongoose db without having to manually map each key to the schema. This is what I have currently (a bit clun ...

What could be causing my map to not function properly with MeshPhongMaterial?

I am currently working on creating a virtual representation of planet Earth using three.js. Initially, I applied a texture on a MeshBasicMaterial and everything was functioning flawlessly. However, upon switching the material to a MeshPhongMaterial, the ma ...

Using Jquery to display text when the condition is not met

Here is the code snippet I am currently working with: http://jsfiddle.net/spadez/mn77f/6/ I am trying to make it display a message when there are no fields (questions) present. I attempted to achieve this by adding the following lines of code: } else ...

Using JQuery, a button is programmed to take a URL and then proceed to submit

My application is designed to shorten URLs for users who are authenticated. The form only requires the full URL input, and it will then generate a shortened version of the link. I am interested in creating a button that can be embedded on pages with long, ...

Modify one single object on the screen

I am currently using the three.js library for working with WebGL. In my project, I have two objects within the scene and I want to update them independently. I am utilizing shaders to alter the color of these objects and would like to adjust a uniform pa ...

Utilizing JQuery to select list items for pagination purposes

I am currently working on a pagination script and everything seems to be functioning well, except for one minor issue. I am struggling with triggering an action when the page number (li) is clicked. The pagination data is being retrieved via ajax and disp ...

What is the method to clearly pinpoint entities from the global namespace in Typescript?

Instead of relying on Javascript's prototype, I am considering utilizing the inheritance feature of Typescript. My goal is to incorporate some helpful methods in the class String within my designated namespace Util. This way, the String class can imp ...

Showing a restricted number of rows in the JSP page

<table class="grid_alt" cellspacing="0" rules="all" border="1" id="id1" style="width:720px;border-collapse:collapse;"> <tbody> <tr align="left"> <th scope="col"><%=partner %></th><th scope="col"><%=item %>< ...

Tips for updating the state of an individual component in ReactJS without having to re-render the entire component

As a beginner in ReactJS, I am seeking guidance on how to modify the state of a specific component that was created within a Map function. Imagine I have a basic component named panels, with multiple panel-items. Each panel-item is essentially one componen ...

Eliminate the disappearance of checkmark and error icons in Dropzone

This is my current setup: var dropzone = new Dropzone("#dropzone", { url: "<?php echo site_url($this->data['controller']."/Upload")?>", params: { 'transaction_id': "<?php echo $upload_transaction_id; ?>", ...

Arranging items by their values while appending them to an array using lodash's find method

When using an API, I receive an object called 'results' which contains other objects of type article or detail. Each result (article or detail) includes its own results object with different pages of that type. My goal is to organize these resu ...

JQuery Confetti System

I'm currently working on a project where I want to scatter 50 randomly colored circles, resembling confetti, within a defined box. However, my current code only displays a single black circle in the top left corner of the box. "use stri ...

Bringing Angular ECharts into a Stackblitz 15.1 setup: A How-To Guide

Recently, Stackblitz made a change to use a standalone configuration for Angular Projects. However, when trying to initialize the module for Angular ECharts (ngx-echarts), an error occurred: Error in src/main.ts (18:5) Type 'ModuleWithProviders<Ngx ...

It seems that the JavaScript object is producing varied values in distinct locations despite no alterations made in between

I've encountered a puzzling issue where a variable is returning different values within a function, despite no modifications being made to it. This problem arises in a form component created using Vue.js (v2) that triggers a Vuex action. While I beli ...

Different tiers of log levels

I am trying to figure out how to log only "INFO" level messages to the console for users, and to a file store "DEBUG" level posts. Currently, I have come across a solution that involves using multiple "getLogger()" functions like so: log4js.getLogger(&ap ...

Techniques for retrieving the URL generated after submitting a form using Javascript and Ajax

I am seeking assistance with creating a clickable URL. Currently, we are using PeopleCode in PeopleSoft to call an Iscript that then calls HTML. To build our URL, we have constructed the form below: We are submitting the form using the following JavaScrip ...

Exploring the efficiency of AngularJS when binding to deeply nested object properties

Are there any performance differences to consider when data binding in Angularjs between the following: <div>{{bar}}</div> and <div>{{foo.bar}}</div>? What about <div>{{foo.bar.baz.qux}}</div>? Our team is working o ...

Ways to generate arrays in Typescript

My dilemma lies in a generator method I've created that asynchronously adds items to an array, and then yields each item using yield* array at the end of the process. However, TypeScript compiler is throwing me off with an error message (TS2766) that ...

Obtaining the output of a JavaScript function within a Selenium WebDriver script

Is there a way to return an array from a JavaScript function using Selenium WebDriver? Below is the code I have attempted: System.setProperty("webdriver.chrome.driver", "D:/chromedriver_win32/chromedriver.exe"); wd=new ChromeDriver(); wd.navigate( ...

Meteor throws a "ReferenceError: module is not defined" error message following the installation of a package

I have created a meteor package that includes the ZiggeoSDK API to seamlessly integrate Ziggeo into my meteor app. However, upon installing this package, I encountered the following error: ReferenceError: module is not defined The Ziggeo Node Server SD ...