# Pick points in viewport instead using sliders

**URL:** <https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338>\
**Category:** ShapeDiver\
**Created:** [May 2, 2020, 5:55pm UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338 "2020-05-02T17:55:08Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![kristian](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/kristian/32/150799_2.png) [@kristian](https://discourse.mcneel.com/u/kristian)\
**Post date:** [May 2, 2020, 5:55pm UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/1 "2020-05-02T17:55:08Z")

</div>

Let’s say you had this polyline, how difficult is it to implement direct point manipulation in stead of using sliders?

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/d/5/d5eb6dd3e61ecd0c17526f3954a4d34b91254c6e.png)

K

---

<div class="post-metadata">

**Author:** ![mathieu1](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mathieu1/32/491677_2.png) [@mathieu1](https://discourse.mcneel.com/u/mathieu1)\
**Post date:** [May 4, 2020, 12:36pm UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/2 "2020-05-04T12:36:39Z")

</div>

At the moment, you won’t be able to do that without using the API. I will prepare a more complete tutorial in the near future, but here is a quick overview of how you would implement this in ShapeDiver at the moment:

1. **Grasshopper definition**  
a. _Inputting the positions of the points_  
If you don’t want to use three different sliders for each point input, and especially if you are going to use a variable number of points, you will need a more compact and flexible way to input point positions. I would recommend to use a JSON string containing a list of points as input, with a list that can have a variable number of points. This can be sent from the website to the ShapeDiver model using the ShapeDiverTextInput component. Use the ShapeDiver JSON components to parse and extract the points from the input:  
 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/9/e/9eb25b51ac838250223f535c83a1a4705d6bf695.png)  
b. _Create the geometry and display it._  
Use the points to create your Polyline, and then of course display the polyline, as well as the point handlers from your sketch. Note that if you want to select the points individually, you need to send them in separate tree branches to the ShapeDiverDisplayGeometry component. Also note that at the moment, curves are not draggable in the viewer (this is a small problem, we will fix soon), so you should rather represent the points with small meshes.  
 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/0/4/0455083db683d36237e867f328f8253972370f5d.png)

Find below the complete Grasshopper definition from this example.

[edit\_polyline.gh](https://discourse.mcneel.com/uploads/short-url/8MeKk1YpDNPKx9F742mP6KEoAhP.gh) (22.8 KB)

1. **Online point picker**  
After you upload the model to ShapeDiver and embed it somewhere, you can use the API to create the behaviour you need. Without going in too much detail, here are the steps you need. You’ll find a link to the full working code of the example that you web developer should be able to work with.  
a. Define a group of hoverable an draggable objects in the viewer, specifying which effects happen when you hover or drag the objects of the group. In my example, I turn the objects dark red whey they are hovered, and then bright red when they are dragged.  
b. Add the points coming from the ShapeDiver model to this interaction group. Now the points can be hovered and dragged around in the scene.  
c. Whenever a point is released (when dragging ends), send the list of points locations to the ShapeDiver model, in order to update the shape of the polyline.

Find the code and try the example here: [https://codepen.io/ShapeDiver/pen/pojdQKR?editors=0010](https://codepen.io/ShapeDiver/pen/pojdQKR?editors=0010)

https://codepen.io/ShapeDiver/embed/pojdQKR?height=265&theme-id=light&default-tab=result

You will probably agree that a potential flaw of this approach is that the polyline does not update in real time, but only after the Grasshopper definition is updated through the servers. In general, this will make sense if you are updating not only a polyline but also some more complex geometry that will need to go through Rhino and Grasshopper. If this is only meant as an input, I would recommend to implement a separate point picker with a native front-end method, for example in a canvas. See for example [this configurator](https://shapelamp.com/create/). Then you just have to connect this canvas to the inputs of the model (the logic above is still valid in this case).

---

<div class="post-metadata">

**Author:** ![kristian](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/kristian/32/150799_2.png) [@kristian](https://discourse.mcneel.com/u/kristian)\
**Post date:** [May 6, 2020, 5:28pm UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/3 "2020-05-06T17:28:29Z")

</div>

Wow thanks for a really comprehensive answer Mathieu! It’s awesome that you can do this kind of stuff so seemingly “easily”. For me that option could work, as there is actually a whole lot of updating that will happen after the points are moved anyways.

The only thing that would be necessary for me is a grid snap so that the points would be on exact 100mm x and y coordinates after moving.

Best regards  
Kris

---

<div class="post-metadata">

**Author:** ![mathieu1](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mathieu1/32/491677_2.png) [@mathieu1](https://discourse.mcneel.com/u/mathieu1)\
**Post date:** [May 6, 2020, 7:18pm UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/4 "2020-05-06T19:18:37Z")

</div>

As a matter of fact, we just added a snapping feature to the API.

I created a second version of the example above, with three added functionalities:

- The Grasshopper model includes a simple grid. It also generates some more complex geometry (nothing to fancy, a good old Voronoi pattern, it’s just to make a point).
- The code adds a snapping module for the dragged points on to the background grid.
- I also made a fancier version of the polyline update which is now happening in real time. This requires the manual creation and updating of a THREE.JS object.

As a warning, I would consider the last two points (and especially the last one) as advanced API tasks. It will definitely make sense in the future to expose some of these features to the Grasshopper plugin, in order to avoid the API learning curve.

Full example: [https://codepen.io/ShapeDiver/pen/ZEbvmQQ](https://codepen.io/ShapeDiver/pen/ZEbvmQQ)

https://codepen.io/ShapeDiver/embed/ZEbvmQQ?height=400&theme-id=light&default-tab=result

---

<div class="post-metadata">

**Author:** ![kristian](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/kristian/32/150799_2.png) [@kristian](https://discourse.mcneel.com/u/kristian)\
**Post date:** [May 13, 2020, 6:40pm UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/5 "2020-05-13T18:40:20Z")

</div>

Hi Mathieu

Sorry for late answer, i have been too busy lately…  
That was very impressive! It would be exactly what i need for the configurator i am currently working on! Unfortunately it is confidential at the moment so i can not show it. It involves moving points in simple polyline shapes though, and the direct moving of points like above is way more intuitive for the users than a bunch of sliders.

Best regards!  
K

Best regards

---

<div class="post-metadata">

**Author:** ![pvilarim](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pvilarim/32/512257_2.png) [@pvilarim](https://discourse.mcneel.com/u/pvilarim)\
**Post date:** [December 8, 2021, 1:29pm UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/6 "2021-12-08T13:29:30Z")

</div>

Hi @mathieu1 !  
Would you know if there is any function that uses these same points to create a spline?

// create the live polyline  
polylineAsset = polylineAsset(positions.points);  
api.scene.updateAsync([polylineAsset]);

---

<div class="post-metadata">

**Author:** ![mathieu1](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mathieu1/32/491677_2.png) [@mathieu1](https://discourse.mcneel.com/u/mathieu1)\
**Post date:** [December 10, 2021, 8:42am UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/7 "2021-12-10T08:42:20Z")

</div>

I was about to say no but I found that [three.js has a builtin spline function](https://threejs.org/docs/#api/en/extras/curves/SplineCurve) from a series of points:

So it should be straightforward to adapt the above example to a spline envelope. If you manage to create a codepen from it, it would be great to share it here! Otherwise I will have try and create an example when I have a moment.

---

<div class="post-metadata">

**Author:** ![mathieu1](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mathieu1/32/491677_2.png) [@mathieu1](https://discourse.mcneel.com/u/mathieu1)\
**Post date:** [December 10, 2021, 10:07am UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/8 "2021-12-10T10:07:21Z")

</div>

I already came up with a new version:  
https://codepen.io/ShapeDiver/embed/preview/NWaRNzJ?default-tabs=js%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=NWaRNzJ

Along with the new definition:  
[211210\_EditSpline.gh](https://discourse.mcneel.com/uploads/short-url/OCwYfDMMMDap9T2lmR2zBT9Vkn.gh) (19.5 KB)

Note that the three js splines only have uniform knot spacing apparently, so the knot style has to be set to uniform in the definition.

---

<div class="post-metadata">

**Author:** ![pvilarim](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pvilarim/32/512257_2.png) [@pvilarim](https://discourse.mcneel.com/u/pvilarim)\
**Post date:** [December 18, 2021, 5:41am UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/9 "2021-12-18T05:41:00Z")

</div>

thank you very much Mathieu!  
this will help me a lot.

---

<div class="post-metadata">

**Author:** ![Filipe\_Brandao](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/filipe_brandao/32/480912_2.png) [@Filipe\_Brandao](https://discourse.mcneel.com/u/Filipe_Brandao)\
**Post date:** [December 29, 2021, 12:04am UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/10 "2021-12-29T00:04:50Z")

</div>

Hello @mathieu1! This is slightly off topic but point input, i.e., creation not manipulation, on the canvas has been promised for sometime. I was under the impression that this feature was available in the new beta. Is this the case? If yes, is it only available through the API?

Best,

---

<div class="post-metadata">

**Author:** ![mathieu1](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mathieu1/32/491677_2.png) [@mathieu1](https://discourse.mcneel.com/u/mathieu1)\
**Post date:** [January 7, 2022, 10:07am UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/11 "2022-01-07T10:07:11Z")

</div>

It has always been possible to define point inputs using the API, with the following steps:

- Make the relevant objects in your scene selectable using the API, and bind them with the SELECT\_ON event which catches any click on the selectable objects of the scene.
- In the callback to this event, find the event property containing the location of the point that was clicked on the object, and send the coordinates to the grasshopper definition, using a text input with a JSON object for example.
- Use the location in Grasshopper for your purpose, optionally displaying a sphere or other visual element at the selected location.

We have an old tutorial regarding this process, check it out here: [https://support.shapediver.com/hc/en-us/articles/360030890392-Tutorial-Pick-and-Drag-Points-on-an-Object](https://support.shapediver.com/hc/en-us/articles/360030890392-Tutorial-Pick-and-Drag-Points-on-an-Object) (make sure to adapt it to the latest version of the viewer)

There is nothing new regarding point inputs in the beta version yet. We do plan to add a “Point input” component that wraps all these API steps without having to write any code, but it is not available yet.

---

<div class="post-metadata">

**Author:** ![Filipe\_Brandao](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/filipe_brandao/32/480912_2.png) [@Filipe\_Brandao](https://discourse.mcneel.com/u/Filipe_Brandao)\
**Post date:** [January 18, 2022, 4:49pm UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/12 "2022-01-18T16:49:25Z")

</div>

Thanks @mathieu1, I missed your reply. I’m aware of that workflow but that is not what I was looking for. I want users to create points that are not on the Grasshopper definition. Like [in this JavaScript app](https://filipebrandao.pt/2021/03/10/rs-and-sd-with-json/) were they click on the canvas to draw a polygon.

---

<div class="post-metadata">

**Author:** ![manojdotwork](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/manojdotwork/32/445178_2.png) [@manojdotwork](https://discourse.mcneel.com/u/manojdotwork)\
**Post date:** [March 14, 2022, 3:12pm UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/13 "2022-03-14T15:12:31Z")

</div>

Hi @mathieu1  
Is the snapping feature available in API v3?

---

<div class="post-metadata">

**Author:** ![MajorMeerkatThe3rd](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/majormeerkatthe3rd/32/475431_2.png) [@MajorMeerkatThe3rd](https://discourse.mcneel.com/u/MajorMeerkatThe3rd)\
**Post date:** [March 14, 2022, 3:44pm UTC](https://discourse.mcneel.com/t/pick-points-in-viewport-instead-using-sliders/101338/14 "2022-03-14T15:44:37Z")

</div>

Hello @manojdotwork,  
snapping has now been fully integrated into our interactions. You can have a look [here](https://help.shapediver.com/doc/Interactions---Part-1.1852899330.html)  
Cheers, Michael
