## A little guidance please (New rope script page 3)

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

Koba
Posts: 0
Joined: Thu Apr 15, 2004 9:48 am
Ok...

I think I may venture to say that I understand vaguely what is happening. I am probably biting off more than I can chew: I'm not at University yet, I'm one of the 6 people in my school who even know what a vector product is (having been one of the few who studied Further Maths).

Taylor expansions? I've never used them but I vaguely know what it is. Luckily I can avoid them for now. Even Euler is at the brink of what I have been taught.

But I may well have a go at this system. I will need some help. Now you have shown me a superior system, I would prefer to use it instead. Here is what I understand.

-The motion is handled by Verlet integrator. It calculates the future position of a point using the current position and the position before that.

-The constraints I would need would be a distance constraint (as mentioned). The constraint is simplya mathematical expression to satisfy (effectively these are loci). If the constraints are satisfied the Verlet integration does the rest (thats the magic of it). Constraints are satisfied by (what looks to me cheating): changing the values so they are what you want (if they are not what you want of course)

-The constraints are solved by interation by some mathematical magic. An atempt must be made to satisfy all the constraints.

-The square root approximation is not essential so I can leave it out for now.

So as far as a rope simulator is concerned:

-Each vertex has a "stick" constraint to the next based on the original length. The Verlet integrator does the rest. I will have to investigate how you solve all those constraints together a little more closely.

To be honest, this system strikes me as being a very fast and clever IK system that is adapted to strings, cloth and rag-doll physics. Coding this may be worthwile as it could be used for loads of things.

If this ever gets as far as collisions, I suppose I could use my brute force method (which I may be able to do) or use Solid. If I use Solid I'll need some serious help (but thats a while yet).

Anyway...thanks eeshlo! (Maybe you could even help me out a little )

Koba

lightning
Posts: 0
Joined: Sat May 17, 2003 9:06 pm
Well, I only understand a fraction of what you do, but it sounds like you're on the right track

If you havent seen it, someone is working on a colision detection system for python over at elysiun:

http://www.elysiun.com/forum/viewtopic.php?t=28155

I'm not sure but I think this might be useful to you.

later
The dawn of a new error...

eeshlo
Posts: 73
Joined: Wed Nov 06, 2002 10:02 pm
Well, I can see you are really trying to get something to work here, so if you can give me a mail address, I'll send you the scripts I used to create the cloth and rigidbody videos. Not even theeth has seen them before, I never released them.
Some time ago I rendered the cloth with yafray for testing, I updated them to work with the recent python api, so it will work with the current blender version.
I'm not sure how useful it can be to you (it is a bit hackish), but maybe you can learn something from it, or even point out mistakes I made, who knows...

theeth
Posts: 500
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:
eeshlo wrote:Not even theeth has seen them before, I never released them.
Woah, secret stuff!

Martin
Life is what happens to you when you're busy making other plans.
- John Lennon

mr_rob
Posts: 0
Joined: Fri Jul 04, 2003 5:11 pm
Location: US of A
Contact:
Here's some pseudo-code I just wrote, though when I implemented it in python it didn't work, probably because I'm crossing over from C/C++ to Python and I'm still learning. Maybe you can expand on it.

Code: Select all

``````# controller is an empty that you move to modify the rope
# bones is the list of bones from the armature

# the theory:
# loop through the bones list:
#      set the current bone's head to the last bone's tail position
#      update the current modifier by the previously decided amount
#      increment the current bone's tail's position by the modifier

# controller's xpos minus the last tail on the armature's xpos
distance = controller.x - bones[bonecount-1].tail.x
modifier = 0
increment = distance / (bonecount*2)
i = 0

while i < bonecount:
if (i > 0):
modifier = modifier + increment
bones[i].tail.x = bones[i].tail.x + modifier
i = i + 1

Redraw the window

``````
Ok, I hope that makes sense. If it doesn't, tell me and I'll try and clarify. Basically it makes an exponential progression across the x axis.
Later,
Josh

Koba
Posts: 0
Joined: Thu Apr 15, 2004 9:48 am
Hi

Good news, I seem to be having some sucess with eeshlo's proposed system using Verlet integration. By that I mean I have something that (with a little imagination) is exibiting string-like behaviour. It is currently more of a pendulum than a string as there is only one constraint (and one fixed node).

Gravity doesn't seem to be acting down the Z axis: probably a bug somewhere in the code.

The parameters seem to be having the desired effects so I think I've got the right principle. So now I have two possible string models to finish implementing. I think I'll keep working on the current system for now (in time I may even implement both systems).

My biggest stumbling block at the moment is the Python API. I've been just been pressing Alt+P repeatedly to see the results (using Blender itself as a memory by setting LocX, Y and Z before reading the data back again in the next cycle). This won't do anymore as I need to have data stored from frame 1 (original length data).

This means I need to use keyframes but I'm having problems with IPOs. Maybe someone here can help me. I've posted the problem on {url=http://www.elysiun.com/forum/viewtopic. ... highlight=]elysiun[/url].

Thanks

Koba

EDIT: Actually gravity is not working. Maybe it is only the contraint code operating. Don't see why it always orients itself in the same direction though.

eeshlo
Posts: 73
Joined: Wed Nov 06, 2002 10:02 pm
Did you actually receive the two blendfiles and the extra script I sent you? Or couldn't you get any of them working?

mr_rob
Posts: 0
Joined: Fri Jul 04, 2003 5:11 pm
Location: US of A
Contact:
Ok, using a similar script to the one I posted earlier, I have a "rope hanging from ceiling" / pendulum effect going on. It uses a simple line of vertices and an empty to act as the "controller". After I work on it some more, I'll post a video and the script.

I'm happy it finally worked!
Later,
Josh

Koba
Posts: 0
Joined: Thu Apr 15, 2004 9:48 am
Hi

Just to get something here before mr_rob steals the show.

This is the result from eeshlo's script that he sent me. Shameful, I know but I was working on pretty much the same thing this morning (and got most of the way there by the way). Hopefully, tomorrow, my own work will be up to the same standard (and hopefully without using scriptlinks)

I like the results. And its very fast. You press Alt + P and its already done.

So here it is. A proof-of-principle from eeshlo: here

I can now see how wonderfully useful the new Python Registers are.

Koba

mr_rob
Posts: 0
Joined: Fri Jul 04, 2003 5:11 pm
Location: US of A
Contact:
LOL! The test render I made looks almost exactly like that, except my string swings back and forth. The colors of the rope and background are identical.

Don't worry, I in no way tend to steal the show, but I do intend to help it.
Later,
Josh

Koba
Posts: 0
Joined: Thu Apr 15, 2004 9:48 am
Hi

mr_rob: The default edge setting in materials is black. So black on white is the obvious choice .

What I'm asking myself is what would make a string simulation more useful to the user. Using IPOs/RVKs would allow the user to tweak the results of the simulation. It is important to me that the output of the simulation can be integrated with the rest of Blender. I would prefer it if the simulation uses "real" vertices at all times which can be modified by the user rather than using vertices controlled only by the simulation. This is one of the things I don't like about the current particle system: there is no way to delete/move the stray particle (as far as I know).

On the other hand, the verlet simulation adapts itself well to different situations as described in that article. Maybe it is better to give the user (some) control on individual vertices via the simulation itself eg. letting the simulation know that the top of the rope is parented to moving object x. Thing is, you can only have so much control before things start to break down eg. the top vertex is parented to moving object x and the bottom vertex is parented to moving object y violating the strings length constraint at time z (the objects are further apart than the length of the rope).

Of course an elaborate system would work on priority. Eg. the top vertex MUST move with object x and the bottom vertex must stay as close as it can to object y. Blender already has a constraints system and I'm not willing to implement another (alone anyway)

Maybe the cleverest way is to give the user (almost) complete control and pop up an error if the length constraints are being violated "Your string is too short for these conditions". This could work (at best) on an alternate vertex basis: not violating any of the length constraints would be very difficult if you move neighbouring vertices apart/towards each other (ie you are constrained to a surface). The uneditable vertex in the middle would give a whole volume of freedom. The user could of course adjust the rope itself before the simulation to adapt as necessary eg. add a new vertex between two other points that must be fixed where they are.

This is getting ever more complicated...

I'm wondering how this error message would be generated. Maybe there would be an iteration limit on the SatisfyConstraints loop. Maybe a bit of code can check if the position values have converged within certain bounds before x iterations for example. Or you could let the simulation run and give funny results.

Question is whether the contraints will converge to the best configuration regardless of whether the user contraints are satisfied. In which case, letting the simulation run and letting the user see for themselves what is wrong may be best.

So actually...that's isn't too bad a coding nightmare.

Users will quickly get bored of dropping strings they can't modify to adapt their needs. What do you think?

Does that make sense?

Koba

mr_rob
Posts: 0
Joined: Fri Jul 04, 2003 5:11 pm
Location: US of A
Contact:
This stuff is way too hard for a beginner python programmer like me to implement. Now, in C I'd have this done with my eyes shut.

Maybe I should make a python module in C and run it? Is that a good idea?
Later,
Josh

Koba
Posts: 0
Joined: Thu Apr 15, 2004 9:48 am
Hey!

I'm a beginner programmer in C AND Python (four months since my first work in Python and about a month since I started in C)!

Well, I wouldn't be doing this is it weren't for a nice steep learning curve. Anyway, the Python scripting is only for prototyping (in my mind anyway). I'll be working in C once I have a good idea what I'm implementing.

Do you not have any comments/suggestions about the problems in my above post? I really need to know what people think would be the best system for adapting the simulation.

If no one says anything soon, I'll start implementing my alternative vertex idea whether you like it or not!

The idea is this:

By default, the simulation would only fix the vertex at the top of the rope. There would be a "Set constraints" button which when you click it lets you...set the contraints. This is done by selecting the vertices that need controllling - an empty representing the simulation vertex will appear when a vertex in the string is selected. The emptys will appear at alternate vertices at most. An empty that is left alone represents a fixed point on the string. If the empty is animated, this represents a set simulation vertex moving in that pattern.

Does this make sense to anyone other than me??

Once I know what system to use, coding can begin in earnest.

Koba

Koba
Posts: 0
Joined: Thu Apr 15, 2004 9:48 am
Hi

No internet for a week (at least) due to various issues.

Got a script working well with user-defined strings and I will continue improving it.

When I finally get that bloody broadband connection, I'll put it on my webspace so you can all have a look.

Koba

Koba
Posts: 0
Joined: Thu Apr 15, 2004 9:48 am
Hi

I suppose people have lost interest.

Anyway, I've got a working script which allows user-defined ropes with a constraint system. Moving constraints work fine. I'll release the script some time soon (if anyone would like to see it).

Koba