What could be causing my text mesh to resist rotating continuously?

Is there a way to make my text mesh rotate continuously, without being affected by the TrackballControls (mouse movements)? Currently, my mesh only rotates when I move the mouse. Can someone help me identify what's causing this issue?

Here's the code snippet:

// Setting up basic Three components 
var scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.z = 500;

// Configuring camera controls
var controls = new THREE.TrackballControls( camera );
controls.rotateSpeed = 1.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.8;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
controls.keys = [ 65, 83, 68 ];
controls.addEventListener( 'change', render );

// Initializing the renderer
var renderer = new THREE.WebGLRenderer( { antialias: false } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

window.addEventListener( 'resize', onWindowResize, false );

// Adding a text element
var materialT1 = new THREE.MeshNormalMaterial();
var textGeom = new THREE.TextGeometry( 'Sitescope', {
    font: 'optimer',
    weight: 'normal',
    size: 20                
});

var textMesh = new THREE.Mesh( textGeom, materialT1 );
textMesh.position.set(-40,60,50)
scene.add( textMesh );

function onWindowResize() {

    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize( window.innerWidth, window.innerHeight );
    controls.handleResize();
    render();

}

function animate() {
    requestAnimationFrame( animate );
    controls.update();

}

function render() {
    textMesh.rotation.x += 0.05; // Adjust rotation speed here
    renderer.render( scene, camera );
} 

animate();
render();

Answer №1

The issue lies in the order of operations. You can resolve it by following these steps:

function animate() {
    requestAnimationFrame( animate );
    render();
}

function render() {
    cube.rotation.x += 0.01;
    cube.rotation.y += 0.01;
    textMesh.rotation.x += 0.05;
    controls.update();
    renderer.render( scene, camera );
}

animate();

Additionally, make sure to remove this function call:

controls.addEventListener( 'change', render );

To see a live example, check out this JSFiddle link

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

Time for the browser to evaluate javascript code has arrived

We are looking to enhance the speed at which our Javascript files load in the browser. Although our own Javascript files are simple and small, larger libraries like jQuery and KendoUI take a considerable amount of time to evaluate. We are interested in fin ...

Calculating the total of an array's values using JavaScript

Receiving information from an API and looking to aggregate the values it contains. Consider the following code snippet: function totalPesos(){ $http.get('/api/valueForTest') .then(function(data){ $scope.resumePesos = data.data.Re ...

Exploring Excel files using the exceljs library

Using the exceljs module, I am able to read Excel files when they are in the same folder as my application. The code works perfectly in this scenario: var workbook = new Excel.Workbook(); workbook.xlsx.readFile('Data.xls') .then(function() ...

Unexpected behavior observed: Title attribute malfunctioning upon double clicking span element

I recently implemented the following code: <span title="hello">Hello</span> Under normal circumstances, the title attribute functions correctly when hovering over the element. However, after double clicking on the span element (causing the t ...

Error: Unable to locate the 'react' module in the specified directory

During the execution of my project, I encountered an error that read: Module not found: Can't resolve 'react' in I attempted various solutions to fix this issue. Initially, I ensured that the state in my component was correct and that I had ...

A guide to incorporating external CSS files in Angular 5 components using styleUrls

I have a unique setup where my Angular 5 application resides in a subdirectory within another parent application. The parent application consists of JSP and other AngularJS applications among other things. My goal is to include a CSS file from the parent ...

The blending of Angular 4 HTTP responses creates a jumbled mess

I have encountered an issue while using Angular 4 across different browsers like safari, chrome, and Firefox. In my Angular 4 application, I am sending XHR Requests via httpclient to interact with a REST service. The communication is done in JSON format. ...

Pass the output of canvas.toDataURL function in JavaScript to the $mail->addAttachment method in PHP

Currently, I am working on a web application that allows users to customize a pool by dragging different icons onto a blueprint (such as stairs, skimmer, light...). Once the customization is complete, users can click on a button to receive the blueprint v ...

Is there a way to modify the value of a JavaScript object?

My React componentwillmount fetches data from an ExpressJS API using Axios and receives a JSON response, which is then converted to an object by Axios. [{"client_nick":"PlayTalk","connected_time_record":183710127},{"client_nick":"PlayTalk","connected_time ...

Avoiding node_modules in Webpack 2 with babel-loader

After updating to Webpack 2, I've run into an issue with the "exclude" property in my "rules". It seems I can no longer pass "exclude" into "options". What is the correct approach to handling this now? Previously: { test: /\.js$/, loader: ...

What is the best way to compile TypeScript files without them being dependent on each other?

I have created a TypeScript class file with the following code: class SampleClass { public load(): void { console.log('loaded'); } } Now, I also have another TypeScript file which contains functions that need to utilize this class: // ...

Express with NodeJS Electron

Currently, I am working on developing a web application using electron for the website and desktop application and express for sessions. This is the code snippet from my app.js: const express = require('express'); const {app, BrowserWindow} = re ...

Is it possible to change the src attribute after the page has loaded and execute it

A. I'm trying to figure out how to dynamically change the src attribute of an image using JavaScript after the page has loaded. <img src="http://example.com/image.png" /> to <img src="http://domain.com/different.jpg" /> B. Another questi ...

Manifest for local messaging host was not detected

I am currently facing an issue with establishing a connection between a chrome-extension and a NativeMessagingHost. While everything works smoothly on Windows, I am encountering difficulties on Linux distributions such as Arch, Kali, or Ubuntu. The specifi ...

Is the row removed from the table after successful deletion?

I am struggling to remove the deleted row from the table. The code I tried is not working as expected. Here is the scenario: When a user clicks on the delete link/button, it sends a delete request and removes the data from the Database. After successful de ...

Encountering difficulties retrieving JSON response from Express in a production environment

When in Development mode, react and express connect flawlessly, allowing for successful data retrieval from the backend. However, in Production mode, although a status code of 200 is returned, the JSON response from express cannot be obtained. The specifi ...

Error encountered while connecting to SQL Server from node.js causing the express server to crash due to a ConnectionError

Encountering an issue with node.js tedious error ConnectionError: Failed to connect to sqlserverip:1433 causing unexpected crashes in my express server. Seeking suggestions on how to prevent such crashes. <a href="/cdn-cgi/l/email-protection" class="__ ...

FusionMaps XT integration with VueJs: Troubleshooting connectorClick events issue

I am experiencing some issues with events connectorClick on my VueJS processed map. When I click on the connector line in the example below, the alert function does not seem to work as expected. Vue.use(VueFusionCharts, FusionCharts); let grphMap = new ...

Conflicting Angular controller names within different modules

I'm facing an issue where two modules (A and B) with controllers of the same name are conflicting when imported into module C. Is there a recommended solution to prevent this conflict, such as using a naming convention like "module.controller" for ea ...

The $or operator in mongoose falls short in providing complete data when paired with the find() method

I am currently utilizing the find method in conjunction with the $or operator to search the database for any duplicate data within this specific line. const duplicate = await NewItemsData.find({ $or: newItems }); Upon inspecting the variable in the consol ...