Peyep CGA 函数参考纹理 · 2025.1
版本首页查看 demo →
← 返回 2025.1 分类导航

纹理 Texturing · 10 个函数

UV 投影、缩放、平移与贴图赋值

deleteUV native ✓ cpp-fast ✓ 已验证 39 条 · silver 官方文档 ↗ #
删除指定 UV 集
签名(1 种重载)
deleteUV(uvSet)
参数说明
参数类型说明
uvSetfloatNumber of texture coordinates set (integer number in [0,9]). The numbering corresponds to the texture layers of the material attribute, see also Texturing: Essential knowledge.
官方说明(英文原文)

The deleteUV operation deletes the texture coordinates of the given uvSet.

我方已验证示例:learning case #198(verified_silver)· 点击展开代码 · 在 demo 中运行 →
/* deleteUV operation example */
Lot -->
  extrude(10)
  setupProjection(0, "scope.xy", 1, 1)
  projectUV(0)
  deleteUV(0)
  color("#aa00ff")
normalizeUV native ✓ cpp-fast ✓ 已验证 17 条 · silver 官方文档 ↗ #
归一化 UV 坐标
签名(1 种重载)
normalizeUV(uvSet, normalizeMode, normalizeType)
参数说明
参数类型说明
uvSetfloatNumber of texture coordinates set (integer number in [0,9]). The numbering corresponds to the texture layers of the material attribute, see also Texturing: Essential knowledge.
normalizeModeselector{ uv | uvUniform | u | v }
normalizeTypeselector{ separatePerFace | collectiveAllFaces }
官方说明(英文原文)

The normalizeUV operation normalizes the texture coordinates of the given uvSet parameter. Depending on the mode, the texture coordinates are normalized to the [0, 1] range.

我方已验证示例:learning case #78(verified_silver)· 点击展开代码 · 示例过大,请复制源码到 demo 运行
/**
 * File:    Fence_On_Graph.cga
 * Created: 18 Nov 2015 17:11:40 GMT
 * Author:  Esri R&D Center Zurich
 */

/*

Input shape:  street shape (shape with UVs), street width >= base_depth

Fences are created along the u direction of the street shape.

Notes on Occlusion:

* Occlusion Labels:  The fence parts (post, middle, base post, base middle, upper post, upper middle)
  are each labeled with the given occlusionLabel.  These labeled parts are meant to be occluders which
  can be found when te…
projectUV native ✓ cpp-fast ✓ 已验证 279 条 · silver 官方文档 ↗ #
投影生成 UV 坐标
签名(1 种重载)
projectUV(uvSet)
参数说明
参数类型说明
uvSetfloatNumber of texture coordinates set (integer number in [0,9]) . The numbering corresponds to the texture layers of the material attribute, see also Texturing: Essential knowledge.
官方说明(英文原文)

The projectUV operation creates the final texture coordinates of the selected uv-set by applying the corresponding projection matrix. Thus, this operation 'bakes' the texture projection into the texture coordinates of the geometry of the current shape. The projection is based on the uvw-coordinate system specified by the setupProjection operation.

Note:

Colormap has uvSet 0, bumpmap will have uvSet 1, dirtmap has uvSet 2.

我方已验证示例:learning case #145(verified_silver)· 点击展开代码 · 在 demo 中运行 →
/**
 * texture() 在线贴图示例
 * 
 * 演示如何使用在线 URL 作为贴图。
 * texture(path) 将 path 设置为材质的 colormap。
 * 支持本地路径和在线 URL。
 * 
 * 相关函数:setupProjection, projectUV, color
 */

attr wallTexture = "https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/brick_diffuse.jpg"

Lot -->
    extrude(8)
    comp(f){side: Wall | top: Roof}

Wall -->
    setupProjection(0, scope.xy, 4, 4)
    texture(wallTexture)
    projectUV(0)

Roof -->
    color(0.8, 0.3, 0.2)
rotateUV native ✓ cpp-fast ✓ 已验证 30 条 · silver 官方文档 ↗ #
旋转 UV
签名(1 种重载)
rotateUV(uvSet, angle)
参数说明
参数类型说明
uvSetfloatNumber of texture coordinates set (integer number in [0,9]). The numbering corresponds to the texture layers of the material attribute, see also Texturing: Essential knowledge.
anglefloatDefines the angle of the rotation.
官方说明(英文原文)

The rotateUV operation rotates the texture coordinates (uvs) of the current shape by the angle.

Note:
  • The rotation center is at the texture position u=0 and v=0.
  • Rotating uvs works only after the uvs have been projected.

官方示例 · 点击展开
brickMap = "assets/bricks.jpg"
dirtMap = "assets/dirt.jpg"
randBuildingHeight = 1

Lot -->
s ('.75,'1,'.75)
center(xz)
extrude(world.up, randBuildingHeight)
comp(f) { side : Facade 
        | top  : set(material.color.a, 
                     .3) 
		      Roof. }

Facade -->
  # color, uv set 0
  setupProjection(0, scope.xy, scope.sx, 
                  scope.sy)
  texture(brickMap)
  projectUV(0)  # projection of the uvs
  rotateUV(0,10)# rotate command after 
                  the projection
我方已验证示例:learning case #78(verified_silver)· 点击展开代码 · 示例过大,请复制源码到 demo 运行
/**
 * File:    Fence_On_Graph.cga
 * Created: 18 Nov 2015 17:11:40 GMT
 * Author:  Esri R&D Center Zurich
 */

/*

Input shape:  street shape (shape with UVs), street width >= base_depth

Fences are created along the u direction of the street shape.

Notes on Occlusion:

* Occlusion Labels:  The fence parts (post, middle, base post, base middle, upper post, upper middle)
  are each labeled with the given occlusionLabel.  These labeled parts are meant to be occluders which
  can be found when te…
scaleUV native ✓ cpp-fast ✓ 已验证 31 条 · silver 官方文档 ↗ #
缩放 UV
签名(1 种重载)
scaleUV(uvSet, uFactor, vFactor)
参数说明
参数类型说明
uvSetfloatNumber of texture coordinates set (integer number in [0,9]). The numbering corresponds to the texture layers of the material attribute, see also Texturing: Essential knowledge.
uFactorfloatA factor to multiply all texture coordinates in u-direction.
vFactorfloatA factor to multiply all texture coordinates in v-direction.
官方说明(英文原文)

The scaleUV operation scales the corresponding texture layer by multiplying each of its texture coordinates with uFactor and vFactor.

我方已验证示例:learning case #78(verified_silver)· 点击展开代码 · 示例过大,请复制源码到 demo 运行
/**
 * File:    Fence_On_Graph.cga
 * Created: 18 Nov 2015 17:11:40 GMT
 * Author:  Esri R&D Center Zurich
 */

/*

Input shape:  street shape (shape with UVs), street width >= base_depth

Fences are created along the u direction of the street shape.

Notes on Occlusion:

* Occlusion Labels:  The fence parts (post, middle, base post, base middle, upper post, upper middle)
  are each labeled with the given occlusionLabel.  These labeled parts are meant to be occluders which
  can be found when te…
setupProjection native ✓ cpp-fast ✓ 已验证 283 条 · silver 官方文档 ↗ #
配置纹理投影参数
签名(3 种重载)
setupProjection(uvSet, axes, textureWidth, textureHeight)
setupProjection(uvSet, axesSelector, textureWidth, textureHeight, widthOffset, heightOffset)
setupProjection(uvSet, axesSelector, textureWidth, textureHeight, widthOffset, heightOffset, uwFactor)
参数说明
参数类型说明
uvSetfloatIndex of the uv-set (texture layer) to set up (integer number in [0,9]). The numbering corresponds to the texture layers of the material attribute.
axesselector
textureWidthfloatThe texture width in world coordinate system units (e.g. meters). Values < 0 are allowed and mirror the texture. The operators ~ (floating) and ’ (relative) can be used, see below.
textureHeightfloatThe texture height in world coordinate system units (e.g. meters). Values < 0 are allowed and mirror the texture. The operators ~ (floating) and ’ (relative) can be used, see below.
widthOffsetfloatThe offset in u-direction, in world coordinate system units (e.g. meters).
heightOffsetfloatThe offset in v-direction, in world coordinate system units (e.g. meters).
uwFactorfloatSets the factor by which the texture is applied on the w-axis relative to the u-axis (see examples below). The default value is 0.
官方说明(英文原文)

The setupProjection operation initializes a projection matrix for the chosen uv-set based on the reference coordinates system specified with axes selector. It can be chosen between scope and world coordinate systems. For example, to initialize the u- and v-axes with the x- and y-axes of the current scope, the axes selector has to be set to scope.xy. Note that some combinations result in a mirrored texture.

The textureWidth and textureHeight parameters support usage of the floating and relative operators to avoid complex calculations with the scope dimension, analogous to the transformation and split operations. For example, if the parameter textureWidth is set to ~2, the projection matrix is initialized such that the current scope width is exactly spanned with texture tiles of approximately size 2. Or if the parameter textureHeight is set to ’0.5, the texture will be repeated twice along the height.

Optionally, the influence of the pixels's z-coordinate on the w-texture coordinate relative to the u-coordinate can be set. Note that it defaults to 0 if not provided.

官方示例(共 8 个,展示前 3 个) · 点击展开
Lot -->
    ... Building
    
Building -->
    ... Frontfacade ...
    
Frontfacade -->
    setupProjection(0, scope.xy, 1.5, 1, 0, 0, 1)
                   // setup 1.5m x 1m texture tiles
    setupProjection(2, scope.xy, scope.sx, scope.sy, 0, 0, 1)
                   // using dirtmap (uvSet #2)

    split(y){ groundfloor_height    : Groundfloor 
            | {~floor_height        : Floor}* }
... rules for floors and facade tiles ...
Wall -->
    color(wallColor)
    set(material.colormap, wall_tex)  
    set(material.dirtmap, dirt_tex)
    projectUV(0) projectUV(2)
Door -->
    s('1,'1,0.1)
    t(0,0,-0.5)
    set(material.colormap, frontdoor_tex)    
    primitiveCube()
我方已验证示例:learning case #145(verified_silver)· 点击展开代码 · 在 demo 中运行 →
/**
 * texture() 在线贴图示例
 * 
 * 演示如何使用在线 URL 作为贴图。
 * texture(path) 将 path 设置为材质的 colormap。
 * 支持本地路径和在线 URL。
 * 
 * 相关函数:setupProjection, projectUV, color
 */

attr wallTexture = "https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/brick_diffuse.jpg"

Lot -->
    extrude(8)
    comp(f){side: Wall | top: Roof}

Wall -->
    setupProjection(0, scope.xy, 4, 4)
    texture(wallTexture)
    projectUV(0)

Roof -->
    color(0.8, 0.3, 0.2)
texture native ✓ cpp-fast ✓ 已验证 262 条 · silver 官方文档 ↗ #
为形状赋予贴图
签名(1 种重载)
texture(filePath)
参数说明
参数类型说明
filePathstringName of the texture file to insert. See asset search for information about search locations and built-in assets for a list of built-in textures. Supported image formats are listed in texturing essentials.
官方说明(英文原文)

The texture operation uses the file specified in the filePath to texture the current shape by setting the colormap and, if applicable, the opacitymap attribute. The texture operation is a convenience version of set(material.colormap,..) and (if applicable) set(material.opacitymap,..). The opacitymap attribute is set if the texture contains an alpha channel or is reset to an empty string otherwise.

Note:
The texture operation does not create texture coordinates.
官方示例 · 点击展开
brickMap = "assets/bricks.jpg"
randBuildingHeight = rand(3,20)

Lot -->
s('.75,'1,'.75)
center(xz)
extrude(world.up, randBuildingHeight)
comp(f){side: Facade | 
top: set(material.color.a, .3) Roof.}

Facade -->
	# color, uv set 0
	setupProjection(0, scope.xy, 5, 5)
	texture(brickMap)
	// = set(material.colormap,brickMap)
	projectUV(0)
我方已验证示例:learning case #145(verified_silver)· 点击展开代码 · 在 demo 中运行 →
/**
 * texture() 在线贴图示例
 * 
 * 演示如何使用在线 URL 作为贴图。
 * texture(path) 将 path 设置为材质的 colormap。
 * 支持本地路径和在线 URL。
 * 
 * 相关函数:setupProjection, projectUV, color
 */

attr wallTexture = "https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/brick_diffuse.jpg"

Lot -->
    extrude(8)
    comp(f){side: Wall | top: Roof}

Wall -->
    setupProjection(0, scope.xy, 4, 4)
    texture(wallTexture)
    projectUV(0)

Roof -->
    color(0.8, 0.3, 0.2)
tileUV native ✓ cpp-fast ✓ 已验证 36 条 · silver 官方文档 ↗ #
UV 平铺
签名(1 种重载)
tileUV(uvSet, textureWidth, textureHeight)
参数说明
参数类型说明
uvSetfloatNumber of texture coordinates set (integer number in [0,9]) . The numbering corresponds to the texture layers of the material attribute, see also Texturing: Essential knowledge.
textureWidthfloatThe texture width in world coordinate system units (e.g. meters). Values < 0 are allowed and mirror the texture. The operators ~ (floating) and ’ (relative) can be used, see below. 0 is allowed and means “don't touch this axis”.
textureHeightfloatThe texture texHeight in world coordinate system units (e.g. meters). Values < 0 are allowed and mirror the texture. The operators ~ (floating) and ’ (relative) can be used, see below. 0 is allowed and means “don't touch this axis”.
官方说明(英文原文)

The tileUV operation re-scales the texture coordinates of the selected uv-set such that the uv space gets tiled with tiles of a given width and height. The textureWidth and textureHeight parameters support usage of the floating and relative operators to avoid complex calculations with the texture space dimension. For example, if the parameter textureWidth is set to ~20, the projection matrix is initialized such that the surface of the current shape's geometry is exactly spanned with texture tiles of approximately size 20 along the u direction. Or if the parameter textureHeight is set to ’0.5, the texture will be repeated twice along the height.

官方示例 · 点击展开
Street-->
texture("builtin:uvtest.png")
Street-->
texture("builtin:uvtest.png")
tileUV(0, 20, 10)
Street-->
texture("builtin:uvtest.png")
tileUV(0, ~20, '0.5)
我方已验证示例:learning case #161(verified_silver)· 点击展开代码 · 示例过大,请复制源码到 demo 运行
/**
 * Author:  Esri R&D Center Zurich
 */

version "2025.0"

import roof : "roofs.cga"
import plankTexturing : "plankTexturing.cga"
import landscape : "landscape.cga"

##############################################
# main attributes
##############################################
@Group("ROOF DETAILS")
attr roofTiles = false

@Group("LEVEL OF DETAIL")
attr highLOD = false

@Group("WALL DETAILS")
@Distance
attr wallHeight = 7.5

@Range(min=-1, max=1)
attr wallShift = 0

@Hidden
attr wallEarthDept…
translateUV native ✓ cpp-fast ✓ 已验证 47 条 · silver 官方文档 ↗ #
平移 UV
签名(1 种重载)
translateUV(uvSet, uOffset, vOffset)
参数说明
参数类型说明
uvSetfloatNumber of texture coordinates set (integer number in [0,9]) . The numbering corresponds to the texture layers of the material attribute, see also texturing: essential knowledge.
uOffsetfloatHow much to translate in u direction.
vOffsetfloatHow much to translate in v direction.
官方说明(英文原文)

The translateUV operation translates the corresponding texture layer by adding uOffset and vOffset to each of its texture coordinates. For example, to move the texture to the right by half of the width, use translateUV(0,0.5,0).

我方已验证示例:learning case #161(verified_silver)· 点击展开代码 · 示例过大,请复制源码到 demo 运行
/**
 * Author:  Esri R&D Center Zurich
 */

version "2025.0"

import roof : "roofs.cga"
import plankTexturing : "plankTexturing.cga"
import landscape : "landscape.cga"

##############################################
# main attributes
##############################################
@Group("ROOF DETAILS")
attr roofTiles = false

@Group("LEVEL OF DETAIL")
attr highLOD = false

@Group("WALL DETAILS")
@Distance
attr wallHeight = 7.5

@Range(min=-1, max=1)
attr wallShift = 0

@Hidden
attr wallEarthDept…
copyUV native ✓ cpp-fast ✓ 已验证 8 条 · silver 官方文档 ↗ #
在 UV 集之间复制纹理坐标
签名(1 种重载)
copyUV(uvSetSourceSet, uvSetDest)
参数说明
参数类型说明
uvSetSourcefloatNumber of source texture coordinates set (integer number in [0,9]). The numbering corresponds to the texture layers of the material attribute, see also Texturing: Essential knowledge.
uvSetDestfloatNumber of destination texture coordinates set (integer number in [0,9]).
官方说明(英文原文)

The copyUV operation copies texture coordinates of the given uvSetSource to uvSetDest .

我方已验证示例:learning case #161(verified_silver)· 点击展开代码 · 示例过大,请复制源码到 demo 运行
/**
 * Author:  Esri R&D Center Zurich
 */

version "2025.0"

import roof : "roofs.cga"
import plankTexturing : "plankTexturing.cga"
import landscape : "landscape.cga"

##############################################
# main attributes
##############################################
@Group("ROOF DETAILS")
attr roofTiles = false

@Group("LEVEL OF DETAIL")
attr highLOD = false

@Group("WALL DETAILS")
@Distance
attr wallHeight = 7.5

@Range(min=-1, max=1)
attr wallShift = 0

@Hidden
attr wallEarthDept…