-
-
Save nbriz/4ee2c35872e44fddc494 to your computer and use it in GitHub Desktop.
morph (or stretch) points in your mesh, for threejs_playGnd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ------------------- INSTRUCTIONS ----- | |
to morph (or stretch) points in your mesh | |
place the 'for loop' below, | |
inside your setup() function, | |
below your 'material = new THREE.MeshBasicMaterial(...' | |
and above your 'mesh = new THREE.Mesh(geometry, material)' | |
-------------------------------------- */ | |
for ( var i = 0; i < geometry.vertices.length; i ++ ) { | |
var vertices = []; | |
for ( var v = 0; v < geometry.vertices.length; v ++ ) { | |
vertices.push( geometry.vertices[ v ].clone() ); | |
if ( v === i ) { | |
vertices[ vertices.length - 1 ].x *= 2; | |
vertices[ vertices.length - 1 ].y *= 2; | |
vertices[ vertices.length - 1 ].z *= 2; | |
} | |
} | |
geometry.morphTargets.push( { name: "target" + i, vertices: vertices } ); | |
} | |
/* -------------------------------------- | |
then place the code below | |
below your 'mesh = new THREE.Mesh(geometry, material)' | |
above your 'scene.add(mesh);' | |
-------------------------------------- */ | |
mesh.material.morphTargets = true; | |
/* -------------------------------------- | |
then add the code below to your | |
draw() fucntion | |
change the [ 0 ] to a different number | |
to target a different point | |
you can target as many points as you want | |
by copy+paste'n the code below and changing | |
the number. | |
-------------------------------------- */ | |
mesh.morphTargetInfluences[ 0 ] = Math.sin( Date.now() * 0.002 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment