Adjusting the z-axis rotation in a three.js animated scene

Is there a way to add a function that changes the Z rotation value of the teapot from within the updateTeapot function? I came across this helpful answer on Three.js camera tilt up or down and keep horizon level. However, I am unsure how to integrate a z rotation function into this existing function.

function updateTeapot() {
        if (teapot != null) {
        teaPotHeight+=1;
        teapot.position.y = teaPotHeight%200;
        } 
    }    
(function ( lab3 , $, undefined) {

lab3.init = function(hook) {
    // Set up renderer
    var WIDTH = 600,
    HEIGHT = 500;
    var renderer = new THREE.WebGLRenderer();
    renderer.setSize(WIDTH, HEIGHT);
    hook.append(renderer.domElement);
    var scene = new THREE.Scene();

    // Add lights
    var pointLight = new THREE.PointLight(0xFFFFFF);
    pointLight.position = new THREE.Vector3(-10, 100, 100);
    scene.add(pointLight);

    // Add ambient light
    var ambient = new THREE.AmbientLight( 0x555555 ); 
    scene.add( ambient ); 

    // Set up camera
    var VIEW_ANGLE = 65,
    ASPECT = WIDTH / HEIGHT,
    NEAR = 0.1,
    FAR = 10000;
    var camera = new THREE.PerspectiveCamera(VIEW_ANGLE, ASPECT, NEAR, FAR);
    camera.position.z = 300;
    scene.add(camera);

    // Add controls
    var controls = new THREE.TrackballControls( camera );
    controls.target.set( 0, 0, 0 ); 

    // Create a cube
    var material = new THREE.MeshLambertMaterial({ color: 0x00bbcc }); 
    var cube = new THREE.Mesh(new THREE.CubeGeometry(40, 55, 30), material);
    scene.add(cube);

    // Animation
    function renderLoop() {
        renderer.render(scene, camera);
        controls.update();
        window.requestAnimationFrame(renderLoop);
        updateTeapot();
    }
    window.requestAnimationFrame(renderLoop);   

////////////////////////////////////////////////    

    var teapot = null;
    var teaPotHeight = 0;

    loader = new THREE.JSONLoader();
    loader.load( "models/utah-teapot.json", function( geometry ) {
    teapot = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial({
          color: 0x00bb00,
          side: THREE.DoubleSide
        }));
    teapot.scale.set( 20, 20, 20 );
    teapot.position = new THREE.Vector3(-30, 100, 20); 
    function updateTeapot() {
        if (teapot != null) {
        teaPotHeight+=1;
        teapot.position.y = teaPotHeight%200;
        } 
    }    
    scene.add(teapot);
    });

}

})(window.lab3 = window.lab3 || {} , jQuery)

Answer №1

Insert the following code snippet:

teapot.rotation.z = numInRadians;

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

What is the process for creating a sub-menu for a dropdown menu item in Bootstrap 5?

https://i.sstatic.net/o4FLn.pngthis is my code which i have created this navigation bar with bootstrap and all of its drop downs but i want to add another drop down to the services drop down section inside of webdevelopment but it can't any easy solut ...

Having trouble displaying the API response data on the screen in Next.js

I am currently experiencing an issue with my OCR API that is supposed to return text from a given image. The data is being received on the client side and can be seen in the console. However, for some reason, the element is not updating with the data. Bel ...

I require the use of Nodejs with the gm module to process images, but it is essential that it

There are two methods to consider, but I am struggling to make it synchronous. Despite attempting to use Promise.all to synchronize the process, I am faced with the challenge of images processing asynchronously and inability to reject or resolve in a loop. ...

Using jQuery and Flask-WTF to achieve live word count in a TextAreaField - a step-by-step guide!

I am interested in adding a real-time word count feature to a TextAreaField using jQuery. I found an example that I plan to use as the basis for my code: <html lang="en"> <head> <script src= "https://code.jquery.com/jquery ...

What is the best way to dynamically change the color of my component depending on the prop passed to it?

I am facing an issue with the color of my component changing based on the value of the prop 'level'. Despite using states to set the backgroundColor, all components end up having the same color due to the state being altered for every comment. I ...

What is the process of connecting a Yarn module to a Docker container in another repository?

I'm currently facing a challenge in linking a module to a Docker container from another repository. To provide some background, I have a container hosting a React application named launch-control-admin. This project relies on a yarn module called @com ...

Loading Bootstrap Modal with click event triggering

I am currently working on a project where I need to load ajax content into a bootstrap modal when a link is clicked. I have been able to successfully load the content without any issues, but I am facing some difficulties triggering the modal window to open ...

Steer clear of manually inputting URLs in your React components

As I embark on my journey with Gatsby, I am noticing a recurring pattern in my code. A prime example is when creating links, where I often find myself doing something like this: import {kebabCase} from "lodash"; // ... <Link to={`tags/${kebabCase( ...

Every time the attribute of the Angular controller changes, it is reinitialized

I'm currently in the process of developing a single page application using angularjs 1 and ngRoute, and I've encountered an issue. Within a view (/posts) I have a controller (PostsController) with an attribute called 'posts' that holds ...

Reactjs button only responds on the second click instead of the first tap

Currently, I am working on a Reactjs/nextjs project and have a video with audio button on my page. There are two things that I want to achieve: 1) I would like the button to have the "bi bi-volume-mute" class by default instead of "bi bi-volume-down". 2) W ...

Creating a dynamic list in HTML by populating it with randomly selected words using JavaScript

Check out my awesome code snippet function wordSelect() { var words = ["Vancouver", "Whistler", "Surrey", "Victoria", "Kelowna"]; //List of randomly-selected words from above var selectedWords = []; for(let i = 0; i &l ...

Iterate through the .json file and add markers to a leaflet map

Apologies for the basic question, but I'm struggling with understanding JavaScript and json files. I have a .json file that updates server object locations every 5 seconds, and I want to plot these coordinates on a map using leaflet for staff access. ...

Issues with clicking on the ion-tab icon in AngularJS are hindering the functionality

I'm currently facing a challenge with an ion-tab icon in my AngularJS project. I've been attempting to add a click action using the code below, but unfortunately, nothing is displaying as expected. HTML <ion-tab title="Share" icon="icon ion- ...

jquery method to make entire navigation bar clickable

I have a single menu bar. I recently discovered an interesting way to make the entire menu bar area clickable using jQuery. Design code snippet: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="MenuControl.ascx.cs" Inherits="MenuControl"%> ...

Navigate to a different directory within Cypress by utilizing the cy.exec() function

Dealing with cypress to execute a python script in another directory. However, it seems like the directory change is not functioning as expected. visitPythonProject() { cy.exec("cd /Users/**/Desktop/project/"); cy.exec("ls"); // thi ...

Generating a new division element with a unique identifier and subsequently making adjustments to it

Just starting out with HTML and JS here, so please excuse my lack of experience and not-so-great English. I have an ID on an HTML element that I want to add content to using a function. Additionally, I need to create another element (inside the first one) ...

Troubleshooting Problem with jQuery Function Call in Drupal 7

Encountering a particular issue in Drupal, though it may not be exclusively related to Drupal. This is the simple javascript code I am working with: (function ($) { function testing(){ alert('TEST function responding!'); } })(jQuery); ...

Migrating to Angular Universal for server-side rendering with an external API server

Thank you for taking the time to read my query. I have developed a project using server-side Node.js and client-side Angular 6. The purpose of the app is to provide information on cryptocurrency prices and details. I am now looking to transition my Angu ...

Accessing a JSON file from a nearby location using JavaScript

I am currently working on an artistic project based on weather data, which will be hosted locally with the JSON file updating via FTP synchronization. This means that the JSON file will be sourced from the same computer where it is stored. The code snippet ...

Tips for troubleshooting objects within an Angular template in an HTML file

When I'm creating a template, I embed some Angular code within my HTML elements: <button id="btnMainMenu" class="button button-icon fa fa-chevron-left header-icon" ng-if="(!CoursesVm.showcheckboxes || (CoursesVm.tabSelected == 'curren ...