The process of raycasting with specific points within a collection of points in a Three.js Point

I am facing an issue with my PointCloud object. I want to draw a bounding box around a specific point when clicked, but I can't figure out how to access that individual point within the PointCloud.

This is the raycasting code snippet I have been using...

window.addEventListener('dblclick', function (ev) {
    var mouse = { x: 1, y: 1 };
    mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
    mouse.y = -( event.clientY / window.innerHeight ) * 2 + 1;

    var raycaster = new THREE.Raycaster();

    raycaster.params.PointCloud.threshold = 15;
    var vector = new THREE.Vector3(mouse.x, mouse.y, 0.5).unproject(camera);
    raycaster.ray.set(camera.position, vector.sub(camera.position).normalize());
    scene.updateMatrixWorld();
    var intersects = raycaster.intersectObject(particles);

    if (intersects.length > 0) {

        console.log(intersects[0]);
        var hex  = 0x000000;

        var bbox = new THREE.BoundingBoxHelper(intersects[0], hex);
        bbox.update();
        scene.add( bbox );

    } else {
        // do nothing
    }
});

While I can obtain the coordinates of the clicked point using intersects[0].point.x, passing intersects[0] to BoxHelper doesn't work as expected. It seems that intersects[0] is not an instance of Object3D. Similarly, utilizing intersects[0].object draws a box encompassing the entire PointCloud, whereas I specifically require it to be drawn only around the clicked point.

Is there a way to achieve this, and if so, what approach should I follow?

Thank you for any guidance provided!

Answer №1

Here are some examples that will assist you in working with particle and point clouds:

Explore webgl_interactive_particles as well as webgl_interactive_raycasting_pointcloud.

By using intersects[0].index, you can easily determine the index of the intersected point, allowing you to locate your specific point:

var index = intersects[0].index;
var point = particles.geometry.vertices[index];

You mentioned the need for an Object3D to draw a BoundingBox. Given that a single particle is essentially just a point in space, creating a BoundingBox around it would result in a box with dimensions of 0. Unfortunately, I am unable to provide guidance on this aspect.

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

5% of the time, Ajax fails and the response is "error"

When utilizing jQuery for Ajax calls, I have encountered a situation where the call fails approximately 5% of the time. To troubleshoot and understand the issue better, I implement this code: $.ajax({ type:'POST', url:'somepage.php ...

Analyzing similarities between objects and arrays to find and return the matches

Items {670: true, 671: true} List 0: {id: 669, item_id: 35} 1: {id: 670, item_id: 35} Desired outcome 0: {id: 670, item_id: 35} Is there a way to compare two datasets and return the matching entries based on their ids? ...

What drawbacks should be considered when utilizing meteor.js for development?

After viewing the meteor.js screencast, I was truly impressed by its seamless web application development capabilities, especially in terms of live updates and database synchronization. However, I am curious about its scalability once the website goes live ...

Struggling to implement a vertical scroll bar in HTML code?

<body ng-app="myApp" ng-controller="myCtrl"> <div ng-show = "dataFromRest" ng-repeat = "x in dataFromRest.posts" > <div class="tittle" style="width: 25%;"> <a href="" ng-click="showDi ...

How can you obtain values from a nested JSON object and combine them together?

I have a javascript object that is structured in the following format. My goal is to combine the Name and Status values for each block and then store them in an array. { "datatype": "local", "data": [ { "Name": "John", ...

Using Vue along with bootstrap-vue: Ensuring only one list element is expanded in a list (v-for) at any given time

In my Vue project with bootstrap-vue, I am utilizing the b-collapse feature within a v-for loop for lists. While it is functioning correctly, I am struggling to automatically close expanded list elements when a new one is clicked. Here is my question: Ho ...

Unable to retrieve the selected name in the controller

Forgive me for this, but I am still learning angularjs. I am facing an issue with a select control that is populated using the following code: <select ng-model="limit" data-ng-options="listLimit.name for listLimit in listLimits" data-ng-change="limitC ...

Tips for including descriptions on individual images within the jQuery PhotoStack gallery

Recently, I encountered a challenge. I am currently utilizing a PHP file for accessing images stored in a specific folder. Here is the snippet of my PHP code: <?php $location = 'albums'; $album_name = $_GET['album_name']; $files ...

Instafeed running on Ionic/AngularJS is unable to reach the scope

I have a question regarding the behavior of code in Ionic. I have added the following snippet to my controller in AngularJS and it works perfectly fine in pure AngularJS. However, in Ionic, the same code snippet does not work as expected. The tagName prope ...

Infinite loop triggered by jQuery dropdown menu on page resize was causing an issue

I have been working on developing a navigation menu for a website that displays as a horizontal bar on larger screens, but transforms into a jQuery dropdown menu when the window width is less than 980px. During initial page load with a window width below ...

The triggering of fire OnClick is contingent upon the outcome of OnClientClick

I am currently faced with integrating legacy code written in JavaScript and C#. I need to write a new piece of code that will determine whether the OnClick event should fire based on certain conditions. My approach involves checking these conditions within ...

WindowWizard - Unlocks the ability to open two windows simultaneously with just one click

Every time I click on the button below, it seems to open the page twice. I'm having trouble identifying the issue: The code in the .cs file: protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { btnPrint. ...

What is the best way to extract specific information from this JSON dataset while bypassing the top three

Can anybody help me with writing JavaScript code to parse this JSON? I am struggling to figure out how to skip the first 3 nodes and access the data within an iteration: [ { "Table":[ { "id":1, ...

jQuery's ajax request ends up in an error state

This is a function that removes a member: function removeMember(myElement){ jQuery.ajax({ url: "", data: { op: "showProjectWidget.projectHandler", rem:myElement.rel[0],// tried also (removing this comma) same iss ...

What is the code in CodeIgniter to retrieve the string 'Sugar & Jaggery, Salt' using <a>?

Can someone please help me? I am a beginner in CodeIgniter and I am having trouble passing a URL with a string. The controller is not accepting the string as expected. How can I fix this issue? //Below is the HTML code for passing a string value index.ph ...

Retrieve information from a website and transfer it to a Google spreadsheet

Despite the wealth of information on this topic, I have yet to find a solution that works for me. My goal is to transfer variables obtained from another website to Google Spreadsheet. These are the variables: var a = parseInt($('table.thinline:eq(4) ...

Elessar - addressing touch event issues

I have been experimenting with implementing multiple ranges using a library called elessar. Despite being a great library, the documentation is lacking. I managed to set everything up but it doesn't seem to work on touch devices. There are no errors s ...

Obtaining distinct form control values for replicated form fields with Angular

Issue with Dynamic Form Duplicates: I am currently working with a reactive form that has two fields - name and value. There is an add button that duplicates the form by copying these fields. The challenge I am facing is with updating the values of the dup ...

Creating multiple routes within a single component in Angular without triggering unnecessary redraws

Within the ChildComponent, there is a reactive form that allows for data entry. Upon saving the filled form, the route should be updated by appending an id to the current route. Currently, when saving, the component renders twice and causes screen flicke ...

Adding a custom script with wp_enqueue_script() upon form submission: Steps and guidelines

Currently, I'm working on a WordPress plugin that allows users to input inline scripts in a text-area on the plugin settings page, and then save it. My goal is to grab the submitted script and enqueue it in the header/footer of the theme. I've ...