Why the Split( ) Operation is Your Friend

The basic idea behind rule-based procedural modeling is easy:  you are given a block of say, styrofoam and you follow a sequence of steps to carve, detail and otherwise fashion whatever structure you want out of this mass.  This sequence can be diagrammed in a “tree” structure containing “root” shapes (arrows) and “leaf” shapes (squares).  Processes within the sequence may branch off from each other but collectively they are contained within a single, unified set of rules.   ESRI’s documentation tells us “Leaves are very important because the sum of all leaves represents the generated model”.

Figure 1: A CGA code structure diagrammed as root (arrow) and leaf (square) shapes – figure adapted from ESRI CityEngine Help

To do so, you must be able to split pieces off the shape and work with them individually.  As a simple example, we created a water tower structure with three distinct segments from that one block of styrofoam.  The CGA code for all of the shape in the diagram is at the bottom of the page. The steps in the process are:

  1. Create a block representing the “scope”, the space in three dimensions the structure will occupy.
  2. Split the block into three parts along the “y” axis.
  3. Convert each section of the block into a “primitive shape”,  a cone, a cylinder and a sphere to form a base, a standpipe and a reservoir.
  4. Set dimensions for each of the elements and position them vertically.

In the tree structure diagram below the illustration, the three components of the water tower are represented by each of the square “leaves” in the tree.

 

 

Figure 2: The raw shape is divided vertically and each portion is worked with individually to form the final piece.
Figure 3: The three components of the water tower are represented by each of the square “leaves” in the tree.
/**
 * File: tank.cga
 * Created: 7 Jan 2017 08:41:36 GMT
 * Author: (c)Jeff Herzer | jeffherzer.com
 */

version "2016.1"

###########################

# 1. INITIAL FORM

@StartRule
Tank1 --> 
 primitiveCube(40,150,40)

###########################

# 2. SPLIT THE INITIAL FORM

@StartRule
Tank2 --> 
 primitiveCube(40,150,40)
 split(y){
 30 : Base2 |
 80 : Standpipe2 |
 40 : Reservoir2
 }

# Color the sections
Base2 -->
 color("#ff0000")

Standpipe2 -->
 color("#00ff00")

Reservoir2 -->
 color("#0000ff") 


###########################

# 3. SHAPE THE FORM SEGMENTS

@StartRule
Tank3 --> 
 primitiveCube(40,150,40)
 split(y){
 30 : Base3 |
 80 : Standpipe3 |
 40 : Reservoir3
 }
 
# Create and color the base
Base3 -->
 primitiveCone(16,16,80) 
 color("#ff0000")

# Create and color the standpipe
# Raise the component vertically for exploded display
Standpipe3 --> 
 primitiveCylinder(16,10,80) 
 color("#00ff00") 
 t(0,60,0)

# Create and color the reservoir
# Raise the component vertically for exploded display
Reservoir3 -->
 primitiveSphere(16,8,30)
 t(0,70,0) 
 color("#0000ff")


###########################

# 4. THE FINISHED STRUCTURE


# Create a scope for the structure and apply 
# the "Splitz" rule  
@StartRule
Tank --> 
 primitiveCube(40,150,40)
 Splitz


# Split the mass into three sections along the Y axis
# and then apply the rules to shape and color 
Splitz -->
 split(y){
 30 : Base |
 80 : Standpipe |
 40 : Reservoir 
 }


# Shape and color the three sections
# Base
Base -->
 primitiveCone(16,16,80) 
 color("#ff0000")

# Standpipe
Standpipe --> 
 primitiveCylinder(16,10,80) 
 color("#00ff00")

# Reservoir
Reservoir --> 
 primitiveSphere(16,8,30)
 t(0,-10,0) 
 color("#0000ff")


# E N D #

*   *   *   *   *

Leave a Reply

Your email address will not be published. Required fields are marked *