Maintaining stability in Three.js: How to prevent an object from moving during zoom

In my application, I utilize Three.js for creating a 2D presentation. To achieve this, I set up an Orthographic camera with MapControls. Within the scene, there are various objects that can be panned and zoomed in and out in a 2D space. However, there is one specific object - an arrow with unique shape and animated rotation - that needs to remain static, meaning it should not be affected by panning or zooming. Due to its dynamic nature, drawing this arrow using CSS is not a viable option.

Following the guidance provided in this StackOverflow post, I was able to successfully restrict panning but encountered issues with zooming.

scene.add(camera);
...
camera.add(directionArrow);

Despite my efforts, when zooming in or out using the mouse wheel, the arrow also gets magnified along with the rest of the scene.

To demonstrate this issue further, I have created a jsfiddle showcasing a minimal reproduction of the problem.

The main goal is to keep the triangle (arrow) stationary during zooming, similar to how it functions during panning operations.

Answer №1

Enhance your design with a GUI layer and Render layer combination.

By placing the Pointer in the GUI layer, you have the freedom to modify the Render Layer independently without impacting the GUI layer.

In most cases, Three.js GUI layers are crafted using HTML.

Once you've achieved this setup, it's crucial to retrieve the object's coordinates and update the HTML accordingly. This step can be quite intricate, so we recommend checking out the following article for guidance and examples:

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

Incorporating dynamic numerical values into image names within a Vue JS application

I have linked an image with the following code <img title="head" :src="availableParts.heads[selectNextHeadIndex].src"/> This image is called from a JSON file: { id: 1, description: 'A robot head with an ...

Understanding the rotation direction or handedness in three.js

It has come to my attention that when I perform rotation around the Z axis on my model, as shown below: model.rotateZ(rotatedAngle * Math.PI / 180); The rotation appears to be in a counter-clockwise direction around the axis. Can this observation be co ...

Generating a fresh object from an existing object by incorporating updated values using Angular and Ionic version 3

Currently, I am actively working on an Ionic 3 project that utilizes Angular framework. Within my project, I have a JSON object called 'person' which consists of data fields such as name, job, and home. One feature in my app is an Ionic toggle b ...

Intellisense with JavaScript methods is not supported in Vue files

While running Vue 2.6 in VSCode, I've noticed that my intellisense functions perfectly within js files. However, as soon as I switch to a vue file, all my intellisense capabilities disappear. I have the most up-to-date version of VSCode installed and ...

Dynamic Routing in ExpressJS: Dynamically adding routes on the fly

I have been exploring ways to dynamically add new routes during runtime in NodeJS & ExpressJS without having to restart the server. Following a similar approach to the one outlined in this article: I've been successful in adding new files and logic ...

Is it possible to store multiple keys in HTML local storage?

Is there a way to store multiple keys to local storage without overwriting the previous ones when multiple people take a survey and refresh? Could they be grouped by userID or sorted in any way? $('form').submit(function() { $('input, ...

What is the best way to group all matched objects from an array based on multiple keys?

const data = [ { amount:10, gameId:7 , consoleId:3, id: 1 }, { amount:5, gameId:18 ,consoleId:3, id: 2 }, { amount:5, gameId:18 ,consoleId:3, id: 3 }, { amount:10, gameId:7 ,consoleId:3, id: 4 ...

Using AngularJS to handle ng-click events and callback functions

Within my web application, there exist two distinct user types: guests and logged users. Regardless of the user type, both are presented with identical content on the main page. The objective : Upon a registered user clicking a link, 2 ajax requests ($h ...

Display alternative component upon button click in React.js

After creating the default layout, I'm aiming for a scenario where clicking each button only alters specific parts of the layout through the content component. React router is being utilized to manage different pages. Each button corresponds to a uni ...

A guide to displaying JSON information within a data list element (dl)

I am facing an issue while trying to iterate through a multidimensional json data array. Each time I loop through the array, only the last element gets printed. var data = [ [{ "id": "67", "name": "Baby & Toddler Clothing ...

Discover in Mongo DB with Mongoose, except for the find() method, which excludes documents containing a specific property

I'm searching for a condition in Mongoose that will help me locate all users except those with the role 'Admin':2000. Keep in mind that admin users also have other roles, such as "User" and "Editor", as shown below: { "name": &q ...

The req.body in Express.js appears to be empty when utilizing form-data

snapshot of postman When I send data using form-data in my Express.js application, req.body appears to be empty. However, if I send the data using raw JSON, the expected object is present in req.body. Below is how my setup looks: Here is my index.js file ...

The transitions on my jQuery Mobile page are not functioning correctly

I am currently working on a custom MVC structure using Handlebars and jQuery Mobile. To manually manage routing, I have disabled two jQM parameters: $.mobile.linkBindingEnabled = false; $.mobile.hashListeningEnabled = false; These lines disable link bind ...

What is the process of including types in a Vite library build?

After following the documentation on Vite for implementing library mode, I successfully created a functional component library. Utilizing the vue-ts preset, I defined props with their respective types and utilized interfaces within my components. However ...

Employing jQuery to extract the text from the h4 class="ng-binding" element beyond the Angular scope

Is it possible to retrieve the current text content of <h4 class="ng-binding"></h4>? The text content is generated dynamically within the angular.js setup. I am interested in finding a way to extract this text using jQuery or JavaScript from ...

creating a JSON object in PHP that can be easily parsed by JavaScript

In my project, I have an extensive list of items, each item further divided into four sub-items. While it's convenient for me to organize this data in nested arrays using PHP, I encounter issues when trying to transfer them as a JSON object to the cli ...

How to use the groupBy function in Underscore.js

{ collectionId: 1, category: 'a', collectionType: 'typea' }, { collectionId: 1, category: 'a', collectionType: 'typea' }, { collectionId: 1, category: 'b', col ...

Discover the secret to loading multiple Google charts simultaneously, despite the limitation that Google charts typically only allow one package to load at a time

I currently have a pie chart displaying smoothly on my webpage, but now I am looking to add a treemap as well. The code snippet for the treemap includes the package {'packages':['treemap']}. It has been stated that only one call should ...

Trouble obtaining AJAX result using onClick event

As a newbie to AJAX, I am still trying to grasp the concept. My task involves using an AJAX call to extract specified information from an XML file. Even after carefully parsing all tag elements into my JavaScript code, I encounter a problem when attempting ...

Send text values to a JavaScript function that includes unique characters

Hi there, can you help me figure out how to pass the following value as an argument in a JavaScript function? I am receiving this value dynamically from a Java string variable like so: String vals= "The apostrophe ( ’ or ' ) is a punctuation < ...