CGA Code Lesson #1: Primitive Shapes

Most any building, structure or structural element can be created using the five so-called primitive shapes found in CGA code: the cone, cube, cylinder, disk, quad  or sphere.

CGA OPERATIONS COVERED

primitiveCone(sides,radius,height)

primitiveCube(width,height,depth)

primitiveCylinder(sides,radius,height)

primitiveDisk(nVertices,radius)

primitiveQuad(widthlength)

primitiveSphere(sides,divisions,radius)

EXERCISE

Create a new rule file in the rules folder of your Project file. Paste the code at the bottom of the page into the rule file and save as lesson_01.cga.  Since there are no values in the parenthesis after each operation, the shapes are drawn to default values. Experiment with each by changing parameters to the commented values in the code, saving the rule file, then clicking on the shape and regenerating it with (CTL + G).  These values will adjust things like height, width , depth or number of sides. Experiment with these values.

We will create instances of each primitive shape and adjust the parameters. Follow the instructions under CODE below.

  • To begin each shape, go to Shapes > Rectangular Shape Creation and draw five rectangular shapes in the viewport of your CityEngine scene, as in Figure 1A. The dimensions will not matter.
  • Left click on each shape and in the Shape Inspector, click the assign button and select the lesson_01.cga rule file.  Next, click Select and assign a rule. Assign a different rule to each of the five shapes.
Figure 1 – click to view a larger image 

CODE

/**
 * File: lesson_01.cga
 * Created: 5 Feb 2017 20:18:39 GMT
 * Author: Jeff Herzer | jeffherzer.com
 */

version "2016.1"

StartCone-->
 primitiveCone()
// try parameters (24,30,120) 
 
StartCube-->
 primitiveCube()
// try parameters (40,90,10) 
 
StartCylinder-->
 primitiveCylinder()
// try parameters (8,30,70)

StartDisk-->
 primitiveDisk()
// try parameters (8,25)
 
StartQuad-->
 primitiveQuad()
// try parameters (60,30)

Leave a Reply

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