After consolidating buffer geometries, adjusting the transparency/opacity of the shapes is not an option for me

I've been working on a model with multiple boxes and trying to optimize draw calls by using buffer geometry merger. However, I'm facing an issue where I can't change the opacity of geometries after merging.

Here are the things I've tried so far:

I attempted setting the opacity of the element using

element.setAttribute('material', {opacity: 0.6});

But unfortunately, I didn't see the expected change.

I also experimented with setting the opacity by creating a

geometry.addAttribute('opacity', new THREE.BufferAttribute(new Float32Array(geometry.attributes.position.array.length), 1)
and assigning all elements a value of 0.6.

However, this approach didn't yield the desired results either.

I've set up a small example that you can check out here:

The transparency-setting function is as follows:

function setTransparency(object, value) {
    var mesh;
    var geometry;
    var opacity;

    mesh = object.object3DMap.mesh;

    if (!mesh || !mesh.geometry) {
        // Event listener for updating when object is set
        el.addEventListener('object3dset', function reUpdate(evt) {
            if (evt.detail.type !== 'mesh') {
                return;
            }
            el.removeEventListener('object3dset', reUpdate);
            self.update(oldData);
        });
        return;
    }

    geometry = mesh.geometry;

    // Check empty geometry
    if (!geometry.attributes.position) {
        console.warn('Geometry has no vertices', el);
        return;
    }

    if (!geometry.attributes.opacity) {
        geometry.addAttribute('opacity',
            new THREE.BufferAttribute(
                new Float32Array(geometry.attributes.position.array.length), 1)
        );
    }

    opacity = geometry.attributes.opacity.array;

    for (i = 0; i < opacity.length; i += 1) {
        opacity[i] = 1 - value;
    }

    geometry.attributes.opacity.needsUpdate = true;
}

If anyone could guide me on what might be causing the issue or how to manipulate the opacity post-merging, I would greatly appreciate it!

Thanks in advance!

Answer №1

To adjust the transparency of the combined mesh, simply modify the opacity setting within the material component of the parent entity:

<a-entity buffer-geometry-merger material="opacity: 0.5; transparent: true">
  <a-box></a-box>
  <a-cylinder></a-cylinder>
</a-entity>

Check out the code snippet on this JSFiddle link.

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

Capture user input to extract data from a JavaScript object

I need help with implementing a search function where users can enter a name and the person's extension will be displayed on the UI either by clicking a button or pressing "return". Any ideas on how to make this feature work seamlessly? UI <html ...

Is there a way to set the content to be hidden by default in Jquery?

Can anyone advise on how to modify the provided code snippet, sourced from (http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide_show), so that the element remains hidden by default? <!DOCTYPE html> <html> <head> <scrip ...

The values of React children props will always remain consistent

While attempting to incorporate an ErrorBoundary HoC component for error handling following the guidelines from React16 documentation, I designed the ErrorBoundary component as a PureComponent. It became apparent that the children props remained consistent ...

What might be preventing combineLatest from executing?

Currently, I am attempting to run a block of code utilizing the combineLatest function. Within my translation library, there exists an RXJS Observable that is returned. Imported as individual functions are combineLatest, map, and tap. combineLatest(this. ...

Tips for setting up a popup menu when clicking a button on a webpage

I am currently working on developing a popup menu with a greyed-out background that appears when the user clicks on a button in React. My code implementation is as follows: // The ifButtonClicked function is called when another button is clicked // Some ...

Button press triggers the fadeIn function successfully, but the keypress event does not have the same effect

I'm currently facing an issue with two div elements on my webpage. I want only one of them to be visible at a time, depending on which key is pressed. If the 1 key is pressed, I want 'div1' to fadeIn (if it's not already visible) and fo ...

Sending data from local storage to ajax call

Below is the code snippet in question: $.ajax({ url: localStorage.getItem("isntagram link"), // url: "https://api.instagram.com/v1/users/self/feed?access_token=233291163.8a612cd.c49f77de073746e9a2f53116b720302e", met ...

Sending a multi-level property object to the controller in a post request

I am facing a challenge where I need to transfer an object from the view to the controller, and the model comprises a list of objects, each containing another list of complex objects. Let's consider the following models: public class CourseVm { p ...

Control the HTML button's state according to the information received from the server

I am currently working with datatable Jquery and using an ajax call to retrieve data from the server. Let's assume that the database consists of three attributes: "Attribute1, Attribute2, Status". Depending on the Status attribute, I need to enable or ...

Trigger oncopy on the body excluding specific class

Is there a way to execute a function on document.body.oncopy but exclude a certain class (defined for div elements) from this function call? I want to avoid calling the function on specific classes, is there a method to achieve this? ...

Ways to choose an option from a drop-down menu without the select tag using Selenium

I'm looking to perform automated testing with Selenium using Java but I'm facing an issue when trying to select an item from a dropdown list. The HTML structure does not include a select tag for the drop-down menu items (such as Auth ID and Corre ...

In Vue.js, utilize a contenteditable div to dynamically add an HTML element and bind it with v-model

Below is the HTML code I have written. <div id="app"> <button @click="renderHtml">Click to append html</button> <div class="flex"> <div class="message" @input="fakeVmodel" v-html="html" contenteditable="true">< ...

A tool that enhances the visibility and readability of web languages such as HTML, PHP, and CSS

Looking to organize my own code examples, I need a way to display my code with syntax highlighting. Similar to how Symfony framework showcases it on their website: http://prntscr.com/bqrmzk. I'm wondering if there is a JavaScript framework that can a ...

Callback Method Ajaxify

Just started using Ajaxify and so far it's been a great experience. However, I'm wondering if there is a callback function available that doesn't require any specific inputs in the script. I've searched around but haven't found wh ...

Tracking the progress of reading position using Jquery within an article

Here is an example of a reading progress indicator where the width increases as you scroll down the page: http://jsfiddle.net/SnJXQ/61/ We want the progress bar width to start increasing when the article content div reaches the end of the article c ...

Implementing Next.js with Firebase's onAuthStateChanged method allows seamless user

const checkUserAuth = () => { const [user, setUser] = useState(''); useEffect(() => { auth.onAuthStateChanged(function handleAuth(user) { if (user) { setUser(user); } else { setUser(null); } }) ...

Creating a topographical map from a 3D model

<!--B"H--> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Custom Terrain Heightmap Generator</title> ...

Modifying the HTML <select> element with JavaScript

[resolved] I'm encountering an issue with the code below that is supposed to dynamically change the options in a second drop-down menu based on the selection made in the first menu. I've tried to troubleshoot the problem but haven't been suc ...

Model Abstracted Aurelia Validation

I recently completed an online course on Aurelia by Scott Allen where he introduced the Aurelia-Validation plugin for form validation. As a result, my view-model now looks like this in edit.js: import {inject} from "aurelia-framework"; import {MovieServi ...

Loading a local FBX file in Three.js without the need to upload it

When attempting to load files selected by users in an HTML input, I encountered a problem with the loader expecting a URL in Linux style. I have tried various methods such as using a blob as a URL object, providing raw data to the FBX loader, and even usin ...