# Mesh kisses

Wow, you did it in Python

I almost studied all of it and already learning much of it. I am very happy with it because I now learning of how to work with meshes in Python.

I tried it also with three separated meshes, and understand by that it is meant for ‘two meshes.’
I am going to see how I can ‘expand it.’ I was thinking of using ‘anemone’ to loop, but first I am going to try to see if I can make it work with more than two meshes.

20190216 problem mesh kiss 07.gh (51.5 KB)

1 Like

I haven’t tested it beyond your example, but it might already work for more than two meshes. It just evaluates the kissing for mesh pairs, but it loops every mesh. You might have to play with the sliders for it to work though.

A mesh is created for every neighbor close by the ‘target mesh’ within the loop.

As a student I am already very impressed by what you helped me with giving me something to learn from So, again, thank you.

I am now trying collecting all new_mi’s vectors and new_mj’s vectors together and take then the average of every ‘group’ vectors per point per mesh to deform them.

the mesh loops resulting in four meshes

I am going to try to change this part

The nested for loop that you posted above, loops each mesh, like we would chose team mates from a pool of players at a sports game. Nobody, can be chosen twice!
If you have four Meshes, at the first iteration, the first mesh (i = 0) is compared to the 2nd (j = i+1 = 1), 3rd (j = 2), and 4th (j= 3) mesh. At the 2nd iteration, the 2nd mesh (i = 1) is compared to the 3rd (j = i+1 = 2), and 4th mesh (j=3). At the 3rd iteration, the 3rd mesh (i = 2) is compared to only the 3rd mesh (j = i+1 = 3). At the fourth and last iteration (i=3), there are no meshes left to chose from, since j = i + 1 = 4 and there is no item beyond index 3.

Now, the problem with the duplicate 2nd mesh (from the top) is caused, because - at the first iteration - it’s closest neighbouring mesh is the 2nd one directly below. So the script attracts both meshes to each other and stores the new meshes in `pulled_meshes`.
At the 2nd iteration, however, the unchanged 2nd Mesh from Meshes (that has already been attracted and saved in the previous iteration) is evaluated with the 3rd mesh, as its closest neighbour. It performs the kissing action and both meshes are saved into `pulled_meshes`. Unfortunately, the 2nd mesh gets stored twice, and that’s where the duplicates come from. Thanks for pointing that out!

You want to calculate all the vertex movements, save them per mesh vertex and average them later, in order to find its average movement and avoid duplicates? Seems to be a great work around!
I’ll also look into it tonight.

Instead of performing the vertex movement in the `pull_mesh()` method, you could try to refractor the code.
A new method could for instance only return the movement vectors between two compared meshes. You would call it in the lower nested loop portion and save all the movement vectors in some kind of structured nested list. You should also take count of how many times a given mesh has been evaluated, since you will probably need that later for averaging the movement vectors.
Another method, can then do the averaging and perform the vertex moving.

1 Like

brain dizz
Do you know might know how to get the average of points, counting the XYZ one by one? I think I might do something wrong.

I made the meshes more simple with lesser points so it does testing the script lessen freezing.

20190216 problem mesh kiss 08.gh (92.3 KB)

Hello @ForestOwl,

I’ve implemented the averaging and it seems to work.

There are still some things that could be optimised or added, but the script works so far.
Let me know what you think!

20190216 problem mesh kiss 08.gh (47.8 KB)

7 Likes

Wow, super cool @diff-arch !

You helped me a lot with this! This is really what I was looking for, so helpful, thank you. I am going to use this script to study, with this example I can understand meshes in python much faster. Such example you gave me is very helpful.

Really thank you! What a relief having this for study.

Really thank you.

1 Like

Do you might know how to use the snap of kangaroo; snapping the meshes?
I want to understand this to understand how it can work in python, but besides that, do you know how to use the snap of kangaroo?

Well, I don’t know if this is the officially mandated procedure, but it seems to work for this simple example.

What do you think, @DanielPiker? Anything @ForestOwl could add to make the snapping snappier?

Revisit the above example! It does snapping with a falloff.
Oh yeah, you forgot to internalise your data.

1 Like

I want to make it snappy like when they are not above each other they or precisely next to each other as in my last given file; that they snap to each other even to each other’s mesh faces.

I was not able to make that. Is that possible you think?

Sorry, I see, I forget to internalise the geos.
problem using magnet snap kangaroo 01.gh (17.6 KB)

Isn’t this doable with the Python script?

I thought Kangaroo can do it too, and if so, I can see how to do it with python with it.

How exactly should it be? Can you be more precise?

I am sorry. So, what I mean is:
When a mesh is partly above or underneath another mesh I want that those parts of both meshes attract to each other like two pieces of paper partly connect to each other like with glue; after that I can smooth it or relax the mesh.

I can do it with measuring the distance, divide it by half to not let them go through each other; but thought maybe it is faster with Kangeroo.

I can also python it but wanted to know if it is possible with kangaroo.

I am trying to move the mesh points only along the z-axis.

OK, so let’s say you look at this one mesh at a time. For each mesh, (1) you first have to find which of the other meshes are close enough to potentially snap to.
Then you have to (2) identify the overlapping vertices (or faces) for each mesh and its closest mesh neighbours.
Now, you have two choices, depending on what you want: (3a) either each overlapping vertex from the current mesh produces a vector to the closest overlapping vertex of the closest mesh, (3b) or the vector can simply point to the closest point on the other mesh (not a vertex).
The vectors can then be used to (4) move each overlapping vertex of your current mesh by half its length in the vector direction. The same can be done for the concerned, overlapping vertices of the other mesh, but in the reverse direction.
Finally, (5) you can rebuild your mesh, and if you haven’t messed up your initial vertex order during the vertex moving step, you should be able to use the initial faces.

On thing to think about is how to threat the boundary zone that gets stretched by moving the vertices. Maybe you want to introduce some more rules here, to get a smoother transition or keep a cleaner mesh topography here.

Could be, but you would probably have less control. And compiling the specific goals for the solver could be quite complicated, i guess.

Maybe somebody else could have a look at this, @DanielPiker, @AndersDeleuran, @HS_Kim, @Michael_Pryor, @corellaman, and everybody else. I’m not a Kangaroo expert myself!

1 Like

found a minute to ‘flex a muscle’ @ForestOwl

another try here, where instead of snapping I use Daniel’s ‘pull to surface’ example - I figure using all meshes would require more maneuvers or would make it slower so I used two meshes only

mesh_kiss_rev.gh (62.4 KB)

could definitely be improved…

Hope all is good

1 Like

Wow, you managed to create something similar to my above Python script with Kangaroo! Very cool, however I think that the primary goal was to mutually attract two or more close meshes. I guess introducing surfaces would make it much more complex and heavy.
Nonetheless, thanks for sharing! What do you think, @ForestOwl?

1 Like

Sorry for asking my simple questions.

I was using Kangeroo and found something similar but wanted a different result. With your example I can do something with vertextneighbors to make it more smooth but I am not able to stretch it like an actual sheet by which:
the part of the mesh to the mesh above is completely attached to the mesh above;
while smoothing the mesh preventing rough angles in the sheet;
and allowing some point to lift with when the angles become to rough;
with limiting the movement to half in order the let the mesh above attach in a similar way halfway to the mesh below.

If this was a fictional world based on the SpongeBob city Bikini Bottom, a city which every adult probably associate with topless models, I do not aim for being a Patrick Star character.
Although I associate this character’s last name with something very cool, no, I try to work very hard.