"Exploring the world of scale animation with Three.js and gsap

Currently, I am attempting to create a mousemove event in three.js that will trigger a scale effect when the user hovers over a geometry. In order to animate this effect, I have integrated GSAP as an alternative to using the tween function which was not working for me. However, every time I attempt to scale my geometry, I encounter the following error message: https://i.sstatic.net/ZIhUy.png

I'm puzzled by this issue because the official GSAP documentation showcases the use of scale without the need for a plugin. Here is a snippet from their website:

gsap.to(".box", 1, {
    scale: 0.1, 
    y: 60,
    yoyo: true, 
    repeat: -1, 
    ease: "power1.inOut",
    delay:1,
    stagger: {
      amount: 1.5, 
      grid: "auto",
      from: "center"
    }
  });

Below is the code snippet in question:

function init () {

/*------Several lines of three.js code and initialization*/
 window.addEventListener('mousemove',onMouseMove);

}

function onMouseMove(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(scene.children, true);

                for(var i = 0; i < intersects.length; i++) {
                    gsap.to(intersects[i].object.scale, {duration: 1, scale: 0.8});
                }

            }

Answer №1

After some investigation, I have found the solution. It appears that in three.js, the gsap scale property does not function as expected. You must ensure that you reference scale before applying transformations, and then use x and y (or possibly z - I have not tested) to increase or decrease the size. Here is the code snippet that resolved the issue for me:

gsap.to(intersects[i].object.scale, {duration: .7, x: 1.2, y: 1.2});

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

Swap out a picture with one that has been uploaded

Can anyone help me with an issue I'm having regarding image uploading? I am currently using an HTML file upload form along with a jQuery function to check the file type of any image selected by the user. My goal is to replace the existing image on a w ...

Managing multiple Sequelize DB connections in NestJS: A guide

I recently came across the example in the NestJS documentation regarding setting up a Sequelize DB connection. I'm curious about how to connect to multiple databases using Sequelize and TypeScript with NestJS. Can anyone provide guidance on this? ...

How can I use an array to dynamically populate an option html tag in react?

I am attempting to populate an option in jsx with values from an array called currencyOptions. Despite using this method, the options are remaining blank. The array is passed down to the component as a prop, set using useState, and the data is fetched from ...

Adjusting image dynamically based on conditions

I need to dynamically display images on my HTML based on specific conditions using TypeScript. In my TypeScript file: styleArray = ["Solitary", "Visual","Auditory","Logical","Physical","Social","Verbal",]; constructor(){ for (var i = 0; this.sty ...

Leveraging jQuery's load within a series of sequential operations

I am currently working on populating different cells in a table with the IDs #RECALRow1, #RECALCol1, and #RECALBodySum. Each cell is being filled from a database using AJAX with jQuery's load method. In my initial approach, I had separate functions f ...

Creating synchronous automation in Selenium: A step-by-step guide

I am feeling increasingly frustrated at the moment and I am hoping to seek assistance on stackexchange. First and foremost, I must admit that I am not a seasoned Javascript developer, probably not even an experienced developer overall, but I do have some ...

Implement an event listener on the reference obtained from the React context

Within the React context provider, a ref is established to be utilized by another component for setting a blur event listener. The issue arises when the blur event fails to trigger the listener. The following is a snippet of code from the context provider ...

New input has been added: a checkbox element that is void of any value

I am facing an issue when trying to add a new input:checkbox. Even after adding a new input and checking it, I am unable to retrieve the value of the checked input:checkbox when clicking on the button. How can I fix this problem? DEMO: http://jsfiddle.net ...

I Tried Adding Up All the Numbers, but It Doesn't Seem to Work for Every Dynamic Total Field

In my project, I am utilizing Laravel 5.7 and VueJs 2.5.*. The issue I am facing is that when I input values, the Total field calculates correctly. However, when I dynamically add rows for items, the calculation only works for the first row and not for the ...

How can you link a Razor Function to a JavaScript Variable?

Trying to incorporate a Razor C# Function into a JavaScript Function has been a challenge for me. While it's simple to do in HTML, I'm encountering compilation errors when attempting it in JavaScript. I've experimented with the <text> ...

XPages component retrieval function is malfunctioning

Utilizing an XPage with JQuery dialog and client-side validation adds efficiency to the user input process. However, there seems to be a disconnect between the client-side validation and server-side properties. Although the client-side validation functions ...

Utilizing External Library Functions with VueJS

I have been looking everywhere for a working example of how to connect an external JS file and call its function, but I haven't had any luck. Essentially, my goal is to link an external JavaScript file and execute its function using VueJS. <script ...

Tally up the values of selected checkboxes

  I'm in search of a method to tally up data-values associated with checkboxes. In the example provided below, selecting locations from the checkboxes results in the calculation of primary values, which are displayed in the green box. I also need to ...

The Jquery function is failing to retrieve data from the MySQL database

I am currently attempting to retrieve values from phpMyAdmin and populate them into the second select field based on the selection made in the first select field. However, I seem to be encountering an issue as the selected value is not being passed to my P ...

Alter numerous classifications based on varying circumstances at regular intervals

This code snippet is designed to change randomly all the <div class="percentx"> elements, for example from <div class="percent31"> to <div class="percent52"> (with values between 1-100). It works smoothly. I ...

How can I resize and horizontally align an image using html/css?

Is it possible to resize, crop and center an image using only HTML/CSS? (Using the img tag or CSS sprite) For instance, if I have a 500x500 pixel image, I would like to resize it to a 250x250 pixel image To make the actual visible image 100x100 pixe ...

Issue with publishing npm package using yarn package manager

I'm currently in the process of releasing a fresh package. Utilizing ES6, I've been transpiling my files through babel to start with. However, I've hit a roadblock at this particular stage: https://i.stack.imgur.com/iIVp6.png This part se ...

Using javascript, what is the best way to clear a text field with a specific condition?

When I clear the text field #t1, I expect text field #d1 to also clear. However, the last two lines of code do not achieve this result. function utl() { var tField = document.getElementById('t1'); var dField = document.getElementById(&a ...

Removing an element from an array within MongoDB

After closely examining my mongodb data structure, it appears like this: [ { "_id": "582bc918e3ff1bf021ae8b66", "boardName": "Test Board", "created_at": 1479264483957, "__v": 0, "person": [ { "name": "Steve", "w ...

Looping through color transitions upon hover using CSS

I am trying to create a color transition effect on hover, where the background changes from yellow to red and then back to yellow in a loop. I'm having trouble figuring out how to make this transition repeat continuously. Do I need to incorporate Java ...