When the parent matrix in Threejs is altered, the changes are not automatically applied to the

My goal is to have the child object apply the same matrix as the parent object when the matrix is applied to the parent.

//set transformmatrix
const m = new THREE.Matrix4();
m.elements = [...];

//parent
var Parent = new THREE.CylinderBufferGeometry(30, 30, 30, 10);
var colortex = new THREE.Color();
colortex.setRGB(255, 0, 0);

var MatParent = new THREE.MeshStandardMaterial({
    color: colortex,
    metalness: 0,
    roughness: 0,
});

var MeshParent = new THREE.Mesh(Parent, MatParent);
scene.add(MeshParent);

//child
var Child1= new THREE.SphereBufferGeometry(100, 64, 32);
var MatChild1 = new THREE.MeshStandardMaterial({
    color: colortex,
    metalness: 0,
    roughness: 0,
});

var MeshChild = new THREE.Mesh(Child1, MatChild1);

MeshParent.add(MeshChild );
MeshChild.position.x = 0;
MeshChild.position.y = 0;
MeshChild.position.z = 200;

MeshParent.matrixAutoUpdate = false;
MeshParent.geometry.applyMatrix(m);
MeshParent.updateMatrix(true);

Before applying the matrix

https://i.sstatic.net/HlIwv.png

After applying the matrix

https://i.sstatic.net/dPhVk.png

As shown in the images, after applying the matrix, the cylinder object moved and rotated along the x-axis. However, the child object did not move accordingly. I want the child object to be placed at the red circle that I drew.

If anyone can offer advice, please do so. Thank you for reading.

Apologies for the image upload issue.

Answer №1

When manipulating the geometry of a 3D object using code like

MeshParent.geometry.applyMatrix(m);
, it's important to note that this will not affect the transformations of its descendants. To properly adjust the position, rotation, or scale of the object and its children, you should directly modify the position, rotation, and scale properties. Alternatively, if you set matrixAutoUpdate to false and make changes to Object3D.matrix manually, remember not to call updateMatrix() since you are already setting it yourself.

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

Create your own custom block on the frontend product page

I am trying to create a custom block on the Product Page of my Magento store. I attempted it like this: Magento- How can i add a new custom block in product details page using module Unfortunately, it did not work as expected. Did I make any mistakes he ...

Retrieve the Flot graph object using Javascript

Seeking advice on a function that should return a JavaScript object. function get_temp(){ var datasets_temp = { "sens1": {data: [[1340803113,22.9],[1340803474,23],[1340803836,23],[1340804197,23.1]] }, "sens2": {data: [[134084 ...

Is it possible for the r.js optimizer to generate a fresh index.html file that links to the compiled files

After using r.js to optimize my project, I'm wondering how to generate a single index.html file that includes just one optimized script and one CSS file. Would I need to manually write this post-build or is there another way to achieve this? ...

Error: Jest react testing encountered an issue when attempting to read the property 'type' from an undefined value

While conducting tests on my app components created with the material UI library using jest and enzyme, I encountered an error in one of my packages. Here is a screenshot of the error: Click here to view ...

Error found in the HTML tag data when viewing the page source for an issue

I am displaying some data from my express to ejs in HTML tag format. It appears correctly on the ejs template page and the web page. However, when I check the page source, the HTML tags are encoded and displayed as unescaped characters. Is there a solution ...

Convert the contents of the uploaded file to a JSON format

I've recently started using angularjs for file uploads and came across this helpful model on github: https://github.com/danialfarid/angular-file-upload The file upload process is working smoothly for me. However, I'm facing a challenge after upl ...

"Material-Table does not have the ability to insert a new row

Just started learning JS and React. I'm attempting to integrate Material-table with an add row button, but encountering issues where the added row is not reflecting. Every time I refresh the page, the rows are reset. I suspect there's a problem w ...

Choosing a request date that falls within a specified range of dates in PHP Laravel

In my database, I currently store two dates: depart_date and return_date. When a user is filling out a form on the view blade, they need to select an accident_date that falls between depart_date and return_date. Therefore, before submitting the form, it ne ...

Performing a consistent influx of data into a MySQL database using Node.js encounters an issue: "Unable to enqueue Handshake as a Handshake has

I am trying to insert values into a database in a continuous manner. Here is the code I have attempted: var mysql = require("mysql"); const random = require("random"); var con = mysql.createConnection({ host: "xxx", user: "xxx", password: "xxx", ...

What could be the reason for this simple sails socket not functioning properly?

Just curious why the simple web socket code below isn't functioning? io.socket.on('user', function(event){ console.log("RECEIVED EVENT:",event); }) I have included sails.io.js in my index file and the above code is located in a test.js ...

What causes the variance in AJAX errors between IE and Chrome browsers?

Consider the code example provided below: <script> function xyz() { $.ajax({ type: "GET", url: "https://zx/xyz/uvw", timeout: 6000, dataType: "jsonp", ...

The pre-save function in Mongoose does not seem to be working properly when using discrimin

I am facing an issue where the pre save hook is not being called before saving the owner in mongoose. Is there a workaround for this problem? const baseOptions = { discriminatorKey: '__type', collection: 'users' } const Base = ...

What is the best way to conceal the outline in a popup window?

I have successfully implemented a popup/modal window using JavaScript, but now I need to find a way to hide the outline map container. The initialization code for the map is as follows: self.mapDialogOptions = { autoOpen: false, m ...

Retrieve telephone number prefix from Cookies using React

Being able to retrieve the ISO code of a country is possible using this method: import Cookies from 'js-cookie'; const iso = Cookies.get('CK_ISO_CODE'); console.log(iso); // -> 'us' I am curious if there is a method to obt ...

Mongoose and ES6 promises are not delivering the expected results

I'm currently working on a piece of code that involves creating an array of promises to save specific numbers. The issue I'm facing is that when the output is printed, it displays the same record 10 times. Below is the code snippet: 'use s ...

Utilizing a relationship's remote method in Loopback

My current project involves using loopback where I have a MyUser model that is related (hasMany) to a SellerRequests model. After discovering that I can create a new seller request linked to the user by making a POST request to /api/MyUsers/:id/sellerRequ ...

Retrieve the highest value indexes from a three-dimensional array with JavaScript

In my dataset, I have an array structured like this: [34, 12, 56] [100,125,19] [30,50,69] The highest value in this array is 125, so the index [1,1] is returned. This means that 125, the highest value, can be found in row 1, column 1. To determine the i ...

What is the best way to retrieve the value of a JavaScript variable and display it within an HTML label tag

In my JavaScript code, I'm attempting to retrieve location coordinates using the onchange event and then display those coordinates in a label. I've tried alerting the coordinates successfully, but I'm struggling to update the label using doc ...

Troubleshooting issue with Rails 5.2.3 AJAX request: JSON key-value pairs containing the plus sign are not being received

In my Rails 5.2.3 project, I am attempting to send an AJAX request that includes a JSON representation of a callflow object (the specifics of which are not relevant). This JSON representation is located within a textarea with the id "newCallflowJsonDisplay ...

Sending data from express js to a different server

Currently, I am faced with a scenario where I need to send a file from Jquery to my Express server and then transfer that request to another server without parsing the file in the Express server. Below are the code snippets I have been using so far: Jquery ...