Clicking changes the texture and automatically hides other objects

I have a sphere in my scene and I want to change its texture when a click event occurs. However, when I apply the new texture to the sphere using my current code, it rearranges the elements in the scene causing other objects to be hidden behind the sphere. Adjusting the opacity of the sphere allows me to see the obscured elements clearly.

How can I maintain the order of elements in the scene while changing the texture of the sphere?

$("#button").click(function(){
    var textureLoader = new THREE.TextureLoader(manager);
    var materials = [
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.left), transparent: true, opacity: 1}), // right
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.right), transparent: true, opacity: 1}), // left
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.top), transparent: true, opacity: 1}), // top
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.bottom), transparent: true, opacity: 1}), // bottom
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.back), transparent: true, opacity: 1}), // back
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.front), transparent: true, opacity: 1})  // front
    ];

    mesh.material = new THREE.MultiMaterial(materials);
});

Sphere:

var mesh;
var geometry;
var scene = new THREE.Scene();

function init() {
    geometry = new THREE.SphereBufferGeometry(500, 60, 40);
    geometry.scale(-1, 1, 1);

    var textureLoader = new THREE.TextureLoader(manager);
    var materials = [
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.left)}), // right
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.right)}), // left
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.top)}), // top
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.bottom)}), // bottom
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.back)}), // back
        new THREE.MeshBasicMaterial({map: textureLoader.load(options.cubic.file.front)})  // front
    ];
    mesh = new THREE.Mesh(new THREE.BoxGeometry(1000, 1000, 1000, 7, 7, 7), new THREE.MultiMaterial(materials));
    mesh.scale.x = -1;
    scene.add(mesh);
}

Answer №1

Perhaps the issue lies in how the renderer organizes transparent objects.

You could experiment with changing the parameter

renderer.sortObjects = false // default is true ///

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

Tips for handling Ajax urlencode in PHP

I'm facing an issue with a problem and need some assistance to resolve it. Currently, I am attempting to utilize Ajax urlencode in PHP, but the POST content is not being displayed by PHP as expected when HTML is sent directly to PHP. The following c ...

In which situations is it required to specify the return type of a function in TypeScript?

When it comes to making functions in typescript, the language can often infer the return type automatically. Take for instance this basic function: function calculateProduct(x: number, y: number) { return x * y; } However, there are scenarios where dec ...

Error in Angular-CLI: The return type of a public method from an exported class is referencing the name 'ErrorObservable' from an external module, but it cannot be named as such

Upon completing the development of an app that mirrors an existing Angular 2 (non-cli) application, I am encountering errors in several of my files now that the project has been transitioned to Angular-CLI. I am puzzled as to why these errors are arising i ...

Retrieving the value from a vuetify v-text-field to use in another text field

Looking to suggest a username based on the user's first and last name. The concept is that after the user fills out the first name and last name fields, the value in the username field will be a combination of their first and last names. firstName = B ...

Encountering JSON parsing errors while using fetch() POST requests in Express

Currently, I am experimenting with HTTP requests and my main focus is on sending a POST request. The data for this request is coming from an input field and I am using fetch() to send it to a URL on my local host which is set up with express. My goal is to ...

After the completion of the AJAX request, navigate to the bottom of the specified

I have come across a solution on how to scroll to the bottom of a div here. However, it seems that it is not working for me, the same goes for autofocus. I suspect the problem lies in the fact that I am making an AJAX call, and it is not functioning prope ...

Exploring the seamless integration of the Material UI Link component alongside the Next.JS Link Component

Currently, I am integrating Material-UI with Next.js and would like to leverage the Material-UI Link component for its variant and other Material UI related API props. However, I also require the functionality of the Next.js Link component for navigating b ...

Attempting to eliminate the padding from the unordered list (ul) element within the pop-up box

Upon clicking the chip with chipName="button test IPA", a popup window appears. I am attempting to remove the padding from the ul tag within that popup. The issue I'm facing is that I cannot locate the ul tag in my HTML or JSX code. I have assigned a ...

Save the current active tab when refreshing the page

Struggling to find a way for the browser to remember the last active tab but haven't been successful. function ShowMyDiv(Obj){ var elements = document.getElementsByTagName('div'); for (var i = 0; i < elements.length; i++) if(element ...

Learn how to customize the signature of the onClick event in TypeScript

Looking at a sub-component example: import React from 'react'; interface TodoListProps { items: { id: string; text: string }[]; buttonHandler: (todoId: string) => void; } const TodoList: React.FC<TodoListProps> = (props) => { ...

Incorporate the value of a variable from the .gs file into a personalized HTML sidebar

In my google sheet, I have set up a custom sidebar through scripting. Within this sidebar, I aim to showcase the value from column I in the currently active row. I've successfully created a script that captures and stores the 'I' variable ...

Utilizing React's useState with array.map for handling multiple elements

I want to create multiple useStates for dynamically generated elements within an array.map. Each element in the array.map should share the same useState but have a unique assigned value. For instance, if the array.map contains three different elements, e ...

Using forEach Loop with Promise.all in Node.js

I am seeking a solution for a task where I need to read a directory, copy its contents, and create a new file within that same directory. function createFiles(countryCode) { fs.readdir('./app/data', (err, directories) => { if (err) { ...

Detecting Collisions in a Canvas-Based Game

As part of my educational project, I am developing a basic shooter game using HTML5 canvas. The objective of the game is to move left and right while shooting with the spacebar key. When the bullets are fired, they travel upwards, and the enemy moves downw ...

Exploring Json parsing in Python with Django

I am currently using Django for my web application. I am facing an issue where I cannot access Nodes and edges by calling decoded_data['nodes']. Instead, I am encountering the error message: 'NoneType' object is not subscriptable Thi ...

Is there a way to achieve this without relying on Ext.getCmp in this particular code snippet?

I am currently using the following code to trigger a button click event once the window show event is called. It works perfectly fine, but I want to achieve the same functionality without using Ext.getCmp. Here is the line of code: Ext.getCmp('recen ...

Attempting to transpile JavaScript or TypeScript files for compatibility within a Node environment

Our node environment requires that our JavaScript files undergo Babel processing. Figuring out how to handle this has been manageable. The challenge lies in the fact that we have a mix of file types including .js, .jsx, .ts, and .tsx, which is not subject ...

What measures do websites such as yelp and urbandictionary implement to avoid multiple votes from unregistered users?

It is interesting to note that on urbandictionary, you do not need to be logged in to upvote a definition. For example, if you visit and upvote the first word, it will record your vote. Even if you open an incognito window and try to upvote again, or use ...

Incorporating interactive buttons within Leaflet popups

I'm facing an issue with adding buttons to a Leaflet popup that appears when clicking on the map. My goal is to have the popup display 2 buttons: Start from Here Go to this Location The desired outcome looks like this sketch: ___________________ ...

What is the process for retrieving an Object from $cookies?

I've encountered an issue where I'm storing a user object on a Cookie and, upon the client's return visit to the site, I want to utilize this object's properties. However, upon the client's return, my cookie object appears as [obj ...