[040] Understanding Object Coordinate Selectors in CityEngine
Learn the fundamental differences between local and object coordinate systems to achieve consistent procedural results.
This tutorial explains how to differentiate between local selectors and object-based selectors in CityEngine CGA. By understanding the hierarchy of coordinate systems—World, Object, and Local—you will be able to reliably target specific building facades regardless of how complex your procedural rule tree becomes.
I was planning to move on to creating forms using indices, but then I remembered that I skipped an explanation of object.front, object.right, object.left, object.back, and similar selectors when I previously covered comp().
If you look at the reference above, front and back belong to the "local coordinate system," while selectors starting with object. belong to the "object coordinate system."
So what exactly is the difference between them?
First, let's build a simple example to compare them.
First, I created two initial shapes as shown above.
We will compare them by using 'right' for Lot1 and 'object.right' for Lot2.
The code looks like this:
Lot1 --> extrude(20) A
A --> comp(f) {right : color(1,0,0) X.}
Lot2 --> extrude(20) B
B --> comp(f) { object.right: color(1,0,0) X.}
For both objects, the right face is colored red, and the rest are discarded.
The result is:
Yes. For both, only the right face based on the first edge has been colored red. At first glance, there seems to be no difference between the two.
Now, let's create a slightly more complex form.
Comparing Local and Object Coordinate Behavior
The shape above was created using the following steps:
1st. Extruding the initial shape upward by 20m.
2nd. Splitting the right face vertically into top and bottom segments.
3rd. Extruding the upper split face 10m to the right.
4th. Coloring the front face of the newly extruded part red.
Lot1 uses standard selectors, while Lot2 uses object-based selectors.
Let's compare the two codes.
Lot1 --> extrude(20) A
A --> comp(f){right : A1 |all : X.}
A1 --> split(y){'0.5 : X. | '0.5 : A2}
A2 --> extrude(10) A3
A3 --> comp(f){left : A4 | all : X.}
A4 --> color(1,0,0) X.
Lot2 --> extrude(20) B
B --> comp(f){object.right : B1 | all : X.}
B1 --> split(y){'0.5 : X. | '0.5 : B2}
B2 --> extrude(10) B3
B3 --> comp(f){object.front : B4 | all : X.}
B4 --> color(1,0,0) X.
Key Difference Between Local and Object Selectors
Both codes are identical, except:
In Lot1, 'left' was used on line 10 to specify the red color, whereas in Lot2, 'object.front' was specified on line 24.
With standard front/back/left/right selectors like those in Lot1, the basis is the first edge of the immediately preceding shape.
With object-based selectors like those in Lot2, the basis is the first edge of the *very first initial* shape.
As illustrated below:
The object-based selector distinguishes front, back, left, and right based on the first edge of the earliest stage, rather than the immediate previous stage.
The object-based selector is actually very convenient to use.
With standard selectors like 'front', you have to manually check the first edge of the shape that serves as the blueprint for the current object every time. However, for the object-based selector, you only need to know the direction of the first edge of the initial shape to distinguish front, back, left, and right relative to it.
Which selectors should be used for the following diagram?
In the case of general front/back/left/right distinction like Lot1, you would have to use 'top', but if you use the object-based selector like Lot2, you would use 'object.right'.
This concept can feel confusing at first. For now, it is enough to simply understand the general idea.
Coordinate System Hierarchy in CityEngine
Briefly, let me explain the scope of coordinate systems.
I mentioned that CityEngine has world, local, and object coordinate systems.
Intuition might suggest that the range of coordinate systems follows the order world > local > object, but in CityEngine, the actual range is world > object > local.
World, Object, and Local Coordinate Systems
World is North, South, East, West. It does not change.
Object is a coordinate system created by the highest-level shape and is accessible from all lower-level rules.
Local is a coordinate system created for each object as rules progress (pivot and scope coordinates belong here).
Just keep in mind that something like object.front refers to the "object coordinate system," while front, right, etc., refer to the "local coordinate system."
Next time, we will cover creating forms using indices.
- Learn previous workflow in [039] Procedural Modeling Practice in Esri CityEngine: Split, Comp, and Extrude
- Continue learning with [041] How to Precisely Target Faces Using comp.index in CityEngine CGA
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.)