Jump to content
Search Community

Animate vertices in Three.js with GSAP

Daniel Hult test
Moderator Tag

Recommended Posts

Hey guys,

Im trying to animate some vertices positions in Three JS with GSAP and not sure how to setup the GSAP part.

Demo code (doesn't work):

gsap.to(this.geometry.attributes.position, {
    array: geometry2.attributes.position.array
});


This DOES work (this is what I need to do in GSAP over a set duration):
 

this.geometry.attributes.position.array = geometry2.attributes.position.array;



The relevant code in codepen starts on line 165 :) 

See the Pen PoNJbMd by daniel-hult (@daniel-hult) on CodePen

Link to comment
Share on other sites

  • 1 year later...

Is the same to do it in a cycle? like below

 

for (let i = 0; i < this.particleCloud1.particlesGeometry.attributes.position.array.length; i+=3) {

    const pos = {
        x : this.particleCloud1.particlesGeometry.attributes.position.array[i],
        y : this.particleCloud1.particlesGeometry.attributes.position.array[i+1],
        z : this.particleCloud1.particlesGeometry.attributes.position.array[i+2]
    }

    gsap.to(pos, {
        x: pos.x + 5,
        y: pos.y + 5,
        z: pos.z + 5,
        duration: 5,
        // Make sure to tell it to update
        onUpdate: function () {


            this.particleCloud1.particlesGeometry.attributes.position.array[i] = pos.x;
            this.particleCloud1.particlesGeometry.attributes.position.array[i+1] = pos.y;
            this.particleCloud1.particlesGeometry.attributes.position.array[i+2] = pos.z;

            this.particleCloud1.particlesGeometry.attributes.position.needsUpdate = true


        }.bind(this)
    })

}
  • Like 1
Link to comment
Share on other sites

  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...