Rule file import

Importing a rule file makes all rules, attributes, and functions of the imported rule file available under the specified prefix. For more information, see CGA reference.

The following rule files both define a Facade rule. Each textures a building facade in a different way:

# -- facade1.cga

actualFloorHeight = scope.sy/rint(scope.sy/4)
actualTileWidth   = scope.sx/rint(scope.sx/4)
    
Facade --> setupProjection(0, scope.xy, 2, 2)
           projectUV(0)
           texture("facade1.jpg")
# -- facade2.cga

actualFloorHeight = scope.sy/rint(scope.sy/6)
actualTileWidth   = scope.sx/rint(scope.sx/4)
    
Facade --> setupProjection(0, scope.xy, 3, 2)
           projectUV(0)
           texture("facade2.jpg")

The next rule file contains a Lot rule that creates a building mass and splits it into its side faces and a roof face:

# -- structure.cga

// the attribute height will be overridden by the
// attribute height from "main.cga" if this rule
// file is included. Thus if this rule file is
// used standalone, the buildings will be of height
// 100, if this rule file is included by "main.cga",
// the buildings will be of height 200.

attr height = 5

Lot --> extrude(height)
        comp(f) { side : Facade | top : Roof. }

Finally, the main rule file with the Lot start rule imports both facade rules and the structure rule.

  • The Lot rule calls the Lot rule in structure.cga using the st. namespace.
  • The height attribute in structure.cga is overwritten by the height attribute in main.cga, so a building of height 10 is created.
    Note:

    If structure.cga is used as a stand-alone rule file, a building of height 5 will be created.

  • The Facade rule for structure.cga is defined in main.cga. It calls the Facade rule of either facade1.cga or facade2.cga.

# -- main.cga

// define an attribute "height", potentially
// overriding the same attribute in imported
// rule files.

import f1 : "facade1.cga"
import f2 : "facade2.cga"
import st : "structure.cga"

attr height = 10

Lot --> st.Lot

st.Facade --> 50% : f1.Facade else : f2.Facade