Showing posts with label 3DMax. Show all posts
Showing posts with label 3DMax. Show all posts

Tuesday, 19 May 2009

Netlogo to 3D Max: Code

Based on the pseudocode for the Netlogo to 3DMax implementation, I have now decided to post a short tutorial on exporting the Netlogo traffic simulation to 3DMax. This tutorial will mainly cover the output of the turtles and visualising it in 3DMax.

Netlogo (traffic grid simulation):

For the turtles, I output during runtime, therefore, open the file at the first tick, keep writing, and close the file at the last tick, depending on how many ticks you would want to output, in my case 500.

if ticks = 0 [file-open "myfile.txt"]
ask turtles [
file-write xcor file-type " " file-show ycor
]
if ticks >= 500 [file-close]

This will output in the form:

-12 (turtle: 2) 11
-17 (turtle: 0) 5
-4 (turtle: 1) -8

I didn't find a simple way just to output only the turtle id number, so I manually delete the brackets and text using find and replace, giving me an output as seen below:

-12 2 11
-17 0 5
-4 1 -8

Now our next step is to import it into 3DMax. Once the output file has been stored, the script below can be run, and on clicking the 'Make' button, locate the output file, and it will create the animation.

The code works by importing the Netlogo output file into an array. It can be found here.

I have commented the code in order to explain what is happening at each step.

Running this script will result in the animation shown in my previous post. To get the road patches, and traffic lights in 3DMax, the code can be extended further to store the patches and traffic light states in arrays for each frame, once imported from the Netlogo output.

Update: As pointed out by a reader, there is actually a simple way to output only the turtle id number using the command:

ask turtles [print who]

Therefore, the Netlogo output above can be obtained by using the following command

ask turtles 
[
file-type word xcor " " file-type word who " " file-print ycor
]

Tuesday, 14 April 2009

Pedestrian model for a Tokyo style intersection of Oxford Circus

As has been recently announced, Oxford circus is to get a pedestrian-friendly revamp. Here is a video of a pedestrian model, first referred to me by Duncan Smith, a PhD student at CASA. The model consists of 5000 people, where a particle-based system was used to run the simulation. These particles were then replaced by animated people.

The model was created by designhive, and a map of the redesign can be seen here.




Here, the pedestrian and traffic simulation models are combined with a 3D Studio Max model of the Oxford Circus proposals, which makes this finished video very realistic.

This is a type of application, where a 3D visualisation of the model can be used to enhance the communication of ideas, and making it more accessible to others.

Sunday, 5 April 2009

Netlogo to 3DMax: Pseudocode



As mentioned in an earlier post that I will be posting a pseudocode for a Netlogo to 3DMax implementation.
This pseudocode is mainly for the Netlogo traffic simulation, but I will try and make it as general as possible in order to use in other models.

Netlogo:
For each tick:
1. Output to file - x coordinate, turtle id, y coordinate

Please note, that when the data is exported into a text file, it will have other test such as 'turtle id:', all text needs to be deleted, and should leave you with 3 numbers. An example for 3 turtles (1 tick) can be seen below:



This creates a file that has the turtle id and locations for each tick. Now, our next step is to import it into 3DMax, but this time each tick represents a frame. I did this by creating a script that would store the data in an array for each frame.


3DMax:
1. Initialise an object (eg, box), for each turtle in the output file
2. Read in netlogo output file, and store xy coordinates for each object per tick in an array. (I stored the array in a 2D form [object id][xy coordinates])
3. Initialise positions of each object for first frame
4. While not end of array
5. Advance frame, and update object position corresponding to the object id in the array
6. Keep repeating step 5 till end of file is reached.
7. Render final animation

Same process for traffic lights, where each traffic light is a turtle in netlogo.

Sunday, 8 March 2009

Netlogo to 3D Max: Visualisation

The first few posts will be a catch up of what has been done so far. The first piece I worked on was a Netlogo to 3D Max implementation. This implementation is for a street level scale of a city. Although, 3D Max is used for crowd and particle simulations, in order to model these complex systems, an external package like Netlogo is used. Through the use of loose coupling with 3D Max, it allows us to easily visualise these systems.

The movie below was first posted on the Digital Urban blog. This was my first step to export a basic traffic model from Netlogo to 3D Max. The movements of the cars were first output into a file, the second step was to write a 3DS script to import these movements and animate them in 3D Max.


NetLogo to 3D Max - Proof of Concept from digitalurban on Vimeo.


I have noticed quite a few comments asking how this import was done. I will be posting a pseudocode soon, and will try and give a summary for each step.

ShareThis