Turn off the orbit camera in three.js when utilizing the transform control

In my project, I have a complex scene composed of multiple meshes, each assigned to a unique transformControl. To select different objects in the scene, I rely on raycasting techniques. Additionally, I utilize an orbit camera for navigating through the scene.

However, I've encountered an issue where when I adjust the position, rotation, or scale of an object using the transform control, the orbit camera remains active. This poses a problem as sometimes I inadvertently click on the background of the scene while selecting an object, causing the orbit camera to move unexpectedly.

I have attempted to resolve this issue by implementing various raycasting techniques, but unfortunately, none have been successful in preventing the unwanted behavior. If anyone has any suggestions or alternative solutions, I would greatly appreciate it.

Answer №1

Came across this and found it quite useful to find the answer (props to BuildingJarl):

// if you have a definition like
var controls = new THREE.OrbitControls( camera );

// you can easily turn it off with
controls.enabled = false;

In my situation, I encountered issues with a UI overlay and struggled to give it focus. Disabling the controls resolved my problems.

Best, Mat

Answer №2

Incorporating a snippet from the three.js editor's example code, one can easily deactivate orbitControls while utilizing transformControls:

import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { TransformControls } from 'three/addons/controls/TransformControls.js';

let orbitControls= new OrbitControls(camera, renderer.domElement);
orbitControls.addEventListener('change', render);

let transformControls = new TransformControls(camera, renderer.domElement);
transformControls.addEventListener('change', render);
transformControls.attach(targetObject);
transformControls.addEventListener('dragging-changed', function (event) {
    orbitControls.enabled = !event.value;
});

Whenever controls are dragged, orbitControls will be disabled with orbitControls.enabled = false.

Note that in case you have

targetObject.matrixAutoUpdate = false
, it is essential to invoke targetObject.updateMatrix() prior to calling render in the change event handler.

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

Unable to dynamically display an HTML5 video using JavaScript

I'm facing an issue with displaying videos in a modal dynamically. Here's the scenario: +------------+---------+ | Name | View | +------------+---------+ | 1.mp4 | X | | 2.mp4 | X | +------------+---------+ The X ...

warning: issue detected with the password value in jquery

Why is the following script generating an incorrect JavaScript alert message? <script type="text/javascript> $('#cpassword').change(function() { var pass=$('#password').val(); alert(pass); var cpass=$(& ...

Building Vertical Tabs with external JS for loading custom visuals

I am trying to figure out how to display the visuals I created in an alternate page within my Vertical tabs. The tabs are already styled, and I have omitted the CSS due to its length. The HTML file I am working with is test.html, and the visuals are in the ...

Seeking assistance with changing the pages

Looking for assistance with troubleshooting my function. All variables are accounted for. var swith = document.getElementById("sub"); var one = document.getElementById("rule"); var two = document.getElementById("cool"); var three = document.getElementByI ...

What is the process through which Generator.next() works with its parameter?

According to the documentation, it mentions that "You can also provide a parameter to the next method to send a value to the generator." But where exactly does it send this value to? Let's consider these 3 different generator functions: function* fi ...

Configuring Axios header in Java backend based on the value stored in the express session

I am currently working on a frontend app using node.js express for server-side rendering. This app calls java backend endpoints and I use Axios to make the requests. A specific header named "agent-id" needs to be set in every request that is sent from expr ...

Video DTO not defined with the utilization of a brightcove player

Hey there, just a quick question from a newcomer.. I tried following the example at to extract information about the current video DTO in order to display it on my page. However, when accessing it via JS, the value of the video DTO always turns out to be ...

Exporting CSS file from css-loader in Webpack: A step-by-step guide

My application structure is set up like this: /src /app.js /styles.css /images /img.png The content of the app.js file is as follows: const styles = require('./styles.css'); console.log(styles) // => I want a URL to t ...

How to Use Conditional In-Line CSS for Internet Explorer and Other Browsers

After inspecting the source code for this website, I noticed a cool feature where the page changes based on your scrolling position. It creates a visually appealing effect. Upon further examination of the source in FireFox, I observed the use of -webkit-t ...

tips for dealing with login pop-ups using Python's Selenium

When using selenium, I am facing a challenge of handling a Chrome popup on a virtual machine, even when the remote desktop connection is closed. https://i.sstatic.net/ep1s9.png I have successfully managed to automatically fill in the credentials in Chrom ...

Issue with saving Twitter stream data to MongoDB using Mongoose not being properly handled

My goal was to store data from the Twitter Streaming API into MongoDB using Mongoose. However, I'm facing an issue where only a single document is saved out of the continuous stream of data when I run the code: var mongoose = require('mongoose&a ...

Issue with unrecognized expression in JQuery when processing Ajax response

Recently, I implemented a JQuery Ajax Form on my website. $('#modal-body-sign-in').on('submit', '#sign-in', function(e) { e.preventDefault(); var data = $(this).serialize(); var url = $(this).attr(&apo ...

What is the best way to create a sign-up box that appears on the same page when you click on the sign-up button

I am interested in implementing a 'sign up' box overlay at the center of my index page for new users who do not have an account. I would like them to be able to easily sign up by clicking on the 'sign up' button. Once they complete the ...

Exploring the power of React Hooks with the useState() function and an array filled

When creating new "Todo" items and modifying the fields, everything works fine. However, my problem arises when trying to retrieve the child data after clicking the "show all objects" button. To better understand my issue, here is a code example: const Co ...

The Ubuntu virtual machine hosted on Google Cloud is experiencing difficulties connecting through Node.js using an external IP address

const express = require('express'); const bodyParser = require('body-parser'); const path = require('path'); const app = express(); app.listen(3000, function(){ console.log('Server is now live on port 3000' ...

Exploring the capabilities of JSON.stringify in Internet Explorer 11

I encountered a puzzling issue with my JavaScript code – it works flawlessly in Google Chrome 49.0.2623, but causes my entire file to crash in Explorer 11. The problem arises when I attempt to 'Export' JavaScript objects using AJAX. Let me shar ...

How can we extract Euler angles from Trackball Controls in Three.js?

I am currently implementing the three.js trackball controls to allow rotation around my object. However, I am looking for a way for the view to automatically rotate slowly around the vertical axis when the user is not actively using the trackball. Does an ...

Using a combination of Javascript and PHP to dynamically update the innerHTML of multiple elements

I am working on updating the innerHTML of a webpage using Javascript after an onclick event. In my java.js file, I am utilizing this code to access a PHP page that echoes back the text for updating the innerHTML. The issue arises when attempting to update ...

Dealing with Uncaught Type Errors in the Fixed Data Table

I am attempting to implement a fixed data table using the following code snippet. var MyCompi = React.createClass({ getInitialState: function() { return { rows : [ {"id":1,"first_name":"William","last_name":"Elliott","email":"<a ...

Enhancing Security: Implementing Node.js API Authentication

Looking for guidance on setting up multiple authentications with different roles in Next.js development. Can anyone help me navigate this aspect of website building? Using Next.js for the frontend Utilizing Node.js and JWT (JSON web token) for the backend ...