How to obtain mouse coordinates on a texture using three.js

I am looking to develop an engaging interactive panorama similar to the one showcased here:

However, I am interested in allowing users to have the ability to interact with it.

Is it feasible to retrieve coordinates from the texture based on mouse movement in order to create a three-dimensional image map using three.js?

Many thanks!

Answer №1

Take a look at this: Converting mouse position to Object coordinates

Once you identify the triangle that the ray intersects, you can collect the 3D coordinates and UVs of the triangle's vertices. With this information, you can calculate the UV position for the intersection point.

Here is some pseudo-code to help illustrate:

x0 = mouse.x; y0 = mouse.y;
vec3 samplePoint = unproject(x0, y0);  // provides (x, y, near-plane-z) coordinates
ray.origin = camera.position;
ray.direction = samplePoint - camera.position;
var triangleComplexObj = check_for_intersections( scene, ray );  // identifies triangle, its vertices, their UV and 3D coordinates, and intersection point coordinates
calulateUV( triangleComplexObj , triangleComplexObj.intersectionPoint );

It may seem a bit intricate at first, but it should get the job done. I hope this explanation is helpful.

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

In AngularJS, the visibility of controller data seems to be elusive to me

Here is a snippet of code from my template: <ul> <li ng-repeat="x in names"> {{ x.name + ', ' + x.country }} </li> </ul> And here is the corresponding JavaScript code: app.controller('TestCtrl', ['$sc ...

When using Reactjs with leaflet-routing-machine, the waypoint is rendered twice

While attempting to use the leaflet-routing-machine library, I encountered a bug. The issue is that the "Waypoints" section is rendering twice. Why is this happening? Can anyone offer assistance? Thank you https://i.sstatic.net/MlkQ2.jpg My code is lis ...

Issue: Query cannot be added to the queue after quit has been called

I am encountering an error "Error: Cannot enqueue Query after invoking quit" when trying to run the code below. I need assistance with inserting data into two tables. As a newcomer to node.js, I would greatly appreciate your help in correcting the code. ...

Anticipated the server's HTML to have a corresponding "a" tag within it

Recently encountering an error in my React and Next.js code, but struggling to pinpoint its origin. Expected server HTML to contain a matching "a" element within the component stack. "a" "p" "a" I suspect it may be originating from this section of my c ...

Using Jquery to insert error messages that are returned by PHP using JSON

I am attempting to utilize AJAX to submit a form. I send the form to PHP which returns error messages in Json format. Everything works fine if there are no errors. However, if there are errors, I am unable to insert the error message. I am not sure why th ...

What is the best way to invoke my Python function within my JavaScript file?

I am facing an issue with using my Python function in JavaScript. Although the actual code I am working on is more complex, I have simplified it to demonstrate the problem below: main.mjs dbutils.notebook.run("./aPythonFile.py", 5, {"parame ...

Uncovering the Telltale Signs of a Modified Ext.FormPanel

How can I enable the "Save" button in my Ext.FormPanel only when a user modifies values within the form? What is the best method to detect changes made by the user? I attempted using form.on("change") and SelectionMode but encountered no success. ...

Steps to dynamically populate a datatable with JSON data by triggering a click event in jQuery

I am facing an issue with feeding JSON data into datatables when the search button is clicked. The JSON data structure is as follows: [ { "port_code":"BOM", "cont_details_id":"9", "price":"44.000", "cont_price":"500", "c ...

The weight of the Blender model is excessive

Seeking advice on optimizing loading times for my threeJS website. Currently experiencing long initial loading due to 4 models and textures. Check it out: Any suggestions on how to effectively reduce model size would be greatly appreciated! Thank you in ...

Is it possible to combine asynchronous and synchronous functions in the same code?

I've recently started experimenting with Node.js and I'm running into issues with asynchronous functions. While I was able to create a small game, the only way I could successfully integrate asynchronous functions with synchronous functions was b ...

The integration of numerous filters in the Google Maps API allows for complex intersection

After weeks of searching, I finally found a solution for filtering multiple criteria using JavaScript and the Google Maps API. The functionality I found is exactly what I need for my map, but I'm struggling to get it to work properly. Can someone help ...

Displaying a table in Chrome/Firefox with a mouseover feature

Hovering over the rows of this table triggers a display of descriptions. html: <tr title="{{transaction.submissionLog}}" class="mastertooltip">... JavaScript: $('.masterTooltip').hover(function(){ // Hover functionality ...

Ways to retrieve the file name from the content-disposition header

I received a file through an AJAX response. I am trying to extract the filename and file type from the content-disposition header in order to display a thumbnail for it. Despite conducting multiple searches, I have been unable to find a solution. $(". ...

Tips for ensuring that Raycaster accurately identifies mesh intersections within react-three-fiber

I am a newcomer to Three.js and React Three Fiber. I am currently trying to implement ray casting using Raycaster from Three, with 2 mesh boxes - one static and the other movable via keyboard events. My goal is to log the static mesh when the movable mesh ...

Playing with Data in AG-Grid using Javascript

I am working on implementing data display using AG Grid with an AJAX call, but I am facing an issue where no data is being shown in the grid. Even though my AJAX call seems to be functioning correctly and returning the desired object List, the grid itsel ...

Utilizing JavaScript to Trigger a Function from Code Behind

Having trouble calling a function through javascript and receiving an error message "CS0103: The name 'bidindex' does not exist in the current context". Can anyone provide assistance? Thank you! JavaScript code snippet: <script> funct ...

Is it more advantageous to pass a value as a prop to a child component, or should the child component retrieve it from Redux instead?

In my scenario, there are two components called <Parent> and <Child>. The <Parent> component is connected to a Redux state property named prop1 using the mapStateToProps() function. Now, I also need the <Child> component to have acc ...

Tips for formatting dates in Angular 6

I am currently working on a function that displays real-time dates based on user input. Currently, when the user enters the input, it is displayed in the front end as follows: 28.10.2018 10:09 However, I would like the date to change dynamically based on ...

Steps for exporting all elements of an array to an Excel file using the exceljs library in Node.js

I am facing an issue where I need to export all elements from an array to an Excel file using exceljs in Node.js. Here is an example of my array structure: array image After defining my array, the goal is to create an Excel file that looks like this: exce ...

Here's how to use the useState hook directly in your React components without

Currently, I am using the code snippet below to import useState: import * as React from 'react' import {useState} from 'react' I wanted to see if there is a way to condense this into one line, so I attempted the following: import * a ...