Is it possible to identify when a particle is being hovered over in a particle system using three.js?

I've been attempting to detect when the mouse hovers over a particle within my particle system. The detection process that I have implemented is as follows and runs continuously:

function check_intersections() {
    var vect = new THREE.Vector3(
         mouse.x,
         mouse.y,
        0.5
    );
    projectr.unprojectVector( vect, camera );

     var raycaster = new THREE.Ray( camera.position, vect.subSelf( camera.position ).normalize() );
     var intersects = raycaster.intersectObjects( particleSystem ); 

    if ( intersects.length > 0 ) {

        //intersects[ 0 ].object.materials[ 0 ].color.setHex( Math.random() * 0xffffff );
        noticeDiv.text('Intersection');

    }
}`

The variable particleSystem represents my particle system containing numerous particles, while 'mouse' is defined whenever it moves, like so:

function onDocumentMouseMove( event ) {  
    // update the mouse variable
    mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
    mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
}

Despite studying various examples, I haven't been able to get this implementation right.

Answer №1

When using Raycaster.intersectObjects( objects ), keep in mind that it works with an array of THREE.Particles, but not with a particleSystem.

To see a practical example of its usage in CanvasRenderer, check out this demo.

Remember, WebGLRenderer does not provide support for THREE.Particle elements.

Make sure to study the functionality of Raycaster.js to gain a better understanding of how it operates.

This information is based on three.js version r.54.

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

Is it possible to provide an offset to the raycaster in three.js?

I am currently working on developing a pool game using three.js. As part of the gameplay, I have incorporated a helper ruler that indicates the direction of the hit. This ruler is represented by an ArrowHelper and is positioned at y=0, which aligns with ...

The contact form displays a confirmation message indicating successful submission, however, it fails to actually send the email

Having issues with a PHP script I created for the contact page on my website. After a user fills out and submits the form, they see a success message but the email is not sent. Can someone review this script and point out where I went wrong? <?php ...

The Uniqueness within Nested Arrays

let unique_segments = segment_arr.filter((elem, index) => { return segment_arr.indexOf(elem) === index; }); In the segment array, each element is represented as [ [x1,y1] , [x2,y2] ] which defines a segment between two points. Can anyone assist me i ...

Tips on transmitting checkbox data from AJAX to PHP

I'm currently working with this code and facing an issue where data from checkboxes is being sent to PHP one by one. I want to be able to send multiple selected data at once. How can I modify the code to achieve this? $('#lunas').click(funct ...

Enhancing MEAN Stack Application by Updating Table Post Database Collection Modification

In my efforts to ensure that my table data remains synchronized with the database information, I have encountered an issue. Whenever Data Changes: $scope.changeStatus = function($event,label,status){ var target = $event.currentTarget; target ...

In Three.js, FBX bones exhibit smooth rotation, but GLTF bones display strange rotation behavior

Currently, I have successfully implemented a dynamic model that works with an FBX file using the Three.js FBXLoader. However, for convenience sake, I decided to switch to using a GLTF/GLB file as it contains textures within the same file. To achieve this, ...

How can I implement pagination using jQuery?

I'm looking to incorporate jQuery pagination in my CodeIgniter project. After doing some research on the CodeIgniter forum and CodeIgniter AJAX Pagination Example/Guideline, I came across suggestions to check out a solution on TOHIN's blog. Howe ...

Retrieve storage information when an internet connection is unavailable on React Native

One of my recent projects involves creating an application that retrieves data from a URL in the form of an array of objects and then displays this data using FlatList. Upon launching the application, the data is displayed correctly since it's retriev ...

I am unable to implement v-bind click within a v-for loop

While working with VueJS framework v-for, I encountered a problem when trying to loop through lists of items. Each item index was supposed to be assigned to a variable, but the v-bind click event wasn't being attached properly inside the v-for element ...

Access AWS Lambda environment variables in Node.js using webpack

Looking to access environment variables in Node.js with Webpack? When trying to access them using process.env null values are returned. ...

The default styling of Next.js react-chatbot-kit is not functioning properly

import Chatbot from 'react-chatbot-kit' import config from './config' import ActionProvider from './actionProvider' import MessageParser from './messageParser' const ChatBotFlight = () => { return ( <div> ...

The updateItem function in the JSGrid controller was not called

Currently, I am working on a project involving js-grid. However, I have encountered an issue where the updateitem function of the controller is not being invoked when attempting to update a column field. Additionally, the field resets to its old value wi ...

Command field in Javascript

I've crafted an exquisite search box for my website, but I'm struggling to make it functional and display search results. Below are the Html and CSS files pertaining to this section of my site: .searchbox{ /*setting width of the form eleme ...

Converting JSON to Array: A Step-by-Step Guide

Greetings, StackOverflow community! This is my inaugural question here. I believe the answer is not overly complex, but my knowledge of Javascript is quite rudimentary. Currently, I have a JQuery AJAX function that processes this JSON object: { "Users" ...

Tribal Code Typescript Compiler

Typescript is a great alternative to Javascript in my opinion, but it bothers me that it requires node.js as a dependency. Additionally, I find it frustrating that there seems to be only one compiler available for this language, and it's self-hosted. ...

Guide on properly importing a .glb 3D file into Gatsby with R3F

I'm attempting to upload a 3D .glb file using R3F. However, I keep encountering the following error: ModuleParseError: Module parse failed: Unexpected character '☻' (1:4) You may need an appropriate loader to handle this file type, as cur ...

Synchronous: Establishing a connection to MongoDB once the server has successfully launched

I am curious to understand the interaction between Node.js asynchronous functions and MongoDB. If the server initializes before establishing a connection, and if my templates or Ajax requests rely on database data, will the serving of the HTML fail or will ...

Caution: React detecting an active event listener on a scrolling-dependent 'touchstart' action

I am facing an issue with a React component that contains a Material-UI Slider. Whenever this component renders, I receive the following warning message: "Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking ...

Why is ReactCSSTransitionGroup creating numerous components when I am anticipating just one?

While experimenting with ReactCSSTransitionGroup for animations, I encountered a peculiar situation that doesn't quite add up in my understanding. In the scenario below, every time I click on <div className="HeartControl">, it updates the heigh ...

The height map method for plane displacement is experiencing issues

The heightmap I have selected: Scene without grass.jpg map : Scene with grass.jpg map: https://i.sstatic.net/q6ScO.png import * as THREE from 'three'; import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'; import ...