# Line connecting two Objects

**URL:** <https://discourse.threejs.org/t/line-connecting-two-objects/44667>\
**Category:** Questions\
**Tags:** lines\
**Created:** [November 14, 2022, 8:22am UTC](https://discourse.threejs.org/t/line-connecting-two-objects/44667 "2022-11-14T08:22:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diimsch](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/diimsch/32/31055_2.png) [@Diimsch](https://discourse.threejs.org/u/Diimsch)\
**Post date:** [November 14, 2022, 8:22am UTC](https://discourse.threejs.org/t/line-connecting-two-objects/44667/1 "2022-11-14T08:22:42Z")

</div>

Hello I’ve been trying to recreate a sankey chart in threejs.  
Currently im struggling with creating the lines that connect the different nodes.  
I’ve tried using normal lines but it’s not possible to apply a width on them.  
I’ve also tried using the fatLines example from threejs: [three.js examples](https://threejs.org/examples/?q=fat#webgl_lines_fat) but since the width for those is applied in every direction the result looked strange.  
I also tried using MeshLines: [GitHub - spite/THREE.MeshLine: Mesh replacement for THREE.Line](https://github.com/spite/THREE.MeshLine)  
They pretty much do what i need but its not possible to disable the billboarding on them.

Im running out of ideas right now and was wondering if i missed some other approaches.  
Essentially i want to create lines as in the attached picture.  
Where both ends of the lines are flat.  
Any suggestions are appreciated.  
 ![Sankey-Chart](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/7/5/75dba9ed7c89bc0c131e23ab5ed4430d6a21ab9e.jpeg)

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [November 14, 2022, 8:32am UTC](https://discourse.threejs.org/t/line-connecting-two-objects/44667/2 "2022-11-14T08:32:43Z")

</div>

Hi!  
You can deform/bend a plane 🤔

---

<div class="post-metadata">

**Author:** ![anidivr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/anidivr/32/32924_2.png) [@anidivr](https://discourse.threejs.org/u/anidivr)\
**Post date:** [November 14, 2022, 12:50pm UTC](https://discourse.threejs.org/t/line-connecting-two-objects/44667/3 "2022-11-14T12:50:34Z")

</div>

Another approach could be to draw a curve from one box to the top of the next box. Get the points for this. Draw another curve from the bottom of one box to the bottom of the next box. Finally draw a shape connecting points from both curves to form a curved rectangle. The shape should be filled.

---

<div class="post-metadata">

**Author:** ![anidivr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/anidivr/32/32924_2.png) [@anidivr](https://discourse.threejs.org/u/anidivr)\
**Post date:** [November 14, 2022, 12:57pm UTC](https://discourse.threejs.org/t/line-connecting-two-objects/44667/4 "2022-11-14T12:57:25Z")

</div>

If this is a one-time thing (just a piece of art, no runtime changes), you could draw in a tool that supports exporting to SVG. Then just load and color the SVG version. It could be flat, or you could extrude to give it depth.

---

<div class="post-metadata">

**Author:** ![anidivr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/anidivr/32/32924_2.png) [@anidivr](https://discourse.threejs.org/u/anidivr)\
**Post date:** [November 14, 2022, 10:11pm UTC](https://discourse.threejs.org/t/line-connecting-two-objects/44667/5 "2022-11-14T22:11:09Z")

</div>

This code draws a ribbon between two points at startposition and endposition. Use width to vary the thickness.

You can increase above 25 to get smoother curves.

```nohighlight
  width = 0.005;

  private updatecurve() {
    if (this.mesh.geometry) this.mesh.geometry.dispose();

    const startplus = start.clone()
    const endplus = end.clone()
    const diff = Math.abs(start.x - end.x)/4;

    startplus.x += diff;
    endplus.x -= diff;

    const points: Array<Vector2> = [start, startplus, endplus, end];

    const curve = new SplineCurve(points);

    const toppoints = curve.getPoints(25);
    const first = toppoints[0]

    const ribbon = new Shape()

    ribbon.moveTo(first.x, first.y + this.width);
    toppoints.forEach(point => {
      ribbon.lineTo(point.x, point.y + this.width);
    });
    toppoints.reverse().forEach(point => {
      ribbon.lineTo(point.x, point.y - this.width);
    });
    ribbon.closePath();

    this.mesh.geometry = new ShapeGeometry(ribbon);
  }

```

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/b/7/b72201123b9a04d10f33569b8033c31958ce351d.png)

Hope this helps

---

<div class="post-metadata">

**Author:** ![Diimsch](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/diimsch/32/31055_2.png) [@Diimsch](https://discourse.threejs.org/u/Diimsch)\
**Post date:** [November 15, 2022, 10:07am UTC](https://discourse.threejs.org/t/line-connecting-two-objects/44667/6 "2022-11-15T10:07:47Z")

</div>

Thanks for the responses.  
I went with the SVG approach since im creating the chart with D3js as an SVG anyway.  
Im extruding the nodes while keeping the links flat as @anidivr mentioned.  
Im also able to make runtime changes thanks to D3js.

Heres what i ended up with for now:

 ![Bildschirm­foto 2022-11-15 um 11.07.03](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/3/0/301a8a0b7f003dcc13cd02de7bb59f9375a0fe82.png)
