Three.js - Transformation Handles

Utilizing the transformControls for translating, rotating, and scaling objects in my scene has been successful. However, I am encountering an issue where the clickable area of geometries is offset:

https://i.sstatic.net/7SOA5.jpg

This means that clicking on the lower part of the object does not select it, but rather the upper part.

The problem is exacerbated when dealing with collada files.

I believe the issue lies within this section:

function onDocumentTouchStart(event){
    event.preventDefault();
    event.clientX = event.touches[0].clientX;
    event.clientY = event.touches[0].clientY;
    onDocumentMouseDown(event);
}
function onDocumentMouseDown(event){
    event.preventDefault();
    mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
    mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
    raycaster.setFromCamera(mouse, camera);
    var intersects = raycaster.intersectObjects(objects);
    if(intersects.length > 0){
        SELECTED = intersects[ 0 ].object;
        scene.add(control);
        control.attach(SELECTED);
    } else{
        scene.remove(control);
    }
}

EDIT :

After some investigation, it turns out the issue was due to certain margins present...

However, now I am struggling with attaching transformControls to my object properly. While using transformControls, the problem persists. Interestingly, changing the material color upon click works seamlessly. Could there be margins associated with transformControls? Here is a snippet of what I tried:

if(intersects.length > 0){
            SELECTED = intersects[ 0 ].object;
            scene.add(control);
            control.attach(SELECTED);
        } else{
            scene.remove(control);
        }

Answer №1

It became clear that...

    if(intersects.length > 0){
    SELECTED_OBJECT = intersects[ 0 ].object;

    controller.attach(SELECTED_OBJECT);
    scene.add(controller);

} else{
    controller.detach(SELECTED_OBJECT);
    scene.remove(controller);
}

I overlooked detaching the controls

Answer №2

sRcBh's response is mostly accurate, although there is a slight error in the code provided. The detach function within the TransformControls does not require any parameters to be passed.

if (intersects.length > 0) {
    SELECTED = intersects[ 0 ].object;
    control.attach(SELECTED);
    scene.add(control);
} else {
    control.detach(); // This line is correct
    scene.remove(control);
}

(For more information, refer to )

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

Fill the rows of the <Table> using HTML code

I am encountering an issue with displaying data in a table on a screen: <table id="TransactionTable" class="table table-responsive table-striped"> <thead> <tr> <th></th> <th>Date</ ...

Elevate your website's design with Vue and create eye-catching CSS

I've been working on a Vue hamburger menu component, but I'm facing an issue with the animations. The animation process seems to reach the desired end result, yet there is no actual animation displayed. The animation triggering is done through a ...

Is there a way to preserve the context in React when transitioning to a new page?

Currently, I am encountering a challenge within my React application involving multiple components, each utilizing its own context through the useContext hook. My goal is to uphold the context for each component even when there are changes in the URL. I a ...

Using Javascript to send a post request and handle multiple responses

Is it possible to receive multiple responses from the server? When making a post request, my code only seems to capture the first response from the server. How can I ensure that all three responses are captured and processed? Below is the index.html page ...

I seem to be experiencing some confusion with labeling in my pie chart and doughnut chart using Chart.js. Additionally, I am unable to properly display the charts themselves

Struggling to generate charts using vue js. The chart is displaying with crossed labels instead of the actual chart. I'm puzzled about what could be causing this issue. https://i.sstatic.net/5hZXR.png Supposedly, this should be a pie chart. However, ...

Exploring the meaning behind RxJS debounce principles

Referencing information found in this source: const debouncedInput = example.debounceTime(5); const subscribe = debouncedInput.subscribe(val => { console.log(`Debounced Input: ${val}`); }); When the first keyup event occurs, will the debouncedI ...

Issues accessing my Facebook account due to domain problems

I have developed an HTML5 game that I am currently running in my web browser. My objective is to integrate Facebook login functionality, so I followed a tutorial and replaced the necessary information with my App ID. However, upon running it, an error mes ...

Troubleshooting checkbox problem with AJAX request in PHP

Experiencing an issue with a simple AJAX call that checks if a checkbox is checked. Currently, regardless of whether the checkbox is checked or not, it always prints "not checked". I've attempted changing the "POST"/"GET" methods in the PHP code, howe ...

An issue occurred while running the "gulp test" command due to a problem with the 'gulp-tslint-log'

Having issues running gulp on a JHipster generated project. I've already installed all node_modules using npm install and here are my package.json and gulpfile.js: { "name": "myapp", "version": "0.0.0", "description": "Description for myapp", ...

Leveraging TypeScript's library extensions in combination with requirejs

Currently, I am experimenting with THREE.js and socket.io to develop a small game. I am looking to utilize the OrbitControls extension for THREE.js for camera controls, which I have successfully used in a previous project. However, it seems that the clien ...

Discovering checkboxes in HTML using jQuery

Greetings! I have limited knowledge when it comes to using jQuery. I am currently facing an issue with the Checkbox attribute. Below, you will find the code snippet that I have mentioned: Code: $( this ).html() Output: <input name="cb_kot[]" class= ...

How can I extract the width of an uploaded image and verify it using JavaScript?

Is it possible to retrieve the image width through upload using PHP and then validate it in JavaScript? $_FILES['image'] If the image size is not equal to 560px, can we return false and display an alert message using JavaScript? Also, I am won ...

Is there a way to determine if the content of a rich text editor is empty?

My blog is equipped with a rich text editor called Quill, but I am facing an issue. I am wondering if there is a way to determine whether the content in the Quill editor is empty? I am using Quill alongside React, Express JS, and MongoDB, and I want to ...

In relation to User Interface: Analyzing target tracking and studying the flow of time

Is there a way to track mouse cursor movements, button clicks, and click times to an external database using only CSS, HTML5, and Javascript? I am curious about the possibility of conducting usability studies in this manner. ...

Develop a new object using NodeJS within a module for a function

I am working with a file named item.js exports.itemParam = function(name, price, url, id){ this.name = name; this.price = price; this.id = id; this.url = url; }; In my www.js file, I have imported item.js like this: var item = require('../m ...

Is there a way to achieve a transparent background while animating the second text?

I am seeking to create a unique typography animation that involves animating the second text, which is colored and consists of multiple text elements to animate. The animation should showcase each text element appearing and disappearing one after the other ...

Location-based services: Updating the position of a Google Maps marker without refreshing the entire map interface

How can I update only the marker on a map when the device is in motion or has increased accuracy? I want to reload the map when the position changes, but only move the marker. Below is the code snippet that I currently have: if (navigator.geolocation) { ...

Common causes leading to my header component experiencing hydration errors in Next.js

I am currently developing a job portal and encountering an issue with user authentication using JWT in combination with local storage. The problem arises in my header component when the user is authenticated, and if the web page is reloaded, I receive a hy ...

The LineDashMaterial and LineBasicMaterial color functionalities are failing to work properly in Autodesk Forge Viewer version 7

I'm having an issue with adding lines of two different materials, LineDashedMaterial and LineBasicMaterial, using Three.js in Forge viewer v7. The LineDashedMaterial isn't displaying the dashed pattern and material color in both scene and sceneAf ...

How do I adjust brightness and contrast filters on a base64 URL?

When presented with an image in base64 format like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABDAAwfqNRk/rjcYX+PxrV/wtWqwJSTlboMgAAAABJRU5ErkJggg== What is the most efficient method to programmatically alter a filter (such as brightness or cont ...