Select to view content in your preferred language

Vehicle placement on CityEngine-generated streets.

5592
22
Jump to solution
08-07-2012 06:24 AM
JoshWade
Emerging Contributor
Hello again 🙂

I am beginning to create driving scenarios for a driving simulator. (For example, on a highway you are traveling at 70mph when suddenly the vehicle in front of you applies the brakes hard). I see that CE uses some mechanism for placing the cars on the roads neatly between the lines (Even on curved roads).

I am hoping that I can use your algorithm for my AI-driven cars. I assume it has something to do with the street network edges as well as the particular attributes of the street?

Any help would be wonderful!

-Josh
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MatthiasBuehler1
Deactivated User
edit the code around line 240 :

1] note the MakeLaneMarkers shape copy after the Vehicles().
2] add the code for the marker creation and position reports

Streetsides -->  case calcNbrOfLanes < 1.1 : Asphalt  case Nbr_of_left_lanes == 0 && Nbr_of_right_lanes == 0:   split(v,unitSpace,0){ ~calcLanesLeft    : Lanes(calcNbrOfLanes,connectionEnd,0) Vehicles(0) MarkerCreation("left")        | Median_width      : Median        | ~calcLanesRight   : scaleUV(0,-1,-1) Lanes(calcNbrOfLanes,connectionStart,2) Vehicles(2) MarkerCreation("right") }  else:   split(v,unitSpace,0){ ~Nbr_of_left_lanes : Lanes(Nbr_of_left_lanes,connectionEnd,0) Vehicles(0) MarkerCreation("left")        | Median_width      : Median        | ~Nbr_of_right_lanes : scaleUV(0,-1,-1) Lanes(Nbr_of_right_lanes,connectionStart,2) Vehicles(2) MarkerCreation("right")}  @Range ( "all", "left", "right") @Group("MARKERS") attr markerOutput = "all"  MarkerCreation(side) -->  case markerOutput == "all" :   MakeLaneMarkers  case markerOutput == side :   MakeLaneMarkers  else :   NIL  MakeLaneMarkers -->  color(1,0,0)  t (0,.1,0)  split(v,unitSpace,0) { ~Lane_width : LaneShape }*  LaneShape -->  split(v,unitSpace,0) { ~1 : NIL | markerDim : LaneCenterLine | ~1 : NIL }  markerDim = 0.25 markerDist = 15  LaneCenterLine -->  split(u,unitSpace,0) {{ markerDim : LaneMarker | ~ markerDist : NIL }* | markerDim : LaneMarker }  LaneMarker -->  report("markerPosX", convert(x, scope, world, pos, 0.5 * scope.sx, 0.5 * scope.sy, 0.5 * scope.sz))  report("markerPosY", convert(y, scope, world, pos, 0.5 * scope.sx, 0.5 * scope.sy, 0.5 * scope.sz))  report("markerPosZ", convert(z, scope, world, pos, 0.5 * scope.sx, 0.5 * scope.sy, 0.5 * scope.sz))  X. # NIL



Now once you generate a street, you should get the reports in the Inspector's Reports tab.

To grab those and produce your java script code :
1] copy the attached .py script to your scripts folder
2] run the Script Based Exporter ( Python ), where you select the new script under the Misc options, then run it.
3] open the console ( Python output ) and get your code.

To adapt the offset, just copy paste your export offset values and edit the Python script accordingly.

I also just added the lane direction switch called (markerOutput).

Note also that now, the markers are produced as geometry, thus you may want to NIL it as commented out in the last line after the reports ( X. # NIL )

let me know if it works on your machine too. 😉

View solution in original post

0 Kudos
22 Replies
MatthiasBuehler1
Deactivated User
hi !

the vehicles are actually placed 'geometrically'. for this, the streets are split according to their UV coordinates. First into lanes and medians, then into smaller segments, on which the cars are inserted.

at the current state, CityEngine has no actual lane information available to work with. Thus, all cars you see are simply placed 'randomly'.

for a driving simulator, what you could do is 'create some metadata' which lets you recreate the curve network for use in your simulator, using Python scripting.
but for this, I'd of course need to know what your simulator needs as input data.
0 Kudos
JoshWade
Emerging Contributor
Thanks for the reply!

I have begun to incorporate the Unity plugin called iTweens into my project. It requires an array of nodes (which are just 3d vector coordinates x,y,z). I would like to dynamically create nodes along the street that are properly on and above the street so that my AI car can drive on it.

These nodes would form a path (even on curved streets) which would then be stored in an array to be used by iTweens.
0 Kudos
MatthiasBuehler1
Deactivated User
hi !

so you just need the position of those nodes and the curve network is created by that iTween system ? did I understand this correctly ?

because if that's the case, your main task is 'just' to report those markers, which is not too hard in CE.

lemme know. 🙂
0 Kudos
JoshWade
Emerging Contributor
Hello 🙂

Yes that is correct. I just need to know the coordinates of the nodes the street. I assume that I can create 'lanes' via displacing the nodes in the path in some direction or another.

How do I go about finding/accessing/utilizing these markers?

-josh
0 Kudos
MatthiasBuehler1
Deactivated User
- are you using the modern streets example for your street models ?
- which version of CityEngine do you have ? Advanced ( PRO ) ?

because you need Python Scripting to write that metadata out.

lemme know.
0 Kudos
JoshWade
Emerging Contributor
I have Advanced 64 Bit (2011.2) for Windows 7 OS. The example I'm using is the Philadelphia model (4 copies to create one very large version, but with different rule file attributes to create variation). The street network has been modified slightly in the original section of the city, but the networks in the surrounding quadrants are entirely different.
0 Kudos
MatthiasBuehler1
Deactivated User
I've played a little with the Philly code to produce some visible markers on the lanes.

what you could do now is report those positions and create some script code for UNITY ( BOO / JScript ) that produces your markers in all those locations.

Though the driving direction and the precise linking of lanes over the crossroads must be done manually, or if possible within that system you use. CE cannot really help there efficiently.

Let me know what you think.

matt

ps. of course you can get the code, but let's first find the workflow.
0 Kudos
JoshWade
Emerging Contributor
Yes! 😄 This is fantastic. If I am able to successfully produce corresponding points in Unity using these markers, then this is exactly what I need. I can figure out some way to determine direction and network connectivity later on.

What shall I do in terms of Python and creating these markers?
0 Kudos
MatthiasBuehler1
Deactivated User
cool so far then.

I guess we're faster if I quickly write the code down, then pass the stuff on for refinement.

can you find me a line of code which creates such a marker via code ?

pseudo code :
putStreetMarker(x,y,z)


then I could create directly the text you can run which produces all markers for you.

let me know ..
0 Kudos