[036] CityEngine comp(): Selecting Sloped Faces with Horizontal, Vertical, Aslant, and Nutant
Learn to target specific building surfaces based on their angle and orientation using sloped-based comp selectors.
This tutorial explains how to use the horizontal, aslant, vertical, and nutant selectors in the comp() command. It provides a deep dive into how CityEngine classifies faces based on their normal angles relative to the local coordinate system and explains selector precedence when multiple selectors coexist within a single comp() rule.
First, take a look at the example below.
The following code demonstrates how to apply these selectors to the sphere shown above.
CGA Code Example and Visual Results
Lot1 --> primitiveSphere(10, 10, 10) Horizontal
Lot2 --> primitiveSphere(10, 10, 10) Aslant
Lot3 --> primitiveSphere(10, 10, 10) Vertical
Lot4 --> primitiveSphere(10, 10, 10) Nutant
Horizontal --> comp(f){horizontal : color(1,0,0) X.}
Aslant --> comp(f){aslant : color(1,0,0) X.}
Vertical --> comp(f){vertical : color(1,0,0) X.}
Nutant --> comp(f){nutant : color(1,0,0) X.}
And the results are as follows...
As shown in the results, horizontal represents faces close to a flat plane, aslant represents faces tilted upwards, vertical represents faces close to vertical, and nutant represents faces tilted downwards (the opposite of aslant).
Technical Criteria and Angle Ranges
If we look at the official reference for these selectors:
Horizontal Selector
First, you can see that these selectors use the local coordinate system, and faces are classified based on the angle between the face normal and the XZ plane of the base shape.
That angle logic is illustrated in the figure below.
As confirmed in the figure above, it refers to the angle between the normal direction of each face (represented by the sky blue arrow) and the XZ-plane of the shape.
Comparing Aslant, Nutant, and Other Selectors
Now, shall we compare selectors with similar ranges that we have learned so far?
You can immediately grasp the difference just by looking at the image above.
As a note, since the reference coordinate systems are different, a significant difference occurs when rotating the object, as shown below.
I explained this in the previous session as well.
CityEngine comp() Selector Rotation & Local Coordinates
You can choose and use selectors related to direction and slope as needed.
You can also mix and use them as shown below.
Lot1 --> primitiveSphere(10, 10, 10) Mix
Mix -->
comp(f){
aslant : color(1,0,0) X. |
bottom : color(0,1,0) X. |
world.west : color(0,0,1) X.
}
Line 4 aslant : Sloped faces facing upwards in red,
Line 5 bottom : Bottom faces in green,
Line 6 world.west : West-facing faces in blue.
Let's look at the results.
We used various selectors utilizing both local and world coordinate systems.
Even when mixed like this, each maintains its respective reference coordinate system.
Video 2: Mixing Local and World Coordinate Selectors in CityEngine
Even when the object rotates, the world.west selector continues to highlight polygons facing West.
Selector Precedence and Execution Order in comp()
Now, here is one very important point...
Let's look at the following code.
Lot1 --> primitiveSphere(10, 10, 10) Mix1
Lot2 --> primitiveSphere(10, 10, 10) Mix2
Mix1 -->
comp(f){
aslant : color(1,0,0) X. |
world.west : color(0,0,1) X. |
bottom : color(0,1,0) X.
}
Mix2 -->
comp(f){
aslant : color(1,0,0) X. |
bottom : color(0,1,0) X. |
world.west : color(0,0,1) X.
}
The order of the selectors has changed.
In other words, the sequence of the "splitting" operation has been swapped.
For Lot1, world.west was defined before bottom, and
for Lot2, bottom was defined first.
What kind of difference will this make?
First, let's look at the output.
The generated outputs appear identical initially.
Let's try rotating them to see what changes occur.
Video 3: CGA Rule Priority: Order of Operations in comp() Selectors
Can you spot the difference?
Yes. Priority is granted according to the split order.
In the case of Lot1, since world.west was processed before
bottom, in regions where both conditions overlap, the
world.west selector takes precedence. Therefore, parts of the
bottom that face West change to blue.
In the case of Lot2, since bottom was processed before
world.west, the world.west rule cannot "take over"
the region already claimed by the bottom selector.
Among the selectors, there is all. This means "all elements."
Let's look at the next code.
Lot1 --> primitiveSphere(10, 10, 10) Mix1
Mix1 -->
comp(f){
all : color(1,0,0) X. |
world.west : color(0,0,1) X. |
bottom : color(0,1,0) X.
}
In Line 5, the all selector takes first priority, followed by
world.west and bottom.
What kind of result will come out?
You can see that everything following is ignored, and all has
claimed every face.
Literally, all means everything.
Let's look at the next example.
Lot1 --> primitiveSphere(10, 10, 10) Mix1
Mix1 -->
comp(f){
world.east : color(0,0,1) X. |
all : color(1,0,0) X. |
top : color(0,1,0) X.
}
In this case, world.east takes first priority, followed by
all and top.
You can probably guess the result by now.
world.east claimed its area first, and then all took
everything else that remained.
Let's look at one final variation.
Lot1 --> primitiveSphere(10, 10, 10) Mix1
Mix1 -->
comp(f){
world.east : color(0,0,1) X. |
top : color(0,1,0) X. |
all : color(1,0,0) X.
}
Here, world.east is first priority, top is second
priority, and all is last.
The result:
world.west took its polygons first, then top claimed
the top faces that weren't already taken by world.west, and
finally, all claimed everything else.
This demonstrates how split order and selector priority work inside comp().
In the next session, we will explore
eave | hip | valley | ridge, which are selectors used
exclusively with the comp(e) command for edge components.
- Learn previous workflow in [035] How to Use World Coordinate Selectors in CityEngine CGA
- Continue learning with [037] How to Select Roof Edge Types Using Comp(e) Selectors in CityEngine
Comments
Post a Comment
Feel free to leave a comment if you have any questions about Global Mapper or CityEngine. I will get back to you with a sincere response as soon as possible. (Please note that all comments are moderated and manually approved to maintain a high-quality community. Promotional or spam content will not be published.)