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

A little guidance please (New rope script page 3)

Post by Koba »

Hi

A few months ago, Blender started me programming with Python. Since then I've gotten interested in coding and have done my best to to teach myself C/C++ and even a bit of assembly (but I didn't get very far :? ).

As a first project, I wrote a simple raytracer in C but now I would like to help out with the Blender code to the best of my abilities.

I've dowloaded the source currently on the CVS and have use doxygen to document it. I've also read the floating panel coding tutorial: It just about made sense but there is a lot of code which in my current ignorance seems arbitary. There also appears to be a lot of external functions I'm going to have to understand and call correctly.

Could anyone give me some guidance as to what to do next. What c/cpp files are the simplest to understand? Which c/cpp files did people first modify successfully? I'm happy starting with something simple (such as a tooltip :wink: ).

I am completely self-taught so my knowledge is unlikely to be complete. I do, however, have an internet connection (to access online resources), time to work on this (a couple of months) and a willingness to learn.

Koba
Last edited by Koba on Thu Aug 26, 2004 7:47 pm, edited 3 times in total.

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

Post by Koba »

No one got any suggestions?

Ah well. I think I have a plan now.

I have seen a good tutorial for coding a string/rope simulator. I could prototype a simple simulator in Blender Python for visual output (moving spheres around or something) to allow debugging. When I am happy with it I can port the code to C/C++ with the python script as a reference for correct output. A Python script may also help as I've heard that the Python API mirrors Blender's internal structure. Finally, the Python implementation would also mean I only touch the Blender source once I have a good idea of what I am doing.

Once that is all done, I can use the floating panel tutorial to try to make a bit of an interface and learn (somehow) how to create/move vertices internally. This probably will take a while and I may well have to start REAL simple (tooltips again).

I'm not aware of Blender having a sting/rope simulator yet unless I have missed something (in my ignorance). I know softbodies from instinctive blender has finally been ported but I doubt such code would be very reliable/efficient for ropes. As a rope model would have a 3D surface, a cloth simulator would treat it as a cylinder fabric (ie a 2D array of strings) resulting in inefficiency (or so I would imagine).

This project can be broken into small steps, I've got a tutorial to work on and it is sufficiently interesting to keep me going. What do you think? Would a rope simulator be useful to anyone? I am confident I can manage it (I got the raytracer working didn't I :) ).

I'm now waiting for the go-ahead from the community (or lack of).

Koba

kencanvey
Posts: 0
Joined: Mon Jun 02, 2003 7:54 am
Location: Smethwick West Midlands UK

Post by kencanvey »

Hi Koba

I would like Blender to have a String/rope simulator,what features of rope simulation would you implement.
I was wondering if you might get more responce from the Elysiun forum : http://www.elysiun.com/forum/index.php

Go for it I say and good luck! :D

Ken

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

Post by Koba »

Hi

FIrst I will try to implement this tutorial in Python. Initially I would be working on the points on a polyline with each vertex acting as a point mass. Uneven distribution of vertices may lead to some interesting behaviour.

IF all that goes to plan, then I have to consider fixing vertices (so you can have hanging chains etc). I'm not sure if the simulation could be impoved by having "virtual" mass nodes between the "real" vertices.

I don't know how I can use a spline to control the deformation of a model (what is the 1D equivalent to a control lattice - a control line?). Maybe dupliverts could be used somehow. Admittedly, I haven't really checked what is available yet. Anyway, the simulation could be initially used for modelling in stills (eg. dungeon stills with loops of chains hanging from the ceiling).

Of course it is technically possible to extend the simulation to cloth. If all goes incredibly smoothly that may be a possibility eventually.

Enough! This is all hypothetical and this is only my first project! IF things go well I can start thinking about these things. Right now, I'll be happy if I have the most basic code which actually works.

Koba

Pablosbrain
Posts: 254
Joined: Wed Jan 28, 2004 7:39 pm

Post by Pablosbrain »

I'd be interested in the simulator!

mr_rob
Posts: 0
Joined: Fri Jul 04, 2003 5:11 pm
Location: US of A
Contact:

Post by mr_rob »

Good Luck!

Do you have webspace? If you do, maybe you can upload your source code of your projects to it and we can help. Would this be a projects.blender.org appropriate project? If so, you could use CVS.
Later,
Josh
:twisted: :twisted:

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

Post by Koba »

Hi

I do have webspace - for the next 5 days. I'm switching to broadband so for some reason my ISP no longer provides webspace. Don't see the logic myself.

I may sign up for free webspace but I may well use a "pay as you go" dial up connection so I can keep my old webspace.

I'll see how this pans out,

Koba

kencanvey
Posts: 0
Joined: Mon Jun 02, 2003 7:54 am
Location: Smethwick West Midlands UK

Post by kencanvey »

Hi Koba,

You might want to have a look at this, I use them and have had no problems.

http://members3.freewebs.com/index.jsp

Freewebs.

Ken

IanCalvert
Posts: 0
Joined: Sun Feb 29, 2004 8:12 pm

Post by IanCalvert »

Koba, do you want some hosting? What kind of file sizes would you want to upload?

I might be able to supply you with some decent webspace. Only no SQL.

I coded that string in C++, only in 2d, and no collisions, but if you want a shufty, say the word. I had to tweak some of the variables to get something even remotely looking relaistic.

I am moving on to look at a raytracer now, trying to work without tutorials and doing all the math myself (i really am bored in work). This will probably fail within 3 days, hehehe.

Instinctive blender already has soft bodies, btw, but it would be a good project to code.

Ian

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

Post by eeshlo »

First, congratulations with your raytracer! As far as coding for Blender is concerned, I am completely selftaught as well, and hardly know much about math either. So i'd say if I can do it (?), you most certainly can. It all comes mostly from experience. The way I approach things is with a sort of 'stubborness', I never ask questions, unless I really really have to, like the last few days before the cvs freeze. Doing it the hard way like that, takes a lot more time of course, but also makes me learn more about how it all works.
So in that case of a tooltip, I simply would take a look at that tooltip (the string), and search for it through the source code (using grep or something similar), probably one of the buttons_***.c files in blender/source/blender/src. Then simply modify and compile.
But I suppose such an approach doesn't work for everybody, most certainly not the impatient.

Anyway, for your rope simulator, I remember Ripsting created a script once called 'tangix' that did something similar.
Another approach that is very simple to implement is the 'Jakobsen' method, which is used in games a lot (hitman series). I used this method for the Dynamica cloth and rigidbody test videos you might have seen.
You can find more info on this approach here:
http://www.ioi.dk/Homepages/tj/publications/gdc2001.htm

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

Post by Koba »

Hi

There has been a positive response so I'm gonna have a good go at it.

I just hope I don't disappoint. I'm sure you understand that its going to start simple and get more interesting as I add more features. Collision is something best left till last I think seeing as I have no idea to do it. Well to be truthful, just saying that has just got me thinking...

Here is an algorithm that I've just thought up for collisions that MAY even be possible to implement in Python:

-Find the location of the node (point on the string)
-Scan the interacting mesh for location of ALL the vertices (oh help me)
- Use pythagoras to determine the 3 nearest vertices (A, B and C) to a node at any particular time.
-Vector subtract vertex A from C then B from C then use the cross product to get the normal.
-Pythagoras again to get a unit normal vector.
-Use this normal to find the plane equation of the nearest face.
-Test to see if the node is on the plane. This may be a problem as the point is likely to be either above the plane or below the plane and never actually ON it.
-Use this information to affect the node movement probably by reversing the velocity component of the node parallel to the normal multiplied by some constant (elasticity of the collision).

Now I'm really jumping ahead . I've just had an idea for testing when the point hits the plane!

-A line-plane intersection would be better.
-The line can be formed with its direction vector being the particles velocity and a point on it being the location of that node at that point in time.
-A point on the plane where the line intersects it is found.
-Its distance from the actual node is found (pythagoras) and when it is within a certain bound it registers as a hit.

Now you can tell me all the things that are inefficient and unneccessary with this idea. It is all quite doable but here is what could do with improving:

- Do you have to got through ALL the meshes vertices and do Pythagoras on them for EVERY one of the strings nodes to find the nearest faces?

- The line-plane intersection idea is an Euler integration like method: If there is a lot of acceleration, it may lead to imperfect results.

All this is mathematically sound (I think). The question is whether it work fast enough to be useful.

At the start of this post I never thought I would ever understand how collision detection worked never mind coming up with my own scheme in 5 minutes! I must admit I'm rather pleased! :?

Anyway. Enough. I don't even have a simple string working yet! But I'm working on it!

Koba

P.S> Thanks eeshlo for the advice. I think that for now I'll stick with the tutorial I've got. I'll have a look into it later but if it is designed to be fast, the method you are suggesting may be more suited to the game engine than what I have in mind.

matt_e
Posts: 410
Joined: Mon Oct 14, 2002 4:32 am
Location: Sydney, Australia
Contact:

Post by matt_e »

Just an idea out of the blue (which doesn't really mesh with your aim of doing it yourself to learn), but Solid is already in Blender and I know that's used for collision detection - does anyone know if it could be used for this? Seems a shame to just waste it, particularly when it's quite mature code.

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

Post by Koba »

Hi

I've been working on it today and have some results (looking like a piece of elastic being stretched before being let go :D)

The script has a long way to go but at least I have done something.

- I can include an arbitary number of vertices (currently spheres) in the simulation.
-I have figured out how to fix vertices at multiple points.

Still to do (maybe I'll get some of this done by tonight):

-Gravity/Mass
-Wind?
-A little animation to show you all :D

I need to know how to deal with velocities in Python so I can implement mass. I've only seen displacements (eg LocX). Is there a VelocityX or equivalent in the API?

Koba

EDIT: It is 4:22 now and I've already added gravity. Its really easy: A constant of 9.8 in the Z Force factor.
Last edited by Koba on Tue Aug 03, 2004 5:00 pm, edited 1 time in total.

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

Post by eeshlo »

Koba wrote: P.S> Thanks eeshlo for the advice. I think that for now I'll stick with the tutorial I've got. I'll have a look into it later but if it is designed to be fast, the method you are suggesting may be more suited to the game engine than what I have in mind.
Well, with the spring model it is more difficult to make very stiff springs, which you would require to model a rope, unless you want it to look like a rubber band. The method from the link above can do this very easily, and you can still make it elastic if you want to.

Also as far collision is concerned, you really don't want to brute force calculate collisions for a large set of faces. For this you really need some optimization in the form of some spatial subdivision method. But I guess that is not really an option in this case.
Using some library like solid would help. This was a real problem for Dynamica as well, in the end I created a python module using Opcode, but never released.

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

Post by Koba »

Hi

You are right: so far everything am doing looks like elastic. I'll have a look at that paper and I'll see what I can do.

Koba

Post Reply