Incorporating Three.js and Collada Loader to modify specific sections of a model within a .dae file

In my current project, I am using the Elf Girl model provided by three.js as an example. You can check out the model here.

I am looking to replace the image with this CE2 image instead of the original CE image.

Answer №1

Utilize the following code snippet:

var chosenObject;
modelOrScene.traverse( (obj)=>{
  if(obj.material && obj.material.map)
      console.log(obj.name) //display names of objects with material map image paths
  if(obj.name == 'NameOfTheObjectWithTheTexture")
      chosenObject = obj;
})

on your model to identify objects and materials with texture maps.

Once you have identified the object with the desired material+map, you can load a new texture using

   if(chosenObject)
      new THREE.TextureLoader().load( "yourOtherImage.png" ,(tex)=>{
       chosenObject.material.map  = tex;  //Update the object's material after loading the new texture.
    })

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

Associating an event with a newly created element in Angular2

I'm looking to add a new row with just one click on the + button. This new row will come equipped with a - button that can then be used to delete the newly created row. However, I've encountered an issue in attaching a click event to this new - b ...

Tips on implementing href with "javascript:window.open..." in AngularJS

I've been trying to utilize an anchor tag in my HTML code to open a new modal browser window with a URL retrieved through an Angular value like this: <a href="javascript:OpenPopUpPage('{{listing.Linktest}}');">Test Link</a> Alt ...

Issue with React component not reflecting updated state following Axios call

I have a series of chained axios calls to different APIs. When I log the state inside the function, I see that it is being updated correctly. However, when I log the state in the render() method, I do not see the updated state. The function is triggered a ...

How can I apply a texture to a 3D rectangle in THREE.js?

I am attempting to create a 3D box in THREE.js that represents a box made up of 2x4 Legos, measuring 24 pieces wide by 48 pieces long and an unspecified number of pieces tall. I have created a texture displaying this pattern using random colors: https://i ...

Serve the JS files in Express separately

I am facing issues with my webapp loading too slowly when using the express.static middleware to serve all my js files. I am considering serving each js file only when needed, such as when serving the html from jade that uses the js file. I have attempted ...

Finding the index of a nested div element with a click event using jQuery

I'm currently working on a click event to retrieve the index of the outermost parent div, but I'm facing some difficulties in getting it to work. Here is a snippet showcasing a list of several divs: <div class="owl-item"> <div class= ...

Control checkbox state based on Grandparent or parent selection in Vue

Currently, I am attempting to toggle a checkbox based on the status of either the grandparent or parent checkboxes: new Vue({ el: '.app', data: { grand_parent: false, parent: false } }) Unfortunately, it is not working as expected ...

filtering elements with selectable functionality in jQuery UI

I'm trying to exclude the <div> children from being selected within this list item and only select the entire <li>. The structure of the HTML is as follows: <ul id="selectable"> <li> <div id="1"></div> ...

I'm feeling completely lost trying to understand cors in conjunction with fetch, particularly when an options request is

I am using whatwg fetch in the code snippet below: const headers = new Headers(); //uncommenting this causes the preflight options request to be sent //headers.append('x-something', 'foo'); const response = await fetch(&apos ...

Is there a safe method to convert an HTML attribute (Javascript Object) into an array using Javascript or JQuery?

I have an HTML element containing a javascript object: <div ui-jq="easyPieChart" ui-options="{ percent: 75, lineWidth: 5, trackColor: '#e8eff0', barColor: ...

Any ideas on how to extract binary data from PHP passthru using a JavaScript ajax request?

I am facing an issue with retrieving and playing an audio file from a server using JavaScript. The ajax call in my code doesn't seem to callback, and I'm not certain if I'm handling the audio correctly in JavaScript. Below is the PHP file t ...

Searching MySQL data with ng-repeat filter

I am facing a challenge in populating a div tag with ng-repeat and data from a MySQL database. My intention is to utilize ng-repeat for its filtering capabilities in the future. The dilemma lies in the integration of Angular and SQL. My desired HTML struc ...

Having a THREE.js application running in Chrome causes my browser to slow down significantly

As I work on developing a small 2D game using THREE.js, I've encountered an issue where having a tab open with my THREE.js app loaded causes all my other tabs to slow down significantly. However, when I switch tabs and hide the THREE.js tab, everythin ...

Error: The element 'scrollable' is not recognized in Angular2

I recently updated my angular2 project to the final release after previously using angular2 RC5 for development. However, I encountered an error message stating "scrollable is not a known element." If I change <scrollable><!--- angular code -- ...

Troubleshooting encoding problems with Google Cloud's Speech-to-Text API using Node.js

I'm currently working on a project that involves capturing audio from a user's microphone and sending it to a server for translation using Google's Speech-to-Text API. I am utilizing navigator.mediaDevices.getUserMedia() to access the audio, ...

The issue arises when interfaces are extended by another interface

Is there a way to have classes that implement both the Observer and Comparable interfaces together? interface Comparable<T> { equals: (item: T) => boolean; } interface Observer extends Comparable<Observer> { notify: () => void } ...

What could be causing the issue with this JS code?

var feedback = {}; feedback.data = ["Great!", "See ya", "Not a fan..."]; feedback.display = function() { this.data.forEach(function(item) { console.log(feedback.display()); }); } The goal here is to showcase the content stored within the ...

managing a multitude of requests to a node.js api

Recently, I was tasked with creating a straightforward REST API using Node.js and developing a script to populate the database with 10000 elements via API calls. Utilizing the Hapi framework, I set up the server. Interestingly, when sending either a single ...

Enable the feature for users to upload images to a specific folder within the Chrome extension without the need for

I need to implement a feature in my Chrome extension that allows users to upload images directly to a specific folder named "upload" without needing a submit button. <form action="/upload"> <input type="file" name="myimages" accept="image/*"> ...

Ways to retain specific div elements following the execution of .html(data) command

Imagine I have a div structured in this way: <div id = "foo" style = "display: grid"> <div id = "bar"> keep me! </div> </div> If I use JQuery's .html(data) method like shown below: $('#foo').html(data); when m ...