Is there a way to adjust the parameters of objects within my scene that were loaded using OBJMTLLoader?

I am working on a scene that includes 3 cubes and a DAT.GUI menu. My goal is to switch any cube to wireframe mode when it is selected in the menu individually.

Although my code is successful for 2 out of the 3 cubes, I am facing an issue where the first cube remains unmodified. You can view the example here.

Here is the main part of the code:

var loader = new THREE.OBJMTLLoader( manager );

    loader.load( '/pruebas/models/cubosMateriales.obj', "/pruebas/models/textures/cubosMateriales.mtl", function(object){

        contenido = object;
        contenido.position.set(0,0,0);
        contenido.position.y = -80;
        contenido.name = "cubes";

        scene.add(contenido);
        console.log(contenido);

        return contenido;
    })

    renderer.setSize( window.innerWidth, window.innerHeight );
    canvas.appendChild( renderer.domElement );

    window.addEventListener( 'resize', onWindowResize, false );
}

function animate()
{

    requestAnimationFrame( animate );
    controls.update();

    if(contenido != undefined){             
        contenido.traverse( function( object ) {            
                    if( object.material ) {
                        object.material.opacity = opciones.Opacidad;
                        object.material.transparent = true;

                        contenido.getObjectByName("Box001").material.wireframe=opciones.cube_1;
                        contenido.getObjectByName("Box002").material.wireframe=opciones.cube_2;
                        contenido.getObjectByName("Box003").material.wireframe=opciones.cube_3;     
                   }
        })
    }
    render();
}

Examining the DOM Tree reveals the structure created for the three cubes.

In positions 1, 3, and 5 are the cubes while the remaining positions seem to have unidentified meshes (pun intended).

I need assistance identifying why I cannot modify the first cube and what these unnamed meshes represent.

Answer №1

While OBJMTLLoader may be deprecated, achieving the same result is possible by combining OBJLoader and MTLLoader. The issue arises when objects sharing the same material in the OBJ file (objects with identical materials assigned in 3DS Max) inherit that property in Three.js. Despite how the DOM Tree appears, each material is connected to its geometry, causing modifications to one child to affect all children with that material.

The workaround is to assign a distinct material to each object in 3DS Max before exporting to OBJ + MTL format.

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

Utilizing Fullcalendar Qtip to display information on mouseover rather than utilizing the eventRender

I have a challenge with integrating Qtip to the eventMousever event instead of the eventRender event in fullcalendar. The main reason for this adjustment is due to the server hosting the data being located in another country, resulting in significant late ...

Error with Vimeo SDK: Mysterious Player Issue Post Setup (VueJS)

I have a requirement to showcase multiple videos on a Vue-powered website using a Vimeo player. To achieve this, I have developed a VideoPlayer component specifically designed for each video: <template> <div class="video-element__containe ...

What is the best way to access and utilize the data stored in my database using mySQL, PHP, and JavaScript?

My Objective : When a user selects a location from the dropdown list, I want the function "newMark()" to place a marker on Google Maps; Current Achievements : The map is displayed along with the select field containing all locations saved in my database. ...

Slide your finger upwards to shut down the mobile navbar in bootstrap

Hey there, I'm currently developing a website using Bootstrap framework v3.3.4. I have a mobile navbar that opens when I click a toggle button, but I would like it to slide up to close the navigation instead. Here is an image showing the issue Do y ...

Having trouble showing the success message following row edits in jqgrid

I'm currently developing a web-based application with Bootstrap and I'm facing a challenge with implementing inline editing in my grid upon page load. The issue arises when displaying the success or failure message after performing an edit functi ...

Can you explain the TypeScript type for the queryKey in React Query?

Currently utilizing react query in conjunction with typescript. What should be the type of arguments passed to the function? export const useIsTokenValid = () => { const { data: token } = useQuery<string | null>(['token'], getToken, { r ...

The property 'scrollHeight' is undefined and cannot be read

I've created a messaging system using javascript and php, but I'm facing an issue. When new messages are received or the chat log grows longer, it creates a scrollbar. The problem is that when a new message arrives, the user has to manually scrol ...

Extract user's location using JavaScript and transfer it to PHP

My goal is to utilize JavaScript to retrieve the latitude and longitude, then compare it with the previous location, similar to how Facebook authenticates logins from different devices. To accomplish this, I have implemented 2 hidden fields which will capt ...

Utilizing a drop-down selection menu and a designated container to store chosen preferences

My form includes a select dropdown that displays available options (populated from a PHP database). Users can choose options from the list, which are then added to a box below to show all selected items. However, I am facing a challenge with the multiple s ...

What a great method to execute a button click within the same button click using jQuery!

Here's an example of code that attempts to make an ajax call when a user clicks a button. If the ajax call fails, the button should be reclicked. I've tried this code below, but it doesn't seem to work. $("#click_me").click(function(){ ...

Is the next function triggered only after the iframe has finished loading?

First and foremost, I understand the importance of running things asynchronously whenever possible. In my code, there exists a function known as wrap: This function essentially loads the current page within an iframe. This is necessary to ensure that Jav ...

What sets Koa apart when it comes to understanding the distinctions among await next(), return await next(), return next(), and next() in middleware?

The provided information explains the function of using 'await next()' in middleware to pause the middleware and initiate the next middleware downstream until all middlewares have completed execution. Once this happens, the process will start in ...

I could not retrieve data from the Promise {} object

Currently, I am in the midst of developing a discord bot using discord.js. When attempting to retrieve the target user, I utilize the following code: let target = message.guild.members.fetch(id). This method yields either Promise { <pending> } if the ...

Exploring the Validation of POST Requests with JSON Content

When working with NodeJS and Express 4, I often come across situations where the client sends JSON data that needs to be processed: { "data" : "xx" "nested" : { field1: "111", field2: "222" } } However, on the server side, I ...

The useEffect hook is not successfully fetching data from the local db.json file

I'm attempting to emulate a Plant API by utilizing a db.json file (with relative path: src\plant-api\db.json), and passing it from the parent component (ItemList) to its child (Item) but I am facing an issue where no data is being displayed ...

JavaScript Discord bot encounters an issue: .sendMessage function is not recognized

Currently, I am developing a bot and testing its messaging functionality using .sendMessage method. (I prefer the bot not to send messages upon receiving any input, hence avoiding the use of: bot.on("message", function(message) {}); However, I am encoun ...

Do I need to use the "--save" flag in npm to add dependencies to the "package.json" file?

Do I really need to use the "--save" flag in order to add an installed dependency to the "package.json" file? I conducted a test without the "save" flag and found that the package was still added to the "dependencies" section. It seems like it is the defa ...

Received extra keys from getStaticPaths in NextJs

Currently engrossed in a project for a client using NextJs, The blog section comprises various paths like blog/[:category], blog/[:category]/[:post], and blog/author/[:author]. To achieve this, I am utilizing getStaticPaths and getStaticProps. My approach ...

Implementing AngularJS directives with jQuery

Utilizing Jquery Selectric to enhance the select box in my AngularJS app led me to create a directive for rendering the element. Below you'll find the directive code along with how it's implemented. The Directive: angular.module('shoeReva ...

The JSON page does not display the image

I am facing an issue where the images are not displaying on both the JSON page and the HTML page, even though the image source name is being outputted. How can I ensure that the images show up on the HTML page? Thank you for taking the time to help. line ...