// Source: peyep 官方 demo 回填(原始 cityengine 规则)· https://www.peyep.com/#/demo/haobite-block-20260927 /** * File: CreateUrbanHouBiTel-1.cga * Created: 3 Aug 2023 04:37:35 GMT * Author: mapda */ version "2022.1" ##### block buildlot attr attr WallHeight = 0.2 # 城墙高度 attr pier_thickness = 1 #墙垛厚度 attr pier_Width = 1.2 attr top_Height = 0 const MerlonWidth = pier_Width const PlatformWidth = 0.3 const StepWidth = 0.5 //const StepCount = 0 const totalWidth = pier_thickness + PlatformWidth + stepsWidth const stepsWidth = StepWidth*3 const battlementBaseHeight = WallHeight + top_Height const platformHeight = WallHeight ##### total attr // attr width = 120 // attr length = 160 attr perShapeChimneyProbability = 0.35 ##### const tree model const treeSpacing = 10 const tree_width = 0.9 const tree_height = 3 const treeStump_width = 0.2 const treeStump_height = 0.5 const treeStumpOverlap = 0.1 ##### const color const roofcolor ="#5B5B5B" const gardoncolor = "#B9B973" const sidewalkcolor = "#d0d0d0" const streetsidecolor = "#9D9D9D" const treecolor = "#C2FF68" const stonecolor = "#462b18" const rivercolor = "#5CADAD" const riversidecolor = "#F0FFF0" const treepoolcolor = "#BEBEBE" const grasscolor = "#CCCC99" const bridgecolor = "#FFEEDD" ##### Roof attr const roofAngle = rand(30,40) const chimneyDimXZ = rand(.8, 1.4) const chimneyDimY = rand(2, 3) const cupolaDimXZ = rand(1.5,3) const cupolaDimY = rand(1.5,3) ##### // 屋顶自定义函数 roofTexDimHorizontal = 1.5 roofTexDimVertical = 1.5 dirt_tex = "" relativeHeight = 0.65 #################### #################### #################### #################### Lot--> primitiveQuad(width, length) split(x){39 : split(z){38 : blocklot |{ 5 :roadlot | 57 :blocklot }* } | { 3 : split(z){34.5 : roadlot |{ 12 :roadlot | 53.5 :roadlot }* } | 58 : split(z){38 : blocklot |{ 5 :roadlot | 57 :blocklot }* } | 5 : split(z){38 : roadlot |{ 5 :roadlot | 57 :roadlot }* } }* } //建筑地块生成 blocklot--> alignScopeToAxes(y) //s('1,0,'1) offset(-totalWidth) comp(f){border: reverseNormals alignScopeToAxes(y) roadside | inside : buildlot} // 道路 铺装 行道树 roadside --> split(z) {stepsWidth : color(gardoncolor)Steps | PlatformWidth : extrude(-WallHeight * 0.95) Platform | pier_thickness : Battlement} Battlement --> extrude(-battlementBaseHeight) comp(f){top: Crenels | front: RockTextureOffset | all : RockTexture} Crenels --> //行道树与铺地 split(x){ ~(MerlonWidth * 0.5): color(sidewalkcolor) RockTextureTop | {~MerlonWidth *5: color(sidewalkcolor)RockTextureTop| pier_Width: treepool}* | ~MerlonWidth *5: color(sidewalkcolor)RockTextureTop | ~(MerlonWidth * 0.5): color(sidewalkcolor)RockTextureTop} treepool--> [Treemodel] //封装行道树模型 offset(-0.15) comp(f) { inside : color(grasscolor)grasslot| border : extrude(0.05) color(treepoolcolor) poorside } // tree模型规则编写 Treemodel--> //reverseNormals alignScopeToAxes(y) //约束y轴朝上并垂直 s(tree_width, tree_height, tree_width) //r(90,0,0) center(xz) primitiveCube() TreeStump TreeCrown TreeStump--> s(treeStump_width, treeStump_height + treeStumpOverlap, treeStump_width) center(xz) primitiveCylinder() color(treecolor) TreeCrown--> t(0, treeStump_height, 0) s('1, tree_height-treeStump_height, '1) primitiveSphere() color(treecolor) treelot--> Treemodel // 生成建筑地块 buildlot--> splitAndSetbackPerimeter(0) { rand(1,2) : rand(1.2, 2.3) : lottobuild }* { remainder : centerlot } centerlot--> setback(1.5) { all : blockroadside | remainder : centerbuildlot } blockroadside--> roadlot centerbuildlot--> case geometry.area>100 : split(x){~12 : split(y){~12 : otherbuildlot | ~3 :roadlot | ~13:otherbuildlot } | ~3.5 : split(y){~3.5 : roadlot | ~5 :roadlot | ~3.5:roadlot } | ~12 : split(y){~12 : otherbuildlot | ~5 :roadlot | ~17:otherbuildlot } } else : otherbuildlot otherbuildlot--> splitAndSetbackPerimeter(0) { 5 : rand(0.7, 2.7) : gardonlot }* { remainder : centerbuild} //生成主要建筑 centerbuild--> case geometry.area>55:extrude(rand(3.5,5))comp(f){side: buildsidefacade | top: RR} else :gardonlot //场景其他要素 lottobuild--> 10% : color(rand(0,1),rand(0,1),rand(0,1))extrude(rand(0.25, 0.5)) anybox. else : gardonlot //屋顶样式生成 RR--> //Acoperis.Roof //report("mianji", geometry.area) case geometry.area > 350 : roofGable(rand(21,32)) comp(f) {bottom : NIL | all : //RoofPlane setupProjection(0, scope.xy, roofTexDimHorizontal, roofTexDimVertical) # scope is zUp after comp(f) ! projectUV(0) texture ( "Textures/Houses/Roofs/roof1.jpg" ) # dirt, UV set 2 setupProjection(2, scope.xy, '1, '1) projectUV(2) set (material.dirtmap, dirt_tex ) translateUV(2, rand(1), 0) roof1. alignScopeToAxes(y) split(y) {'relativeHeight : NIL | ~1:PotentialChimneyShape} } case geometry.area > 300 : roofHip(rand(21,32)) comp(f) {bottom : NIL | all : //RoofPlane setupProjection(0, scope.xy, roofTexDimHorizontal, roofTexDimVertical) # scope is zUp after comp(f) ! projectUV(0) texture ( "Textures/Houses/Roofs/roof2.jpg" ) # dirt, UV set 2 setupProjection(2, scope.xy, '1, '1) projectUV(2) set (material.dirtmap, dirt_tex ) translateUV(2, rand(1), 0) roof2. alignScopeToAxes(y) split(y) {'relativeHeight : NIL | ~1:PotentialChimneyShape} } case geometry.area > 250 : roofGable(rand(21,32)) comp(f) {bottom : NIL | all : //RoofPlane setupProjection(0, scope.xy, roofTexDimHorizontal, roofTexDimVertical) # scope is zUp after comp(f) ! projectUV(0) texture ( "Textures/Houses/Roofs/roof3.jpg" ) # dirt, UV set 2 setupProjection(2, scope.xy, '1, '1) projectUV(2) set (material.dirtmap, dirt_tex ) translateUV(2, rand(1), 0) roof3. alignScopeToAxes(y) split(y) {'relativeHeight : NIL | ~1:PotentialChimneyShape} } case geometry.area > 200 : roofHip(rand(21,32)) comp(f) {bottom : NIL | all : //RoofPlane setupProjection(0, scope.xy, roofTexDimHorizontal, roofTexDimVertical) # scope is zUp after comp(f) ! projectUV(0) texture ( "Textures/Houses/Roofs/roof4.jpg" ) # dirt, UV set 2 setupProjection(2, scope.xy, '1, '1) projectUV(2) set (material.dirtmap, dirt_tex ) translateUV(2, rand(1), 0) roof4. alignScopeToAxes(y) split(y) {'relativeHeight : NIL | ~1:PotentialChimneyShape} } case geometry.area > 150 : roofGable(rand(21,32)) comp(f) {bottom : NIL | all : //RoofPlane setupProjection(0, scope.xy, roofTexDimHorizontal, roofTexDimVertical) # scope is zUp after comp(f) ! projectUV(0) texture ( "Textures/Houses/Roofs/roof5.jpg") # dirt, UV set 2 setupProjection(2, scope.xy, '1, '1) projectUV(2) set (material.dirtmap, dirt_tex ) translateUV(2, rand(1), 0) roof5. alignScopeToAxes(y) split(y) {'relativeHeight : NIL | ~1:PotentialChimneyShape} } case geometry.area > 100 : roofHip(rand(21,32)) comp(f) {bottom : NIL | all : //RoofPlane setupProjection(0, scope.xy, roofTexDimHorizontal, roofTexDimVertical) # scope is zUp after comp(f) ! projectUV(0) texture ( "Textures/Houses/Roofs/roof6.jpg") # dirt, UV set 2 setupProjection(2, scope.xy, '1, '1) projectUV(2) set (material.dirtmap, dirt_tex ) translateUV(2, rand(1), 0) roof6. alignScopeToAxes(y) split(y) {'relativeHeight : NIL | ~1:PotentialChimneyShape} } else : //geometry.area > 300 : roofGable(rand(21,32)) comp(f) {bottom : NIL | all : //RoofPlane setupProjection(0, scope.xy, roofTexDimHorizontal, roofTexDimVertical) # scope is zUp after comp(f) ! projectUV(0) texture ( "Textures/Houses/Roofs/roof7.jpg" ) # dirt, UV set 2 setupProjection(2, scope.xy, '1, '1) projectUV(2) set (material.dirtmap, dirt_tex ) translateUV(2, rand(1), 0) roof7. alignScopeToAxes(y) split(y) {'relativeHeight : NIL | ~1:PotentialChimneyShape} } PotentialChimneyShape --> case geometry.angle(maxSlope) > 59 : # delete almost vertical shapes NIL else : ChimneyShape ChimneyShape --> case p(perShapeChimneyProbability) : scatter(surface, 1, uniform){PutChimney} else : NIL PutChimney --> 75%: alignScopeToAxes(y) s(chimneyDimXZ, chimneyDimY, chimneyDimXZ) center(xz) t(0,-0.4,0) i(fileRandom("Objects/Chimneys/Chimney*.obj")) Chimney. else: alignScopeToAxes(y) s(cupolaDimXZ, cupolaDimY, cupolaDimXZ) center(xz) t(0,-0.7,0) i(fileRandom("Objects/Chimneys/Copula*.obj")) Chimney. // 绿化部分 gardonlot--> color(gardoncolor) lvhua. //路生成 roadlot--> color("#7B7B7B") road_tex.