Multibody Building From weighted Graph

Hey, i am trying to build a multibody from a weighted graph, the weights define the shape of a bodypart and the edges and vertices symbolize bones and joints.
Input: A List of vertices with, a vertice is defined by it two coordinates, a list of edges, an edge is defined by the two indices to the corresponding vertices. The weight is simply the distance of two vertices.

Since i want this to be done automatically, i can not do it bodypart by bodypart manually.
However i have not been able to automize it. I try to loop over the edges and always add new edges to an existing body, however this is not working since i would need to store the bodys somewhere in a loop to access them later and rust doesnt allow this.
Now i wanted to ask if there is a specific technique for building these multibodies? (Note the graph is simple and connected).
Thanks in advance

Hi!

I try to loop over the edges and always add new edges to an existing body, however this is not working since i would need to store the bodys somewhere in a loop to access them later and rust doesnt allow this.

I’m not completely sure I understand this. Could you perhaps write us the code of some things you attempted so we can get a better understanding of your context?

Perhaps one thing you could try is to create a multibody for the first node of your graph. First you construct a MultibodyDesc structure and then call its .build() method. This will give you an instance of the Multibody structure.

Then, for each new multibody link as you iterate on your graph, you can create a MultibodyDesc as usual and build it with the build_with_parent method.

Hey,
Thanks for your advise, i was able to solve it by now. The problem was not due to nphysics but my lack of understanding in some regards of the rust language. It was mainly that i found no fast work around for the borrow of variables in my loop creating the body. I had hoped there was already an existing function in the library.
For those interested: my solution was a recursive function always calling for each child of the current part itself and giving the current body as a parameter.