When using Three.js raycaster to intersect objects, it may not function properly if THREE.Points contains only one vertex or if the vertices are arranged in a straight line

I've spent quite a bit of time trying to figure out this issue. It seems that the

raycaster.intersectObject( pointCloud );
method does not intersect my 'pointCloud' Object when it only has one vertex in its position array attribute with three elements. Strangely, it works fine when the object has two or more vertices.

The geometry I'm working with is a THREE.BufferGeometry(), and I am using a custom ShaderMaterial. The object itself is a THREE.Points.

this.pointCloud = new THREE.Points( geometry, material0 );

Any ideas on how to resolve this?

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ Updated version of my question ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

It appears that the issue lies in the calculation of the boundingBox's min and max values when dealing with a THREE.Point that has a Buffer Geometry with just one vertex. In this specific scenario, the boundingBox calculations yield the same values for both min and max, resulting in no intersection detection. Even with multiple vertices aligned in a straight line, the boundingBox draws a line rather than a box, leading to the same problem.

Further details:

In the case of raycast intersection failures:

//in my file.js
intersections = raycaster.intersectObject( pc.pointCloud , true);  
//line 7734 three.js
intersectObject( object, this, intersects, recursive ); 
//line 7678 three.js 
object.raycast( raycaster, intersects ); 
//line 16542 three.js
if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {... 
//line 6152 three.js
intersectBox: function ( box, optionalTarget ) {...

Within the intersectBox function:

//line 6188 three.js 
if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;

The evaluation returns null due to the similarities between the x and y positions in the boundedBox, causing ( tmin > tymax) or (tymin > tmax) to be true. Changing particle positions to have different coordinates still results in no intersection.

If anyone can suggest a solution based on this information, whether by editing the three.js function or modifying the geometry for a valid boundingBox, it would be greatly appreciated!

Thank you!

Three.js 72

Answer №1

I received the solution from @WestLangley on GitHub.

@WestLangley advised:
"Your bounding box has no volume. Try this and let me know the results:

 pointCloud.geometry.boundingBox = null;

"

I followed the suggestion and it worked flawlessly! The detection now performs even better than before.


Another valuable insight shared by @Beiller in the comments, which I believe is crucial to mention here.

I had previously used

this.geometry.computeBoundingBox();

...for my geometry, however, since the points are not volumes, single points or those aligned along one axis (x, y, or z) were not being detected. By using instead:

this.geometry.computeBoundingSphere() 

the issue was resolved as well.

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

Discover the ins and outs of the "DOM" within a string, treating it as HTML in AngularJS

Looking to extract data from a legal HTML string based on tags and attributes, but want to avoid using jQuery in favor of Angular. Are there built-in functions in Angular for this task? ...

Guide on changing query using Ajax and Laravel when clicking a link

I am currently facing a challenging issue that seems unsolvable (I'm struggling to even understand where to begin). I have a total of four hyperlinks: https://i.sstatic.net/kn5vx.png When landing on the page initially, all the links are displayed b ...

Combining Playwright and Cucumber for Seamless Integration

I am seeking guidance on integrating Playwright with Cucumber. What is the reason for using a Cucumber.js file instead of a Playwright.config.js file to set up the paths for Cucumber feature files and step definitions? If it's possible, How can we spe ...

Delete particular user inputs following a $.ajax request

I have created a search feature with inputs that allow users to search the database using ajax requests. Unfortunately, I am facing an issue where the response from the server includes the search inputs themselves. This is not what I want. Here's a ...

The component 'createSvgIcon' from 'material-ui' is not available in the 'utils' module of '@material-ui/core'

After installing material-ui/lab to utilize the alert component, I encountered an issue when trying to import it using import Alert from '@material-ui/lab/Alert';. It failed to compile and threw the following error: ./node_modules/@material-ui/l ...

Safari failing to display Arc on 2D context

When attempting to draw a simple circle on a canvas, everything works smoothly in Chrome but encounters issues in Safari. What's puzzling is that even though I can retrieve the x position of the circle as expected, it simply fails to render correctly ...

Produce an additional page while remaining on the present one

I have a PHP-based invoice system that displays all customer invoices. I am interested in adding a feature that allows users to print an invoice directly from the list page without navigating away. While I am familiar with window.print() and media="print" ...

Press the Spin button located in the Protractor app

<hs-details-item ng-repeat="item in amenities" style="overflow:hidden" class="ng-scope"> <hs-label class="ng-binding">Pepsi</hs-label> <hs-value-block> <hs> <hs-sp ...

I would greatly appreciate your assistance in deciphering the JavaScript code provided in the book "Ajax in Action"

While reading through the Ajax in Action book, I came across a code snippet that has left me with a couple of questions. As someone who is new to web programming and still getting to grips with JavaScript, I am hoping for some clarity on the following: ...

How to activate a single element within a React array

I am currently working on developing a comment system similar to the one found on YouTube. In my setup, when I click on modify, all comments turn into input fields, but only the selected input should be modified. How can I trigger only the element I clicke ...

The $.Get method does not retain its value within an each() loop

When using the jQuery each() method on a DropDown select, I iterate through an li element. However, my $.get() function takes time to fetch data from the server, so I use a loading image that toggles visibility. The issue is that the each() method does not ...

The issue of JQuery UI Dialog remaining open even after triggering it through an Input focus event

I am facing an issue with JQuery and JQuery UI. I thought upgrading to the latest stable version would solve it, but unfortunately, that was not the case. I am currently using Chrome. When I initiate the dialog by clicking on a specific element, everythin ...

Problem with jQuery's .prepend method being called twice on list items

Looking to enhance the appearance of a list by adding some icons before the anchor links within each list item. <ul class="submenu-children"> <li><a href="#">Link</a></li> <li><a href="#">Link</a></li> ...

Unable to specify a particular <div> for fetching data using jQuery AJAX in ASP.NET

While working on the following Javascript code, I encountered an issue where the text specified inside the CommentItem div I am appending is not displaying. However, my main concern revolves around targeting ContainerPh which is located above the txtCommen ...

Discovering the value of an object through its prototypes

Is it possible to create a function that can locate the value "5" within an object's prototype? What is the proper algorithm to achieve this? var rex = { "Name": "rex", "Age": 16, } te = { "to": 5, } rex.te = Object.create(te); function findValu ...

After an ajax call in ASP .NET MVC3 using Razor, jQuery may not function properly

When I perform a post back to obtain a partial view using ajax, I utilize the following code to render the partial view within a div named 'DivSearchGrid'. <script type ="text/javascript" > $('#Retrieve').click(function ( ...

Having issues with JavaScript function returning value from Ajax request

My AJAX request function is functioning well - returning 1 for success and 2 for failure. However, I am facing an issue when trying to perform actions outside of this function based on the return value. Instead of getting either 1 or 2, I always receive "u ...

unorthodox method of transmitting parameters within express.js source code

While searching for the source code of express router, I came across this interesting piece: var debug = require('debug')('express:router:route'); I am curious to know more about this unusual way of passing arguments. Can someone ...

Incorporate React Components into a traditional HTML, CSS, and JavaScript project

Can I incorporate a React Native Component (https://www.npmjs.com/package/react-native-gifted-chat) into my vanilla JavaScript project? Is it feasible to embed a React Native component within a vanilla JavaScript project? If yes, then what is the process ...

Unable to apply ng-class when condition is met after ng-click

I am currently experiencing an issue with ng-class. When I click, I pass a variable and then check if it is true in ng-class. If it is indeed true, I append the "col-xs-6" class. Here is what I have attempted: <div ng-class="{'col-xs-6': myV ...