How can I best move the projection in Three.js?

I am currently utilizing threex.webar (https://github.com/jeromeetienne/threex.webar) in a project involving Three.js with ArucoJS. My goal is to create a projection (markerObject3D) based on an AR marker, but positioned next to the marker rather than directly on it.

To achieve this, I have implemented the following using Three.js translateX() :

function render() {

    translateMarker3D(markerObject3D);
        movieMaterial.update();
        backgroundTexture.update();
        effect.render(scene, camera)
}
function translateMarker3D(marker3D) {
       marker3D.translateX( 80 );
}  

Although this method somewhat works, there is flickering happening when the projection is placed next to the marker, while it looks fine when it's directly on the marker.

I also attempted adjusting the returning values from aruco (in threex.jsarucomarker.js):

object3d.position.x = translation[0] + 80;

However, this change resulted in the same flickering issue.

Therefore, my question is: what is the most effective approach to creating a projection next to an AR marker using Three.js?

EDIT :

Setting up a live demo might be challenging, so I have uploaded a video on Youtube to demonstrate the problem : https://www.youtube.com/watch?v=SM1dZ29SZRk&feature=youtu.be

Nevertheless, you can access the complete code here : https://github.com/cned-di-dev/three-ar-proto/blob/master/tests/stereoscopic/index.html

Challenges I am facing :

  • Flickering object during translation (it occasionally "bumps" when moved)
  • Projection inaccuracies at times (when near the screen edge, the object shifts due to perspective camera, and I'm unable to resolve it)

Please note: I do not possess extensive knowledge in 3D concepts such as geometry and matrices.

Answer №1

Understanding the concept of "flickering" was initially challenging, but after conducting some tests, I believe I have identified the issue. It seems that the detectMarkers() function struggles to consistently locate the exact marker position in every frame. This results in the markerObject being first rotated and then translated.

Due to the slight rotation variation of the marker in each frame, coupled with its translation along a new x-axis, the markerObject experiences vertical jumping movements. The extent of this fluctuation increases as the translation distance extends.

To tackle this challenge, the solution hinges on the specific requirements for the translation behavior. One approach involves translating the markerObject along the global x-axis by assigning it a parent object:

var markerParent = new THREE.Object3D();
var markerObject3D = new THREE.Object3D();
markerParent.add(markerObject3D);
markerParent.translateX(80); // perform this step once
scene.add(markerParent)

Alternatively, altering the transformation order in the source code of

markerToObject3D(marker, object3d)
can facilitate smoother motion by positioning the translation before rotation. This would involve including your translation in object3d.position.x.

If maintaining translation along the markerObject's local x-axis is essential, eliminating flickering becomes more complex. One strategy could be providing the markerObject with the average translation or rotation from recent frames instead of recalculating them each frame using JsArucoMarker.

An additional method to enhance movement smoothness entails interpolating positions per frame to reduce sudden shifts.

UPDATE

Upon reviewing your video, an observation confirmed one issue concerning translation, represented in the image here: https://i.sstatic.net/TSSr9.png

This image underscores the impact of rotational leverage around the local z-axis, which also affects rotations around the x and y axes. Imperfect marker detection leads to increased apparent errors during translation. Implementing an average translation over previous frames minimizes these discrepancies.

A noticeable occurrence was the marker occasionally "swooshing" sideways. This stemmed from flawed markerDetection, where at times the marker isn't detected in certain frames. In such instances, the markerObject underwent unnecessary translations by 40 units. To rectify this:

Delete line 359:

translateMarker3D(markerObject3D);

and insert this into line 323:

markerObject3D.translateX(40);

This adjustment ensures the markerObject translates only following successful marker detection.

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 a "ReferenceError: document is not defined" error while attempting to run tests on a create-react

Here is the content of my __tests__/App.js file: import React from 'react'; import ReactDOM from 'react-dom'; import App from '../src/containers/App'; it('renders without crashing', () => { const div = documen ...

Using HTML and JavaScript to choose relatives from the extended family: Uncles and Aunts

Looking for a better way to target elements in your HTML code? <div class="chunk" id=""> <div class="chunkContent"> <div class="textLeft" ></div> <div class="textRight" ></div> <div class= ...

Rearrange Firebase data on the client side

Having trouble sorting data in Firebase for a web project. I tried using orderByChild to filter the data, but now I need to also order it by date. Here's what I've attempted: Tried using object.values with .sort, no luck Attempted to use lodas ...

Synchronizing Form Data in Angular 5: Pass and Populate Dropdowns between Components

I have developed a unique form (material dialog modal) that allows users to create an account. When the user clicks on the Register button, their created account should appear in a dropdown menu without redirecting or reloading the current page. I am facin ...

When trying to retrieve an XML file that contains an escaped ampersand, a jQuery AJAX call is throwing an error

Before sending text input to a server to be stored in a MySQL database using XML, I first escape the "&" characters: var copyright = copyright.replace(/&/g,"&amp;"); The wrapped XML data block is then sent to the server through jQuery's ...

Imagine a scenario where your json_encode function returns API data that is already in JSON format. What would

It has been a while since I last worked with JSON/PHP/AJAX, and now I am struggling to access the returned data. The AJAX function calls a PHP script that makes an API call returning JSON in $data. The JSON is then decoded using $newJSON = json_decode($da ...

I'm interested in learning about the most efficient practices for handling JSON, performing math operations, and utilizing loops in JS/React. What techniques

Short version: I'm working with a large array of JSON objects (60K+ elements) in my application I need to perform various mathematical operations such as comparison and addition Currently, I am handling this through multiple for loops (simplified ...

"Unable to locate the specified file or directory" error message pops up while attempting to save a file

Currently, I am in the process of generating a JSON file using my website with intentions to deploy it later. Below is the code snippet that I have implemented: saveFile = (i, data) => { var filename = `${i}_may.json`; var folder_list = ["desktop", ...

What is the best way to include Javascript in a dynamically populated checkbox list?

I have successfully implemented a checkboxList control that I manually populated with data and integrated with JavaScript: <script type="text/javascript"> function ShowHide(chk, txt,txt2) { //Get the Textbox based on selected checkbox ...

Express 4 Alert: Headers cannot be modified once they have been sent

I recently upgraded to version 4 of Express while setting up a basic chat system. However, I encountered an error message that says: info - socket.io started Express server listening on port 3000 GET / 304 790.443 ms - - Error: Can't set headers ...

Changing color of entire SVG image: a step-by-step guide

Check out this SVG image I found: https://jsfiddle.net/hey0qvgk/3/ <?xml version="1.0" encoding="utf-8"?> <!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> <svg version="1.1" width="90" height="9 ...

Tips for choosing the following row in an Angular user interface grid

How can I deselect the currently selected row and select the one that follows it by clicking a button? I am using AngularHotkeys.js for this purpose. It gets even more complicated because I can sort the table with different columns. It would be helpful to ...

Having trouble with implementing image resizing and cropping in a Node.js environment

Struggling with image processing in node js, this task is crucial for my application. The goal is clear: 1) User uploads an image (multipart formdata sent to the server - successful) 2) Resize the image to a max width of 640px 3) Crop the picture within s ...

Executing several Javascript functions when the page is loaded

I have attempted to invoke 4 JavaScript functions from the HTML body when the page is loaded. Each function calls a JSP servlet to retrieve data from a database and populate the respective list boxes. Currently, I am focusing on the edit screen where I am ...

Adjust the background color of children based on the parent's mouseover event

Seeking a solution to fill three bars with varying percentages: <div class="bars" style="width:0%; background-color: red;"> <span class="bar"></span> <span class="bar"></span> <span class="bar"></span> </ ...

I am unable to locate the appropriate TypeScript type for the `displayName` attribute when it is used as a prop for the `type` component

Having trouble finding the correct type as mentioned in the title. After inspecting with DevTools, I have confirmed that every component I am programmatically looking at has Component.type.displayName. For anything that is not an ElementType, the type is a ...

Activate the function for items that are overlapping

Here is a scenario I am working on: HTML <body> <div> <p>Text</p> </div> <body> JQuery $('div').click(function(){ $(this).find('p').fadeToggle('fast'); }); $('bo ...

Attempting to reset my react-final-form fields led to receiving an empty object as the values instead

Currently, I am facing a situation where I need to clear all field values except for "retainThisObj" upon the initial page load. The problem I encountered is that my { } ended up empty, meaning that my "retainThisObj" was also deleted. ...

Particles.js is functioning properly in a .html file, however, it is not working in an .ejs file

I am currently working on a web development project to enhance my skills in HTML, CSS, and Javascript. I am utilizing NPM and Express for my server.js file. My goal is to incorporate Particles.js as the background on all of my pages, however, it seems to b ...

The process of raycasting with specific points within a collection of points in a Three.js Point

I am facing an issue with my PointCloud object. I want to draw a bounding box around a specific point when clicked, but I can't figure out how to access that individual point within the PointCloud. This is the raycasting code snippet I have been usin ...