导入关键字

语法

  • 导入 id:filePath
  • 导入 id( style-id_1, ... , style-id_n ):filePath
  • 导入 id:filePath( attribute_1, ... , attribute_n )
  • 导入 id:filePath( attribute_1 = value, ... , attribute_n = value )
  • 导入 id:filePath()

参数

  1. id

    导入的规则、属性和函数的唯一前缀。

  2. filePath - 字符串
    CGA 规则文件(例如,“file.cga”)的绝对路径或相对路径。 有关支持的语法的详细信息,请参阅资产搜索

说明

现有规则文件中的规则、属性和函数可由规则文件通过“导入”(语法 1)进行导入。 导入规则文件可将导入规则文件的所有规则、属性和函数的前缀设置为“id”。 如果导入的规则文件包含多个样式(语法 2),则默认导入所有样式并在样式管理器中进行显示。 为了限制导入规则文件中的可用样式,可通过以下方式指定导入样式集:在导入 id 后的括号中枚举导入样式,与 id(语法 2)导入语句的第二种形式相同。

默认情况下,导入规则文件中的属性值(例如以下“main.cga”中的“高度”)将传播到导入的规则文件(例如,“structure.cga”中的“高度”值获取自下面的“main.cga”中的“高度”)。 要禁用此默认行为(例如,由于导入的规则文件中的属性名称相同但语义不同,因此不应进行覆盖),可通过在规则文件后进行枚举(语法 3)来保护导入的规则文件中的属性。 不仅可以保护属性,导入规则文件还可以使用表达式重新定义属性(语法 4)来指定新的属性值,其中右侧表达式在导入规则文件的范围内进行计算。

使用空白括号可保护所有导入属性。

如果在检查器中将导入属性的属性源设置为“规则定义的值”之外的值,将完全禁用该属性的此行为,改为从指定的源获取值。

可对导入进行注记以控制其在检查器中的属性演示。 请参阅注记

示例

使用结构合并两个立面

// -- facade1.cga

actualFloorHeight = 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.cga

actualFloorHeight = 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 = 100

Lot-->extrude(height) Mass

Mass-->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.cga
	st.Lot

// define rule "Facade" for structure.cga
st.Facade-->
	// reference rule "Facade" in facade1.cga
	50%  : f1.Facade  
	// reference rule "Facade" in facade2.cga
	else : f2.Facade

在本主题中