CityEngine2016-学习笔记(1)writing rules

这是学习CGA规则的笔记,版本是cityengine 2016.0,参考help文件。
CityEngine Help Manual > Rule-based Modeling > Writing Rules

1 Standard Rule 标准规则

形式上:

PredecessorShape --> Successor

示例:

Lot -->s('0.8, '1, '0.8) center(xz) extrude(20) Envelope
Envelope -->split(y) { ~4: Floor.} *

注意:在Floor后面加“.”,可以避免编辑器的错误提醒“undefined”

1.1 物体坐标

Geometry
Scope
Pivot

1.2 s operation

s(float xSize, float ySize, float zSize)
参数:xSize (float), ySize (float), zSize (float)
Sizes of the new scope dimensions.
s命令设置向量“scope.s”,相对操作符“’”设置相对的比例,举例:
s('sx, 0, 0) 等价于 s(sx * scope.sx, 0, 0)
举栗:
s('0.5,'1,'1.5) 等价于 s(0.5scope.sx,scope.sy,1.5scope.sz)

1.3 center()

center(axesSelector)
参数:axesSelector (keyword)
Axes to include in center calculation (x|y|z|xy|xz|yz|xyz).
轴选项,可以使xyz的任意平面、轴,或者xyz三维空间
The center operation moves the scope of the current shape tothe center of the previous shape’s scope.‘Previous shape’ means the previous shape on the shape stack.

在代码示例中,center是解释s操作的,cityengine坐标轴如上图所示,与cad中不一致,纵向是y轴。

1.4 extrude()

extrude(distance)
extrude(extrusionType, distance)

1.5 split()

XYZ Split (Cartesian Space)

split(splitAxis) { size1 : operations1 | size2 : operations2 | … | sizen-1 : operationsn-1 }

split(splitAxis) { size1 : operations1 | size2 : operations2 | … | sizen-1 : operationsn-1 }*

split(splitAxis, adjustSelector) { size1 : operations1 | … | sizen-1 : operationsn-1 }

split(splitAxis, adjustSelector) { size1 : operations1 | … | sizen-1 : operationsn-1 }*

UV Split (Texture Space)

split(splitDirection, surfaceParameterization, uvSet) { size1 : operations1 | … | sizen-1 : operationsn-1 }*

按给定轴向切割模型。
注意:关于 * ——Repeat switch: the repeat switch triggers the repetition of the defined split into the current shape’s scope, as many times as possible. The number of repetitions and floating dimensions are adapted to the best solution (best number of repetitions and least stretching).

2 Parameterized Rule 参数化规则

注意:不需要明确的参数数据类型。cga语法中有三种简单类型:float, boolean, string,分别是浮点数、布尔数、字符串。所有数字都是浮点数,整数也是。
举栗1:

Lot -->s('0.8, '1, '0.8)center(xz)Footprint(20)
Footprint(height) -->extrude(height * 0.8)Envelope.

举栗2:

Lot -->s(0.5*scope.sx, '1, '1)center(xz)Footprint(20, geometry.area)
Footprint(height, area) -->t(0,0,0)extrude(height)Envelope(area)
Envelope(area) -->split(y) {~4 : Floor.} *

举栗3:

Lot -->Footprint("just an example")
Footprint(height,area) -->t(0,0,1) extrude(height) Envelope(area)
Footprint(text) -->print(text)

Finally, rule overloading is shown in example 3. There are two Footprint rules, one with two float parameters and one with one string parameter. The compiler automatically makes sure that only the matching one is used during shape creation (i.e. during execution of the Lot rule above, a Footprint shape with a string parameter is created).
Note: If no matching rule exists a new leaf is generated.

3 Conditional Rule 条件判断规则

PredecessorShape -->
case condition1: Successor1
case condition2: Successor2

else: SuccessorN
举栗1:

Footprint(type) -->case type == "residential" :extrude(10) Envelopecase geometry.area / 2 < 200 :extrude(20) Envelopeelse: NIL

举栗2:

Footprint(type) -->case type == "residential" || type == "park"     : case geometry.area/2 < 200 && geometry.area > 10 : extrude(10) Envelopeelse: extrude(15) Envelopecase type == "industrial" : extrude(100) Factoryelse : NIL

栗子2是嵌套的条件判断和布尔运算。

4 stochastic rule 随机规则

与条件规则类似,cga语法允许随机规则,比如创建随机变量。

PredecessorShape --> percentage%: Successor1 percentage%: Successor2...else: SuccessorN

注意:比例汇总不能大于100%
举栗1:

attr red = "#FF0000"
attr green = "#00FF00"
attr blue = "#0000FF"Lot -->30%  : color(green)20%  : color(red)else : color(blue)

这一段是按比例随机赋给红绿蓝三种颜色。
举栗2:
嵌套的随机规则。

Lot -->30%  : 50% : Lot("residential")else : NIL 20%  : Lot("retail")else : Lot("industrial")

注意:else是必须的,总比例加在一起不要超过100%

5 attribute 属性

属性在cga文件中是一系列全局变量。每一个属性在文件中都会初始化赋予一个数值。但是针对每个形状,都可以赋予一个独立的属性值,同时这个属性值也可以在检查页(inspector)中修改。
举栗:

attr height = 150
attr landuse = "residential"
Lot --> extrude(height) Envelope(landuse)

用attr定义了两个属性,height和landuse,用在Lot规则中。
属性也可以设置成条件式或者随机数。

attr landuse = 50% : "residential"else: "industrial"

注意:在属性定义时使用条件或者随机形式的时候,在整个生成过程,属性值只计算一次。如果一个这样的属性被赋予了多个形状,那么这些属性将被一次性计算出来,并且会一直保持下去。
同样滴,也可以使用rand()函数:

attr height = rand(30, 50)
Lot -->extrude(height) Envelope
Envelope -->case height < 40 : SmallBuildingelse: LargeBuilding

被赋予height数值,起始规则为Lot的形状,height属性将为30-50的浮点数,并且会一直保持静态不变。

6 style 风格

理解不深刻,以后再补。

7 import 导入

Rules from an existing rule filecan be imported by a rule file through “import”. Importing a rule file makes all rules,attributes and functions of the importedrule file available under the given prefix.
关键字import用于导入已经存在的rule文件,导入rule文件使得被导入文件的规则、属性、函数在当前文件中可以使用。
举栗:在一个结构中合并两个立面

# -- facade1.cgaactualFloorHeight = scope.sy/rint(scope.sy/4)
actualTileWidth   = scope.sx/rint(scope.sx/4)Facade -->setupUV(0, 8*actualTileWidth, 8*actualFloorHeight)set(material.colormap, "f1.tif")bakeUV(0)# -- facade2.cgaactualFloorHeight = scope.sy/rint(scope.sy/6)
actualTileWidth   = scope.sx/rint(scope.sx/4)Facade -->setupUV(0, 8*actualTileWidth, 8*actualFloorHeight)set(material.colormap, "f2.tif")bakeUV(0)# -- 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 = 100Lot-->extrude(height) MassMass-->comp(f){ side: Facade | top: Roof }# -- main.cga// define an attribute "height", potentially
// overriding the same attribute in imported
// rule files.attr height = 200// import facades
import f1 : "facade1.cga"
import f2 : "facade2.cga"// import structure
import st : "structure.cga"Lot-->// reference rule "Lot" in structure.cgast.Lot// define rule "Facade" for structure.cga
st.Facade-->// reference rule "Facade" in facade1.cga50%  : f1.Facade  // reference rule "Facade" in facade2.cgaelse : f2.Facade

8 function 函数

函数用于在规则中封装多次使用的计算估值。和规则不同,函数返回一个数值,但是不改变现有的形状。函数可以带参数,条件式或者使用随机数。
举栗:

getHeight(area) =case area > 1000: 300case area > 500:20%: 20050%: 150else: 100else: rand(20,50)

调用函数:

Lot -->extrude(getHeight(geometry.area)) Envelope.

注意:与属性相反,在每次调用中都会对函数进行评估。 这意味着像height = rand(30,50)这样的函数仅出于专用目的才有意义,因为每次使用它都会返回一个不同的值。
静态函数:
可以使用const关键字使函数变成静态函数。 const函数的行为与attrs相同,唯一的区别是const函数在规则文件内部,不能在检查器中映射修改。

9 comments 注释

cga文件使用“//”或者“#”进行注释。
也可以使用块注释“/* … */”

/* block commentscan be used to writemulti-line comments
*/
or inline comments
Lot -->Garden House /*Garage*/ Fence...comp(f){front : F  | /* side : S  | */ top : T}

CityEngine2016-学习笔记(1)Writing Rules相关推荐

  1. TOEFL 学习笔记 (writing 7)

    So valuable is water resource that weshould protect it. So expensive is the fee of internationaltour ...

  2. IELTS writing skills——学习笔记

    小作文Part1-5学习笔记摘录自知乎:https://www.zhihu.com/question/21133796/answer/830942135 仅供学习使用,侵删. IELTS writin ...

  3. amazeui学习笔记二(进阶开发4)--JavaScript规范Rules

    amazeui学习笔记二(进阶开发4)--JavaScript规范Rules 一.总结 1.注释规范总原则: As short as possible(如无必要,勿增注释):尽量提高代码本身的清晰性. ...

  4. Writing a Scientific Research Report (IMRaD)学习笔记

    参考资料:Writing a Scientific Research Report (IMRaD) IMRAD (Introduction, Methods, Results and Discussi ...

  5. pelican学习笔记(二)之Writing content

    学习http://docs.getpelican.com/en/stable/content.html时做非精准翻译,权当笔记 前文见pelican学习笔记之GITHUB建站(一) Writing c ...

  6. Redis学习笔记(五)——持久化及redis.conf配置文件叙述

    对于日常使用来说,学习完SpringBoot集成Redis就够我们工作中使用了,但是既然学习了,我们就学习一些Redis的配置及概念,使我们可以更深层次的理解Redis,以及增强我们的面试成功概率,接 ...

  7. Spring Cloud 学习笔记(1 / 3)

    Spring Cloud 学习笔记(2 / 3) Spring Cloud 学习笔记(3 / 3) - - - 01_前言闲聊和课程说明 02_零基础微服务架构理论入门 03_第二季Boot和Clou ...

  8. 嵌入式linux学习笔记--TCP通讯整理

    嵌入式linux学习笔记–TCP通讯整理 之前的项目中使用到了比较多的tcp 通讯相关的知识,一直也没有进行整理,今天准备拿出时间好好的整理一下TCP通讯的整个过程.预计会整理linux和window ...

  9. Programming Languages PartA Week2学习笔记——SML基本语法

    Programming Languages PartA Week2学习笔记--SML基本语法 首先简单介绍使用的SML语言,参考维基百科和百度百科: ML(Meta Language:元语言)是由爱丁 ...

  10. 34.Oracle深度学习笔记——12C的AWR初步解读

    34.Oracle深度学习笔记--12C的AWR初步解读 关于AWR,蛤蟆也经常看.因为经常看别人给出的建议,很难有深刻体会.对此,计划花费几个晚上时间好好体会一把并记录下来.此处以单实例为例.列出目 ...

最新文章

  1. vue结合php增删改查实例,从vue基础开始创建一个简单的增删改查的实例
  2. mysql 端口time_wait_TIME_WAIT状态全是3306解决办法
  3. 《游戏编程模式》读书笔记之一
  4. koa-static使用时报Unexpected token function
  5. C#中判断空字符串的3种方法性能分析
  6. ASP.NET MVC Filter过滤机制(过滤器、拦截器)
  7. 【CodeForces - 246D】Colorful Graph (暴力,图,存边,STL)
  8. stm32usb做虚拟串口和键盘_关于stm32f103的USB虚拟串口程序移植
  9. C#设计模式之9-装饰者模式
  10. spin lock自旋锁
  11. 计算机科学与技术 军校,清华大学计算机科学与技术系
  12. Startlsback常见使用过程中的问题
  13. prolog初学语法结构
  14. 文件与文件系统的压缩与打包
  15. 玩转MP4视频格式制作转换秘籍
  16. 腾讯云云服务器遭DDoS攻击被封堵的解决方法
  17. win10镜像文件能直接安装吗
  18. yolov5模型转换(pt=>onnx=>rknn)和板端验证测试
  19. c语言中如何判断元音字母,C 语言实例 – 判断元音,辅音
  20. input 起止时间_几种常用的控件(下拉框 可选框 起止日期 在HTML页面直接读取当前时间)...

热门文章

  1. 3 天天向上的力量 c语言
  2. 网络硬件三剑客的集线器(Hub)、交换机(Switch)与路由器(Router)
  3. Justinmind6.X软件及汉化包下载地址
  4. CMPP错误码(zzzz)
  5. 世界地图展开图,来自 Simon's World Map
  6. 各大浏览器兼容性问题
  7. 椭圆曲线上两种基本的运算:点集运算、P+Q详解
  8. 外酥里嫩的锅包肉做法
  9. 输入经纬度在地图中标注位置(百度地图)
  10. 苦禅箜mm让我帮她做的作业