Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to find the graph of all parts that are welded to a given part?

Asked by
doomiiii 112
5 years ago

What I need:

Find the set of all parts that have been welded together, starting from any part P in that weld configuration.

Bruteforce solution:

  1. Iterate over the entire workspace hierarchy and find the set W of all WeldConstraint, Weld and ManualWeld objects that reference P
  2. Do a DFS (probably easier to implement efficiently than BFS or other graph exploration methods) from all w in W (this is a graph where welds are edges and parts are nodes) to define the complete connected subgraph of parts
  3. Return that set of nodes

The problem:

The above method is highly inefficient, and it would require me to do a workspace-wide bookkeeping effort to handle efficiently. However, since the physics engine already needs an efficient representation of that connectivity graph, I would assume that the physics engine should expose an API to tap into that. However, I haven't found that API? Is anyone aware of such API?

Motivation:

There is several use cases that I will need this for in the near future, most urgently:

Scripts that are supposed to work on "dynamic" (i.e. unanchored) parts Q must, generally speaking, make sure that any Q is not welded (directly or indirectly) to an anchored part, or else, it might generate some very strange physical behavior because it tries to treat a part that is welded to an anchored part as freely moving about.

0
@SinisterMemories Keeping (1) weld configuration and (2) tags in sync would be a tax paid by the designer. I'd rather solve this more holistically using a method that can assure that I would not accidentally overlook any parts in the weld configuration. doomiiii 112 — 5y

Answer this question