How can you efficiently load the materials for a THREE.BoxGeometry using THREE.LoadingManager()?

I am looking to enhance the image quality of a geometry after user interaction by initially loading low-resolution assets and then switching to high-resolution assets when the user interacts with it. When using the following standard code:

var materials = [
    new THREE.MeshPhongMaterial({ map:loader.load('assets/object/0.jpg' )  }),
    new THREE.MeshPhongMaterial({ map:loader.load('assets/object/1.jpg' )  }),
    new THREE.MeshPhongMaterial({ map:loader.load('assets/object/2.jpg' )  }),
    new THREE.MeshPhongMaterial({ map:loader.load('assets/object/3.jpg' )  }),
    new THREE.MeshPhongMaterial({ map:loader.load('assets/object/4.jpg' )  }),
    new THREE.MeshPhongMaterial({ map:loader.load('assets/object/5.jpg' )  }),
]; 
target.material.map.needsUpdate = true;
var texture = new THREE.MeshFaceMaterial(materials);
target.material = texture;

The low-resolution assets disappear from the geometry at first, showing the base color, while the high-resolution assets take a moment to load before appearing on the geometry.

I have read about using THREE.LoadingManager() for asset loading and swapping, but I am encountering errors in my implementation.

Here's what I have so far, which is causing issues:

var textureManager = new THREE.LoadingManager();
textureManager.onProgress = function (item, loaded, total) {
    console.log(item + ' = ' + loaded / total * 100) + '%';
};
textureManager.onLoad = function () {
    console.log(' loading complete');

    var materials = [
        new THREE.MeshPhongMaterial({ map: myTextureArray[0] }),
        new THREE.MeshPhongMaterial({ map: myTextureArray[1] }),
        new THREE.MeshPhongMaterial({ map: myTextureArray[2] }),
        new THREE.MeshPhongMaterial({ map: myTextureArray[3] }),
        new THREE.MeshPhongMaterial({ map: myTextureArray[4] }),
        new THREE.MeshPhongMaterial({ map: myTextureArray[5] })
    ]; 
    target.children[i].material.materials.map.needsUpdate = true;
    var texture = new THREE.MeshFaceMaterial(materials);
    target.children[i].material = texture;
};

var textureLoader = new THREE.ImageLoader(textureManager);
myTextureArray = [];
var myTexture = new THREE.Texture();

myTextureArray.push(textureLoader.load('assets/objtect1/hires/0.jpg', function (image) { myTexture.image = image; }));
myTextureArray.push(textureLoader.load('assets/objtect1/hires/1.jpg', function (image) { myTexture.image = image; }));
myTextureArray.push(textureLoader.load('assets/objtect1/hires/2.jpg', function (image) { myTexture.image = image; }));
myTextureArray.push(textureLoader.load('assets/objtect1/hires/3.jpg', function (image) { myTexture.image = image; }));
myTextureArray.push(textureLoader.load('assets/objtect1/hires/4.jpg', function (image) { myTexture.image = image; }));
myTextureArray.push(textureLoader.load('assets/objtect1/hires/5.jpg', function (image) { myTexture.image = image; }));

Any suggestions on where I might be making mistakes?

Answer №1

To assist others, the issue arose from my utilization of the ImageLoader instead of TextureLoader.

Substitute:

var textureLoader = new THREE.ImageLoader( textureManager );

With

var textureLoader = new THREE.TextureLoader( textureManager );

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

I encountered an issue when trying to dynamically add a text field in Angular 2. The error message received was "ERROR TypeError: Cannot read property '0' of

I am currently utilizing Angular2 in my project, and I am attempting to dynamically add a text field. However, I keep encountering an error: Error Message (TS): ngOnInit() { this.myForm = this._fb.group({ myArray: this._fb.array([ ...

Incorporate this form created externally onto my website

I have been working on my website and I am looking to incorporate a form that opens up once the login button is clicked. This form was generated using an online form builder which provides an embed code for seamless integration onto websites. Below, you wi ...

Journey Swiftly Control

I have a question. Is it possible to manipulate routes in Express? Can I assign multiple routes to the same get or post request when providing an address? module.exports = function (app) { var controller = app.controllers.maps.cliente; app.route(&apos ...

jQuery eliminates initial div just a single time

Here is a function I have created: function removeDiv() { var topmost = jQuery('.xx'); var totContent = topmost.find('.zz').length; var $target = jQuery('.xx').find('.zz').eq(0); if(totCont ...

The PlaneGeometry mesh is causing a black screen when used in Three.JS

As someone who is new to ThreeJS, I am trying to set a background image for a Scene. However, when I run the code below, all I see is a blank (black) screen. Can anyone help me identify the issue in the code? $().ready(function(){ var width= window.i ...

Can a component be passed as props and utilized within a child Component in Vue.js?

If we have components A, B, and C in a Vue 2.0 app, A declares, registers, and uses B. Can we pass C from A to B? For example: <template> <div class="A"> <B :child_component="C" /> </div> </template ...

Enhancing code readability in vim with custom Javascript syntax highlighting

Is anyone else experiencing issues with VIM's syntax highlighting for Javascript? I have noticed that at times, the highlighting seems to disappear and I have to scroll around to get it adjusted properly. Does anyone know of any workarounds or soluti ...

Develop a custom script function for every instance of a @foreach loop

I have a challenge where I need to style automatically generated table rows by clicking on a button. Currently, my code appears as follows: @foreach($tours as $tour) <tr id="{{$tour->id}}"> <td> {{$tour->tournr}} &l ...

Issue with handling click events on action column in Datatable using jQuery

Utilizing jquery datatable with an action column containing "edit" and "delete" links. The table populates correctly, but encountering an issue when trying to open a bootstrap modal form upon clicking the edit button within the table. However, the modal do ...

Why is Node.js unable to locate my files?

I'm currently utilizing Node.js as my server, and I'm encountering some difficulties in serving my JS and CSS files. For some reason, index.html is unable to locate them. Whenever I try to load up my browser, I encounter the following error: htt ...

How can we pass the onClick prop from a child component to a parent component in React with Typescript?

Currently, I am utilizing React along with TypeScript. I am curious about the process of passing an event from the parent component to a child component using props. Here is an example for better understanding: parent.tsx const ParentComponent: React.F ...

having difficulty applying border color to input when clicked

Is there a way to change the border color of an input field on an onClick event? In my scenario, if the 'Other' radio button is selected and a user attempts to save without entering any value in the input field, I want the border color of the in ...

Combining two states in the Vuex store

In my Vuex store, I have two states: notes (synced notes with the server/DB) localNotes (unsynced notes that will move to 'notes' state upon syncing) To display the notes in a list, I use a getter that merges the two objects and returns the me ...

The function Event.preventDefault seems ineffective when attempting to block input of CJK (Korean) characters in a v-text-field of type

Currently, I am tackling an issue in a Vue project where I need to fix a small bug. However, the solution seems quite challenging. I have managed to make the v-text-field accept only numerical input, which is functioning well. <v-text-field type=" ...

"Deleting a specific row from a SQL Server using Node.js: Step-by-Step Guide

Currently, my setup involves using nodeJs as the backend language and sql server as the database. While I have managed to delete whole table rows from the database successfully, I am facing a challenge when it comes to deleting a specific row. Here is the ...

How does the use of let versus const differ when iterating through a collection?

Utilizing Node.js (ES6) to iterate through each item in a collection like the one provided below: var statuses = [{ statusId: 1, description: 'New' }, { statusId: 2, description: 'Pending' }, { ...

Utilize React MaterialUI's ExpansionPanelSummary by incorporating a counter to a specific div id

I am in need of a feature that will automatically increment a counter in the div id every time the render function is invoked. The main goal is to ensure that each div has a unique identifier. Below is the current render function implementation - render ...

Utilizing AngularJS to iterate through an array of dictionaries

Within a specific section of my HTML code, I am initializing a scope variable like this: $scope.my_data = [ { c1: "r1c1", c2: "r1c2", c3: "r1c3", ...

Display a sneak peek on a separate tab

I have an editor on my website where users can input and edit their own HTML code. Instead of saving this to a database, I want to display the current user's HTML code in a new window using JavaScript. How can I achieve this without storing the code p ...

Incorporating the ThreeJS Transform tool into the Autodesk Forge Viewer

Trying to implement ThreeJS Transform control into the Forge Viewer by following an informative tutorial: The current issue is being able to add the Transform Control successfully, but not being able to interact with it. I had to make a slight adjustment ...