### Define and Invoke start Rules in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-start-keyword.htm Demonstrates how to define a start rule in a CGA file and how to invoke it generically from another file using the import statement. The start keyword allows rules to be called via the generic start identifier or by their specific name. ```CGA // rule.cga start Init --> start(20) // same as Init(20) start Init(height) --> extrude(height) ``` ```CGA // main.cga import rule : "rule.cga" Lot --> rule.start(10) // same as rule.Init(10) ``` -------------------------------- ### Wildcard and Regex search examples Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-file-search-function.htm Examples of using wildcards and regular expressions to filter files based on specific naming patterns or directory structures. ```CGA filesSearch("*.png"); filesSearch("?.png"); filesSearch("*/?.png"); filesSearch("textures/*"); filesSearch("$[12].png"); ``` -------------------------------- ### findFirst Function Example (CityEngine CGA) Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-find-first-function.htm Demonstrates how to use the findFirst function to locate the starting index of a substring within a larger string in CityEngine CGA. The function returns the 0-based index or -1 if not found. ```cga findFirst("rule your city with cityengine","city") # result = 10 # "rule your " = 10 characters; then the match string starts ``` -------------------------------- ### Subdivide Mass Model for Insertion Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-i.htm A complex example demonstrating the subdivision of a lot into facades and floors using 'comp' and 'split' operations, followed by the insertion of window assets. ```CGA Lot--> extrude(47) comp(f) { side : Facade | top : X } Facade--> split(y) { { ~1 : X | ~8 : Floor }* | ~1 : X } Floor--> split(x) { { ~1 : X | ~5 : Window }* | ~1 : X } ``` -------------------------------- ### Mark Rule as Start Rule (@StartRule) Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-annotations.htm The @StartRule annotation designates a specific rule as a starting point for the CGA process. This allows users to select different starting rules from the start rule chooser in CityEngine, enabling varied generation outcomes from the same rule file. ```cga @StartRule Start-->NIL ``` -------------------------------- ### CGA shapeL, shapeU, and shapeO syntax examples Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-shapeluo-operations.htm Basic syntax demonstration for applying L, U, and O shape operations to a geometry. ```CGA Left --> shapeL(4,4) { shape : Shape | remainder: Remainder } Middle --> shapeU(4,4,4) { ... } Right --> shapeO(4,4,4,4) { ... } ``` -------------------------------- ### CGA Rule Setup and Coloring Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-split.htm Defines basic rules for coloring and sizing shapes along the X, Y, and Z axes. These rules serve as the foundation for demonstrating split operations. ```CGA X(h)--> s('1,'h,'1) color("#0000ff") Y(h)--> s('1,'h,'1) color("#ffff00") Z(h)--> s('1,'h,'1) color("#00ff00") ``` -------------------------------- ### CGA Example: Reporting Window State and Area Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-report.htm Demonstrates the use of the 'report' operation within CGA rules to collect information about facades, window areas, and window states (open/closed). This example shows how to assign keys and values, including calculated geometry areas. ```cga Lot --> extrude(30) comp(f) { side : Facade | top : Roof } Facade --> report("facades", 1) split(y) { ~5 : Floor | ~0.5 : Ledge }* Floor --> split(x) { ~1 : Tile | 2 : Window | ~1 : Tile}* Window --> 40%: report("windowarea", geometry.area()) report("windows.open", 1) NIL else: report("windowarea", geometry.area()) report("windows.closed", 1) color("#aaffaa") ``` -------------------------------- ### Select Envelope Components using CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-comp.htm Demonstrates how to use the comp() operation with the 'e' selector to target faces sharing edges with specific tagged components. It includes examples of filtering by tags and inserting geometry at edge-vertex intersections. ```CGA Init --> envelope(normal,4, 0,45, 3,45, 2.5,50, 2,50) comp(f) { isTagged("envelope.bottom", e) : ShowEnvelopeAutoTags } Init --> envelope(normal,4, 0,45, 3,45, 2.5,50, 2,50) comp(f) { isTagged("envelope.bottom", e) && isTagged("envelope.side.slope") : ShowEnvelopeAutoTags } Init --> envelope(normal,4, 0,45, 3,45, 2.5,50, 2,50) comp(e) { isTagged("envelope.bottom", v) : Edge } Edge --> s('1, 0.5, 0.5) center(yz) color("#09de1f") primitiveCube() ``` -------------------------------- ### CGA Example: Using contextCount with Labels Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-context-queries.htm Demonstrates a two-pass generation process where labels are applied in the first pass, and then contextCount is used in the second pass to count shapes with a specific label. ```cga Lot --> label("label") print(contextCount(intra, "label")) label("label") ``` -------------------------------- ### Perform Unit-Based Street Split Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-split.htm Uses the split operation in unitSpace to create repeating patterns along a street. This example creates a 3-meter wide red band every 20 meters. ```CGA Street--> split(u, unitSpace, 0) { ~10 : NIL | ~3 : color("#ff0000") X | ~10 : NIL }* ``` -------------------------------- ### Parse text files using splitString Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-split-string-function.htm A practical example showing how to read a text file and split its contents into rows and columns using the splitString function. ```CGA const file = readTextFile("table.txt") const rows = splitString(file, "\n") const headers = splitString(rows[0], ";") ``` -------------------------------- ### splitAndSetbackPerimeter Basic Example - CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-split-and-setback-perimeter.htm Demonstrates the basic usage of the splitAndSetbackPerimeter operation in CGA. It splits a 'Lot' shape into sections with specified lengths and setbacks, assigning colors to the resulting sections and the remainder. ```cga Lot --> splitAndSetbackPerimeter(6) { 40 : 5 : Yellow | 20 : 10 : Blue } { remainder : Grey } Yellow --> color("#F2BB1D") Blue --> color("#3957A5") Grey --> color("#CAC9C6") ``` -------------------------------- ### Taper Operation with Tag Propagation Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-geometry-tagging-essential-knowledge.htm An example of the taper operation following a subtract operation, where tag propagation rules are implicitly applied. The VisualizeTags rule is used to display the resulting tags. ```cga Init --> subtract { A | B } taper(4) VisualizeTags ``` -------------------------------- ### Split string using delimiters and regex in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-split-string-function.htm Examples demonstrating the use of splitString with simple string delimiters, special characters, and regular expressions to parse data. ```CGA splitString("a.b.c", ".") splitString("a.b\nc.d", "\n") splitString("a;b;c", "$;") splitString("a.b.c", "$\\.") splitString("a b c", "$\\s+") ``` -------------------------------- ### CGA comp Attributes Syntax and Usage Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-comp-attribute.htm Demonstrates the syntax and provides an example of using comp.sel, comp.index, and comp.total attributes in CityEngine's CGA to access information about component splits. ```cga string comp.sel float comp.index float comp.total ... primitiveCube() comp(f) { front : Front | side : Side | all = All } ``` -------------------------------- ### Get Vertex Indices using comp function in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-comp-function.htm This example demonstrates how to split a shape into its vertices and retrieve the index of each vertex using the comp function. The result is an array of vertex indices ordered by vertex index. ```cga const array = comp(v) { all : comp.index } Lot --> print(array) ``` -------------------------------- ### SetupProjection and ProjectUV in Wall Rule (CGA) Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-setup-projection.htm Demonstrates the placement of setupProjection relative to projectUV within a Wall rule, illustrating its impact on texture spanning and seams compared to placing it at the facade level. ```cga Frontfacade --> setupProjection(0, scope.xy, 1.5, 0, 0, 1) setupProjection(2, scope.xy, scope.sx, scope.sy, 0, 0, 1) ... ... Wall --> color(wallColor) set(material.colormap, wall_tex) set(material.dirtmap, dirt_tex) projectUV(0) projectUV(2) ``` ```cga Frontfacade --> setupProjection(2, scope.xy, scope.sx, scope.sy, 0, 0, 1) ... Wall --> color(wallColor) setupProjection(0, scope.xy, 1.5, 1, 0, 0, 1) set(material.colormap, wall_tex) set(material.dirtmap, dirt_tex) projectUV(0) projectUV(2) ``` -------------------------------- ### Get Edge Lengths using comp function in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-comp-function.htm This example shows how to split a shape into its border edges and retrieve the length of each edge using the comp function and scope attributes. Unselected edges are assigned a default value of 0. ```cga edgeLength = scope.sx const array = comp(e) { border : edgeLength } ``` -------------------------------- ### Get Tree Key in CGA: TreeKey Consistency During Derivation Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-get-tree-key-function.htm Illustrates that the TreeKey remains constant throughout the derivation of a rule for a specific shape. This example shows that even when a shape is split into multiple sub-shapes, the initial TreeKey for the parent shape is printed for each derived child shape. ```cga ShapeA --> print(getTreeKey) split(x){ 2: ShapeB print(getTreeKey) | 3: ShapeC print(getTreeKey) } ``` -------------------------------- ### setupProjection Operation Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-setup-projection.htm Initializes a projection matrix for a specified UV set using scope or world coordinate systems. Supports various parameter combinations for texture tiling, mirroring, and offsets. ```APIDOC ## setupProjection Operation ### Description The `setupProjection` operation initializes a projection matrix for the chosen uv-set based on the reference coordinates system specified with `axes` selector. It can be chosen between scope and world coordinate systems. The `textureWidth` and `textureHeight` parameters support usage of the floating and relative operators to avoid complex calculations with the scope dimension. Optionally, the influence of the pixels's z-coordinate on the w-texture coordinate relative to the u-coordinate can be set. ### Syntax * `setupProjection(_uvSet, axes, textureWidth, textureHeight_) * `setupProjection(_uvSet, axesSelector, textureWidth, textureHeight, widthOffset, heightOffset_) * `setupProjection(_uvSet, axesSelector, textureWidth, textureHeight, widthOffset, heightOffset, uwFactor_) ### Parameters #### Path Parameters * **_uvSet** (float) - Required - Index of the uv-set (texture layer) to set up (integer number in [0,9]). The numbering corresponds to the texture layers of the material attribute. * **_axes** (selector) - Required - Describes the origin and which axes are taken as u- and v-axes. Possible values: `{ scope.xy | scope.xz | scope.yx | scope.yz | scope.zx | scope.zy }` or `{ world.xy | world.xz | world.yx | world.yz | world.zx | world.zy }`. * **_axesSelector** (selector) - Required - Describes the origin and which axes are taken as u- and v-axes. Possible values: `{ scope.xy | scope.xz | scope.yx | scope.yz | scope.zx | scope.zy }` or `{ world.xy | world.xz | world.yx | world.yz | world.zx | world.zy }`. * **textureWidth** (float) - Required - The texture width in world coordinate system units (e.g. meters). Values < 0 are allowed and mirror the texture. The operators ~ (floating) and ’ (relative) can be used. * **textureHeight** (float) - Required - The texture height in world coordinate system units (e.g. meters). Values < 0 are allowed and mirror the texture. The operators ~ (floating) and ’ (relative) can be used. * **widthOffset** (float) - Optional - The offset in u-direction, in world coordinate system units (e.g. meters). * **heightOffset** (float) - Optional - The offset in v-direction, in world coordinate system units (e.g. meters). * **uwFactor** (float) - Optional - Sets the factor by which the texture is applied on the w-axis relative to the u-axis. The default value is 0. ### Request Example ```cga // setup 1.5m x 1m texture tiles setupProjection(0, scope.xy, 1.5, 1, 0, 0, 1) // using dirtmap (uvSet #2) setupProjection(2, scope.xy, scope.sx, scope.sy, 0, 0, 1) ``` ### Response This operation does not return a value directly but modifies the projection matrix for subsequent UV operations. #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Get Tree Key in CGA: Basic Shape Derivation Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-get-tree-key-function.htm Demonstrates the use of the getTreeKey function in CGA to identify shapes during procedural generation. The TreeKey, a string list of integer numbers, represents the path from the root shape to the current shape. This example shows how TreeKey changes as shapes are split and derived. ```cga Init--> print(getTreeKey() + " - Init") center(xz) extrude(10) comp(f) { front: Facade} Facade--> print(getTreeKey() + " - Facade") split(y) {'0.5 : Floor }* Floor--> print(getTreeKey() + " - Floor") split(x) { '0.1 : Wall | '0.3 : Window | '0.1 : Wall }* Wall--> print(getTreeKey() + " - Wall") Window--> print(getTreeKey() + " - Window") ``` -------------------------------- ### CGA 'with' Keyword Examples Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-with-keyword.htm Demonstrates the usage of the 'with' keyword in CGA to define and utilize local variables within different contexts like attribute assignments, constant definitions, function calls, and rule applications. It shows how intermediate results can be stored and referenced. ```cga attr a with ( x := "example" ) = x const b with ( x := [0,1,2] y := 0 ) = x[y] f(a) with ( x := a y := x ) = y Lot with ( x := f(1) ) --> extrude(x) ``` ```cga dist2d(x1, y1, x2, y2) with ( d1 := x2-x1 d2 := y2-y1 ) = sqrt(d1*d1 + d2*d2) Lot --> print("distance: " + dist2d(1,1,2,2)) // 1.414 ``` ```cga Lot with ( area := geometry.area() ) --> s('2,0,'2) print("initial area: " + area) print("altered area: " + geometry.area()) ``` -------------------------------- ### Offsetting Texture Projection to Avoid Artifacts (CGA) Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-setup-projection.htm Demonstrates using offset parameters in setupProjection to avoid texture artifacts caused by numerical issues in different coordinate systems, ensuring consistent texture application. ```cga attr buildingheight = 20 const textureWidth = 586 const textureHeight = 442 offsetx = convert(x, scope, world, pos, 0, 0, 0) - (convert(x, scope, world, pos, 0, 0, 0) % textureWidth) offsetz = convert(z, scope, world, pos, 0, 0, 0) - (convert(z, scope, world, pos, 0, 0, 0) % textureHeight) Lot --> set(trim.vertical, false) extrude(buildingheight) comp(f) {top : Roof | side : Facade} Roof --> setupProjection(0, world.xz, textureWidth, textureHeight, -offsetx, offsetz) projectUV(0) scaleUV(0, 1, -1) set(material.colormap, "test_0102_ortho.jpg") ``` -------------------------------- ### Insert primitive cylinder in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-primitive-cylinder.htm Demonstrates the use of the primitiveCylinder operation. The first example fits the cylinder to the current scope, while the second example defines specific geometric parameters. ```CGA Lot--> primitiveCylinder() texture("builtin:uvtest.png") ``` ```CGA Lot--> primitiveCylinder(8,10,15) texture("builtin:uvtest.png") ``` -------------------------------- ### Example: Sampling Color on Cylinder Edges (CGA) Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-edge-attr-function.htm Illustrates sampling a string color attribute ('colors') for the vertical edges of a cylinder. This example demonstrates sampling on edges. ```cga Edge --> s('1,0,1) primitiveQuad Lot --> primitiveCylinder(22, 5, 10) comp(e) { vertical : color(getColor) Edge } ``` -------------------------------- ### CGA setupProjection and projectUV Operations Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-changelog.htm Shows the usage of the new `setupProjection` and `projectUV` operations in CGA, which replace the deprecated `setupUV` and `bakeUV` operations. These new operations provide enhanced control over UV mapping projections. ```cga setupProjection(...) ``` ```cga projectUV(...) ``` -------------------------------- ### CGA Example: Recursive Element Selection Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-item-operator-function.htm A practical example demonstrating how to use the index operator in conjunction with the size function to recursively find the index of the largest element in an array. ```cga indexOfLargest(array) = indexOfLargest(array, 0, 0) indexOfLargest(array, i, iLargest) = case i == size(array) : iLargest else : case array[i] > array[iLargest] : indexOfLargest(array, i+1, i) else : indexOfLargest(array, i+1, iLargest) const edgeLengths = comp(e) { all : scope.sx } indexOfLongestEdge = indexOfLargest(edgeLengths) Lot --> comp(e) { indexOfLongestEdge : LongestEdge. } ``` -------------------------------- ### Extruding Lot Shapes and Applying Roof Texture (CGA) Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-setup-projection.htm Shows how to extrude initial shapes to create mass models and then apply a roof texture using global axes for projection, including correction for inverted texture. ```cga attr buildingheight = 20 Lot --> set(trim.vertical, false) extrude(buildingheight) comp(f) {top : Roof | side : Facade} Roof --> setupProjection(0, world.xz, 586, 442) projectUV(0) scaleUV(0, 1, -1) set(material.colormap, "test_0102_ortho.jpg") ``` -------------------------------- ### Insert Quad Geometry with primitiveQuad Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-primitive-quad.htm Demonstrates how to use the primitiveQuad operation to insert a quad into the current scope. The first example fits the quad to the scope, while the second example defines specific dimensions. ```CGA Lot--> rotateScope(0, 0, 90) // scope.sx is 0 primitiveQuad() texture("builtin:uvtest.png") ``` ```CGA Lot--> rotateScope(0, 0, 90) // scope.sx is 0 primitiveQuad(10,20) texture("builtin:uvtest.png") ``` -------------------------------- ### Generating House Components with Push/Pop Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-pop-push.htm Shows how to generate a roof independently of the main building extrusion by using push/pop to manage the shape stack. ```CGA House --> [ t(0,10,0) roofHip(45) Roof. ] extrude(10) comp(f) { top : NIL | all = House. } ``` -------------------------------- ### Example: Sampling Color on Quad Face Edges (CGA) Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-edge-attr-function.htm Shows how to sample a string color attribute ('colors') for all face edges of a quad. This example highlights sampling on face edges. ```cga Lot --> primitiveQuad(10, 10) comp(fe) { all : color(getColor) Edge } ``` -------------------------------- ### CGA Example: Order of Operands in Subtract Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-boolean-3d-operations.htm Demonstrates the impact of operand order in the subtract operation. The example shows that subtracting a Cylinder from a Cube results in a different shape than subtracting a Cube from a Cylinder. ```cga Left --> subtract { Cube | Cylinder } Right --> subtract { Cylinder | Cube } Cube --> primitiveCube Blue Cylinder --> t(3,3,3) primitiveCylinder Green ``` -------------------------------- ### Apply Texture to Geometry in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-texture.htm This example demonstrates how to define a texture path and apply it to a facade using the texture operation. It includes the necessary setupProjection and projectUV operations to ensure the texture is mapped correctly to the geometry. ```CGA brickMap = "assets/bricks.jpg" randBuildingHeight = rand(3,20) Lot --> s('.75,'1,'.75) center(xz) extrude(world.up, randBuildingHeight) comp(f){side: Facade | top: set(material.color.a, .3) Roof.} Facade --> # color, uv set 0 setupProjection(0, scope.xy, 5, 5) texture(brickMap) // = set(material.colormap,brickMap) projectUV(0) ``` -------------------------------- ### Apply PBR Materials and Textures in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-material-attribute.htm This example demonstrates how to define material attributes and apply them to geometry using the set operation. It shows the workflow for setting a color, assigning a colormap and dirtmap, and projecting UV coordinates for proper texture alignment. ```CGA attr wallC = "#FFFFFF" attr wallTexture = "facade/walls/wall.c.09.tif" attr dirtTexture = "dirtmaps/dirtmap.16.tif" Wall --> primitiveCube() color(wallC) set(material.colormap, wallTexture) projectUV(0) set(material.dirtmap, dirtTexture) projectUV(2) ``` -------------------------------- ### Rotate Shape Around Scope Center (CGA) Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-r.htm This example shows how to rotate slices of a mass model around the shape's scope center. Similar to the scope origin example, it distributes rotation across the y-axis for each slice. ```cga height = 18 dy = 2 Lot--> extrude(height) split(y) { dy : r(scopeCenter, 0, 360*split.index/split.total, 0) X }* ``` -------------------------------- ### CGA Color Definitions for Examples Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-boolean-3d-operations.htm Defines a set of color constants used in various CityEngine CGA examples. These definitions allow for easy application of specific colors to geometry elements within the rules. ```cga Blue --> color("#0399F5") Green --> color("#09DE1F") Yellow --> color("#FADB19") Purple --> color("#8D09DE") Red --> color("#FF360A") Orange --> color("#FA9100") ``` -------------------------------- ### Encapsulating Rotations with Push/Pop Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-pop-push.htm Demonstrates how to use push/pop to make rotations independent of each other, ensuring that multiple shapes coincide at the same origin rather than building upon previous transformations. ```CGA Lot--> extrude(15) [ r(scopeCenter, 0, 22.5, 0) X ] [ r(scopeCenter, 0, 22.5, 0) X ] [ r(scopeCenter, 0, 22.5, 0) X ] ``` -------------------------------- ### contextCount Function Example (CGA) Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-context-count-function.htm Demonstrates the usage of the contextCount function in CGA to count shapes with the label 'Tile' and color them based on the count. This example applies a Lot rule, splits shapes, and then colors tiles conditionally. ```cga Lot --> split(x) { ~1 : Split }* Split --> split(z) { ~1 : Tile }* Tile --> label("Tile") Color Color --> case contextCount(intra, "Tile") <= 9 : color(0,1,0) else : color(1,0,0) ``` -------------------------------- ### Split Geometry into Vertices Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-comp.htm Demonstrates splitting models into vertices using 'v' or 'fv' selectors. This is useful for placing objects at specific vertex positions with defined coordinate system alignments. ```CGA Lot--> extrude(10) MassModel comp(v) { all : VShapes } Lot --> comp(fv) { all : VShapes. } ``` -------------------------------- ### CGA Example: Order of Operands in Union Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-boolean-3d-operations.htm Illustrates the effect of operand order in the union operation, specifically concerning material attributes. The example shows that the first operand determines the material of overlapping faces when shapes are unified. ```cga Left --> union { Quad | Circle } Right --> union { Circle | Quad } Quad --> primitiveQuad Blue Circle --> t(3,0,3) primitiveDisk Green ``` -------------------------------- ### CGA Geometry Cutting and NIL Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-split.htm Demonstrates how to insert geometry into a shape and use the NIL keyword within a split operation to create holes or cut surfaces. ```CGA A--> i("cylinder.hor.obj") t(0,'0.5,0) split(x) { { ~0.75 : XX | ~1 : NIL }* | ~0.5 : XX } ``` -------------------------------- ### CGA sum Function: Geometric Property Examples Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-sum-function.htm Examples demonstrating the use of the sum function in CGA for calculating geometric properties. This includes summing front lengths based on street scope and counting small faces based on geometry area. ```cga frontLength = sum( comp(fe) { street.front : scope.sx } ) numberSmallFaces = sum( comp(f) { all : geometry.area < 0.1 } ) ``` -------------------------------- ### Recursive Setbacks Example using resetGeometry Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-reset-geometry-operation.htm This example demonstrates how to apply setbacks recursively to calculate gross floor area. The resetGeometry operation is used before each setback to ensure it's applied relative to the initial shape. Shape attributes like color are preserved. ```cga const maxGFA = 5000 const floorHeight = 10 Example --> color("#FFAA00") SetBackRec(0, 0) SetBackRec(sumGFA, iFloor) --> resetGeometry() setback(iFloor*3) { all : NIL | remainder : Floor(sumGFA + geometry.area, iFloor) } Floor(sumGFA, iFloor) --> CreateFloor(sumGFA, iFloor) SetBackRec(sumGFA, iFloor + 1) CreateFloor(sumGFA, iFloor) --> set(material.opacity, case sumGFA > maxGFA : 0.1 else : 1) t(0, iFloor*floorHeight, 0) extrude(floorHeight) ``` -------------------------------- ### Create building footprint and extrusion in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-footprint-operation.htm This example demonstrates how to import a 3D asset and generate a schematic low-poly version by calculating the footprint and extruding it to a specific height. It includes setting material properties for visualization. ```CGA Example --> i("building.obj") ShowAsset. Footprint(scope.sy) Footprint(height) --> footprint() extrude(height) set(material.opacity, 0.25) ``` -------------------------------- ### CGA Boolean Operations: Reference Table Examples Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-boolean-3d-operations.htm Provides reference examples for various combinations of open and closed operands in union, subtract, and intersect operations. This table clarifies how the operations behave based on operand closure and orientation. ```cga union { Blue | Green } subtract { Blue | Green } subtract { Green | Blue } intersect { Blue | Green } inline(unify) { Green Blue } ``` -------------------------------- ### Translate shape along world and object axes in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-translate.htm Examples demonstrating the use of the translate operation to shift primitive cubes by two units along the x-axis. The first example uses the world coordinate system, while the second uses the object coordinate system. ```CGA Init --> split(x) { '0.2 : split(z) { '0.2 : PP }* }* PP --> 43% : primitiveCube() X translate(rel, world, 2, 0, 0) color("#ff0000") X else : NIL ``` ```CGA Init --> split(x) { '0.2 : split(z) { '0.2 : PP }* }* PP --> 43% : primitiveCube() X translate(rel, object, 2, 0, 0) color("#ff0000") X else : NIL ``` -------------------------------- ### CGA setupProjection Operators Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-changelog.htm Shows the new `~` and `'` operators that can be used with the `setupProjection` operation in CGA. These operators provide additional control for setting up UV projections. ```cga setupProjection ~ ... ``` ```cga setupProjection ' ... ``` -------------------------------- ### CGA Example: Order of Operands in Intersect Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-boolean-3d-operations.htm Shows how the order of operands affects the resulting shape's attributes when using the intersect operation. The example highlights that the first operand dictates the attributes (like extrusion height) of the final intersected geometry. ```cga attr Height = 0 Left --> intersect { Quad | Circle } extrude(Height) // Height == 10 Right --> intersect { Circle | Quad } extrude(Height) // Height == 1 Quad --> set(Height, 10) primitiveQuad Circle --> set(Height, 1) t(3,0,3) primitiveDisk ``` -------------------------------- ### Initialize 1D and 2D Arrays in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-array-initialization-function.htm Demonstrates how to create 1D arrays using comma separators and 2D arrays using semicolon separators to define rows. It also shows how to nest existing arrays within new array structures. ```CGA const a = ["B", "C", "D"] const b = ["A", a, "E"] const c = [-1 ; -2] const d = [0:2 ; 3, 3, 3] const e = [a, b ; b, a] ``` -------------------------------- ### Use Built-in Cube with UV Test Texture in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-builtin-assets-and-textures.htm This example shows how to initialize a unit cube and apply the built-in UV test texture in CityEngine's CGA language. It requires no external dependencies. ```cga Init--> primitiveCube() texture("builtin:uvtest.png") ``` -------------------------------- ### CGA Split Shape Attribute Example Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-split-attribute.htm This example demonstrates how to use the split.index and split.total attributes in CGA to apply different colors based on the shape's position within a split operation. The split.index represents the current shape's index, and split.total represents the total number of shapes after the split. ```cga Lot --> extrude(20) A A --> split(y){2 : B}* B --> case (split.index == 0) : color("#ff0000") X case (split.index == split.total-1) : color("#0000ff") X else: X ``` -------------------------------- ### Basic setback operation syntax Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-setback.htm Demonstrates the fundamental syntax for applying setbacks to specific edges or the remainder of a shape. ```CGA setback(4) { front : Shape } setback(4) { front : NIL | remainder : Remainder } ``` -------------------------------- ### CGA Boolean Operations: Handling Open and Closed Operands Example Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-boolean-3d-operations.htm Illustrates how CityEngine handles Boolean operations with open (e.g., planes) and closed operands. In 3D, open operands are treated as closed unless boundaries intersect. The example shows using 'bool' auto-tags for subsequent comp operations. ```cga subtract { Blue | Green } intersect { Blue | Green } comp(f) { isTagged("bool.A") : Blue } ``` -------------------------------- ### CityEngine CGA Example: Coloring based on contextCompare Ranks Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-context-compare-function.htm This example demonstrates how to use the contextCompare function in CityEngine CGA to apply different colors to geometries based on their ranks. It first applies a Lot rule, extrudes, and labels shapes. Then, it uses contextCompare to identify the highest and lowest ranked geometries for specific coloring. ```cga Lot --> extrude(rand(10)) label("label") Color Color --> case contextCompare(inter, "label", world.highest) == 0 : color(1,0,0) case contextCompare(inter, "label", world.lowest) == 0 : color(0,1,0) else : color(0,0,1) ``` -------------------------------- ### Basic Extrusion Operations in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-extrude.htm Demonstrates standard extrusion techniques including extrusion along face normals and vertex normals. These examples show how to apply distance parameters to define the height of the resulting 3D geometry. ```CGA Lot --> extrude(10) Lot --> extrude(face.normal, 10) Lot --> extrude(vertex.normal, 10) ``` -------------------------------- ### CGA O-Shape generation Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-shapeluo-operations.htm Example of generating an O-shaped footprint within a lot using the shapeO operation. ```CGA attr myFrontDepth = 5 attr myRightWidth = 3 attr myBackDepth = 2 attr myLeftWidth = 11 LotInner --> Lot Lot --> offset( -3, inside) shapeO( myFrontDepth, myRightWidth, myBackDepth, myLeftWidth ) { shape : Footprint | remainder : NIL } Footprint --> extrude(rand(10,20)) color(1,0,0) ``` -------------------------------- ### Load Plants with Dynamic Imports in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-import-keyword.htm This CGA example shows how to use dynamic imports for the plant loader, allowing the 'plant.Name' attribute to be set at runtime. This provides flexibility in choosing tree types and ensures dependent attributes like height and radius are correctly re-initialized. ```cga import plant:"/ESRI.lib/rules/Plants/Plant_Loader.cga" getName = 33% : "California Bay" 33% : "California Incense Cedar" else : "California Walnut" Lot --> scatter(surface, 10, uniform) { Plant } Plant --> plant( Name = getName ).Generate ``` -------------------------------- ### CGA U-Shape generation Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-shapeluo-operations.htm Example of generating a U-shaped footprint within a lot using the shapeU operation. ```CGA attr myFrontDepth = 5 attr myRightWidth = 3 attr myLeftWidth = 11 LotInner --> Lot Lot --> offset(-3, inside) shapeU(myFrontDepth,myRightWidth,myLeftWidth) { shape : Footprint | remainder : NIL } Footprint --> extrude(rand(10,20)) color(1,0,0) ``` -------------------------------- ### CGA L-Shape generation Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-shapeluo-operations.htm Example of generating an L-shaped footprint within a lot using the shapeL operation. ```CGA attr myFrontDepth = 5 attr myLeftWidth = 11 LotInner --> Lot Lot --> offset(-3,inside) shapeL(myFrontDepth,myLeftWidth) { shape : Footprint | remainder : NIL } Footprint --> extrude(rand(10,20)) color(1,0,0) ``` -------------------------------- ### CGA UV Space Splitting Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-split.htm Illustrates splitting based on UV coordinates using either uvSpace (normalized) or unitSpace (absolute). Useful for texture-based subdivision on facades. ```CGA Facade--> setupProjection(0, scope.xy, '1, '1) projectUV(0) texture("builtin:uvtest.png") split(u, uvSpace, 0) { 0.5 : X }* Facade--> setupProjection(0, scope.xy, '1, '1) projectUV(0) texture("builtin:uvtest.png") split(u, unitSpace, 0) { 5 : X }* ``` -------------------------------- ### Offsetting Split Patterns in CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-split-and-setback-perimeter.htm Demonstrates how to offset the start of a split pattern by a percentage of the perimeter length using the splitOffset parameter. ```CGA Lot --> splitAndSetbackPerimeter('0.1) { '0.5 : 10 : extrude(15) Yellow | ~1 : 0 : NIL | '0.4 : 8 : extrude(10) Blue | ~1 : 0 : NIL } { remainder : Grey } ``` -------------------------------- ### CGA Split Operations Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-split.htm Demonstrates various split techniques including relative sizes, floating ratios, absolute constraints, and repeat splits. These operations allow for complex geometric subdivision of shapes. ```CGA A--> split(x){ '0.5 : Z | '0.1 : Y(2) | '0.2 : X(1) } A--> split(x){ ~0.5 : Z | ~0.1 : Y(2) | ~0.2 : X(1) } A--> split(x){ 3.3 : Z(1) | ~3 : Y(2) | 5 : X(1) } A--> split(x){ 2 : X(2) | 1 : Y(1) }* A--> split(x){ ~2 : X(2) | ~1 : Y(1) }* ``` -------------------------------- ### Trim Plane Insertion and Cutting Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-comp.htm Illustrates the use of trim planes to cut inserted geometry. It shows default trim plane insertion, cutting with default planes, and enabling/disabling horizontal trim planes for different results. ```cga Start--> s(10,10,10) primitiveCube() comp(f) {5 : X } ``` ```cga X--> s(15,'1, 2) center(xyz) primitiveCube() ``` ```cga Start--> s(10,10,10) primitiveCube() set(trim.horizontal, true) comp(f) {5 : X } ``` -------------------------------- ### Generate Simple Temple Model with CGA Source: https://doc.arcgis.com/en/cityengine/2025.1/cga/cga-import-keyword.htm This rule file defines a simple temple model using CGA. It includes rules for generating columns and a hip roof, with customizable column height. Extension rules and attributes can be redefined in import statements for customization. ```cga // temple.cga attr columnHeight = 12 start Temple --> CreateColumns CreateRoof extension Column --> primitiveCube extension Roof --> roofHip(22) const columnWidth = columnHeight/9 CreateColumns --> offset(-columnWidth, border) comp(f) { all : extrude(columnHeight) split(x) { { ~columnWidth : Column | ~2*columnWidth : NIL }* | ~columnWidth : NIL } } CreateRoof --> t(0,columnHeight,0) Roof ```