mercredi 30 novembre 2016

Three JS Plane Animation

I have a plane and each frame I am trying to animate its vertices using perlin noise. I tried to follow this codepen but in my project its animating way to fast. I know the simplex.noise3D values are different but its because they values from codepen demo react different in my version. Below is the code I am using and here is a codepen

function createCube() {
    groundGeometry = new THREE.PlaneGeometry(10, 10, 20, 20);
    groundMaterial = new THREE.MeshLambertMaterial({color: 0x2d2d2d, wireframe: true});
    groundMesh = new THREE.Mesh(groundGeometry, groundMaterial);

    groundMesh.receiveShadow = false;
    groundMesh.castShadow = false;
    groundMesh.rotation.x = -0.5 * Math.PI;
    groundMesh.position.set(0, 0, 0);

    scene.add(groundMesh);
}

var tick = 0;

function loop(){

    tick++;
    groundGeometry.verticesNeedUpdate = true;
    groundGeometry.colorsNeedUpdate = true;
    for (var i = 0; i < groundGeometry.vertices.length; i++) {
        var vert = groundGeometry.vertices[i],
        noiseVal = simplex.noise3D(vert.x * 0.025, vert.y * 0.025, tick * 0.025);
        vert.z = noiseVal;
    }

    renderer.render(scene, camera);
    requestAnimationFrame(loop);
}




Aucun commentaire:

Enregistrer un commentaire