EdgesGeometry: raycasting precision issues

I'm currently working with EdgesGeometry on PlaneGeometry and it appears to be creating a larger hitbox in mouse events. Interestingly, this issue doesn't arise when using CircleGeometry. Below is the code snippet I am using:

    createPanel = function(width, height, widthSegments) {

      var geometry = new THREE.PlaneBufferGeometry(width, height, widthSegments);

      var edges = new THREE.EdgesGeometry( geometry );

      var panel = new THREE.LineSegments( edges, new THREE.LineBasicMaterial({ 
      color: 0xffffff }));

      return panel;

    }

   var tile = createPanel(1.45, .6, 1);

Currently, I am utilizing a RayInput library to handle raycasting, but for the sake of this scenario, let's assume I am solely using a standard raycaster for mouse events. When utilizing only the plane without the edges, the collision boundaries are accurate.

However, upon adding EdgesGeometry, the vertical hitbox appears to have significantly expanded, causing the object to register as clicked even when not directly clicked on. On the other hand, the expansion of the horizontal hitbox seems to be minimal. As this is my first time working with EdgesGeometry, I am unsure of the cause behind this behavior. Any insights would be greatly appreciated.

Thank you in advance.

Answer №1

When performing raycasting against objects of type THREE.Line or THREE.LineSegments, it is important to adjust the Line.threshold parameter based on the scale of your scene:

raycaster.params.Line.threshold = 0.1; // the default value is 1

This information is applicable to three.js version r.114

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 element is inferred to have the 'any' type. No index signature matching the parameter type 'string' was found on the 'User1' type

I have been experimenting with computed properties in TypeScript, but I've encountered a specific issue: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'User1'. ...

Make sure link opens in the same window/tab

Currently, I am utilizing the Open Link in Same Tab extension on Google Chrome. This extension can be found here. The purpose of this extension is to ensure that all links open in the same window/tab, which is necessary for touch screen kiosk left/right s ...

The target element is out of reach for the Puppeteer selector

When trying to extract the source of multiple images, I encountered an issue with the selectors not working properly. It seems like the elements are fake or not actually present on the page. Every page contains one of the desired elements (the main image) ...

Tips for passing input fields from a React Function component to a function

How can I retrieve the values from 4 input fields in my react functional component using a function called contactMeButtonPressed? The inputs include name, email, company name, and message when the contact me button is clicked. Do I need to implement stat ...

When placed in a conditional, the type of the body variable changes from a string to undefined

Unexpectedly, the final if block fails to retain the value of the body variable and transforms it into undefined. While the console log statement just before the block correctly displays the type of the variable as a "string", during the condition check an ...

Guide on launching a mobile application upon clicking a button in a mobile browser (with the assistance of JavaScript/React) [Utilizing Deep Linking]

My goal is to create a functionality where, on a mobile browser, when the user clicks on a button: If the app is already installed on the user's mobile device, it should open up. If the app is not yet installed, I aim to redirect the user to the appr ...

Customizable form fields in AngularJS

Consider the scenario of the form below: First Name: string Last Name: string Married: checkbox % Display the following once the checkbox is selected % Partner First Name: Partner Last Name: [Submit] How can a form with optional fields be created in Angu ...

Deduce the generic types of conditional return based on object property

My goal is to determine the generic type of Model for each property. Currently, everything is displaying as unknown[] instead of the desired types outlined in the comments below. playground class Model<T> { x?: T } type ArgumentType<T> = T ...

What is the best way to include additional items in a list?

Trying to add a new element of an array to the list while updating one property (id) by making it 1 more than the length of the array has resulted in strange outputs. Each new object added causes all elements to have values of array.length + 1. Various at ...

Display or Conceal Content Depending on the Button's Status

I am currently working on implementing an accordion style button for a project. I have configured my component to hide the list when the button is clicked, but I am encountering an issue where the list does not reappear. Additionally, I would like to inc ...

Issue with using bind(this) in ajax success function was encountered

In my development process, I utilize both react and jQuery. Below is a snippet of the code in question. Prior to mounting the react component, an ajax request is made to determine if the user is logged in. The intention is for the state to be set when a ...

Loading indicator displayed at the top of a div using JavaScript/jQuery

My current challenge involves implementing a progress bar, similar to the pace.js progress bar. The issue arises when the browser is refreshed, as the pace.js progress bar loads on top of the body instead of within a specified div. It is important that the ...

What is the best way to make a CSS element move with Javascript?

Currently working on a JavaScript game where I am in need of a CSS object to replace the original JavaScript object. Specifically, I want my "sword" CSS object to move along with my player object when it is Unsheathead. All the examples I find only show wh ...

Exploring Discord.js: Sorting a Collection of Retrieved Messages Using .sort()

This is a code example I am working with: .sort((a, b) => b.createdAt - a.createdAt) After fetching and filtering messages from a channel (which has a total of 8 messages), the filter operation returns a collection that may not be sorted in order. Ho ...

Passing an extra variable to the callback function in AJAX and saving the XMLHttpRequest.response as a variable

Attempting to read a local file on the server using the standard loadDoc(url, cfunc) function, my goal is to: 1) Search for a specific string in the file (getLine()); 2) If possible, save that line to a variable. For point 1, I provide a string to the c ...

Tips on Calculating the Number of Object Properties and Presenting Each Value Individually on a Dynamic Button with Click Event Attached

When it comes to displaying dynamic data with markers on a map, everything works fine up until this point. However, I've encountered some issues that I'm currently stuck on and not sure how to proceed. Dynamic data: { "page": 2, "data" ...

Working with floating point numbers in Node.js with a zero decimal place

NodeJS interprets float values with a zero after the decimal point as integers, but this behavior occurs at the language level. For example: 5.0 is considered as 5 by NodeJS. In my work with APIs, it's crucial for me to be able to send float values w ...

Sending JSON data along with sendFile() in Node.js and Express done right

After setting up a Node.js server with Express and routing, I am faced with the challenge of passing JSON data onto a specific page ("/users/id") while using sendFile(). While I could make an AJAX request on page load to retrieve the data separately, I am ...

What is the best way to obtain the output of the MULTIPLO.SUPERIOR function using JavaScript?

In Microsoft Excel, there is a function called upper multiple where we can input a number and it will round up to the nearest multiple of a second specified number - for example: 10,986 ; 5 = 15 105,32 ; 5 = 110 ...

the shifting of the camera's rotation in relation to the surrounding environment

Using react-three, I am trying to bind the camera to the player's position and rotate it. However, I want the camera's movement to be based on the world coordinate system, not its own rotated coordinate system. How can I achieve this while also c ...