Skip to content

Instantly share code, notes, and snippets.

@dImrich
Created January 6, 2017 18:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dImrich/39988ff5078800f4f1c6eec85223cacc to your computer and use it in GitHub Desktop.
Save dImrich/39988ff5078800f4f1c6eec85223cacc to your computer and use it in GitHub Desktop.
Bend Three JS Plane Geometry With Bezier Curve
//Bend Three JS plane geometry with bezier curve
//Curved plane generation, bezier curve plane,
function bendPlaneGeometry(planeGeometry, centerBendZ)
{
var curve = new THREE.CubicBezierCurve3(
planeGeometry.vertices[0],
new THREE.Vector3(planeGeometry.parameters.width/2, 0, centerBendZ ),
new THREE.Vector3(planeGeometry.parameters.width/2, 0, centerBendZ ),
planeGeometry.vertices[(planeGeometry.vertices.length/2) - 1]
);
var planePoints = curve.getPoints(Math.abs(planeGeometry.vertices.length/2)-1);
for(var edgeI = 1; edgeI < 3; edgeI++){
for(var pointI = 0; pointI < planePoints.length; pointI++){
planeGeometry.vertices[(edgeI === 2) ? planePoints.length + pointI : pointI].z = planePoints[pointI].z;
}
}
planeGeometry.computeFaceNormals();
planeGeometry.computeVertexNormals();
return planeGeometry;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment