Navigating through scenes with just a few mouse clicks and drags

I'm having an issue with TrackballControls. It's not functioning properly and I can't figure out why. I'm following the example provided here: link to example. I've been searching for a solution but still can't seem to pinpoint what I'm doing wrong. Is there something missing in my code?

Simulation: link to my simulation

I have 2 TrackballControls.js because when I was looking for a solution, someone mentioned that adding the script via a URL helped in their case, rather than using a local file: link.

Code:

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 );`

Then, in the next update function animate:

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

Finally, the animate function is called in the loader:

loader.load('./models/my_pc/models/my_pc.dae', function (collada) {

model = collada.scene;
model.scale.x = model.scale.y = model.scale.z = 0.0125;
model.position.x = -2;
model.position.y = 0;
model.position.z = 2;
model.rotation.x = -1.570796327;
model.rotation.y = 0;
model.rotation.z = 0;

init();
animate();
}

Answer №1

Hello there! It seems like you are only calling your animate function once during the initial load. To fix this, make sure to initialize your code first and then create an animate function with a requestAnimationFrame polyfill like this:

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

By implementing this, you will ensure that your controls are continuously updated every frame (such as translating mouse movement to camera position/rotation) and then re-rendering the scene with the latest information. Additionally, remember to create a render function that at least includes the following:

function render() {
    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

Using Symbol.iterator in Typescript: A step-by-step guide

I have decided to upgrade my old React JavaScript app to React Typescript. While trying to reuse some code that worked perfectly fine in the old app, I encountered errors in TS - this is also my first time using TS. The data type I am exporting is as foll ...

Three.js- I am having trouble with my shadow rendering, as lots of black lines are appearing everywhere instead of the shadows showing

Having recently delved into Three.js, I managed to add shadows to my model with the help of some knowledgeable individuals. However, upon the light hitting the model, numerous lines appear, causing me to question whether it's due to my poor modeling s ...

JSON API WebConnector for Tableau

After creating a tableau webconnector to extract data from an internal API, I used earthquakeUSGS.html as a reference (https://github.com/tableau/webdataconnector). The API responds with json data (see code below). Utilizing the "Web data connector simulat ...

unable to successfully npm install canvas

For my GitHub repository, please visit here This project was actively developed until November of last year, after which I did not commit any changes. Today, I attempted to run the project again but encountered the following error. My current system versi ...

Activate function upon closure of window.open

I'm facing an issue where I need to load a URL in window.open that saves some cookies in my browser. After the window.open is closed, I want to access those cookies but I haven't been able to find a way to do it. I've tried the following cod ...

Is there a way to work around the CORS policy in order to fetch data from URLs?

I have been developing a tool that can analyze URLs from an uploaded CSV file, search the text content of each URL, and calculate the total word count as well as the occurrences of "saas" or "software". The goal is to generate a new CSV file with the origi ...

A guide on parsing through a sequence of addresses stored in a text file and extracting specific fields using Node.js

Recently, I came across a text file containing various addresses in a specific format: 335 Ahan St. Haines City, US 30721 786 Birchmount Dr. Waterloo, IA 52001 My objective is to extract individual fields such as the street number, street name, city ...

Accessing QML Functions from JavaScript

Currently, I am faced with a challenge in my app development using Qt. I need to trigger a QML function from JavaScript when a specific event is triggered from my HTML page. I attempted the following method: app.html <html> <head><title& ...

Express.js - What is the method to determine the total number of routes set up in my application?

Is there a way to calculate the total number of routes set up in Express.js without manually counting them? I have defined routes throughout my application and they are not grouped together, so I can't use a counter inside each one. I've searche ...

Creating dynamic ng-model for input type [text] in AngularJS

Here is the current situation I'm dealing with in my code: <form name="task_form" ng-app="myApp" ng-submit="tasksubmit()"> <ul class="items-list"> <li ng-repeat="task in taskslist ...

What is the mechanism behind making a Promise appear synchronous when using a Proxy in JavaScript?

const handler: ProxyHandler<any> = { get: (target: Promise<any>, prop: string, receiver: any) => { return target.then((o) => { return o[prop].apply(o); }); }, }; return new Proxy(obj, handler) ...

Angular: What methods can I utilize to prevent my $http requests from causing UI blockage?

The following code snippet is from my controller: PartnersService.GetNonPartnerBanks().success(function (data) { vm.nonPartnerBanksList = data; }).error( function () { vm.nonPartnerBanksList = []; }); This code calls the service s ...

Tips for sending a function with arguments in a React application using TypeScript

Is there a way to streamline passing a handleClick function to the son component so that it does not need to be repeated? The code in question is as follows: Mother Component: const Mother = () => { const [selectedOption, setSelectedOption] = useSt ...

Steps for executing the npm 'filestream' sample code

After conducting some research, I came across the filestream module which allows for the usage of a file stream API in the browser. https://github.com/DamonOehlman/filestream The author has provided an example usage code named drag-n-drop.js. Here is a s ...

In Node.js and Express, it is important to note that a variable must be declared before

When I use the express action get('items'), I encounter an issue while trying to call an external JSON-API and display the API response in my local response. The error that I am currently facing states that the items variable is not defined with ...

The NextJS API is throwing an error due to a mysterious column being referenced in

I am currently in the process of developing an API that is designed to extract data from a MySQL table based on a specific category. The code snippet below represents my current implementation: import { sql_query } from "../../../lib/db" export ...

Verify if a particular string is present within an array

I am in possession of the key StudentMembers[1].active, and now I must verify if this particular key exists within the following array const array= ["StudentMembers.Active", "StudentMembers.InActive"] What is the method to eliminate the index [1] from Stu ...

Discovering the method for keeping track of file changes and executing find-replace operations without registering it as an event within the monitored file

I am confused about why the output displays two lines when typing 'fizbuzz' into the test.txt file. I understand that it is performing a find and replace operation, but how can I avoid it being triggered by the watch function? const watch = requ ...

Creating a dynamic variable within a for loop and calculating the total of values to assign to that variable

Is it possible to dynamically create variables and add values to them repeatedly? For example: var totalIncomeCr = 0, totalIncomeDr = 0; for (var k = 1; k <= numOfYears; k++) { if(response[i]["AmountType" + k] == "Cr") { if(response[ ...

Different ways to resize an image in various sizes without relying on PHP thumb

I have developed an admin panel for managing reservations of charter, yacht and other vehicles. I am looking for a solution to upload only one image per vehicle and resize it in multiple sizes without relying on the phpthumb library due to its slow loadi ...