Hi IForce
I need help moving related bodies, as I have copy and pasted model on top of model, but now need to move each model independently, is there any script which could achieve this?
See attachment for further clarity
Help Move related bodies
Help Move related bodies
- Attachments
-
- bodies.jpg (30.1 KiB) Viewed 14895 times
Re: Help Move related bodies
What do you mean by related bodies? You mean bodies that are connected with joints? Bodies with the same name? Bodies that have some custom property in common?
I made a script that selects all bodies connected in a structure, maybe that would help: viewtopic.php?f=9&t=113
Alternatively, here is a script that will take each 'island' of connected bodies and automatically space them out in horizontally. Change the parameters for the translate call at the end to alter the spacing:
Example usage:
After the bodies are made easy to select like this, you should give each island some name or property to identify it with, otherwise your workflow will be chaos 
For example, you could add an integer property to bodies to hold the animation frame they belong to (as I guess that is what you are doing here). Then you could use a script like this to select all bodies in a specific frame at a later time:
I made a script that selects all bodies connected in a structure, maybe that would help: viewtopic.php?f=9&t=113
Alternatively, here is a script that will take each 'island' of connected bodies and automatically space them out in horizontally. Change the parameters for the translate call at the end to alter the spacing:
Code: Select all
body[] bs = sb();
body[] cb; // current bodies
body[] fb; // finished bodies
int n = 0; // for offset
while ( bs.length > 0 ) {
body b = bs[0];
bs.removeAt(0);
if ( fb.find(b) != -1 )
continue;
cb.insertLast(b);
body[] island;
while ( cb.length > 0 ) {
body b = cb[0];
cb.removeAt(0);
if ( fb.find(b) != -1 )
continue;
fb.insertLast(b);
island.insertLast(b);
joint[] js = b.getJoints();
for (uint i = 0; i < js.length; i++) {
b = js[i].getBodyA();
if ( cb.find(b) == -1 && fb.find(b) == -1 )
cb.insertLast(b);
b = js[i].getBodyB();
if ( cb.find(b) == -1 && fb.find(b) == -1 )
cb.insertLast(b);
}
}
translate( island, n * mv(2,0) );
n++;
}

For example, you could add an integer property to bodies to hold the animation frame they belong to (as I guess that is what you are doing here). Then you could use a script like this to select all bodies in a specific frame at a later time:
Code: Select all
int whichFrame = -1;
bool matchingFrameNumber(body b) {
return b.getCustomInt( "frame" ) == whichFrame;
}
void main() {
whichFrame = queryNumericValue("Which frame?");
select( filterBodies( ab(), matchingFrameNumber ) );
}
Re: Help Move related bodies
Yeah related by joints
I am trying the function but the translate function is throwing an error
Line 36, col 25: No matching signatures to 'mv(const uint, const uint)'
Line 36, col 2: No matching signatures to 'translate(body[]&, int)'
Thanks!
I am trying the function but the translate function is throwing an error
Line 36, col 25: No matching signatures to 'mv(const uint, const uint)'
Line 36, col 2: No matching signatures to 'translate(body[]&, int)'
Thanks!
Re: Help Move related bodies
You need version 1.3