Hi !
It all just looks more complex than it actually is.
Let's go through it step by step in the CGA code :
1]
We want to create a Street model from Street shapes. So we use a CGA rule to split that shape and colorize it until it represents a street how you need it.
2]
For now, we only work on Street Shapes, so we NIL Crossing and Sidewalk Shapes in the CGA code. This means no Model is generated.
3]
We define a series of attributes we can use :
- laneOffset : With the offset, we can shift the lanes sideways e.g. 2 left and 3 right can become 1 left and 4 right.
- laneWidth : Width of a street lane in meters (3 meters.. code in meters !! )
- medianWidth : 0.1 meter
- oneWay : @Range ("no", "left", "right") . the attr oneWay gets specified better with that 'annitation'. This makes that you have the 3 options as a dropdown in the Inspector for this attribute.
- doMedian: true or false. This is a 'boolean' value which is either true or false. Depending on it's state, a median will be made or not.
4]
functions : functions are there to calculate some values and return a value.
e.g.
f = 5
if f is called, the value of 5 is returned. In print ( f ), 5 will be printed.
5]
- rint() means round integer. this rounds up or down to the next full integer number. 5.1 will be rounded to 5.
- geometry.dv(0,unitSpace) is the width of a curved street, in meters.
6]
attrs with the @Hidden annotations are not displayed in the Inspector. We use them hidden as 'generic attributes' to pass values down our rules, thus they are set at the very beginning, after Street -->
7]
case : .. else : is the same as an 'if statement' in other programming languages. this tests if something is true or not.
to TEST if something is true or not, the '==' (double equal sign) is used.
E.g.
5 == 5 is 'true' in real world, so we try to create similar statements in CGA to split our geometries.
8]
In the rule called 'DoStreet', we then distinguish the different cases and split the street geometries among the U and V dimension. Those are actually texture coordinates. This is a good trick, because Street Shapes already have proper UV coordinates. The V direction is along the WIDTH of the street.
9]
So in general, with the functions, what we basically do is find out the proper number of possible lanes in each direction, with or without a median and then split the geometries accordingly.
Let me know if this short input helps you a little further...
I know it's complicated at the beginning. But once you know what's happening, the magic becomes easy ! 🙂
m.