The rotation duplication feature in THREE.js is malfunctioning

I'm encountering a bug where I'm trying to synchronize the rotations of two objects by copying the Quaternion from one object and applying it to another. However, I'm having trouble getting the rotation to be applied to the second object.

In this scenario, object 1 is represented as msh and object 2 is represented as msh2. The following code snippet fails to apply the rotation of msh to msh2:

var rot = new THREE.Quaternion().copy(msh.rotation);
msh2.rotation.copy(rot);

You can observe this issue in the provided Stack Snippet which showcases the problem in a minimal reproducible form (although it may not match the exact code structure used in my actual project).

 // JavaScript code here
<script src="https://cdn.rawgit.com/mrdoob/three.js/dev/build/three.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id="can" width="400" height="300"></canvas>

Check out the JSFiddle for a visual representation.

I'm puzzled by this situation. I frequently perform similar operations with Vector3 without any issues, so I'm unsure why it's proving challenging in this case...

Answer №1

It appears that msh.rotation is an instance of THREE.Euler, however you are attempting to copy to/from THREE.Quaternion. To resolve this issue, you can use msh2.rotation.copy(msh.rotation), which should work without any problems. Another option would be msh2.quaternion.copy(msh.quaternion)

Answer №2

If my interpretation is correct, you are looking to have both objects rotate simultaneously with equal speed and angle. To achieve this, simply make adjustments to the render(); function by adding these two lines:

  obj2.rotateX(0.001);
  obj2.rotateY(0.002);

Check out the updated JSFiddle here

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

Emphasize the letter by pressing the shift key along with either the left arrow

When the right and left arrow keys are pressed, my HTML element currently only highlights the next letter when the shift key is also pressed. How can I modify it to highlight all the letters in the word when the shift key and the right or left arrow keys a ...

What is the best way to utilize TypeScript module augmentation with material-ui components?

I have gone through the answers provided in this source and also here in this link, but it appears that they are outdated. I attempted to enhance the type definition for the button component in various ways, including a separate typings file (.d.ts) as we ...

Angular JS and TypeScript - Issue: ng:areq Invalid Argument "Argument 'XXXXXX' is not a function, received undefined"

Encountering a specific error mentioned in the title. I organized models and controllers into distinct files saved under models and controllers folders respectively. Upon trying to establish a connection between them, I received an error stating "ng:areq ...

encountering a problem with npm while trying to execute the project

Encountering a persistent issue when attempting to run my project with npm start, even after downgrading my node version. Despite trying various solutions found on platforms like stackoverflow and stackexchange, such as deleting the node_modules folder, ru ...

Is JavaScript the Key to Navigating Through a Website?

I am faced with the challenge of creating a script to extract a database from a website. The website's main page features a table where each row contains a link to another page that holds the desired database. Currently, my script can successfully e ...

iOS Chrome: Enabling Cookies with "Always Allow"

While the Safari browser on OSX has a setting under Privacy & Security -> Block Cookies -> Always Allow, enabling the storage of entries in the browser's local storage even when accessing pages from third party sites like those running in an ifr ...

Setting up user roles using Firebase Auth in NextJS application

Seeking a solution to implement a multi-level role system for my blog website. Currently utilizing Firebase Auth for authentication with email/password, but all users have the same posting/editing access. Looking to differentiate between Admins, Moderators ...

Issue identified: Upgrading package (buefy) causes disruptions in project functionality (filegator) - potential import conflicts(?

I am currently working on enhancing features for the self-hosted file storage system called filegator. (The project utilizes single-file components for organization, which is important to note.) (It is built on Vue.js and operates as a Node.js server ...

Load a partial view in MVC using Ajax with a complex data structure

Within my main view, I have a section that loads a partial view containing data. Here is the code snippet that is executed upon initial loading: <div id="customerdetailsDIV" class="well main-well clearfix"> @Html.Partial("_customer_details", Mod ...

What is the reason for instanceof Map returning false?

Utilizing the Draft.js plugin called Mention. When accessing editorState.content.entityMap.mention, I am able to retrieve the value by: mention.get('address') However, when I attempt to verify if it is a Map using: console.log('mention&a ...

Update a JSON value using an MUI Switch element

I am currently developing a feature that involves toggling the state of an MUI switch based on API responses. The status of the Switch is determined by the Active field in the API response. If the JSON field is 1, the switch is turned on, and if it's ...

Creating dynamic URL routes for a static website using Vue

I am facing a challenge with my static site as I am unable to add rewrites through htaccess. Currently, our site is built using Vue on top of static .html templates such as \example\index.html. When I want to create a subpage within this layout, ...

JavaScript failing to load following PHP header() redirect

I've set up a page that allows users to sign in by filling out a basic form, which then sends the data to a separate PHP script for validation. After the validation process is complete, the PHP script uses the header() function to redirect the user to ...

Is there a way to obtain the coordinates of an SVG element by simply clicking on a specific point?

I'm still learning about SVG and I'm trying to trigger an event that captures the click coordinates when clicking on the SVG. I have a few questions: Since I'm using Angular, I'm unsure if it's possible to keep my function in th ...

CSS2DRenderer does not belong to the Three.js library

Before we dive in, let me provide some background information: I recently incorporated three.js into a default React project using npm. Now, I'm interested in integrating this example that utilizes CSS2D. Unfortunately, I encountered an error when a ...

The error in React's useEffect occurs when trying to access the property 'map' of an undefined value

import { handleResponse, handleError } from "./apiUtils"; const baseUrl = process.env.REACT_APP_API_URL; export function getAllNotes() { return fetch(baseUrl + "/notes", { method: "GET", headers: { 'Accept': 'application/j ...

How can an Express.js server detect when a browser has been closed or reloaded?

Currently tackling a project with an Express.js server. One query I have is how can this server detect when one of its users (browser) has been closed or reloaded? Any insights on this would be greatly appreciated! ...

Transforming user-entered date/time information across timezones into a UTC timezone using Moment JS

When working on my Node.js application, I encounter a scenario where a user inputs a date, time, and timezone separately. To ensure the date is saved without any offset adjustments (making it timezone-independent), I am utilizing Moment Timezone library. ...

Creating a minigame using JQuery (Javascript)

I am currently developing a collection of mini-games for my big project. The approach I've taken in creating this mini-game is similar to one I used previously. However, unlike my previous version which only had one PuzzleContainer, this new iteration ...

Creating a new function within the moment.js namespace in Typescript

I am attempting to enhance the functionality of the moment.js library by adding a new function that requires a moment() call within its body. Unfortunately, I am struggling to achieve this. Using the latest version of Typescript and moment.js, I have sear ...