Transform the Color of Textures when Hovering with the Mouse in Three.js

I'm having success with using a MouseOver Event to change the color of most objects in my application, but I can't seem to get it working for textures created using "disc.png" (the red dots in the result window). How can I modify my code to only change the color of these textures instead?

var renderer, scene, camera;
var control;
var stats;
var cameraControl;
//var radius = 7.7;
var radius = 15;
var group = new THREE.Object3D();
  
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector3(), INTERSECTED;
  
// Initialize the scene, camera and objects.
function init() {
  
  // To display anything, you need 3 things: (1) Scene, (2) Camera, (3) Renderer
  scene = new THREE.Scene();
  camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
  renderer = new THREE.WebGLRenderer();
  renderer.setClearColor(0x000000, 1.0);
  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.shadowMapEnabled = true;
  
  // Mars needs (1) geometry, (2) material, (3) mesh
  var sphereGeometry = new THREE.SphereGeometry(15, 60, 60);
  var sphereMaterial = createMarsMaterial();
  var marsMesh = new THREE.Mesh(sphereGeometry, sphereMaterial);
  marsMesh.name = 'mars';
  scene.add(marsMesh);
  
  // position and point the camera to the center of the scene
  camera.position.x = 25;
  camera.position.y = 26;
  camera.position.z = 30;
  camera.lookAt(scene.position);
  
  // add controls
  cameraControl = new THREE.OrbitControls(camera);
  
  // setup the control object for the control gui
  control = new function () {
    this.rotationSpeed = 0.000;
  };
  
  // add extras
  addControlGui(control);
  addStatsObject();
  
  // add the output of the renderer to the html element
  document.body.appendChild(renderer.domElement);
  
  // add a star field
  var starsGeometry = new THREE.Geometry();

  for ( var i = 0; i < 10000; i ++ ) {

    var star = new THREE.Vector3();
    star.x = THREE.Math.randFloatSpread( 2000 );
    star.y = THREE.Math.randFloatSpread( 2000 );
    star.z = THREE.Math.randFloatSpread( 2000 );

    starsGeometry.vertices.push( star )

  }

  var starsMaterial = new THREE.PointsMaterial( { color: 0xF9F9CF } )

  var starField = new THREE.Points( starsGeometry, starsMaterial );

  scene.add( starField );

  // start animating
  render();
  
}
  
function createMarsMaterial() {
  
  // 4096 is the maximum width for maps  
  var marsTexture = THREE.ImageUtils;
  marsTexture.crossOrigin = "";
  
  marsTexture = THREE.ImageUtils.loadTexture("https://tatornator12.github.io/classes/final-project/Using_Three_-_D3/mars.jpg");
  var marsMaterial = new...
body {
  /* set margin to 0 and overflow to hidden, to go fullscreen */
  margin: 0;
  overflow: hidden;
}
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<script src="https://tatornator12.github.io/classes/final-project/Using_Three_-_D3/three.js"></script>
<script src="https://tatornator12.github.io/classes/final-project/Using_Three_-_D3/OrbitControls.js"></script>
<script src="https://tatornator12.github.io/classes/final-project/Using_Three_-_D3/dat.gui.min.js"></script>
<script src="https://tatornator12.github.io/classes/final-project/Using_Three_-_D3/stats.min.js"></script>

Answer №1

element, there was a unique initialization process for the bounding sphere of the Point object. The text explained that the radius was set to zero and manually constructed to ensure your mouse never hits it. The scene setup included 3 essential elements: Scene, Camera, and Renderer in the Three.js environment. Various controls and objects were initialized, including a Mars mesh with textures loaded from external sources. Additionally, functions for handling control GUI, stats display, rendering, resizing, and mouse movement interaction were defined. The entire script laid out an intricate web-based visual representation using WebGL technology. External libraries like D3.js, TopoJSON, and specific files for Three.js components were linked within the code snippet for seamless functionality.

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 functionality of the AngularJS UI-Router seems to be impaired following the minification of

Hey there, I just developed an app with Angular and implemented ui-router for routing. To reduce the file size, I minified the entire Angular app using gulp-uglify. However, after minifying the app, the child route (nested route) of ui-router is no longer ...

Matching words with their meanings - exploring storage possibilities

I want to create a system to store vocabulary words and their translations in an organized manner... One idea I had was to use an associative array where each object represents a word and its translation. var vocab = []; vocab.push({"chinese" : "Nǐ", "e ...

Create artwork by drawing and adding text to an image before saving it

I am looking to enhance my website by adding a feature that allows users to draw on images hosted on the server. Additionally, I want users to have the ability to add text to the image and save their edits as a new picture. While it may seem like a simple ...

Verify the validation of the text box

Checking a textbox control for validation is necessary. Validation Criteria: Value should be between 0 and 1000, with up to 2 decimal places (e.g. 1.00, 85.23, 1000.00). Once 2 decimal points are used, users should not be able to enter additional ze ...

Guide on ensuring Bootstrap tooltip remains visible using just JavaScript

Greetings, I recently found myself searching for ways to ensure that the tooltips on my webpage remain visible at all times. During my quest for a solution, I stumbled upon this enlightening discussion on Stack Overflow. Interestingly, all the proposed sol ...

Enable a button or class to dynamically alter its color

Hi there! I'm new to coding and just started learning HTML and CSS. My question is: How can I change the color of buttons once they are clicked? <div class="icon-bar"> <a href="#"><i class="fa fa-search" ...

Discovering a specific element using jQuery

I am trying to work with a div structure like this: <div class="country"> <div class="cty_popover"> <p>TITLE</p> <ul> <li>NAME 1</li> <li>NAME 2</li> ...

What is the method to define a loosely typed object literal in a TypeScript declaration?

We are currently in the process of creating TypeScript definitions for a library called args-js, which is designed to parse query strings and provide the results in an object literal format. For example: ?name=miriam&age=26 This input will produce th ...

The eternal Three.js animation that loops endlessly whenever it is clicked

The Objective My aim is to create a straightforward camera zoom in animation that increases the zoom level by a specific amount each time the button is clicked. The Current Status I have successfully implemented the animation using Three.js and linked i ...

javascript - disable screen capture of specific parts of a webpage

Recently, I've come across certain web pages that have a unique feature preventing screen capture of specific regions. When attempting to take a screenshot using Chrome, some areas that are visible on the live page appear as black frames in the captur ...

What is the best way to display all the properties of an npm package in an aesthetically pleasing format?

My curiosity leads me to explore the various methods and properties of components like GoogleMapReact. I attempted the following code: import GoogleMapReact from 'google-map-react' console.log(GoogleMapReact); However, the output is a long, mess ...

What could be causing the malfunction of the Facebook iframe like button?

Even though it functions offline, there seems to be an issue with its performance online. Here is the code that was used: <iframe src="http://www.facebook.com/plugins/like.php?app_id=125925834166578&amp;href=http%3A%2F%2Fwww.facebook.com%2FBaradei. ...

Issue: Unable to access 'filter' property of null object

I've been working on a small react dropdown task and it's running smoothly in Google Chrome. However, I encountered an error when testing it on MS Explorer. Even after deploying it on a live server, the issue persisted. The specific error message ...

Automatically substitute a term with a clickable link

Is there a way to automatically turn every word into a hyperlink? I have specific words that need to be linked. For example, I want Ronaldo (Only for the First Appearance) to link to a certain page. However, my attempted method did not work. <p> Ro ...

What exactly does the dollar sign signify in plain JavaScript code?

While watching a tutorial on object literals in JavaScript, I noticed something interesting. The instructor demonstrated creating an object like this: var Facebook = { name: 'Facebook', ceo: { firstName: "Mark", favColor: ...

Encountering difficulties when fetching JSON data with the Ionic AngularJS framework

Currently, I am following Lynda's tutorial on Ionic framework and have encountered an issue while working on backend coding. After generating the app, I proceeded to open the www/js/app.js file to include a controller with the following code: .contro ...

I am eager to showcase a Pokémon image sourced from the API, but I am faced with the challenge of only having the image URL and not knowing how to display it effectively

As a beginner in programming, I am seeking some assistance. I have been able to retrieve a random Pokémon from an API and gather its data, including the ID, name, and picture. My main focus now is to display the image of the Pokémon in the custom modal I ...

Is there a simple method to extract all components from an SVG document and insert them into an HTML text box?

Looking to provide users with the option to manually edit an SVG document. Is there a direct way to utilize DOM to extract all elements from an SVG document and place them in a text box? Attempted using innerHTML, but it doesn't work for SVG. Is the ...

React fails to trigger a re-render despite updating the state following an API call

Recently, I started working with React and attempted to retrieve data from my API. However, changing the state does not trigger a re-render of the component. Inside the useEffect function in my component, I have code that fetches the API and then sets the ...

JavaScript: Troubleshooting Array Formatting

Seeking assistance with formatting this JavaScript array accurately. It seems like I am overlooking something crucial: Javascript: <script type="text/javascript"> var dimensions = new Array("225","320","480", "--"); var walls = new Array() ...