Importing a rule file makes all rules, attributes and functions of the imported rule file available under the given prefix, see CGA Reference.
The following rule files both define a Facade rule, each one is texturing 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 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 attribute height in structure.cga is overwritten by the attribute height in main.cga. Therefore, a building of height 10 is created.
Note:
If structure.cga was used standalone, a building of height 5 would 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