What is the best way to consistently apply parent transforms to child elements in the same sequence?

Within my software, users have the ability to select 3D objects on a workplane and then scale, move, or rotate these elements collectively using a "transformation" container. This container, represented by an Object3D, groups all transformations and applies them to every child object. When deselecting the child elements, the parent container's transformation should be passed down to all children. As a result, the children are removed from the transform container and added back to the main scene object.

However, there is an issue with how the child elements are transformed within the transform container. The transformation is applied to the container itself rather than to the individual elements. For example, when applying a scale transformation to the container that contains a child with local rotations, it seems as though the local rotation is applied first and then followed by the container's scale transformation.
When applying the parent's transformations to all children using

child.applyMatrix(parent.matrixWorld)
and placing the child back into the scene container, the order of transformation is reversed.

  1. container[scale]{child[rotation]} -> order: rotation, scale
  2. child.applyMatrix(parent.matrixWorld)
  3. child[scale,rotation]{} -> order: scale, rotation

How can I ensure that the child elements undergo the same transformation order and maintain their appearance?

Update:
I have found a solution to correctly apply the parent's transformations to the child objects. By using the code snippet from Object3D.applyMatrix():

child.matrix.multiplyMatrices(parent_old.matrixWorld, child.matrix);
while also setting child.matrixAutoUpdate = false; and excluding
child.matrix.decompose(child.position, child.quaternion, child.scale);

It seems that having matrixAutoUpdate = true does not produce the desired outcome. Moreover, Matrix4.decompose() alters the matrix values before assigning them to position, scale, and quaternion. Consequently, in my scenario, the shearing transform caused by the parent's scaled transformation is reset.

This inconsistency raises questions about nested object transformations. While nested object transformations usually display the intended effects, using

child.applyMatrix(parent.matrixWorld)
may not yield the correct results for applying parental transformations to child objects. It remains unclear whether this behavior in three.js is intentional. If so, could someone explain the reasoning behind it?

Answer №1

Special thanks to @WestLangley and the helpful THREE.js post along with this insightful SO answer that guided me towards finding a solution tailored to my needs. The challenge I faced stemmed from the underlying design principles of THREE.js.

The concept of representing an object's transform through position, quaternion/rotation, and scale - applied in the sequence S-R-T.

To simplify, introducing a non-uniform scale to an object's parent disrupts this sequence, making it impossible to reverse-engineer back to the familiar properties of position, scale, and quaternion.

The workaround I devised involves

exclusively utilizing matrix representation for the object transform.

This entails setting matrixAutoUpdate = false for my 3D objects and abandoning reliance on traditional position, scale, and quaternion properties. Instead, any transformations are directly applied to the object's matrix using methods from THREE.Matrix4 exclusively.

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

Utilizing a Three.js vertex shader to ensure that all geometry triangles are oriented to face the camera for

Seeking guidance on how to create a vertex shader in Three.js for rendering textured geometry with all triangles facing the camera directly. The aim is to replicate the efficiency of Three.js Points without being restricted by gl_PointSize limitations. I ...

Is it feasible to make an ajax request to fetch data and then send it to a PHP file via a post

Trying to send an ajax GET request to an external controller when a button on the form is clicked in order to use the returned data to dynamically generate "results" using PHP/HTML. The ajax code being used (using jQuery() instead of $() due to wordpress& ...

Checking for the Existence of a Database Table in HTML5 Local Storage

Upon each visit to my page, I automatically generate a few local database tables if they do not already exist. Subsequently, I retrieve records from the Actual Database and insert them into these newly created local tables. I am wondering if there is a me ...

Creating an AI adversary for a simple Tic Tac Toe game board: a step-by-step guide

Being new to programming, I recently completed a basic Tic Tac Toe gameboard successfully. However, as I progress to the next phase of my assignment which involves implementing an AI opponent, I encountered several challenges. As a novice in programming, ...

Guide on creating uniform heights and widths for images with varying dimensions utilizing CSS (and percentage values)

Is there a way to ensure that all images maintain the same height and width using CSS percentages, rather than set pixel values? I'm working on displaying images in circles, where most are uniform in size but a few outliers distort the shape. The wide ...

How to simultaneously update two state array objects in React

Below are the elements in the state array: const [items, setItems] = useState([ { id: 1, completed: true }, { key: 2, complete: true }, { key: 3, complete: true } ]) I want to add a new object and change the ...

Difficulty with Jquery's random selection of grid divs

I am working on a grid layout consisting of 9 divs nested in columns of three. The objective is that when the main grid (with ID #left) is clicked, two divs from the middle row (row="1") should have the class .show randomly applied to them. In the column w ...

Guide: Generating a DIV Element with DOM Instead of Using jQuery

Generate dynamic and user-defined positioning requires input parameters: offsetHeight, offsetLeft, offsetParent, offsetTop, offsetWidth ...

An error occurred while trying to serialize the `.res` response received from the `getServerSideProps` function in

I encountered the following issue while utilizing the getServerSideProps function to fetch data from Binance API. import binance from "../config/binance-config"; export async function getServerSideProps() { const res = await binance.balance(( ...

What is the process for creating static pages that can access local data within a NextJS 13 application?

I recently completed a blog tutorial and I must say, it works like a charm. It's able to generate dynamic pages from .md blog posts stored locally, creating a beautiful output. However, I've hit a roadblock while attempting what seems like a sim ...

What steps should I take to host my Vue js single page application on my Django server?

At present, I am in the process of following a tutorial to integrate my Vue.js frontend with my Django backend. You can find the guide here: https://medium.com/@williamgnlee/simple-integrated-django-vue-js-web-application-configured-for-heroku-deployment-c ...

Understanding how to access POST content in Meteor.js is an important aspect

In my Meteor app, I am trying to retrieve data using POST requests. Here is the code snippet I am using on the server side: __meteor_bootstrap__.app.stack.splice (0, 0, { route: '/input', handle: function(req, res, next) { req.on(' ...

Is it necessary to use the "new" keyword when utilizing JS closure to create objects?

My response to a question about closures on SO included the following code sample: function Constructor() { var privateProperty = 'private'; var privateMethod = function(){ alert('called from public method'); }; ...

Even though the onSubmit attribute is set to false in the HTML form, it still submits

I've been struggling with a form that just won't stop submitting, no matter what I do. I have checked similar questions on SO, but none of the solutions seem to work for me. It's frustrating because it's such a simple task. The reason w ...

The angular view is lacking a CSS class

index.html: <div ng-view="myview.html"></div> myview.html: <table class="table table-striped table-hover"> <tr> <td>Name</td> <td>Product</td> </tr> <tr ng-repeat="deal in deals" class="clickableR ...

What steps should be followed to construct a window identical to the one depicted in the attached image using HTML and CSS?

Check out this link to see the window style I'm trying to recreate using HTML, CSS, and Javascript. No Jquery needed. Thank you in advance. ...

What is the process for monitoring a property in Angular?

Seeking clarification on Angular - is it possible to detect property value changes within the same class? import { Component } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', ...

The close menu button is not functioning properly when clicked outside the menu - the buttonevent.matches is not recognized as a

I am encountering an issue with the dropdown menu that is not closing when clicking outside of the menu button. Despite having faced this problem before, I can't seem to find a solution now. Any help would be greatly appreciated as I am uncertain why ...

Problems with select tag change events

I encountered an issue with select tag onChange events. When I select a value from the select tag, it should display in a textbox that is declared in the script. It works perfectly when I remove the class "input" from the select tag, but I prefer not to re ...

Using Vuejs to pass the SAVE function into a CRUD component

I am facing a challenge in finding a suitable solution that involves advanced parent-child communication in Vue.js. The scenario is such that there are multiple parent components, each with its own logic on how to save data. On the other hand, there is onl ...