A little guidance please (New rope script page 3)

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

SamAdam
Posts: 0
Joined: Thu Mar 04, 2004 1:28 pm
Contact:

Post by SamAdam »

hey koba, i'd like to see the script, just put it in your post.

btw, I got toxicx finished!

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

Post by Koba »

Hi

SamAdam: I saw your posts on the Toxic forum and the "new features" thread on elysiun. Well done!

I am waiting for something from dictoon before I consider anything more with ToxicX. Maybe you would like to help me with this here? I would mainly like help implement a GUI for the simulator (as I have figured out the major code). I'm sure learning to code a Blender panel would be useful for you if you ever want to add your own features to Blender. Anyway....its only a suggestion. :D

I could release the current script but its really buggy. I seem to have broken some functionality in my latest work(The SatisfyConstraints() function doesn't seem to be working again leading to stretchy strings). Here is an older script (simpler to use but no constraints system): String simulator

Releasing a script of some sort may keep interest going.

So for the 2nd rewrite (the first was a rewrite of a short script eeshlo kindly sent me). I have finally figured out how everything is going to work: a nice, flexible yet simple plan is in my head. And I have found the perfect Blender object for the simulator to operate on: the 1D lattice!

1D lattices are the obvious choice for modelling/animating ropes/strings. The polylines I was working on were useless for modelling/animating real meshes with. 1D lattices also get rid of major headaches (figuring out the order of the vertices to structure the simulation and preventing the user from deleting vertices halfway through the simulation).

I was very happy when I found everything I need to work with lattices is already in the API!

Ok. So here is the plan for the GUI:

The essentials:

"No of nodes": (slider) Specifies number of points on the lattice.

"Create Rope": (Button) Creates a 1D rope lattice with number of nodes specified by "No of nodes" slider.

The user can now edit the lattice so it fits inside whatever rope they have modelled.

"Calculate": (button) This starts the simulation. If the lattice hasn't been parented to a model to deform, a dialogue shall appear with yes and no options: "Lattice is not parented. Continue?"

The constraints system:

"Add constraint": (button) Once a rope lattice has been made, the add constraint button will appear. Clicking it will add an empty to a vertex of the lattice. The added empties are spread along the lattice.

"Select constraint": (drop down menu). Allows you to select the constraint for the "length down rope" option.

"Length down rope": (slider) Moves the selected constraint up or down the vertices of the rope.

Other options

These are self-explanatory:

Gravitational field strength
Simulation start frame
Simulation end frame
Accuracy (iterations)

I have thought carefully about all this. It will work and be useful (I hope).

Features of the constraints system:

-The constraints allow the rope to be moved from a point while simulating (eg. rope ladders dangling from a helicopter rescue) using keyframes

-Loops of rope can be made by parenting the constraints to each other and making them overlap (eg. the hangman's noose)

-Ropes can be parented to other ropes! I don't see why this can't happen: by parenting a constraint empty to a vertex of a mesh (deformed by another rope), ropes can be joined together (eg. could be used to make a net).

The last of these is verging on a cloth simulation (something this project can be extended to once the basics are complete). I have an .avi of a cloth sim using verlet integration but as its eeshlo's .blend, I better check with him before I release it.

Anyway, I doubt anyone read all that but give me feedback anyway! :wink:

Koba.

eeshlo
Posts: 73
Joined: Wed Nov 06, 2002 10:02 pm

Post by eeshlo »

Hi Koba, first, sorry for that last PM on elyisun btw, I realize that it might have sounded a bit too depressing. I have this weird habit to go a bit overboard with my pessimism (just ask theeth, I did the same when were working on Dynamica, theeth actually needed therapy after that... :P )

Anyway, your idea of using lattices seems a good one, and would currently be easier to implement than my armatures suggestion. However, unless it was possible to use the lattice directly as a rope, the result might not be quite what you were hoping for. I might be wrong, but the deformation result on other meshes might be a sort of 'soft' or 'weak' approxmiation of the actual lattice shape. Unless that is controlable in some way, I'm not too familiar with lattices. But then again, armatures probably would have similar problems.
Of course, it might look good anyway (or even better), so don't let that stop you. But maybe it could be an option to use the particle/contraint as a mesh directly as before.
With subsurf (for which you will have to add some code to update the mesh properly) it could look good as well, but again would be a sort of approximation of the actual rope shape, but might not really be a problem, haven't really tried it (in animation anyway).

You can show the cloth avi if you want, but as it was one of the dynamica demo video's, it probably has been seen by many two years ago, it is still available here:
http://www.centralsource.com/blender/dynamica/

Also, It is no problem to release the blendfiles I sent you, you can do that if you want. It might be useful to others as well, and I don't have any plans (or time to get involved with anything else) to do anything with it in the near feature anyway.

ilac
Posts: 131
Joined: Mon Oct 14, 2002 8:24 am

Post by ilac »

Koba wrote: Anyway, I doubt anyone read all that but give me feedback anyway! :wink:

Koba.
Read it all.

Feedback: You're beginning to sound like Eeshlo! :P :wink: be more optimistic!

Definetly an interesting project! looking forward to some animated demos!

:D

eeshlo
Posts: 73
Joined: Wed Nov 06, 2002 10:02 pm

Post by eeshlo »

ilac wrote: Feedback: You're beginning to sound like Eeshlo! :P :wink: be more optimistic!
Oh no!

Anyway, sorry for my recurrent pessimistic tone... miserable me...

Alfredo :oops:

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

Post by Koba »

Hi

I've just made this an order of magnitude more complicated (again) but now I really feel that this is going to be useful.

1 x 1 x N lattices seem to be a poor use of a very useful Blender object. Rope lattices shouldn't really be lines as lattices should really be containing the objects they are deforming.

Thats why I am now working on using a 2 x 2 x N lattice now. Far more rope-like for a start and much more likely to give nice deformations. The simulation is still based on a line but the points now represent the midpoint of the cross-sectional faces.

I have it all planned but I need to know the best way of solving the point of intersection between two lines (the cross-sectional diagonals) in Python. This is quite a common task so there is probably an easy way to do it.

Can anyone help me here? I only need to be able to solve simultaneous equations in 2 variables.

EDIT 1: I just noticed the new Matrix Object in the API. I'll solve the equations with matrices unless someone informs me of a better way.

EDIT 2: All the operations needed are there except a simple 2x2 matrix object. Only rotation, translation, shear matrices etc seem to be available and they are of no use to me.

LAST EDIT: Ok I've done it the easy way. It wasn't hard (maybe I was being lazy :? )

The only problem with these larger lattices is that it may take longer to edit to contain a rope that isn't modelled straight. I could probably implement a "Create rope based on path" (or curve) button later which would make this much easier.

Also having a volume, the deformed object doesn't need to be line-like anymore. This system could be used to animate any ridgid object that is hanging from a pivot. It could also be used to create simple IK chains (such as linkages) influenced by gravity.

The script I am currently working on will only implement the translation of cross-sectional faces, in future rotation could also be incorporated leading to nice natural deformations (this will be done by using the vector between nodes to rotate the planes till they are normal to them)

Anyway, here is eeshlos .blend rendered with all the nifty new Blender features just to show the verlet scheme used with cloth. The simulation was calculated in (almost) real time!

Cloth.avi

Thanks,

Koba

P.S> Can anyone also tell me how to go about porting Blender methods and functions from the Python API to C/C++?

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

Post by Koba »

Hello

Debugging has been driving me mad. This project keeps getting harder and harder.

Anyway...there is still a bug and two features still need to be implemented: face rotation and constraints. So here it is....it demonstrates my ideas about using lattices.

The instructions are included in the script. The lattice faces don't rotate so watch what you set the gravity vector to.

latticescript

Can you spot the bug? The rope stretches as if one of the constraints isn't working. Can anyone help me find the problem?

I would really, really like some feedback!! (please :cry: )

Koba

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

Post by Koba »

Hoorah!

I managed to fix the bug so now it is behaving itself. I've updated the link above so you can download the revised version.

I've also increased the default lattice length to give a more rope-like simulation.

Can someone tell me how to deal with rotations around a given point? I need to rotate the lattice faces around the simulation node based on a "normal" between adjacent nodes. Anyone got an idea how to do this?

I still want feedback!

Koba

Oso
Posts: 17
Joined: Sat Oct 19, 2002 2:03 pm
Location: Massachusetts, USA
Contact:

Post by Oso »

Koba,

I've only played with it a little, and I'm afraid I can't help you debug the problem, but I can say, WOW! For someone who didn't know anything about this when you started, you've accomplished a lot in less than 3 weeks!

You are to be congratulated. Keep up the good work.

iluvblender
Posts: 24
Joined: Wed Oct 16, 2002 12:45 am
Location: Mumbai, India
Contact:

Post by iluvblender »

very nice script. very useful.

thanks for sharing.

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

Post by Koba »

Hi :(

This has to be one of the most difficult things I have had to program so far. This rotate function has given me a nervous twitch and a desk covered with papers with all kinds of funny vectors on it.

It took ages just to come up with an idea but I eventually got there. It involves calculating the normal vector, setting a random z coordinate and using the dot product to find an x coordinate which results in a perpendicular vector, finding the vector from the point to the current vertices, calculating the angle between the last two vectors, storing this angle then using a 2x2 rotational matrix to rotate the plane before checking the angle really IS 90 (as the angle function does not give negative values) and if not rotating the plane again by -2*theta.

Then you have to do all the above backwards. Then forwards in a different plane. Then backwards again. What a nightmare.

Anyway, I can now do a forwards pass on the lattice in the x-z plane correctly. I hope I can find someway of using a flag to drop different coordinates (and so work in a different plane) and/or finding a way to reversing the loop to do a backwards pass. I don't want to have four copies of effectively the same code.

Hopefully I can achieve this in the next week. I will then have implemented (in Python) everything needed for a usable string simulator so I can look at coding it in C++.

I know I can code the particle class as it independant of blender methods/functions. I'm still worried that I won't be able to access/write the data from/to other Blender code in the same way as I have been doing with the Python API. This would mean effectively a complete rewrite of the code which I am not really willing to do. Surely there is a way of using Python as an intermediate between bits of C code?

The most important methods I need are getting Lattice point coordinates (Lattice.getPoint) and setting Lattice point coordinates (Lattice.setPoint).

I really really would like an answer to this question and no one has been really able to help me so far.

Koba

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

Post by Koba »

Hi

It was an act of faith but I decided to merge some dodgy code with the rest of the script. Luckily (for my sanity) it worked.

Here it is. It is in an almost useful form now but rotation in one plane still isn't implemented. That should be easy to implement though (it only involves working on a different pair of coordinates). I also know the cause of the bug relating to the top and the bottom of the rope so I can get that sorted soon.

Here is the script. It is ready to roll (just use the arrow keys once it is open). Instructions are included if you want to try your own thing.
Rotation + lattice script

To be honest, I am slowly losing interest in this project. Interest in ideas dies down quickly which makes it hard to continue. I'll keep going but progress is starting to really slow down.

Someone would make me real happy if they rendered an animation of my script at work (I'm useless at rendering nice test animations). Maybe that would lift my spirits :wink:

I see some real potential in this system: for example, It could be used to create grass which sways realistically in the wind. All you would need to do is automate the anchoring of the grass strands (strings) to the ground and the top nodes would be connected by a virtual spring of set length to a virtual point. Add a little mesh randomisation and wind force randomisation and the grass would russle in the wind. I could do this if I had a little more incentive. :(

I really need to get into the C++ coding if I'm going to keep going. Unfortunately my internet access is limited for now so I can't learn much from the internet. One positive thing is I've just read a C++ book and now I know a little bit more, it appears to me that the Python API just provides Python access to C++ class interfaces (set and get member functions). I could be wrong.

Sorry for the depressing post. It would be nice if I could have a little help from someone (a little guidance perhaps?)

Koba

Post Reply