Tutorial 14c: Combining polygonal modeling with rules

To access the tutorials in CityEngine, click Help > Download Tutorials and Examples.... After choosing a tutorial or example, the project is automatically downloaded and added to your workspace.

Polygonal Modeling and Rules

First of all, why would we want to do this? Suppose you want to give all windows of this house a nice 3d frame.

House with flat texture

Currently it’s just a flat texture. Of course you could drag the frame out for every window, but this is quite tedious. Also, the window texture does not adapt nicely when scaled. Here you get some cuts in the windows:

Cuts in the windows

To conveniently place 3d windows, we use a rule on the building. Here is how:

  1. First, create a 3d window. Use the rectangle tool and drag it up.
    Rectangle tool used to create a 3d window
  2. Select the front face with the selection tool and assign the window texture with the texturing tool.
    Textured window created with the texturing tool
  3. Then draw a few rectangles over the window frame with the rectangle tool. Drag them to create a 3d structure. Feel free to experiment with different structures.
  4. This finishes our window.
    Arrow shows the direction of drag for the window rectangle
    To use it in a rule, you have to export it first.
  5. Select the model, then choose File > Export models.
  6. Choose Wavefront OBJ and set the name to window.
  7. Make sure the folder is the tutorial/model folder.
  8. Click Finish.
    Export model to Wavefront OBJ
    Set location to the tutorial/model folder
  9. Now we can apply the rule.
  10. Select the house, right click Assign Rule File.
    Context menu for Assign Rule File
  11. Select rule.cga from the tutorial folder, and then press generate.
  12. Note:

    This rule replaces all polygons with window textures with the 3d window. You can look at it and use it for your projects.

    All windows are now 3d shapes, and you can see the difference by toggling the show/hide models switch.
    Windows with 3d shapes rule applied
    If you drag the window frame, it adapts much nicer.
    Drag the window frame to adjust
    You can also change global parameters.
  13. Bring up the Inspector and select the house.
  14. Enter values in the window parameters and all the windows update automatically.
    Enter values in the parameter to update all windows