Pixi3D attempting to cast ray onto a plane

Having trouble with raycasting in the pixi3D library and finding the documentation lacking.

I'm attempting to make a 3D object track the mouse coordinates on a 3D plane in space.

https://i.sstatic.net/DiTzY.jpg

The goal is for the black box to follow the mouse, but so far it isn't working as expected.

This is my approach:

Firstly, creating the plane:

let normalTest = new Float32Array(3);
        normalTest[0] = 0;
        normalTest[1] = 0;
        normalTest[2] = 1;
        planeTest = new Plane(normalTest, 100);
    

Then in my loop, I attempt to intersect a ray with the plane:

let ray = Camera.main.screenToRay(l.mouseX(), l.mouseY(), {height: 1920, width: 1080 });
        if (ray != undefined) {
            let rayRes = planeTest.rayCast(ray);
            let rayPoint = ray.getPoint(planeTest.rayCast(ray));
            myBlackBox.x = rayPoint[0];
            myBlackBox.y = (-l.mouseY() / 100);
        }
    

Seeking guidance from someone experienced with the pixi3D API who can help me out?

Answer №1

Here is a possible solution:

const plane = new PIXI3D.Plane(new Float32Array([0, 1, 0]), 0.8);

document.addEventListener("mousemove", event => {
  const ray = PIXI3D.Camera.main.screenToRay(event.x, event.y);
  const distance = plane.rayCast(ray);
  const point = ray.getPoint(distance);
  // Assuming 'model' represents a 3D object
  model.position.array = point;
});

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

Encountering Build Issue: "NgSemanticModule is not recognized as an NgModule" persists despite inclusion of dependencies and importing into primary module

I have posted my module, component, and package file here. I am attempting to implement a click event with ngif, but I keep encountering an error. The specific error message is "ERROR in NgSemanticModule is not an NgModule". I'm unsure if this error ...

I am looking to retrieve information from mongodb and then transform it into a JSON object using node.js. Can you guide

I am on a mission to retrieve data from a MongoDB database and transform it into a JSON object in Node.js. The goal is to be able to easily manipulate this data as if it were a simple JSON object. Here's the current code snippet I'm working with: ...

Locate the parent element using a unique child element, then interact with a different child element

Can you help me come up with the correct xpath selector for this specific element? The element only has a unique href. Is it possible to locate the element by searching for the text iphone X within the href="#">iphone X and also checking for its paren ...

Tips for utilizing ng-repeat with standard JSON data structures

I have a JSON structure like this: [{ Entry: [{ ID:123, Name: 'XYZ', Address: '600, PA' }, { ID:123, Name: 'ABC', Address: '700, PA' }, { ID:321, Name: 'RRR', ...

"Troubleshooting: Resolving 404 Errors with JavaScript and CSS Files in a Vue.js and Node.js Application Deploy

I successfully developed a Vue.js + Node.js application on my local server. However, upon deploying it to a live server, I am facing a 404 error for the JavaScript and CSS files. I have double-checked that the files are indeed in the correct directories on ...

Specify the controller to be used dynamically in an Angular directive

I want to be able to specify the controller that a directive uses by adding an attribute to the element - in other words, dynamically: HTML <div data-mydirective data-ctrl="DynamicController"></div> Angular angular.module('app', [ ...

Detecting readiness of video playback on mobile devices using Three.js

When using a video on a sphere texture, I am facing an issue where the sphere only appears once the video has loaded. However, on mobile devices, there is a black sphere shown initially when the video has loaded, and then after a few seconds, the video sta ...

When converting to TypeScript, the error 'express.Router() is not defined' may

Currently, I am in the process of converting my express nodejs project from JavaScript to TypeScript. One of the changes I've made is renaming the file extension and updating 'var' to 'import' for "require()". However, there seems ...

I'm puzzled by the inconsistency of my scrolltop function on mobile, as it seems to be scrolling to various parts of the page depending on my

I am encountering an issue with a function that scrolls to a specific element when a button is clicked. Strangely, this functionality works fine on desktop but fails on mobile devices. It successfully scrolls to the correct position only when at the top of ...

Include More Items in JSON Encoded List

I am currently using a JSON encoded array to display the users in my database for an auto-suggest feature. Here is an example of how I have implemented it: $sql = "SELECT id, name FROM users"; $result = mysqli_query($conn, $sql); $jsonData = array(); w ...

Updating multiple records in Node.js with mongoose using a file as the source of data

I have a CSV file that contains my data, and I am looking to perform a bulk add/update operation. exports.add_questions_from_file = function (file_path, surveyid, callback) { var U = [{}]; fs.readFile(file_path, 'utf8', function(err, dat ...

The issue persists with the program continuously using the incorrect GET request method

I am encountering an issue while using Node JS and Express. Whenever I make a GET request with the following link http://localhost:3500/balanceDue on PostMan, it executes the code within the method getAllMoneyInTransact instead of the code inside the metho ...

Updating a reactive data within the axios response callback in the setup option of Vue 3

I am currently facing a challenge with Axios call in the Setup method of my component. My objective is to set a variable called "books". In Vue 2, I would execute the call within a created hook and utilize `this` to assign the variable. However, with Vue ...

How can I troubleshoot the unresponsive remove div function on my website?

My code is running fine on CodePen (link provided below), but for some reason, it's not working properly in the web browser. I am executing the code from localhost and the button isn't responding as expected. CODE Here is my Visual Studio code ...

Show/Hide sections of content that transition and rearrange the layout of the page

I have a layout with 9 squares on a page. When clicking on a square, I want a full-width div to appear underneath it, pushing the other squares down. I've tried following a tutorial to understand the JavaScript behind this functionality, but I'm ...

What is the best way to remove all elements in jQuery?

I need to remove the selected element in my demo using jstree. I have consulted the plugin's API at http://www.jstree.com/api/#/?f=deselect_all([supress_event]), but it seems that it does not deselect the item properly. Here are the steps I have follo ...

Express req.files returns null when using jQuery FormData

For client side functionality, I am utilizing Bootstrap and jQuery. On the server side, my technology stack includes node.js and express. The form structure is displayed below: <form id="signupform" action=""> <h2&g ...

Exploring React hook functionalities can lead to discovering unexpected issues such as cyclic dependencies on location.hash when

My implementation of a useEffect involves reading the location.hash and adjusting the hash based on certain dependencies. Here is a snippet of how it works: useEffect(() => { const hashAlreadyPresent = () => { const hashArr = history.locati ...

Why does the outcome of running this code vary each time?

I've been working on a code project to create 10 bouncing balls of different colors, but I'm encountering an issue where only one or two balls appear with different colors or the animation works perfectly only 1 out of 10 times. Any thoughts on w ...

Pile of memory depletion

Having some trouble with memory while trying to launch my react app using npm start. The error message reads: <--- Last few GCs ---> [12380:006AE720] 71751 ms: Mark-sweep (reduce) 1215.6 (1266.1) -> 683.3 (1175.2) MB, 195.0 / 0.1 ms (average mu ...