Unity & CityEngine 根据地图中建筑矢量数据批量建模

举报
CoderZ1010 发表于 2022/09/25 05:09:57 2022/09/25
【摘要】 1.首先要拿到目标区域的建筑矢量数据 2.在City Engine中新建一个工程 工程命名 3.将建筑矢量数据导入到CityEngine中 导入建筑矢量数据   4.新建一个场景   5.将shp数据文件拖入到场景当中 6.选择所有Shapes,赋予一个建模规则 我们也...

1.首先要拿到目标区域的建筑矢量数据

2.在City Engine中新建一个工程

工程命名

3.将建筑矢量数据导入到CityEngine中

导入建筑矢量数据

 

4.新建一个场景

 

5.将shp数据文件拖入到场景当中

6.选择所有Shapes,赋予一个建模规则

我们也可以自定义一个建模规则,下面是CityEngine中内置的规则文件,可供参考:


  
  1. /**
  2. * File: Building_From_Footprint.cga
  3. * Created: 20 Mar 2011 16:42:13 GMT
  4. * Updated: 10 April 2014
  5. * Author: Esri R&D Center Zurich
  6. */
  7. version "2014.0"
  8. @Hidden(Usage,BuildingHeight,UpperfloorHeight)
  9. import Facade_Textures:"/ESRI.lib/rules/Facades/Facade_Textures.cga" (BuildingHeight=Eave_Ht,UpperfloorHeight=Floor_Ht*unitScale,Usage=Usage)
  10. @Hidden(Usage,UpperfloorHeight)
  11. import Facade_Schematic:"/ESRI.lib/rules/Facades/Facade_Schematic.cga" (UpperfloorHeight=Floor_Ht*unitScale,Usage=Usage)
  12. import Roof_Textures:"/ESRI.lib/rules/Roofs/Roof_Textures.cga"
  13. ###################################
  14. # Attributes
  15. #
  16. @Group("Building Settings",1)
  17. @Order(1) @Range(1,400) @Description("Distance from ground to bottom of roof")
  18. attr Eave_Ht = _getInitialEaveHeight
  19. @Order(2) @Range(1,400) @Description("Distance from ground to top of roof")
  20. attr Ridge_Ht = _getInitialRidgeHeight
  21. @Order(3) @Range("Random","Agricultural","Assembly","Educational","Industry","Mercantile","Office","Other","Public","Residential","Service","Transport","Unknown","Utility")
  22. attr Usage = _getInitialUsage
  23. @Order(4) @Range("extrusion","setback top","setback facade","setback base","setback everywhere")
  24. attr Building_Form = _getInitialBuildingForm
  25. @Order(5) @Range("flat","shed","pyramid","gable","hip","half-hip","gablet","gambrel","mansard","gambrel-flat","mansard-flat","vault","dome","saltbox","butterfly") # gable & shed combinations
  26. attr Roof_Form = _getInitialRoofForm
  27. @Order(6) @Range(2.9,5.2) @Description("in Meters")
  28. attr Floor_Ht = 3.7
  29. @Hidden
  30. attr Roof_Ht = (Ridge_Ht - Eave_Ht) * unitScale
  31. @Group("Visualization Options",2)
  32. @Order(1) @Range("realistic with facade textures","schematic facades","solid color")
  33. attr Representation = "realistic with facade textures"
  34. @Order(2) @Range(0,1)
  35. attr Transparency = 0
  36. @Order(3) @Range(0,1)
  37. attr OverwriteColor = "#ffffff"
  38. @Group("Rule Options")
  39. @Order(2) @Range("Meters","Feet") @Description("Unit of Height Attributes")
  40. attr Unit = "Meters"
  41. ###################################
  42. # Consts
  43. #
  44. # user-driven constants
  45. const unitScale = case Unit=="Feet": 1/0.3048006096012192 else: 1
  46. # for curved roofs such as dome or vault
  47. const curvedAngleResolution = 10
  48. ###################################
  49. # Functions
  50. #
  51. # for curved roofs such as dome or vault
  52. calcSegmentHt(n) = Roof_Ht * (cos(n*curvedAngleResolution) - cos((n+1)*curvedAngleResolution))
  53. _getInitialBuildingForm =
  54. case Eave_Ht*unitScale < 50 : "extrusion"
  55. case Eave_Ht*unitScale > 100: "setback everywhere"
  56. else : 5%:"extrusion" 15%:"setback top" 15%:"setback facade" 15%:"setback base" else:"setback everywhere"
  57. _getInitialUsage =
  58. case Eave_Ht>30: "Random" else: 80%:"Residential" else:"Random"
  59. _getInitialEaveHeight =
  60. case geometry.area < 100 : geometry.area/rand(5,10)
  61. case geometry.area < 1000: geometry.area/rand(15,25)
  62. case geometry.area < 7000: geometry.area/rand(10,25)
  63. else : geometry.area/rand(70,200)
  64. _getInitialRidgeHeight =
  65. case Eave_Ht<30: Eave_Ht+rand(3,6) else: Eave_Ht
  66. _getInitialRoofForm =
  67. case Ridge_Ht < Eave_Ht+1: "flat"
  68. else: 40%: "hip" 50%: "gable" else: "gambrel"
  69. ###################################
  70. ###################################
  71. #
  72. # RULES
  73. #
  74. ###################################
  75. ###################################
  76. @StartRule
  77. Generate -->
  78. cleanupGeometry(all,1)
  79. alignScopeToAxes(y) s('1,0,'1) # make it horizontal i.e. scale it flat
  80. alignScopeToGeometry(yUp, 0, longest)
  81. set(Eave_Ht,Eave_Ht*unitScale)
  82. set(Floor_Ht,Floor_Ht*unitScale)
  83. report("Footprint Area (m2)",geometry.area) report("Nbr of Floors",rint(Eave_Ht/Floor_Ht))
  84. set(material.opacity,1-Transparency)
  85. color(OverwriteColor)
  86. Footprint
  87. ###################################
  88. # Building Mass
  89. #
  90. Footprint -->
  91. case scope.sz < 10 || scope.sx < 10:
  92. Extrusion(Eave_Ht,true,1)
  93. case Building_Form == "setback top":
  94. SetbackTop
  95. case Building_Form == "setback facade":
  96. SetbackFacade
  97. case Building_Form == "setback base":
  98. SetbackBase
  99. case Building_Form == "setback everywhere":
  100. SetbackAll
  101. else:
  102. Extrusion(Eave_Ht,true,1)
  103. SetbackTop -->
  104. split(x){ 'rand(0.1,0.3): Extrusion(Eave_Ht-rint(rand(3))*Floor_Ht,false,4)
  105. | ~1 : Extrusion(Eave_Ht,true,6)
  106. | 'rand(0.1,0.3): Extrusion(Eave_Ht-rint(rand(3))*Floor_Ht,false,4) }
  107. SetbackFacade -->
  108. split(z){ 'rand(0.03,0.2): Extrusion(Eave_Ht*rand(0.2,0.8),false,2)
  109. | ~1 : Extrusion(Eave_Ht,true,6)
  110. | 'rand(0.03,0.2): Extrusion(Eave_Ht*rand(0.2,0.8),false,2) }
  111. SetbackBase -->
  112. [ extrude(3*Floor_Ht) Mass(false) ]
  113. t(0,3*Floor_Ht,0)
  114. split(x){ 'rand(0.6,0.8): Extrusion(Eave_Ht-3*Floor_Ht,true,6) }
  115. SetbackAll -->
  116. [ extrude(3*Floor_Ht) Mass(false) ]
  117. t(0,3*Floor_Ht,0)
  118. set(Eave_Ht,Eave_Ht-3*Floor_Ht)
  119. split(x){ 'rand(0.6,0.8):
  120. split(z){ '0.2: Extrusion(Eave_Ht*rand(0.2,0.8),false,2)
  121. | ~1 : SetbackTop
  122. | '0.2: Extrusion(Eave_Ht*rand(0.2,0.8),false,2) }
  123. }
  124. Extrusion(height,constructRoof,maxLength) -->
  125. convexify(maxLength)
  126. comp(f){ all: alignScopeToGeometry(yUp, 0, longest) ExtrusionConvexified(height,constructRoof,maxLength) }
  127. ExtrusionConvexified(height,constructRoof,maxLength) -->
  128. case scope.sx < maxLength+1 || scope.sz < maxLength+1: NIL
  129. else:
  130. report("Gross Floor Area (m2)",geometry.area*rint(height/Floor_Ht))
  131. extrude(height) Mass(constructRoof)
  132. Mass(constructRoof) -->
  133. case constructRoof:
  134. comp(f){side : Facade | top : Roof }
  135. else:
  136. comp(f){side : Facade | top : RoofPlane }
  137. ###################################
  138. # Roof Generation
  139. #
  140. Roof -->
  141. case Roof_Form == "shed" : ShedRoof
  142. case Roof_Form == "pyramid" : PyramidRoof
  143. case Roof_Form == "gable" : GableRoof
  144. case Roof_Form == "hip" : HipRoof
  145. case Roof_Form == "half-hip" : HalfHipRoof
  146. case Roof_Form == "gablet" : GabletRoof
  147. case Roof_Form == "gambrel" : GambrelRoof
  148. case Roof_Form == "mansard" : MansardRoof
  149. case Roof_Form == "gambrel-flat": GambrelFlatRoof
  150. case Roof_Form == "mansard-flat": MansardFlatRoof
  151. case Roof_Form == "vault" : VaultRoof
  152. case Roof_Form == "dome" : DomeRoof
  153. case Roof_Form == "saltbox" : SaltboxRoof
  154. case Roof_Form == "butterfly" : ButterflyRoof
  155. else : FlatRoof
  156. # basic roof types
  157. ShedRoof -->
  158. roofShed(15) RoofMassScale
  159. GableRoof -->
  160. roofGable(45,0,0,false,0) RoofMassScale
  161. HipRoof -->
  162. roofHip(45) RoofMassScale
  163. PyramidRoof -->
  164. roofPyramid(45) RoofMassScale
  165. # gable & hip combinations
  166. HalfHipRoof -->
  167. roofGable(45,0,0,false,0) s('1,Roof_Ht,'1) # creates a gable roof and sets its height to the given roof height
  168. split(y){ '0.5: RoofMass(true) # ...
  169. comp(f){ bottom: NIL | horizontal: set(Roof_Ht,Roof_Ht*0.5) HipRoof } } # ... and invokes a hip roof on the top
  170. GabletRoof -->
  171. roofHip(45) s('1,Roof_Ht,'1)
  172. split(y){ '0.5: RoofMass(true)
  173. comp(f){ bottom: NIL | horizontal: set(Roof_Ht,Roof_Ht*0.5) GableRoof } }
  174. # gable/hip double-pitched
  175. GambrelRoof -->
  176. roofGable(70,0,0,false,0)
  177. split(y){ Roof_Ht*0.7: RoofMass(true)
  178. comp(f){ bottom: NIL | horizontal: set(Roof_Ht,Roof_Ht*0.3) GableRoof } }
  179. MansardRoof -->
  180. roofHip(70)
  181. split(y){ Roof_Ht*0.7: RoofMass(true)
  182. comp(f){ bottom: NIL | horizontal: set(Roof_Ht,Roof_Ht*0.3) HipRoof } }
  183. # gable/hip with flat top
  184. GambrelFlatRoof -->
  185. roofGable(45,0,0,false,0)
  186. split(y){ Roof_Ht: RoofMass(false) }
  187. MansardFlatRoof -->
  188. roofHip(45)
  189. split(y){ Roof_Ht: RoofMass(false) }
  190. # round roofs
  191. VaultRoof -->
  192. VaultRoof(90/curvedAngleResolution-1)
  193. VaultRoof(n) -->
  194. case n > 0: roofGable(n*curvedAngleResolution,0,0,false,0)
  195. split(y){ (calcSegmentHt(n)): RoofMass(n!=1)
  196. comp(f){ bottom: NIL | horizontal: VaultRoof(n-1) } }
  197. else: NIL
  198. DomeRoof -->
  199. DomeRoof(90/curvedAngleResolution-1)
  200. DomeRoof(n) -->
  201. case n > 0: roofHip(n*curvedAngleResolution)
  202. split(y){ (calcSegmentHt(n)): RoofMass(n!=1)
  203. comp(f){ bottom: NIL | horizontal: DomeRoof(n-1) } }
  204. else: NIL
  205. # gable & shed combinations
  206. SaltboxRoof -->
  207. roofShed(45) s('1,1.5*Roof_Ht,'1)
  208. split(y){ '0.333: RoofMass(true)
  209. comp(f){ bottom: NIL | horizontal: set(Roof_Ht,Roof_Ht*0.5) roofGable(45,0,0,false,geometry.nVertices-1) RoofMassScale } }
  210. ButterflyRoof -->
  211. split(y){ '0.5: roofShed(45,geometry.nVertices/2) RoofMassScale | '0.5: ShedRoof }
  212. # flat roof
  213. FlatRoof -->
  214. case Roof_Ht > 0.1:
  215. RoofPlane offset(-0.4,border) extrude(Roof_Ht) RoofMass(false)
  216. else:
  217. RoofPlane
  218. # roof volume
  219. RoofMassScale -->
  220. s('1,Roof_Ht,'1)
  221. RoofMass(false)
  222. RoofMass(removeBottomAndTop) -->
  223. case removeBottomAndTop:
  224. comp(f){ horizontal: NIL | vertical: Facade | all: RoofPlane }
  225. else: # remove only the bottom face
  226. comp(f){ bottom: NIL | vertical: Facade | all: RoofPlane }
  227. ###################################
  228. # Surface Texturing & Coloring
  229. #
  230. RoofPlane -->
  231. case Representation == "realistic with facade textures":
  232. Roof_Textures.Generate
  233. else:
  234. SolidColor
  235. Facade -->
  236. case Representation == "realistic with facade textures":
  237. Facade_Textures.Generate
  238. case Representation == "schematic facades":
  239. case OverwriteColor == "#ffffff":
  240. Facade_Schematic.Generate
  241. else:
  242. set(Facade_Schematic.SecondaryColor,OverwriteColor)
  243. Facade_Schematic.Generate
  244. else:
  245. SolidColor
  246. SolidColor -->
  247. color(OverwriteColor)

7.点击Generate,根据建模规则生成建筑模型

8.导出.fbx格式文件

9.将导出的.fbx文件连同贴图一起导入到Unity中

10.将模型放到场景中查看效果

文章来源: coderz.blog.csdn.net,作者:CoderZ1010,版权归原作者所有,如需转载,请联系作者。

原文链接:coderz.blog.csdn.net/article/details/124466335

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。