Using Three.js to Showcase Images within a JSON Data Structure

I am currently utilizing version 71 of the library to showcase an image on each side of a 3D object created in Blender. It doesn't matter if different images are used or if one image is repeated. The object is loaded using a load function post its instantiation as a JSONLoader. Below is an instance of loading the json file. In this scenario, the object is a cube comprising six sides. Is there a method to adjust the code below to achieve this?

    var loaderSix = new THREE.JSONLoader();
    loaderSix.load("./resources/json/six.json", function (model) {
        var materialSix = new THREE.MeshNormalMaterial();

        six = new THREE.Mesh(model, materialSix);
        six.translateY(1);
        six.scale = new THREE.Vector3(3, 3, 3);
        meshSix = THREE.SceneUtils.createMultiMaterialObject(six, materialSix);
    });

Answer №1

1) Have you considered using "MeshFaceMaterial" (docs) if you already have the geometry when loading materials?

var loaderSix = new THREE.JSONLoader();
    loaderSix.load("./resources/json/six.json", function (model) {
        var materialSix = new THREE.MeshFaceMaterial("your materials array: model");

        six = new THREE.Mesh("your cube geometry", materialSix);
        six.translateY(1);
        six.scale = new THREE.Vector3(3, 3, 3);
    });

2) When loading the object and wanting to add different images, "MeshFaceMaterial" can also be an option. A similar example can be found here. I adapted the code to suit the situation:

    var image;        
    var materials = [];
    for (var i=0; i<6; i++) {
     image = "./resources/images/"+fileName+".png"
     materials.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture(image)}));
    }
    var loaderSix = new THREE.JSONLoader();
        loaderSix.load("./resources/json/six.json", function (model) {
            var materialSix = new THREE.MeshFaceMaterial(materials);

            six = new THREE.Mesh(model, materialSix);
            six.translateY(1);
            six.scale = new THREE.Vector3(3, 3, 3);
        });

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

The variable was not able to be assigned any data

Having trouble assigning data to the variable eventsString. I retrieve data from the network using Retrofit within a coroutine, then assign the loaded data to eventsString. However, eventsString still holds the value 12. What am I doing wrong? class Overvi ...

Numerous operations included in a JavaScript document

Looking to enhance my JS file by adding multiple functions, but I'm having trouble as I'm not very familiar with JavaScript. Here's what I've got so far. $(function(){ $('.incentives').hide(); $('.incentives-click&a ...

An error is thrown when using AngularJS .length property

Currently, I am carrying out a regular task within my Filter to verify if angular.module('someApp') .filter('filterSomeData',['$filter',function ($filter) { return function (items, keyObj) { var filterObj ...

Express server unable to process Fetch POST request body

I'm currently developing a React app and I've configured a basic Express API to store user details in the database app.post("/register", jsonParser, (req, res) => { console.log("body is ", req.body); let { usern ...

Code error: JSON unexpected token "&" encountered

When utilizing the $http.get() method for a GET request, the response is in JSON format, but some characters are HTML encoded. For example, the double quote " is encoded as &quot;. { &quot;description&quot;:&quot;invalid&quot;, ...

Element sticking on scroll down and sticking on scroll up movements

I am currently working on a sticky sidebar that catches and stays fixed at a certain scroll point using JavaScript. However, I am facing an issue where I need the sidebar to catch when scrolling back up and not go further than its initial starting point. ...

Vuex data fails to update upon browser reload in Nuxt SSR

After explaining the bug, I discovered something interesting; Component codes async fetch(){ await this.$store.dispatch('bots/getBots') }, computed: { ...mapState('bots', ['bots']) }, Store codes export const state = () ...

Ways to extract single JSON entities from a consolidated JSON structure

I am facing a challenge with parsing multiple JSON objects within a single large JSON object. Currently, the entire JSON object is being stored as one entity, but I need to parse and store them separately in MongoDB. Below is the code snippet I am using. ...

Clicking on the ng-repeat will trigger the ng-click event, which populates all the data using ng

I need help including an HTML page using ng-click within ng-repeat. However, it is currently loading all the content for every ng-repeat element. My specific requirement is to only bind(ng-include) the clicked element. Please see the attachment for m ...

What is the best way to have a text field automatically insert a hyphen after specific numbers?

Is there a way to make a text field insert hyphens automatically after certain numbers? For example, when typing a date like 20120212, could we have the input automatically formatted with hyphens after the first 4 digits and the second two, so it displays ...

What is the proper way to reference a property's value within another property of the same JavaScript Object?

Within a Gulp.js file (or any Javascript file), I have defined paths in a Javascript object: var paths = { devDir : 'builds/development/', devDirGlobs : this.devDir+'*.html' } I am attempting to reference the pro ...

Issue with retrieving query results using node_redis client

I've been struggling with a particular issue that I just can't seem to solve. The problem revolves around not being able to retrieve output values from a Redis query. My setup involves using the node_redis client as the Redis driver for my Node.J ...

Steps to resolve org.json.JSONException: Index 2 out of bounds [0..2) error

I am encountering an error when trying to retrieve data from the following JSON in my API response: {"success":true,"id":"4","name":"VOUCHER GOOGLE PLAY","data":[{"id":10,"product_id":"GLP","product_name":"GOOGLE PLAY","prefix":null,"pembeliankategori_id" ...

At what point is the ajax call considered fully executed?

Whenever a client makes an AJAX call, they upload data to the server (HTTP request) and then receive data from the server (HTTP Response). Once the clients have received all the data, the AJAX request is considered successful, and the success callback func ...

Error in connecting on IOS due to JSON failure

Discover how to work with JSON in iPhone applications by following this tutorial Any device but may encounter issues when there is no internet connection. If the process of reading JSON fails, sometimes it takes a while for the iPhone to get an IP address ...

Is there a way to print the full page including scroll tab content?

https://i.sstatic.net/FJt7P.png I am facing an issue where I want to print the entire page including the scrollable content within a tab. Currently, only the visible screen content is being printed. ...

Creating a unique Angular 2 Custom Pipe tutorial

I've come across various instances of NG2 pipes online and decided to create one myself recently: @Pipe({name: 'planDatePipe'}) export class PlanDatePipe implements PipeTransform { transform(value: string): string { return sessionStor ...

Refreshing and enhancing Android contacts through the Expo project

For my current project, I am utilizing the Expo Contact module to automatically update contact information. Here is a part of my script that focuses on updating a selected phone number: const updateContact = async (callId, newCall) => { getSingleConta ...

When the user presses the enter key to submit data, the Ajax page reloads

I am facing an issue with a simple form for sending messages from one person to another using AJAX method POST to prevent page reload. The problem arises when the user hits [ENTER] in the field, causing the page to reload instead of the AJAX working as int ...

How to utilize Vue method for accessing DOM elements

I'm working on a container with various elements like h1, p, etc. The container has a background and I'm trying to create a method to move it based on mouse coordinates. However, I'm facing an issue where the e.target is showing me ele ...