The touch event in Raycast Three.js is failing to function when utilizing the mouse event

Recently, I have been experimenting with a threejs mouse raycast combined with fabricjs and managed to get it working. However, I encountered an issue where the object did not move when using a smartphone with touch capability. Should I implement a separate event listener for touch events or is it supposed to work with just mouse events?

Here's how I am currently moving the object:

  if (e.target !== this.upperCanvasEl) {
    var positionOnScene = getPositionOnScene(container, e);
    pointer.x = positionOnScene.x;
    pointer.y = positionOnScene.y;
  }

And here's the getPositionOnScene function:

 function getPositionOnScene(sceneContainer, evt) {
    var array = getMousePosition(container, evt.clientX, evt.clientY);
    onClickPosition.fromArray(array);
    var intersects = getIntersects(onClickPosition, scene.children);
    if (intersects.length > 0 && intersects[0].uv) {
      var uv = intersects[0].uv;
      intersects[0].object.material.map.transformUv(uv);
      return {
        x: getRealPosition('x', uv.x),
        y: getRealPosition('y', uv.y)
      }
    }
    return null
  }

Can anyone provide some insight or assistance on this matter? Any thoughts would be greatly appreciated.

Answer №1

Here are two key factors to consider:

1:

The `getPositionOnScene` function currently returns null.

2:

It is important to note that touch events differ from mouse events.

To ensure support for both, you will need to add `document.addEventListener("mousedown", callback)`.
This will enable proper handling of mouse events 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

Having trouble implementing express-unless to exclude specific routes from requiring authentication

Being relatively new to JavaScript and Node.js, I decided to incorporate express-jwt for authenticating most of my APIs. However, I wanted to exclude certain routes like /login and /register from authentication. After exploring the documentation for expr ...

Retrieve the ultimate content of a text field when a key is pressed, only if the click action is permitted to proceed

Is there a method to prevent users from entering certain characters into a text box based on the resulting text in the textbox? One possible approach is outlined below: <input type="text" id="test" /> document.getElementById(&qu ...

Retrieving information from a JavaScript array outputs 'undefined'

I am currently attempting to retrieve the attribute labeled "MediaURL" from my Javascript array object. To provide a clearer understanding, the image below illustrates an expanded view of the array: https://i.sstatic.net/BWNym.png Encountering the follow ...

Steps to eliminate <br> tags from text nodes and enclose them in <p> tags while including <b>, <i>, <a>, and other elements

My current status (UPDATED): <div class="entry-content"> <h1>This heading won't be shown</h1> Written by: Me <br></br> On: 01/01/2017 <br></br> <br></br> When quoting: ...

Deliver the Express.js: transmit outcomes post next() invocation

I have a unique app feature that allows users to create their own routes in real-time. I also want to show a custom 404 message if the route is not found, so I added this code to my last middleware: app.use((req, res, next) => { // ...normal logic ...

arrange the elements in a specified sequence

I am trying to sort an array in a specific order var customOrder = { "1st Presentation / Meeting": 0, "Follow-On Meetings": 1, "Hold\/Uncategorized": 2, "MGL": 3, "PGL": 4, "BGL": 5, "RGL": 6, "SGL": 7, "Uncategorized Leads": 8, ...

Creating custom Bootstrap Card Groups by dynamically generating the specified number of cards with Angular directives

I am currently using Angular 9.1.8 for my project. For my Angular component, I have implemented Bootstrap Card Groups and Cards to display a large result set of cards in rows with more than two cards per row. Below are four example cards: <div class=&q ...

Strategies for formatting JSON object key value pairs to display on individual lines

In one of my components, I have a JSON object stored inside an object called "job". It currently renders as: job {"amount": " 12185","job": "GAPA","month": "JANUARY","year": "20 ...

Displaying an alert when the text box contains a duplicate value

I have a set of input fields with various values that can be edited but must not be left empty (if left empty, display an alert). When I update a field with a new value, if that new value matches any of the other input field values, I want to display an al ...

Is it feasible to develop an asynchronous function in Node.js that executes concurrently?

My objective is to simultaneously execute the longRunnigTask and quickTask functions: function longRunnigTask() { return new Promise((resolve) => { console.log('longRunnigTask started'); for (let i = 0; i < 999999999; i+ ...

Having trouble with a tslint error in Typescript when creating a reducer

I encountered an error while working with a simple reducer in ngRx, specifically with the on() method. https://i.sstatic.net/9fsvj.png In addition, I came across some errors in the reducer_creator.d.ts file: https://i.sstatic.net/sWvMu.png https://i.ss ...

Ways to make JavaScript cycle through a set of images

I'm having trouble trying to set up a code that will rotate multiple images in a cycle for an image gallery I'm working on. So far, I've only been able to get one image to cycle through successfully. Any help or suggestions would be greatly ...

What is the process for integrating a Browserify library module into a project as a standard file?

I have successfully developed a JavaScript library module with browserify --standalone, passing all tests using npm test. Now, I am working on creating a demo application that will utilize this library module in a browser setting. When I run npm update, th ...

Checking the Signature with Elrond in the Backend using PHP

My latest decentralized application allows users to log in using their Elrond wallet and generate a unique signature containing their wallet address and additional data. As part of the authorization process, the signature is included in the payload of req ...

Extensive data entry command

I need to add around 12500 lines to my database for a game server map. This script helps me generate the query: sql = "INSERT INTO `legends`.`map` (`x`, `y`, `land`, `collision`, `impedance`, `effect`) VALUES " for (y=0;y<ig.game.collisionMap.data.leng ...

Transferring Visitor's Country Code Between Two Web Applications Using .NET Framework (ASP/MVC)

I'm currently working on developing an application that collects user information such as country, city, and IP address of the website they're visiting. This data is then sent to another web application of mine, which will be automatically update ...

Using app.use in Express/node.js for routing causes the client to experience excessive delays

After setting up the server-side code in app.js, I encountered an issue: console.log("Server started. If you're reading this then your computer is still alive."); //Unnecessary test command to make sure everything works. var express = require("expre ...

How to format numbers in JavaScript post calculations

Struggling to find a solution to format calculation results with commas for thousand separators (e.g., 10,000). After implementing the .toLocaleString('en-US', {maximumFractionDigits:1}); method to format numbers in the output, I encountered unex ...

When React object state remains unchanged, the page does not update automatically

i have a state object with checkboxes: const [checkboxarray_final, setCheckboxarray_final] = useState({ 2: ",4,,5,", 9: ",1,", }); i'm working on enabling check/uncheck functionality for multiple checkboxes: these are ...

Conceal the information beneath a see-through fixed navigation bar when scrolling downward

the issue: I am facing a challenge with my transparent fixed navbar that has a margin-top gap. The content below the navbar needs to be positioned under it while scrolling down, but the background of the page is a dynamic slideshow of various images. This ...