How to twist geometry around the Y axis?

function twist(geometry) {
  const quaternion = new THREE.Quaternion();

  for (let i = 0; i < geometry.vertices.length; i++) {
    // a single vertex Y position
    const yPos = geometry.vertices[i].y;
    const twistAmount = 10;
    const upVec = new THREE.Vector3(0, 1, 0);

    quaternion.setFromAxisAngle(
      upVec, 
      (Math.PI / 180) * (yPos / twistAmount)
    );

    geometry.vertices[i].applyQuaternion(quaternion);
  }
  
  // tells Three.js to re-render this mesh
  geometry.verticesNeedUpdate = true;
}

Taken from here… Geometry Manipulation in Three.js — Twisting | by Shay Keinan | Medium

Or another thread with options for the same procedure in different ways here…

1 Like