纹理 Texturing · 10 个函数
UV 投影、缩放、平移与贴图赋值
| 参数 | 类型 | 说明 |
|---|---|---|
| uvSet | float | Number 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")
| 参数 | 类型 | 说明 |
|---|---|---|
| uvSet | float | Number 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. |
| normalizeMode | selector | { uv | uvUniform | u | v } |
| normalizeType | selector | { 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…
| 参数 | 类型 | 说明 |
|---|---|---|
| uvSet | float | Number 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)
| 参数 | 类型 | 说明 |
|---|---|---|
| uvSet | float | Number 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. |
| angle | float | Defines 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=0andv=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…
| 参数 | 类型 | 说明 |
|---|---|---|
| uvSet | float | Number 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. |
| uFactor | float | A factor to multiply all texture coordinates in u-direction. |
| vFactor | float | A 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(uvSet, axesSelector, textureWidth, textureHeight, widthOffset, heightOffset)
setupProjection(uvSet, axesSelector, textureWidth, textureHeight, widthOffset, heightOffset, uwFactor)
| 参数 | 类型 | 说明 |
|---|---|---|
| uvSet | float | Index 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. |
| axes | selector | |
| textureWidth | float | The 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. |
| textureHeight | float | The 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. |
| widthOffset | float | The offset in u-direction, in world coordinate system units (e.g. meters). |
| heightOffset | float | The offset in v-direction, in world coordinate system units (e.g. meters). |
| uwFactor | float | Sets 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)
| 参数 | 类型 | 说明 |
|---|---|---|
| filePath | string | Name 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:
Thetexture
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)
| 参数 | 类型 | 说明 |
|---|---|---|
| uvSet | float | Number 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. |
| textureWidth | float | The 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”. |
| textureHeight | float | The 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…
| 参数 | 类型 | 说明 |
|---|---|---|
| uvSet | float | Number 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. |
| uOffset | float | How much to translate in u direction. |
| vOffset | float | How 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…
| 参数 | 类型 | 说明 |
|---|---|---|
| uvSetSource | float | Number 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. |
| uvSetDest | float | Number 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…