Three.js: universal rotation

My goal is to rotate all elements within a scene around the origin point of 0,0,0 specifically along the x-axis. Despite attempting to set obj.rotation.x += 0.1;, I'm facing the issue that instead of rotating around the origin, the object rotates around its center. Is there a straightforward method to achieve the desired rotation around the origin? I've scoured the official documentation and various online resources without success in finding a solution.

Answer №1

To optimize the rendering process, consider adding objects to a THREE.Group() instead of directly to the scene:

var group = new THREE.Group();
scene.add(group);
...
var object1 = new THREE.Mesh(...);
group.add(object1);
var object2 = new THREE.Mesh(...);
group.add(object2);
// continue adding meshes in this manner

In your render loop, apply rotation to the group:

group.rotation.x += 0.1;

This code snippet is compatible with Three.js version r84.

Answer №2

To rotate an object around the x-axis in local space using Three.js, you can create a new Object3D with THREE.Object3D(). Next, add all your meshes to this object by using the method myObject.add(myMesh). Finally, apply the rotation with myObject.rotateX(angle), where the angle is specified in radians. Remember that both myObject and myMesh are objects created within Three.js framework. For more detailed information on Object3D, check out the official documentation: Object3D

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

issue with fetching response from ajax post call in slim framework 3

Update: The issue has been resolved. The correct localhost address for the ajax request should have been 127.0.0.1 instead of 121.0.0.1 On my client side, I am using the following code to send a POST request to localhost/login. <html> <title> ...

Here is an example of how to use a script tag to check the value of a select tag in HTML:

Hi there! I'm working on a piece of code where I need to retrieve the selected value from a dropdown menu in an HTML select tag and display it in the element with the id='h1' at the bottom. The script tag is already included within the head ...

Is it possible to use jQuery/JS to automatically format currency input as it is typed, adding a 1000 separator and ensuring

I'm working on a text input field that needs to format the value as it is being typed, with restrictions of 2 decimal places and 1000 separators. This field should only allow for digits to be entered. Specifically, this input is meant for users to ent ...

Creating a mongoDB query that matches elements in an array of subdocuments with elements in a Typescript Array

In my database, I have stored various Events using mongoDB. Each event comes with multiple fields, including an array of genres, which consists of subdocuments like {genre and subGenre}. For instance, an event could be classified as {genre: "music", subGe ...

Using jQuery's sortable functionality to rearrange rows in a table can cause conflicts with Angular's orderBy feature

In the past, my angular app used a table with orderBy to sort rows based on a specific column. By clicking on a table header, the orderBy arguments would change and the list would be sorted according to the values in that column. Now, I am experimenting w ...

Emphasize today's date on the w3widgets adaptable calendar

While developing a website featuring a calendar to showcase events, I came across w3widgets, which proved to be quite helpful. However, I encountered an issue when trying to highlight the current date on the calendar. It seems that the calendar only highli ...

Obtaining NodeJS from a mysterious subdirectory

-- plugins ---- myplugin1 ------ core ---- myplugin2 ------ core If this represents the directory structure, is there a method to import all core directories from plugins without specifying the specific plugin names like myplugin1? require('/plugins ...

Obtain information in JSP from a JavaScript function that was generated in another JSP file

I have created a code that allows the admin to toggle a user's status between active and inactive using radio buttons. The technologies I have used for this project are JSP, MySQL, and JS. admin.jsp: <tr> <td> ...

Displaying JSON data in HTML using Angular

If you have a straightforward controller: controller: function($scope, $http){ $http.get(templateSource+'/object.customer') .then(function(result){ $scope = result.data; }); } The content of my object.customer file is a ...

What is the best way to determine the total number of pages for posts

Hello there! I'm currently working on implementing an infinite scroll feature for a custom post type, but I'm stuck on how to obtain the max_num_pages and pass it to JavaScript. Below is my current implementation of the infinite scroll: containe ...

JavaScript: function that operates asynchronously

I am new to JavaScript and encountered some issues with async functions. I have a function that fetches data from MongoDB by creating a promise, but it returns a collection with an empty object. async function getRating(item, applicant) { let arr = await ...

Transferring MySQL data from PHP to Javascript using JSON format

I am attempting to utilize a code snippet that fetches data from a mySQL database, assigns that data to a variable, aggregates all the resulting values into a PHP array, and then converts it to JSON format. Subsequently, I transfer the JSON data to JavaScr ...

Utilizing Sequelize validation through condition objects

const db = require("../models"); const Meet = db.meet; checkDuplicateTime = (req, res, next) => { Meet.findAll({ where: { tanggal: req.body.date, waktu: req.body.time } }).then(time => { ...

The $mdSticky feature in AngularJS Material seems to be malfunctioning

It's been a challenge for me to get the md-toolbar to stay in the top position. I decided to create a custom directive using the $mdSticky service in AngularJS. var app=angular.module('app',['ngMaterial']); app.controller(&apos ...

The request to login at the specified API endpoint on localhost:3000 was not successful, resulting in a

As I continue to develop my programming skills, I have been working on configuring a database connected with nodejs in the same folder. However, when trying to make an ajax request to the database, I encountered an error indicating that the database may be ...

Strange outcome in Three.js rendering

Is it possible to correct the reflection issue around the cycles? I noticed some strange results on my object and I've attached pictures to illustrate the problem. Current result in Three.js: https://i.sstatic.net/iJbpm.jpg https://i.sstatic.net/hv ...

Is there a way to prevent the window.status from appearing?

I currently have the following code snippet: <a class="button accessLink" id="loginLink" href="#" data-action="Login" data-dialog="access" data-disabled="false" data-entity="n/a" ...

Tips for preventing $digest cycle already in progress error while testing

I've been struggling to test a service that utilizes the Google Maps Geocoding service. I initially thought it would be simple since the code is pretty straightforward, but it's proving to be more complex than expected. Here's an overview o ...

Incorporate text into the URL of the image

Got a URL of an image like this: https://lipsum.mobi/catalog/product/SE0229E/YG/AAA/4/1/SE0229E-YG-AAA-4.jpg', and looking to add 240x240 within the URL. Current Url: https://lipsum.mobi/catalog/product/SE0229E/YG/AAA/4/1/SE0229E-YG-AAA-4.jpg Desire ...

Unable to retrieve the IDs of various products using AJAX

Struggling with creating an E-commerce site using PHP and AJAX, I'm facing an issue fetching product IDs on my shop view. My shop consists of 3 products with IDs 1, 2, and 3. When a user clicks the "Add to Cart" button, I want to retrieve the corresp ...