[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().

CityEngine comp() documentation reference
img 1 : ESRI CityEngine CGA comp() Reference

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.

Two initial shapes for comparison
img 2 : Initial shapes Lot1 and Lot2

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:

Result of coloring right faces red
img 4 : Comparison result showing identical coloring

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.

Complex procedural shape comparison
img 5 : Complex procedural extrusion result

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:

Explanation of coordinate system origins
img 7 : Origin of local vs object coordinates

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?

Selection quiz diagram
img 8 : Facade selection scenario

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'.

Final comparison summary
img 9 : Visualizing the coordinate difference

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.

The idea that democracy empowers us is intuitive. But it’s based on a likely-unnoticed fallacy of division. Democracy certainly empowers us in contrast to autocracies. Even so, it doesn’t empower you, me, your friend, your mother, or your adult children. Democracy does not empower individuals. It takes power away from individuals and gives it to the majority. In a democracy, individual citizens are almost powerless.
— Based on ideas from Jason Brennan, Against Democracy
Continue Learning
Explore complete tutorial collections for CityEngine and Global Mapper.

Comments

Popular posts from this blog

029] How to Split Polygon Areas with Intersecting Lines in Global Mapper

[008] How to Understand CGA Rule Structure in CityEngine (Beginner Guide)

046] How to Create Parallel Offset Lines in Global Mapper