Issue with ThreeJs OBJLoader and MTLLoader: materials are loading successfully but not displaying on the object

I'm currently working on integrating a low-poly car model into my Three.JS scene using OBJLoader and MTLLoader. The downloaded model unfortunately lacks textures which makes it challenging to display the materials properly (as shown in the right car on the screenshot). Upon inspecting the .obj file in Blender, I noticed that the low-poly car's color is visible in Cycles rendering.

Although the materials are loaded successfully - verified by examining the value returned from ObjMtlLoader.load method (see code snippet below) - the issue persists with material display. Surprisingly, switching to ColladaLoader (left car on the screenshot) did not resolve the material visibility problem except for the wheels.

Given my limited availability due to work commitments, I seek your insights on this matter before delving deeper into troubleshooting. In case no solution emerges, manual creation of materials might be worth exploring as a last resort.

Below is an extract of the code:

// obj-mtl-loader.ts

export class ObjMtlLoader {

    private objLoader: THREE.OBJLoader = new THREE.OBJLoader();
    private mtlLoader: THREE.MTLLoader = new THREE.MTLLoader();

    constructor(basePath?: string) {
        if (basePath) {
            this.objLoader.setPath(basePath);
            this.mtlLoader.setPath(basePath);
        }
    }

    public load(objFile: string, mtlFile: string): Promise<THREE.Group> {
        return new Promise((resolve, reject) => {
            this.mtlLoader.load(
                mtlFile,
                (materialCreator) => {
                    materialCreator.preload();
                    this.objLoader.setMaterials(materialCreator);
                    this.objLoader.load(
                        objFile,
                        (model) => {
                            resolve(model);
                        },
                        () => {},
                        (reason) => reject(reason)
                    );
                },
                () => {},
                (reason) => reject(reason)
            );
        });
    }

}

Here is an example usage:

// renderer.ts
    new ObjMtlLoader().load(
        '/assets/racing/car_model/Low-Poly-Racing-Car.obj',
        '/assets/racing/car_model/Low-Poly-Racing-Car.mtl'
    ).then((car) => {
        this.SCENE.add(car);
    });

Additionally, here is a link to view the screenshot:https://i.sstatic.net/H406s.jpg

Answer №1

It seems that ThreeJS (or perhaps the specific version I am using) is not compatible with multimaterials. However, when I separate my meshes by material in Blender, the rendering appears as expected.

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

An array of objects in Typescript utilizing a generic type with an enum

Here’s a glimpse of code that showcases the issue: enum ServicePlugin { Plugin1, Plugin2, Plugin3, } interface PluginOptions { [ServicePlugin.Plugin1]: { option1: string }; [ServicePlugin.Plugin2]: { option1: number; option2: number }; } type ...

When reducing an Array of object keys, TypeScript automatically deduces the 'never' type in the accumulator object

const getObjectKeys = Object.keys as <T extends object>(obj: T) => Array<keyof T>; interface AB { a: string; b: number; } export function testFunction(config: AB) { Utils.getObjectKeys(config).reduce((memo, key) => { ...

The element is implicitly assigned an 'any' type due to the fact that an expression of type 'any' cannot be used to index types in nodejs and solidity

I am in need of setting networks in my contract using NodeJS and TypeScript. Below is the code I have written: let networkId: any = await global.web3.eth.net.getId(); let tetherData = await Tether.networks[networkId]; Unfortunately, I encountered ...

Tips for preventing the "Too many re-renders" error in React and avoiding infinite loops

While utilizing react typescript, redux toolkit, and material UI together, I encountered an error when calling the API: Error: Too many re-renders. React limits the number of renders to prevent an infinite loop. at renderWithHooks () at mountIndeterminat ...

Fix a typing issue with TypeScript on a coding assistant

I'm struggling with typing a helper function. I need to replace null values in an object with empty strings while preserving the key-value relationships in typescript // from { name: string | undefined url: string | null | undefined icon: ...

Integrating JavaScript functions into TypeScript

When converting a JavaScript function to TypeScript, I encountered an issue. The function works fine in JS but in TS, I receive the following error: [ts] Cannot find name 'PasscodeAuth'. Did you mean 'passcodeAuth'? function passco ...

Checking to see if a string meets the criteria of being a valid ARGB value

How do I verify that a string represents a valid ARGB value, such as #ffffffff for ARGB 255,255,255,255? Is there a way to validate this using TypeScript and C#? ...

Is it possible for a React selector to retrieve a particular data type?

As a newcomer to React and Typescript, I am currently exploring whether a selector can be configured to return a custom type. Below is a basic selector that returns a user of type Map<string, any>: selectors/user.ts import { createSelector } from ...

Can you tell me what that sequence of characters is at the conclusion of a styled-component?

Technology Stack: React, Typescript I believe this question may have been asked before, but I am unsure how to search for it... I am interested in creating a wrapper for the styled-components library... Here is the API reference for the specific packag ...

When a URL is triggered via a browser notification in Angular 2, the target component ceases to function properly

Whenever I access a URL by clicking on a browser notification, the functionality of the page seems to stop working. To demonstrate this issue, I have a small project available here: https://github.com/bdwbdv/quickstart Expected behavior: after starting t ...

Incorporate Typescript into specific sections of the application

I've got a Node.js application that's entirely written in JavaScript. However, there are certain sections of my app where I'd like to utilize TypeScript interfaces or enums. Is there a way for me to incorporate Typescript into only those s ...

Angular HighCharts - Retrieving chart data via API

My goal is to populate the data property of my chart with values obtained from an external API: . I've defined an Interface that matches the structure of the data: export interface ChartData{ item1: number; item2: number; ...

Conceal or remove disabled years in Angular Material datepicker

I previously disabled years prior to 2018, but now I would like to hide or delete them. The year selection range currently starts from 1998, but it should begin at 2018 instead. Is there a way to display only 3-4 years instead of the current 24-year rang ...

Material-UI: Tips for aligning pagination button in the center

My attempt to implement Pagination using Material-UI went well, but now I am struggling to center the arrow buttons and page numbers. I initially tried centering them by wrapping them in a <div style={{textAlign: "center"}}>, however this ...

Cannot display data in template

After successfully retrieving JSON data, I am facing trouble displaying the value in my template. It seems that something went wrong with the way I am trying to output it compared to others. My function looks like this, getUserInfo() { var service ...

Creating a multipart/form-data POST request in Angular2 and performing validation on the input type File

I am working on sending an image (base64) via a POST request and waiting for the response. The POST request should have a Content-Type of multipart/form-data, and the image itself should be of type image/jpg. This is what the POST request should look like ...

Issue encountered while declaring a variable as a function in TSX

Being new to TS, I encountered an interesting issue. The first code snippet worked without any errors: interface Props { active: boolean error: any // unknown input: any // unknown onActivate: Function onKeyUp: Function onSelect: Function onU ...

3D model rotation

I have a cow model in collada format, and I am looking to rotate it around with my mouse. I've tried several solutions but none of them seem to work with my current code. Below is the code snippet: The issue I'm facing is that I want to manuall ...

Ensure that the hook component has completed updating before providing the value to the form

Lately, I've encountered an issue that's been bothering me. I'm trying to set up a simple panel for adding new articles or news to my app using Firebase. To achieve this, I created a custom hook to fetch the highest current article ID, which ...

Angular firebase Error: The parameter 'result' is missing a specified type and is implicitly assigned the 'any' type

I have encountered an issue with the code I am working on and both the result and error are throwing errors: ERROR in src/app/login/phone/phone.component.ts(48,75): error TS7006: Parameter 'result' implicitly has an 'any' type. s ...