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.
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.
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?
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.
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?
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.
I honestly could not found a solution to the problem, that is why I was asking.