The process of rotating an object using its local coordinates involves manipulating its orientation to

Struggling to figure out how to rotate an object around its local coordinates. I've attempted using the rotation property, but it seems to only rotate the object around the world axis. Another approach was to move the object, place it at position (0,0,0), then rotate it before returning it to its original placement, but that method proved unsuccessful.

Any ideas or suggestions on how to achieve this?

Answer №1

See the code in action here.

let camera, scene, renderer, geometry, material, mesh;

initialize();
animateScene();

function initialize() {

    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 10000);
    camera.position.z = 800;
    scene.add(camera);

    geometry = new THREE.BoxGeometry(300, 300, 300);
    material = new THREE.MeshNormalMaterial();

    mesh = new THREE.Mesh(geometry, material);
    scene.add(mesh);

    renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);

    document.body.appendChild(renderer.domElement);

}

function animateScene() {

    requestAnimationFrame(animateScene);
    renderAnimation();

}

function renderAnimation() {

    mesh.rotation.x += 0.02;
    mesh.rotation.y += 0.03;

    renderer.render(scene, camera);

}

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

How can I use `app.js` in Zendesk to connect to an external API using the complete URL

As someone new to developing Zendesk apps, I've been following the step-by-step guide available here. To Summarize I'm facing an issue with passing external API URLs to the AJAX call syntax within Zendesk's app.js file. You can find my sim ...

Turning off a hyperlink with jQuery

Is there a way to effectively disable a link in jQuery without changing the anchor's href attribute? I initially tried setting disabled to true, but it seems that approach isn't working as expected. The goal is to prevent the user from being redi ...

Exploring ReactJS Design Patterns: Comparing Class Components to Custom Components

As I delve into best practices and design patterns using React, I find myself pondering the choice between two similar solutions: The first solution involves a class that does not extend a component. Its constructor returns an element set based on an obje ...

Exploring the Power of Webpack and Web Workers within Ionic 2

In our upcoming Ionic 2 project, we are considering the implementation of web workers. However, due to the usage of ionic-app-scripts (version 1.0.0) with webpack in Ionic 2 (https://github.com/ionic-team/ionic-app-scripts), we face the challenge of having ...

Guide on receiving parameters sent via a socket.io emit event with baconJS

I'm having some trouble with socket.io and bacon.JS: On the client side, I have a socket.IO emit event that sends 2 parameters to the server like this: $("#btn").asEventStream("click").onValue(function(){ socket.emit("event", param1, param2); }) ...

What is the best way to conceal panels while a bootstrap is being utilized?

I have been working on a bootstrap panel that consists of three panels: Panel 1, Panel 2, and Panel 3. The functionality of this panel is working correctly under normal circumstances. My Approach: Clicking on Panel 1 should display its content while hid ...

CSS personalized by the user

I want to develop an application that allows users to input their customized CSS, which will then be implemented on the webpage. Is there a straightforward method to achieve this, or do I need to manually parse and modify the CSS by accessing elements like ...

Generate a unique 4-6-4 pattern using React JS

Hello everyone, I am just starting out with react JS. Can someone please guide me on how to re-format a random string into a 4-6-4 format, using only numbers and A-Z characters? Requirement: When the Submit button is clicked, I need to generate an Access ...

Autocomplete feature fails to operate on a duplicated input

I'm encountering an issue with the jQuery function clone(). I suspect that the problem lies within the withDataAndEvents input parameter of this method. To provide some context, I am working on a dynamic table where rows are added dynamically when a ...

What is the best way to dynamically load utility methods in a Next.js application?

Do you believe it is beneficial to organize logic into utility files and dynamically load them to enhance the speed of a website? For example, I have a method called getInvoiceDetails in a file named getInvoiceDetails.tsx: export default const getInvoiceD ...

The PHP file fails to load JavaScript because it requires another JavaScript file to be loaded beforehand

I created a chat widget using PHP (chat.php) and now I want to embed it into another PHP page (blank.php). To make this work, chat.php requires some scripts that are located in external JavaScript files. So, in blank.php, I added the necessary JS files th ...

Reorganizing JSON data with ES6 techniques

I have a scenario where I need to update tire quantities in an array like this: tires: [{ name: "fancyProduct1", quantity: 1 }, { name: "fancyProduct1", quantity: 1 }, { name: "fancyProduct1", quantity: 1 }, { name: "fancyProduct2", quanti ...

Looking to extract data from JavaScript using Scrapy 1.4.0?

Apologies for my lack of proficiency in English. As a beginner in scrapy, I am seeking guidance on an issue I encountered while trying to scrape a particular website. Below is the code for my spider: import scrapy from bs4 import BeautifulSoup as bs clas ...

Using a MultiSelect Dropdown check box to create an Angular Filter

Do you want to apply a filter on moduleName based on the value selected from a multi-select dropdown? INFORMATION: [ { "_id": "59155aada593f4331499dd59", "uswin": "lovelje", "moduleName": "After Call Survey", "accessLevel": "Read Only", ...

Utilizing ThreeJS: Establishing microphone as audio source

Is there a way to connect the audio source in ThreeJS to the microphone without pushing the sound to the speakers? According to the documentation, I found this code snippet: var listener = new THREE.AudioListener(); camera.add( listener ); // create a gl ...

What is the method to track the number of tspan elements within each span element?

How can I use jQuery to count the tspan elements inside multiple span elements within svg text? var count_tspan = jQuery('span text').children().length; // 4 console.log(count_tspan); <div class="content-inner"> <span id="item-0" cl ...

"Why does the React useState array start off empty when the app loads, but then gets filled when I make edits to the code

I'm facing a challenging task of creating a React card grid with a filter. The data is fetched from an API I developed on MySQL AWS. Each card has a .tags property in JSON format, containing an array of tags associated with it. In App.jsx, I wrote Jav ...

What could be causing an error in my Vue app when attempting to process a payment using Google Pay on a mobile device, resulting in the message "Blocked a frame with origin

When implementing payment through Google Pay on Chrome desktop, it functions smoothly. However, an error occurs when attempting to pay using a smartphone, triggering an additional modal window with a card selection: vue.esm.js?a026:152 Uncaught (in promise ...

Excessive clicks on the Submit button result in extended validation closure within the Jquery Validation Engine

While using the jquery validation engine, I've encountered an issue where spam clicking the submit button causes a delay in closing. The $("#FORM").validationEngine('hide'); method also doesn't seem to work as expected. I am utilizing P ...

Implement a feature that allows a user to upload multiple files from a Uint8ClampedArray using

After creating a binary file in the Browser using JavaScript as Uint8ClampedArray, I am now faced with the task of uploading it to a webserver as if it was selected from a file-picker. My attempt at this resulted in the following code: var data = new Uint ...