几何修整 Geometry Manipulation · 12 个函数
清理、凸包化、镜像、法线等几何级修整操作
The cleanupGeometry operation cleans up the current shape's geometry.
The intent of this operation is to optimize the mesh data structure of the geometry without the intent to change the appearance of the model. The polygon and vertex count may be reduced.
The cleanup can be necessary for subsequent CGA operations. For example, setNormals and softenNormals operations require duplicate vertices to be merged in order to compute vertex normals using adjacent face normals.
Note:
Because discontinuous textures coordinates are preserved cleanup steps could be disabled. In some cases it might be useful to delete the UV coordinates beforehand.
Note:
Because existing component tags are preserved, tagged edges and edges between faces with different tags will not be removed. In some cases it might be useful to delete tags beforehand. See this section for more details.
官方示例 · 点击展开
Init-->
i("myHouse.dae")Init-->
i("myHouse.dae")
cleanupGeometry(all, 0)Init-->
i("myHouse.dae")
cleanupGeometry(all, 0.1)我方已验证示例:cleanupGeometry(verified_gold)· 点击展开代码 · 在 demo 中运行 →
@StartRule Lot --> primitiveQuad(7, 15) extrude(4) cleanupGeometry(0.001) color(0.7, 0.7, 0.8)
convexify(maxLength)
| 参数 | 类型 | 说明 |
|---|---|---|
| maxLength | float | Maximum length of the split line which splits concave polygons into subpolygons. If not provided, no limit is applied, i.e. all resulting polygons are convex. |
The convexify operation splits a concave polygon into a number of convex polygons. If a maxLength parameter is provided, only split lines shorter than this value are applied and one of the resulting polygons might still be concave.
官方示例 · 点击展开
attr maxLength = 1
Lot -->
convexify(maxLength)
comp(f) {all: SubShapes}
SubShapes -->
case scope.sx >= maxLength && scope.sy >=
maxLength :
color("#00ff00")
else:
color("#ff0000")我方已验证示例:convexify(verified_gold)· 点击展开代码 · 在 demo 中运行 →
@StartRule Lot --> primitiveQuad(7, 15) extrude(4) convexify() color(0.8, 0.7, 0.5)
The deleteHoles operation deletes the holes in the faces of the current shape's geometry.
我方已验证示例:learning case #203(verified_silver)· 点击展开代码 · 在 demo 中运行 →
/* deleteHoles operation example */
Lot -->
extrude(5)
deleteHoles()
color("#ff4444")
The reverseNormals operation reverses the face normals of the geometry of the
current shape.
Note:
To check the orientation of the face normals, deactivate the "Use Two-Sided Lighting" option under Preferences/General/Grammar Core.
官方示例 · 点击展开
Lot -->
extrude(world.up,1)
comp(f) {side : Facade}
Facade -->
case comp.index = 0:
color("#ff0000")
# = red
t(0,0,0.1)
else:
color("#00ff00")
# = green
t(0,0,0.1)Lot -->
extrude(world.up,1)
comp(f) {side : Facade}
Facade -->
case comp.index = 0:
color("#ff0000")
# = red
t(0,0,0.1)
reverseNormals
else:
color("#00ff00")
# = green
t(0,0,0.1)我方已验证示例:reverseNormals(verified_gold)· 点击展开代码 · 在 demo 中运行 →
@StartRule Lot --> primitiveQuad(7, 15) extrude(4) reverseNormals() color(0.8, 0.5, 0.5)
The setNormals operation sets the normals of the current shapes' geometry to the desired mode.
我方已验证示例:setNormals(verified_gold)· 点击展开代码 · 在 demo 中运行 →
@StartRule Lot --> primitiveQuad(7, 15) extrude(4) setNormals() color(0.5, 0.8, 0.5)
| 参数 | 类型 | 说明 |
|---|---|---|
| angle | float |
The softenNormals operation sets the normals of the current shapes' geometry to the desired mode.
我方已验证示例:learning case #107(verified_silver)· 点击展开代码 · 在 demo 中运行 →
@Description("CityEngine CGA 几何操作函数示例 - extrude / comp / roof / offset / mirror / normals")
@Group("几何操作")
@Order(32)
// ============================================================
// 几何操作 Geometry Operations
// 演示 extrude, comp, roof*, offset, envelope, mirror, normals 等
// ============================================================
@StartRule
Lot --> OperationShowcase
OperationShowcase -->
split(x) { ~8: ExtrudeDemo
| ~8: RoofHipDemo
| ~8: RoofGableDemo
…
| 参数 | 类型 | 说明 |
|---|---|---|
| xFlip | bool | A boolean value (true or false) for the scope x-axis; true means flip along the axis. |
| yFlip | bool | A boolean value (true or false) for the scope y-axis; true means flip along the axis. |
| zFlip | bool | A boolean value (true or false) for the scope z-axis; true means flip along the axis. |
The mirror operation mirrors the geometry of the current shape.
Note:
The current shape's scope stays the same.我方已验证示例:learning case #107(verified_silver)· 点击展开代码 · 在 demo 中运行 →
@Description("CityEngine CGA 几何操作函数示例 - extrude / comp / roof / offset / mirror / normals")
@Group("几何操作")
@Order(32)
// ============================================================
// 几何操作 Geometry Operations
// 演示 extrude, comp, roof*, offset, envelope, mirror, normals 等
// ============================================================
@StartRule
Lot --> OperationShowcase
OperationShowcase -->
split(x) { ~8: ExtrudeDemo
| ~8: RoofHipDemo
| ~8: RoofGableDemo
…
| 参数 | 类型 | 说明 |
|---|---|---|
| angle | float | Maximum deviation in degrees from the right angle in range [0,45]. |
The rectify operation aligns edges to the scope such that they are parallel or
perpendicular to each other if they initially deviate less than
angle from that condition.
The algorithm aligns all edges such that their projection onto
either the xy, yz or zx plane of the scope becomes parallel to the
axes spanning that plane if the angle between the edge and the
respective axis is less than angle. From the planes xy, yz, zx the
one that is most parallel to the shape is chosen as the
projection plane.
Example: For a shape that is parallel to the xy plane of the
scope, all edges with an angle less than angle to the x or y axis are aligned
parallel to the x or y axis, respectively.
Limitations: The operation does not guarantee a good result for all cases, results should therefore be checked by the user. In some cases, the operation will remove holes or create self intersections. The operation is not suitable for initial shapes whose face normals point in very different directions, for example 3D solids.
官方示例 · 点击展开
@Range(min=0,max=45)
attr angle = 15
@StartRule
Lot -->
ShowOrig
ShowRect
ShowOrig -->
color(1, 0, 0)
ShowRect -->
t(0, 0, '-1.1)
rectify(angle)
color(0, 1, 0)我方已验证示例:rectify(verified_gold)· 点击展开代码 · 在 demo 中运行 →
@StartRule Lot --> primitiveQuad(7, 15) extrude(4) r(0, 20, 0) rectify() color(0.7, 0.8, 0.9)
| 参数 | 类型 | 说明 |
|---|---|---|
| tolerance | float | Controls the number of vertices which are going to be removed from the geometry. Valid values are in the range [0,1]. For instance, a value of 0.2 will reduce the vertex count of the geometry by 20%. |
The reduceGeometry
operation simplifies the geometry by applying a series of edge
collapses.
This operation changes the appearance of the model. The algorithm tries to reduce the complexity of the mesh by introducing the least possible delta to the appearance of the existing model.
Note:
The operation removes all component tags from the geometry.
我方已验证示例:learning case #207(verified_silver)· 点击展开代码 · 在 demo 中运行 →
/* reduceGeometry operation example */
Lot -->
extrude(10)
reduceGeometry(0.1)
color("#44ffaa")
The resetGeometry operation resets the geometry to the initial shape's state. Additional operation properties are:
- trim planes are removed,
- shape attributes remain unchanged, but scope and pivot are reset to the initial shape's state,
- generic attributes, which are declared as rule attributes, remain unchanged (see Attributes),
- projection matrices remain unchanged.
官方示例 · 点击展开
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)我方已验证示例:learning case #107(verified_silver)· 点击展开代码 · 在 demo 中运行 →
@Description("CityEngine CGA 几何操作函数示例 - extrude / comp / roof / offset / mirror / normals")
@Group("几何操作")
@Order(32)
// ============================================================
// 几何操作 Geometry Operations
// 演示 extrude, comp, roof*, offset, envelope, mirror, normals 等
// ============================================================
@StartRule
Lot --> OperationShowcase
OperationShowcase -->
split(x) { ~8: ExtrudeDemo
| ~8: RoofHipDemo
| ~8: RoofGableDemo
…
The trim operation applies the current shape's trim planes to the geometry of the current shape. Trim planes are generated by a component split and can be enabled and disabled by the trim attribute. Trimming is automatically performed when a primitive or an asset is inserted in the scope. Use the geometry.isInstanced function to check if an inserted asset was trimmed.
官方示例 · 点击展开
Roof-->
roofHip(45)
comp(f) { 1 : Face }
Face-->
s('2,'2,0.5)
center(x)
extrude(0.5)
set(trim.horizontal, true)
trim()Face-->
s('2,'2,0.5)
center(x)
primitiveCube()我方已验证示例:learning case #107(verified_silver)· 点击展开代码 · 在 demo 中运行 →
@Description("CityEngine CGA 几何操作函数示例 - extrude / comp / roof / offset / mirror / normals")
@Group("几何操作")
@Order(32)
// ============================================================
// 几何操作 Geometry Operations
// 演示 extrude, comp, roof*, offset, envelope, mirror, normals 等
// ============================================================
@StartRule
Lot --> OperationShowcase
OperationShowcase -->
split(x) { ~8: ExtrudeDemo
| ~8: RoofHipDemo
| ~8: RoofGableDemo
…
modify(component, scopeAlignment) { selector operator operations | ... }
| 参数 | 类型 | 说明 |
|---|---|---|
| component, scopeAlignment, selector, operator, operations | — | These parameters are the same as for the comp operation. |
The modify operation edits selected parts of the current geometry. Like the comp operation, it divides a shape into topological components (defined by component, selector, operator) that results in new shapes that are modified according to the specified operations.
Unlike the comp operation, the modify operation always performs shape recomposition implicitly (see Shape Recomposition), i.e., recombining the edited components with the remaining geometry. For face components, the following two lines are therefore equivalent:
modify(f) { ... }inline(recompose) comp(f) { ... | all: X. }
In contrast to an inlined comp operation, modify automatically restores the untouched geometry, removing the need for the "| all: X." clause. It also enables modifying edge and vertex components while returning to the full geometry after the operation.
Note:
The modify operation only changes the current shape's geometry and does not add successor shapes to the shape tree.
Comp shape attributes
Each generated shape has a number of comp shape attributes set. For more information see comp attribute.
官方示例(共 7 个,展示前 3 个) · 点击展开
Init -->
extrude(5)
comp(f) { top: ModifiedRoof | side: Facade. }
ModifiedRoof -->
roofHip(45)
modify(e) { ridge: t(0,2,0) X. }Init -->
extrude(5)
modify(f) { top: s('0.5, '0.5, '0.5) X. }const OpeningL = 2
const Depth = 0.75
const InnerL = 1
Init -->
inline(recompose) split(x) { 5: tag("Front") F.
| ~1: tag("House") H. }
modify(e) { isTagged("Front") && isTagged("House"):
split(x) { ~4: CreateOutset }* }
CreateOutset -->
split(x) { ~1 : Wall.
| 0.01 : tag("Side") Side.
| OpeningL: tag("Outset") Outset
| 0.01 : tag("Side") Side.
| ~1 : Wall. }
Outset --> t(0,-Depth,0) s(InnerL,0,0) center(x)我方已验证示例:learning case #14(verified_silver)· 点击展开代码 · 示例过大,请复制源码到 demo 运行
##############################################
# Extensions
#
@Order(1)
@Description("Highest horizontal 2D shape on the top of the mass.")
extension Rooftop(ParapetHeight, FloorCount) --> color(0.55,0.65,0.55) Rooftop.
@Order(2)
@Description("Horizontal 2D shapes without any floorplates directly above (but not the roof).")
extension Terrace(FloorHeight, FloorLevel) --> color(0.5,0.7,0.5) Terrace.
@Order(3)
@Description("Horizontal 2D shapes on the actual floor level.")
extension Floorplat…