Unusual behavior experienced with raycasting in Three JS when objects are are repositioned

Software Versions

THREE.ObjectLoader2: 2.4.1
THREE.LoaderSupport.MeshBuilder: 1.2.1
THREE.LoaderSupport.WorkerSupport: 2.2.0
THREE.WebGLRenderer: 93
THREE.REVISION: 93

Anomalies Discovered

During a raycast operation on objects within my scene, I encountered precise results down to the pixel level until the object was moved. As part of my program's functionality, the scene is exploded, causing all objects and their child elements to move away from the center of the scene.

To better understand the issue, instead of casting rays on single points with mouse clicks, I decided to raycast the entire screen, resulting in the observations shown in Figure 1:

https://i.sstatic.net/3mlo4.png

(Figure 1) The gaps observed are due to the processing time involved in raycasting every pixel. Instead, only every fourth pixel was raycasted. The gap in the middle occurred as a result of zooming away from the original position.

Further analysis was conducted after exploding the object (Figure 2):

https://i.sstatic.net/iQIi9.png

(Figure 2) As illustrated, an almost circular pattern emerged. The reason for this phenomenon remains uncertain.

Investigation Efforts

I have attempted various methods sourced from online platforms but have not been able to resolve the issue.

Extensive tests were carried out using different models, each showing unique behaviors. Notably, the 'lamborghini-aventador' model created in Blender showcased unusual characteristics.

To rule out problems in the explosion code, the object was simply moved to the right, revealing intriguing outcomes (Figure 3):

https://i.sstatic.net/ORA1O.png

(Figure 3) It seems that the outlines applied to the object (generated by EdgesGeometry) appeared behind it, while the actual object shifted towards the middle, creating discrepancies in the raycasts.

Hypothesized Causes

A scaling-related issue is suspected, prompting the removal of all scaling operations from the code, albeit with no change in results.

If this turns out to be a rookie mistake, I would gladly welcome the revelation :)

Code Analysis

Brave souls willing to venture into my flawed codebase can access it here (demo.js):

GitHub Repository

Functional Testing

Press G to initiate raycasts (may experience brief delays), press X to explode, and press S to unexplode. Standard orbit controls apply.

Documentation Reviewed

The following resources were consulted in attempts to address this issue:

Three.js Raycaster API Documentation

Stack Overflow Discussion on Three.js Raycaster Issues

Three.js GitHub Issue #1325 (Matrix Update Problems)

Tutorial on Projecting Mouse Clicks in Three.js Scenes

... and many more ...

Any insights or suggestions?

Answer №1

It seems like there may be an issue with the bounding boxes or spheres generated for your model. If the shapes appear circular, it could be a result of the rays passing through a bounding sphere that is too small.

You mentioned that you resized or processed your geometries in some way... Have you tried calling geometry.computeBoundingBox() and geometry.computeBoundingSphere() after making those changes to recalibrate the boxes and spheres to see if that resolves the issue?

Update: It turns out that the problem was indeed related to the bounding boxes and spheres not being recalculated...

The solution involved:


scene.traverse( (o)=>if(o.geometry){o.geometry.computeBoundingBox();o.geometry.computeBoundingSphere();} );

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

Error: There was a syntax issue when trying to parse JSON due to an unexpected identifier "object" in the anonymous function

I'm having trouble understanding why there was an issue parsing this file: { "t": -9.30, "p": 728.11, "h": 87.10 } This is the javascript code I used: <script type="text/javascript"> function verify() { $.get("http://....file.json", funct ...

`Welcome to the World of AngularJS with IntelliJ IDEA`

Hey there! I'm currently diving into the world of Angular.js and IntelliJ IDEA, but seems like I've hit a roadblock. I'm attempting to create a basic "hello world" example from a book in the IDE, but it's just not cooperating. After dow ...

How to refresh a specific component or page in Angular without causing the entire page to reload

Is there a way to make the selected file visible without having to reload the entire page? I want to find a cleaner method for displaying the uploaded document. public onFileSelected(event): void { console.log(this.fileId) const file = event.targe ...

What is the best way to choose the element directly beneath a specific element using jQuery?

I am facing a challenge where I need to manipulate HTML content using only jQuery, without changing the original structure. The requirement is to display and slide down content with a specific class (current) upon clicking on an h1 tag. However, I am strug ...

TestingCompilerFactory is not available as a provider

Currently troubleshooting my test file to identify the issue that is hindering a successful test run: import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { Component, Directive, Input, OnInit } from '@angula ...

use jquery to dynamically switch CSS class on navigation with animated arrows

Looking to update arrows to display a right arrow when the parent list item has the .active class. Here is the jQuery code: jQuery(function(){ initAccordion(); }); function initAccordion() { jQuery('.accordion').slideAccordion({ opener ...

Leverage all the documents obtained from a collection to reference in a Vue component

I am attempting to display all documents from a Firestore collection in a table using refs, but I am unsure about accessing each field for template ref. getDocs(collection(db, "usr")) .then((querySnapshot) => { querySnapshot.forEach((doc ...

Retrieve the element by clicking on its individual tooltip

I am currently struggling with a jQuery UI tooltip issue. Specifically, I would like to retrieve the element that the tooltip is associated with when clicking on it. My Approach So Far $(".sample").tooltip({ content: function () { return $(t ...

The designated function name can be either "onButtonClick" or "onClickButton"

I am a Japanese developer working on web projects. Improving my English language skills is one of my goals. What would be the correct name for a function that indicates "when a button has been clicked"? Is it "onButtonClick"? Maybe "onClickButton"? Co ...

No response from jQuery's $.getJSON() function

I'm currently experimenting with jQuery by using a script that I wrote. As a beginner in learning jQuery, I am trying to read data from a .json file and display it in a div. function jQuerytest() { $.getJSON( "books/testbook/pageIndex.json", func ...

Is there a way for me to extract a smaller segment from an ID label?

I am working on a web development project and I have a set of buttons within a specific section. Each button has an id in the format of #balls-left-n, where n ranges from 1 to 15. My goal is that when a user clicks on one of these buttons, I want to extra ...

The clone() function in jQuery causes the properties of the original element to become distorted

Seeking help with a curious issue I'm encountering. After selecting a radio button and cloning it, the original radio button becomes unchecked while the cloned one behaves as expected. Any insights into why this might be happening would be greatly app ...

Retrieving text that has been HTML-escaped from a textarea using jQuery

Within my HTML file, I have a <textarea id="mytextarea"></textarea>. Suppose a user inputs the following text: <hello>, world! How can I retrieve res = "&lt;hello&gt;, world!"; based on the user's input? The current code s ...

The style of MUI Cards is not displaying properly

I've imported the Card component from MUI, but it seems to lack any styling. import * as React from "react"; import Box from "@mui/material/Box"; import Card from "@mui/material/Card"; import CardActions from "@mui/m ...

An index problem with BufferGeometry

Trying to transition code from openFrameworks to THREE.JS for generating a landscape with Perlin noise. The approach involves creating a static index array first, followed by positioning vertices in a square grid, each offset by a specific distance. This s ...

The second attempt at an AJAX call is unsuccessful

I am currently developing a form that displays database results based on two entries: Automarke (brand) and Modell (model). You can view the entries here. The Modell dropdown dynamically changes based on the selected Automarke. Here is the code snippet I ...

Ways to address the warning "promise rejections are deprecated"

I am struggling to understand promises and keep encountering an error about unhandled promise rejection, even though I have a catch block for handling rejections. Can anyone help me figure out what I am doing wrong? Below is the code I am working with: v ...

The largest contentful paint is anticipating an unidentified event

My website is encountering issues with Google Pagespeed and I'm unsure of the cause. The primary bottleneck appears to be the LCP time, which Google reports as taking between 7 and 11 seconds during each test. Upon analyzing the waterfall chart, it ...

Animation for Images in Angular v1.2

After reviewing tutorials and previous questions, I have been trying to pinpoint where my code is going wrong in applying an animation to transition between the images I want to display. The ng-show function effectively displays the selected picture, but ...

Show a decimal value as an integer in Razor

Looking for assistance with razor code: @Html.DisplayFor(model => item.sepordan_melk_foroshes.ghamat_total) The current output is: 123.00 How can I remove the decimal and display it like this?: 123 Any help with this would be greatly appreciated. ...