Traffic Flow Visualization

Hi everyone.

I’m a student studying traffic and transportation engineering, this is my first attempt to writing bpython script.

What I’m trying to do is using blender as a tool to visualize traffic flow on the road. In the study zone there are 100000+ vehicles and the moving trajectory of each vehicle is generated by a traffic simulation package. My current Python script doing the following things:

for each vehicle:
add a object
add ipo curves of loc, rot and layer to that object
add key frames to loc, rot ipo based on the trajectory data
add key frames to layer ipo. When the vehicle in study zone the object in layer 1,
otherwise in layer2

This script works fine in my project, but I think the solution is quite awkward, like representing entering and leaving study zone with layer ipo. So, I’m wondering is there a better solution to this. For example is it possible to control the trajectory of particles and represent vehicles using particles?

Any comments? Thank you.

I’m not sure you can drive particles. the more clever ones are boids, maybe try with it.

you should look at the OpenSteer deamon :
http://opensteer.sourceforge.net/
http://www.red3d.com/cwr/steer/
aothms did a blender gateway to interface with the opensteer deamon :
http://www.youtube.com/user/aoThms
http://blenderartists.org/forum/showthread.php?t=156034

example of use in blender :
http://jerome.le.chat.free.fr/index.php/blender/galleries/city-engine.html
(second video)

Thanks littleneo!

I like you city generation work. In fact I’m considering using it in my traffic visualization project. Any way it’s quite strange to see vehicles running on a white plane, like this :slight_smile:

I followed the links. It looks like they use a similar technique of object+ipo to represent vehicles. Not exactly what I want. May be I should find solution in the particle system code.

p.s sorry for the delayed reply. My internet connection behaves weird lately. I’m not sure it’s an ISP problem or a GFW problem.

in fact the ipos are only there to replay the animation. opensteer send each coords to blender at every new frame, depending on the car situation (proximity with other car, steering, choose a direction at crossings … ).
potentially a lot more could be done, like with the red3d flash animation.

hey maybe we could talk further ?
aothms and I want to develop something about traffic simulation, based on opensteer for the moment.
game engine has also a lot of features that would make it possible. I think it could be interfaced with opensteer or another AI deamon, or something could be written in BGE python…
also I’m about to release the last dev. of the city engine. (not complete but interesting)

see you :slight_smile:

guys, maybe this is little bit above/beyond what you are shooting for, but I guess it is good to look at other professional software packages in this field and see what they ara capable of doing - there is PathPlanner by Simtra: http://www.simtra.com/
It is used in transportation (airports, etc.)
Indeed is a different kind of animal, but could inspire your work. a

Hi, littleneo

in fact the ipos are only there to replay the animation. opensteer send each coords to blender at every new frame, depending on the car situation (proximity with other car, steering, choose a direction at crossings … ).
potentially a lot more could be done, like with the red3d flash animation.

I am doing a similar thing except that my simulation package precomputed all vehicle coords of every frame. Instead of feed blender frame by frame, my bpython script load all coords in one shot. No matter how the data is load, there must be some mechanism in blender to record there coords. Currently I use ipo curves, but I am trying to move to particle system for 2 reasons. First, it’s not memory effective, because blender must mantain a object for every vehicles, even before its entering and after its exiting of the road network. Second, it’s hard to manipulate all vehicles as a whole. After importing, these is no easy way to add just scale for vehicle trajectorys either spacial or temporal.

hey maybe we could talk further ?
aothms and I want to develop something about traffic simulation, based on opensteer for the moment.
game engine has also a lot of features that would make it possible. I think it could be interfaced with opensteer or another AI deamon, or something could be written in BGE python…
also I’m about to release the last dev. of the city engine. (not complete but interesting)

I’m glad to. Where is your discussion post, I’ll join you two there. I’m currently working on a traffic simulation package, so maybe I can provide something useful.

Hi studioa, thank you for your advice.

guys, maybe this is little bit above/beyond what you are shooting for

do you mean it’s hard if not impossible to implement a professional traffic simulation package as a blender module? If yes, I totally agree with you, because I already write a stand-alone(but not sure it’s professional:)) simulation package. This package has already being capable of animating the simulation result through a UI based on OpenGL. So the problem here is simply how to visualize the simulation result from the stand-alone simulation package in blender and makes it look good.

Xiongyaohua - no I do not mean it is impossible, I meant PathPlanner is developed by a lot of developers and they put a lot of time on it. You might be by yourself and few other people, so it is hard to implement all what PathPlanner guys did. Blender is very flexible and could be capable of a lot of things and for sure there is a workaround on implementing very professional features.
My note was just to mention other similar things that could help you by looking at them. I do similarly with architectural projects: I look at other projects and take notes how others solved some issues and I grab ideas that are good to be implemented in the projects I develop. I see a similar approach here: looking at PathPlanner, you will draw some conclusions on how it works and maybe you could bring them in your application.
I can help advise on parts of what you do, from architectural side, in my limited time. a

nǐ hǎo, 你 好, Xiongiaohua,

aothms in in hollydays, but yes there’s two threads :city engine and opensteer
can you share some animations or code or anything about your project ?

First, it’s not memory effective, because blender must mantain a object for every vehicles, even before its entering and after its exiting of the road network.

you can store ipos without linking it to an object.
like any other blender object (mesh, ipo, mats, image, actions…) it can reside in the file even if it has no link. it’s the F flag in the gui, or when you browse a list of material or action for example.
in your case you could import only ipos in a first time, then link it on demand to a ‘car’ mesh.

also as you can link a script that runs at every new frame, you can code something like :


for ipo in ipos :
 if xmin < xpos < xmax and ymin < ypos< ymax :
   if linkedToCar==False :
     linkedToCar=True
     [...]
 elif linkedToCar :
   linkedToCar=False

there’s a registry blender module to remember the variables you need, at every new frame.

also you can share the same mesh between several car objects (maybe you already know that sorry, it’s just in case).

these things could permit to spare some memory.

you could look at the opensteer plugin code in plugins/opensteer/ in the dev version I’m about to publish.
in this case I just add an empty to each ipo, then AFTER it has computed all the ipos, I attach a group of object for the each car (armature, wheels, camera…) to the empty. it’s really more faster to compute at large scale.
theorically I suppose one could get rid of that empty at ipo creation time and only feed a python ipo list with coordinates.
something like your studying zone, a ‘window’, could be great too.
this wondow could be the active camera view.

Second, it’s hard to manipulate all vehicles as a whole. After importing, these is no easy way to add just scale for vehicle trajectorys either spacial or temporal.

so you can only modify once, at the ipo creation time. you right it must be harder to rekey/rescale all channels of all ipos…

see you soon then :slight_smile:

Hi studioa

I’v watched the flash animation for PathPlaner. It’s really helpfull especially it’s UI design.

I can help advise on parts of what you do, from architectural side, in my limited time. a

Thank you in advance.

bonjour littleneo

can you share some animations or code or anything about your project ?

I will post the animation of my experimental scene and python script for reading vehicle trajectory data soon. But I’m not sure if I can post code of my simulation package on internet, because it’s development is funded by government:p.

you can store ipos without linking it to an object.
like any other blender object (mesh, ipo, mats, image, actions…) it can reside in the file even if it has no link. it’s the F flag in the gui, or when you browse a list of material or action for example.
in your case you could import only ipos in a first time, then link it on demand to a ‘car’ mesh.

That’s a good idea, I’ll try it right now.

also you can share the same mesh between several car objects

Yes, I did that. But it’s OK. 有则改之,无则加勉(if you can understand this:))

I’m currently reading your City Engine code, and I’ll be back once I catch up with your progress.

p.s. I am also trying to solve my problem through a modified version of particle system.Here.

Yes, I did that. But it’s OK. 有则改之,无则加勉(if you can understand this)

suuure… it means A chance of no increases Mian. :wink: no sorry I don’t speak chinese.

oh wow if it’s for the government then… it depends who own the package, if you can publish it as gpl, I guess…

the shrinkswap constraint is cool to stich objects to a floor. another advantage is that it works on non-flat terrains : the leading empty is moving on a plan but the car can be animated on hills, roads with holes etc…

I’ve just published a new version that does that.
look at the car setup in layer 20. I guess you can reuse that kind of setup for your needs (impress your boss - help the artistic guy in his work…)

just append the car group(s) in your file to play with it, and copy also the two scripts called cars (for the trajectory) and wheelrotation.py (wheel rotation and steering).

a car need one empty to run, (CAR_MiniO or CAR_MiniG) with Loc xyz channel keyed or attached to a path. don’t key rotations.

I think I’ll publish this car animation thing apart in a separate file.

also in plugins\opensteer\opensteer.plugin
there’s the code to add ipos without objects, then re-link them to a group of object, once the ipos has been built. (it could be improved as I said)

Hi everyone

After think this problem for a while, I decide to focus my effort on a customized particle system.
http://blenderartists.org/forum/showthread.php?t=161741

to littleneo:
Thank you again for all your advice:). They are still very valuable in future visualization project which has smaller scale but focus one the detail.

wow I just looked at your video, your technique looks promising and fast :slight_smile:
please let us know once you’re done, see you later then.