Skip to content

Instantly share code, notes, and snippets.

@xyztlp
Forked from dImrich/curved3Plane.js
Created June 11, 2023 07:46
Show Gist options
  • Save xyztlp/6fa7903fab54fc3d75da1d43ee48bb2c to your computer and use it in GitHub Desktop.
Save xyztlp/6fa7903fab54fc3d75da1d43ee48bb2c 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