Adjusting transparency of uploaded 3D model in Three.js

I've successfully loaded a 3D object model into a three.js scene using the following code:

var skull;

var loader2 = new THREE.ObjectLoader();

loader2.load(
    'skull.json', 
    function(object) {
        skull = object;
        scene.add(skull);
    }

);

Now, I'm trying to figure out how to dynamically adjust the opacity of the model. I have searched through the skull variable but couldn't find any properties related to opacity.

Does anyone have suggestions on how I can achieve this?

Answer №1

In the event that the 'skull' object is represented as a mesh within your JSON file, a simple adjustment like skull.material.opacity = 0.5 would suffice. Sometimes, a 3D model file may consist of multiple objects, requiring traversal through them:

skull.traverse((node) => {
  if (node.isMesh) {
    node.material.opacity = 0.5;
  }
});

For more information, refer to the documentation for THREE.Material and THREE.Object3D. This code snippet is designed for three.js version r91.

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

Show the present category name within breadcrumbs (utilizing angularJS)

Struggling to display category and vendor names on breadcrumbs? Utilizing the ng-breadcrumbs module but encountering difficulties in making curCategory and curVendor globally accessible. Tried various methods without success. Below is the HTML code snippe ...

Having trouble with radio button validation in JS?

I'm having difficulty understanding why the radio button is not staying checked when I select another option. To demonstrate, I created a fiddle where initially the "diy" button is selected but switching to "paid" causes the radio button to jump back ...

Encountering 'Unacceptable' error message when attempting to retrieve response via AJAX in the SPRING

I'm encountering an issue with my code where I am trying to retrieve a JSON array response from a controller class. Whenever I send a request from JavaScript, I receive a "Not Acceptable" error. Can someone please assist me in identifying the bug in m ...

Retrieving a JavaScript variable in PHP on the identical page by simply altering the div tag within the URL

I have a webpage called abc.php that showcases a table of image names. When a user clicks on an image name, an overlay page is loaded at #openModal on the same abc.php page. This new overlay page displays a list of sensor values related to the selected ima ...

Node.js: Extract the object's name and value that are sent from the frontend

I'm in the process of creating a microservice using nodejs. The request is returning the following JSON. { "distCd": "abcd", "distName": "parentLife Distributor (TOD)", "stateCd": "", "subdistInd": false, "maindistInd": true ...

Display a hoverable button for a singular element within an array during the process of mapping through the array

const ChatWidget = () => { const bodyRef = useRef(null) const [{messages,roomMessages,roomID,socket,user}, dispatch] = useStateValue() const [dropdown, setDropdown] = useState(false) useEffect(()=>{ const setScreen = () =>{ bodyRef.cur ...

Are tabs best displayed as an overlay?

I've been searching high and low for a tutorial on how to create an overlay with tabs similar to the Google Chrome webstore. If anyone knows of a tutorial or a combination of tutorials that can help me achieve this, please let me know! Link Any guida ...

The hover state of a div will not be lost if its parent element is not being hovered over

When hovering over the second, third, or fourth item, hidden text will appear on the left side. If you hover your cursor over the hidden text, it will disappear again. I want to be able to hover over the second item, move my cursor to "hide", and click o ...

Revamp your handles using the power of jQuery rotatable!

Greetings! I am currently utilizing a minified plugin created by godswearhats in my project. To activate the plugin, I simply call the following function: $('#em_1').rotatable(); Here is an excerpt of my HTML code: <div class="draggable par ...

The drag-and-drop feature for uploading files is not functioning properly

After following the JavaScript drag and drop script tutorial mentioned here and using the PHP upload script provided here, I made modifications to the XHR request to upload.php in the JS code. The progress now reaches 100%, but the uploaded image does not ...

Is it possible to hide a fixed header on scroll in a mobile device?

I am facing an issue with my Wordpress site where I want the header to hide when the user scrolls. Despite trying various codes, I have been unable to make it work. The reason for wanting to hide the header is that on mobile devices, it causes scroll prob ...

How can JavaScript routes be used to apply specific code to multiple pages on a website?

Can you provide guidance on how to run the same code for multiple pages using routes? Below is an example I am currently exploring: var routeManager = { _routes: {}, // Collection of routes add: function(urls, action) { urls.forEach(fun ...

To implement the replacement of text with a selected item in AngularJS, simply

I have a dropdown in my HTML: <div class="dropdown"> <button class="dropdown-toggle" type="button" data-toggle="dropdown" ng-model="yearName">Filter by year <span class="caret"></span></button> < ...

Using Vue.js to iterate over a list of items and accessing specific array objects by their unique identifier

My JSON array of objects has the following structure: https://i.sstatic.net/1IUVE.png When generating a <ul>, I need to fetch an ID from an API for each <li>: <ul> <li v-for="genre in movie.genre_ids"> {{ genre }} ...

using Javascript to calculate motion based on specified angle

http://pastebin.com/3vwiTUyT I have posted my code here and need assistance. Specifically, I am trying to make krog1 move within the canvas based on a specific angle that I set. Unfortunately, I am unsure how to accomplish this task. ...

The GitHub-hosted package encounters a failure during the npm publish process

Last week everything was running smoothly, but now I am encountering an error and not sure what went wrong. (Apologies for the formatting as there are many lines of log) Running Node version: v10.15.3 Using npm version: 6.4.1 After executing npm publish ...

Strategies for breaking apart a large, monolithic Node.js JavaScript application

My node.js server application is expanding, and I am looking to split it into multiple files. Below is a snippet of the current monolithic server.js file: var express = require('express'); var app = express(); // other initialization code etc / ...

Using a jQuery gallery can cause links to become unresponsive and unclickable

While creating a responsive webpage with the Zurb Foundation framework, I encountered an issue when trying to incorporate nanoGallery which also uses jQuery. After adding the gallery scripts, the top menu generated by the Foundation script became unclickab ...

Switching the visibility of multiple textareas from block to none

I am currently exploring ways to make one text area disappear while another one appears in its place. With limited knowledge of Javascript and just starting my journey into HTML and CSS, I am reaching out to the forum for assistance or guidance on the rig ...

Tips for combining arrays of objects

I have two arrays containing objects const obj = { teamRows: [ {name: 'Alice', admin_id: 1}, {name: 'Bob', admin_id: 2}, {name: 'Charlie', admin_id: 3}, ], roleRows: [ {title: &apos ...