blazerix
blazerix

Reputation: 109

How do you animate or move specific points on a plane in three.js?

I have a texture mapped to a plane. Suppose I only want to move particular points in the plane. How would I go about doing so?

For example, I want to move the bottom right corner at a particular speed and the top right corner at a particular speed.

var camera;
var scene;
var renderer;
var mesh;

init();
animate();

function init() {

    scene = new THREE.Scene();
    camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000);

    var light = new THREE.DirectionalLight( 0xffffff );
    light.position.set( 0, 1, 1 ).normalize();
    scene.add(light);


    var geometry = new THREE.PlaneGeometry( 50, 50);  

    var texture = THREE.ImageUtils.loadTexture('images/03032122.png', {}, function() {
    renderer.render(scene, camera);
    })
    var material = new THREE.MeshBasicMaterial({map: texture, transparent: true })


    mesh = new THREE.Mesh(geometry, material );
    mesh.position.z = -50;
    scene.add( mesh );

    renderer = new THREE.WebGLRenderer({ alpha: true });
    renderer.setSize( window.innerWidth, window.innerHeight );

    renderer.setClearColor( 0xffffff, 1);
    document.body.appendChild( renderer.domElement );

    window.addEventListener( 'resize', onWindowResize, false );

    render();
}

function animate() {
    //mesh.scale.x+= 0.0003;


    render();
    requestAnimationFrame( animate );

}

function render() {
    renderer.render( scene, camera );
}


function onWindowResize() {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize( window.innerWidth, window.innerHeight );
    render();
}

Upvotes: 0

Views: 2070

Answers (1)

Mouloud85
Mouloud85

Reputation: 4234

You can modify the geometry after the mesh creation by accessing its vertices array. If you want the vertex of rank 1 to move linearly in the +x direction, you can add in your render function :

mesh.geometry.vertices[1].x+=.01;
mesh.geometry.verticesNeedUpdate=true;

Beware to use PlaneBufferGeometry instead of PlaneGeometry.

Upvotes: 1

Related Questions