Skip to content

Instantly share code, notes, and snippets.

@imhalid
Last active December 11, 2023 19:55
Show Gist options
  • Save imhalid/b492add47a6fea8e2f563e7d646c1d84 to your computer and use it in GitHub Desktop.
Save imhalid/b492add47a6fea8e2f563e7d646c1d84 to your computer and use it in GitHub Desktop.

Revisions

  1. imhalid revised this gist Dec 11, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion planeCurve.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    function planeCurve(g, z){
    // g: Geometry
    // z: Depth
    // source: https://jsfiddle.net/gkmqzp1w/9/

    function planeCurve(g, z){
    let p = g.parameters;
    let hw = p.width * 0.5;

  2. imhalid revised this gist Dec 11, 2023. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion planeCurve.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    function planeCurve(g, z){

    // g: Geometry
    // z: Depth
    let p = g.parameters;
    let hw = p.width * 0.5;

  3. imhalid created this gist Dec 11, 2023.
    32 changes: 32 additions & 0 deletions planeCurve.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    function planeCurve(g, z){

    let p = g.parameters;
    let hw = p.width * 0.5;

    let a = new THREE.Vector2(-hw, 0);
    let b = new THREE.Vector2(0, z);
    let c = new THREE.Vector2(hw, 0);

    let ab = new THREE.Vector2().subVectors(a, b);
    let bc = new THREE.Vector2().subVectors(b, c);
    let ac = new THREE.Vector2().subVectors(a, c);

    let r = (ab.length() * bc.length() * ac.length()) / (2 * Math.abs(ab.cross(ac)));

    let center = new THREE.Vector2(0, z - r);
    let baseV = new THREE.Vector2().subVectors(a, center);
    let baseAngle = baseV.angle() - (Math.PI * 0.5);
    let arc = baseAngle * 2;

    let uv = g.attributes.uv;
    let pos = g.attributes.position;
    let mainV = new THREE.Vector2();
    for (let i = 0; i < uv.count; i++){
    let uvRatio = 1 - uv.getX(i);
    let y = pos.getY(i);
    mainV.copy(c).rotateAround(center, (arc * uvRatio));
    pos.setXYZ(i, mainV.x, y, -mainV.y);
    }
    pos.needsUpdate = true;
    }