Skip to content

Commit f86787a

Browse files
authored
完善图像资源模块 (cocos#1984)
* 完善图像资源模块 * Commit changes * 调整精灵帧及补充创建 RenderTexture * Apply suggestions from code review
1 parent 0eefce2 commit f86787a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+273
-153
lines changed

en/asset/atlas/spriteframes.png

-214 KB
Loading
-374 KB
Loading
-52 KB
Loading
6.04 KB
Loading

en/asset/sprite-frame.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ __Sprite Frame__ is a container for __UI rendering__ and basic graphics, which m
44

55
## Importing Sprite Frame Assets
66

7-
Use the default [asset import](asset-workflow.md) method to import image assets into the project, then set the type of image as __sprite-frame__ in the **Inspector** panel:
7+
Use the default [asset import](asset-workflow.md) method to import image assets into the project, then set the type of image as __sprite-frame__ in the __Inspector__ panel:
88

99
![set sprite-frame](sprite-frame/set-spriteframe.png)
1010

1111
Creator will then automatically create a spriteFrame resource under it as shown below:
1212

13-
![imported texture](sprite-frame/imported_texture.png)
13+
![imported texture](sprite-frame/spriteframe.png)
1414

15-
Image assets will use thumbnails of their own pictures as icons in the **Assets** panel. When the image sub-asset is selected in the **Assets** panel, a thumbnail of the image is displayed below the **Inspector** panel.
15+
Image assets will use thumbnails of their own pictures as icons in the __Assets__ panel. When the image sub-asset is selected in the __Assets__ panel, a thumbnail of the image is displayed below the __Inspector__ panel.
1616

1717
The `spriteFrame` has the following properties:
1818

@@ -22,21 +22,21 @@ The `spriteFrame` has the following properties:
2222
| Rotated | Read-only property, cannot be changed. Used to see if the sub-asset in the Texture Packer asset is rotated. |
2323
| Offset X, Y | Read-only property, cannot be changed. Used to view the offset of the rectangle in Texture Packer asset. |
2424
| Trim Type | Set the trim type, including:<br>1. Auto -- Automatic trim. For details, please refer to the [Auto Trim for SpriteFrame](../ui-system/components/engine/trim.md) documentation.<br>2. Custom -- Custom trim<br>3. None -- No trim, use original texture. |
25-
| Trim Threshold | Set the transparency threshold, trim off the pixels whose transparency is below the set value.<br>The default value is 1, and the range of values is 0~1.<br>Only takes effect when **Trim Type** is set to **Auto**. |
26-
| Trim X, Y, Width, Height | Sets the trim rect, only takes effect when **Trim Type** is set to **Custom**. |
27-
| Border Top, Bottom, Left, Right | Set the texture margins of the 9-sliced, which can be edited visually by clicking on the **Edit** button below. |
25+
| Trim Threshold | Set the transparency threshold, trim off the pixels whose transparency is below the set value.<br>The default value is 1, and the range of values is 0~1.<br>Only takes effect when __Trim Type__ is set to __Auto__. |
26+
| Trim X, Y, Width, Height | Sets the trim rect, only takes effect when __Trim Type__ is set to __Custom__. |
27+
| Border Top, Bottom, Left, Right | Set the texture margins of the 9-sliced, which can be edited visually by clicking on the __Edit__ button below. |
2828

2929
## Using a Sprite Frame
3030

3131
### The object contained in the container is using textures
3232

33-
In the editor, drag the __SpriteFrame__ asset to the __Sprite Frame__ property of the **Sprite** component to switch the image displayed by the __Sprite__. At runtime, taking the content picture in the above picture as an example, The entire asset is divided into image asset (`content`), its sub-asset (`spriteFrame`) and sub-asset (`texture`). The assets in the game package can be obtained by the following methods:
33+
In the editor, drag the __SpriteFrame__ asset to the __Sprite Frame__ property of the __Sprite__ component to switch the image displayed by the __Sprite__. At runtime, taking the content picture in the above picture as an example, The entire asset is divided into image asset (`content`), its sub-asset (`spriteFrame`) and sub-asset (`texture`). The assets in the game package can be obtained by the following methods:
3434

3535
__Method 1__: (load __ImageAsset__):
3636

3737
```typescript
3838
const self = this;
39-
const url = 'test_assets/test_altas/content';
39+
const url = 'test_assets/test_atlas/content';
4040
resources.load(url, ImageAsset, (err: any, imageAsset) => {
4141
const sprite = this.getComponent(Sprite);
4242
const spriteFrame = new SpriteFrame();
@@ -84,4 +84,4 @@ const sprite = this.getComponent(Sprite);
8484
sprite.spriteFrame = spriteFrame;
8585
```
8686

87-
For API information, please refer to the [SpriteFrame](__APIDOC__/en/classes/asset.spriteframe.html) documentation.
87+
For API information, please refer to the [SpriteFrame](__APIDOC__/en/classes/asset.spriteframe-1.html) documentation.
-58.5 KB
Binary file not shown.
954 Bytes
Loading

en/asset/sprite-frame/spriteframe.png

54.8 KB
Loading

en/asset/texture/imported.png

-4.28 KB
Loading

en/module-map/texture/add-texture.png

-64.5 KB
Binary file not shown.

en/module-map/texture/index.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ A texture is a displayable image, or a piece of intermediate data used for compu
44

55
- Used for 2D UI rendering, see the [SpriteFrame](../../asset/sprite-frame.md) documentation for details.
66

7-
- Used for 3D model rendering. A texture asset needs to be specified in the material, to render and map it to the mesh surface.Textures also support switching to **cube map** and **normal map** when [importing image assets](../../asset/image.md).
8-
9-
![add texture](add-texture.png)
7+
- Used for 3D model rendering. A texture asset needs to be specified in the material, to render and map it to the mesh surface.Textures also support switching to **cube map** or **normal map** when [importing image assets](../../asset/image.md).
108

119
- Used for the particle system to make particles more expressive. As with 3D models, the use of textures in particle system also depends on materials.
1210

zh/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
- [纹理贴图资源](asset/texture.md)
4747
- [精灵帧资源](asset/sprite-frame.md)
4848
- [图像资源的自动剪裁](ui-system/components/engine/trim.md)
49+
- [立方体贴图资源](asset/texture-cube.md)
4950
- [图集资源](asset/atlas.md)
5051
- [自动图集资源](asset/auto-atlas.md)
5152
- [艺术数字资源](asset/label-atlas.md)

zh/asset/atlas.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@
2828

2929
![atlas files](atlas/atlas_files.png)
3030

31-
使用 TexturePacker 打包图集时需要注意,Creator 3.0 不支持 TexturePacker v4.x 以下的图集格式,否则导入时会出现报错。
31+
使用 TexturePacker 打包图集时的设置可参考 [TexturePacker 设置](../ui-system/components/engine/trim.md#texturepacker-%E8%AE%BE%E7%BD%AE)
32+
33+
> **注意**:Cocos Creator 3.x 不支持 TexturePacker v4.x 以下的图集格式,否则导入时会出现报错。
3234
3335
## 导入图集资源
3436

3537
将上面所示的 **plist****png** 文件同时拖拽到 **资源管理器** 中,就可以生成可以在编辑器和脚本中使用的图集资源了。
3638

3739
### Atlas 和 SpriteFrame
3840

39-
[图像资源文档](../ui-system/components/editor/sprite.md)中,我们介绍了 Texture 和 SpriteFrame 的关系。导入图集资源后,我们可以看到类型为 `Atlas` 的图集资源可以点击左边的三角图标展开,展开后可以看到图集资源里包含了很多类型为 `SpriteFrame` 的子资源,每个子资源都是可以单独使用和引用的图片
41+
导入图集资源后,点击类型为 **Atlas** 的图集资源左边的三角图标,展开后可以看到图集资源里包含了很多类型为 `SpriteFrame` 的子资源,每个子资源都可以单独使用/引用
4042

4143
![sprite frame](atlas/spriteframes.png)
4244

43-
接下来对于 Sprite Frame 的使用方法就和图像资源中介绍的一样了,请查阅相关文档
45+
关于 SpriteFrame 的使用方式,详情请参考 [SpriteFrame](sprite-frame.md) 文档
4446

4547
<!-- ## 碎图转图集
4648

zh/asset/atlas/spriteframes.png

-214 KB
Loading

zh/asset/image.md

+31-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
11
# 图像资源
22

3-
图像资源又经常被称作贴图、图片,是游戏中绝大部分图像渲染的数据源。图像资源一般由图像处理软件(比如 Photoshop,Windows 上自带的画图)制作而成并输出成 Cocos Creator 可以使用的文件格式,目前包括 JPGPNG 两种
3+
图像资源又经常被称作贴图、图片,是游戏中绝大部分图像渲染的数据源。图像资源一般由图像处理软件(比如 Photoshop,Windows 上自带的画图)制作而成并输出成 Cocos Creator 可以使用的文件格式,目前支持 **JPG****PNG****BMP** 格式
44

55
## 导入图像资源
66

7-
使用默认的资源导入方式就可以将图像资源导入到项目中,之后我们就可以在 **资源管理器** 中看到如下图所示的图像资源
7+
将图像资源直接拖拽到 **资源管理器** 即可将其导入到项目中,之后我们就可以在 **资源管理器** 中看到如下图所示的图像资源
88

9-
![](texture/imported.png)
9+
![imported](texture/imported.png)
10+
11+
**属性检查器** 中图像资源的相关属性说明如下:
12+
13+
| 属性 | 说明 |
14+
| :--- | :--- |
15+
| Type | 用于设置图像资源的类型,包括 **raw****texture**(默认)、**normal map****sprite-frame****texture cube**,具体说明可参考下文 **图像资源类型** 部分的内容。 |
16+
| Flip Vertical | 是否沿 X 轴垂直翻转导入的贴图。 |
17+
| useComponentTexture | 是否使用压缩纹理,详情请参考 [压缩纹理](compress-texture.md)|
1018

1119
## 图像资源的类型
1220

13-
选中导入的图像资源,在右侧的属性检查器面板上,可以选择图像资源不同的使用方式,目前共有4中使用方式供开发者使用,如下所示:
21+
**资源管理器** 面板选中导入的图像资源,在 **属性检查器** 面板中便可根据需要设置图像资源的使用类型,目前支持以下几种:
22+
23+
![type-change](texture/type-change.png)
24+
25+
- **raw**:原始图片类型,无作用,用户不需要关心。
26+
27+
- **texture**:图像资源类型,也是导入的图像资源的默认类型,详情可参考 [纹理贴图资源](texture.md)
28+
29+
- **normal map**:法线贴图类型,常用于渲染 3D 模型,可在模型材质中勾选 `USE NORMAL MAP` 属性使用。需要注意的是,如果材质中没有定义 `USE NORMAL MAP` 就没有该属性。
30+
31+
![normal-map](texture/normal-map.png)
32+
33+
- **sprite-frame**:精灵帧资源,用于 UI 制作上,详情可参考 [SpriteFrame](sprite-frame.md)
34+
35+
- **texture cube**:立方贴图类型,使用在全景图上,常用于制作天空盒。详情可参考 [立方体贴图](texture-cube.md)
1436

15-
![](texture/type-change.png)
37+
## 子资源
1638

17-
各类型图像资源的详情在下面的章节中有详细介绍:
18-
- raw 类型为原始图片类型,无作用,用户不需使用
19-
- texture 类型为图像资源类型,也为导入的默认类型,详情可参考 [Texture](texture.md)
20-
- normal map 类型为法线贴图类型
21-
- sprite-frame 类型为精灵帧资源,用于 UI 制作上,详情可参考 [SpriteFrame](sprite-frame.md)
22-
- texture cube 类型为立方贴图类型,使用在全景图上,用于制作天空盒上,详情可参考 [天空盒](../concepts/scene/skybox.md#修改天空盒的环境贴图)
39+
每个图像资源导入后或者设置图像资源类型后,编辑器便会自动在其下方创建相应类型的子资源。在 **资源管理器** 中点击图像资源左侧的三角图标,即可展开查看图像资源的子资源。
2340

24-
**资源管理器** 中,图像资源的左边会显示一个和文件夹类似的三角图标,点击就可以展开看到它的子资源(sub asset),每个图像资源导入后编辑器会自动在它下面创建同名的 **选中类型** 的资源。选中资源本身可进行更改资源类型、设置图像翻转及设置图像在各平台的质量的操作。子资源的详细属性说明请参考 [子资源属性面板](texture.md#子资源Texture2D的属性面板)
41+
下图以 texture 类型的图像资源为例:
2542

26-
![](texture/image-info.png)
43+
![image info](texture/sub-texture.png)
2744

28-
![](texture/texture-info.png)
45+
子资源的详细属性说明请参考对应资源类型的文档说明。**normal map** 的子资源属性与 **texture** 一致,可参考 [纹理贴图资源](texture.md)

zh/asset/label-atlas.md

+19-14
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,34 @@
44

55
## 创建艺术数字资源
66

7-
**资源管理器** 的文件夹中点击右键或者点击左上方的加号按钮,然后选择 **创建 -> 艺术数字配置**将会新建一个 **LabelAtlas.labelatlas** 的资源。
7+
**资源管理器** 中点击右键,然后选择 **创建 -> 艺术数字配置**或者点击 **资源管理器** 左上角的加号按钮:
88

99
![create label atlas](label-atlas/create-label-atlas.png)
1010

11-
**艺术数字资源** 在使用之前需要进行一些配置,比如关联事先绘制好的包含所需字体样式的图片,如下图所示
11+
即可新建一个艺术数字资源
1212

13-
![](label-atlas/raw_texture_file.png)
13+
![label atlas](label-atlas/label-atlas.png)
1414

15-
## 配置艺术数字资源
15+
## 属性
1616

17-
**资源管理器** 中选中一个 **艺术数字资源** 后,**属性检查器** 面板将会显示 **艺术数字资源** 的所有可配置项。
17+
| 属性 | 功能说明
18+
| :---------- | :----------
19+
| SpriteFrame | 设置事先绘制好的包含所需字体样式的图片
20+
| Item Width | 指定每一个字符的宽度
21+
| Item Height | 指定每一个字符的高度
22+
| Start Char | 指定艺术数字字体里面的第一个字符,如果字符是空格,也需要在这个属性里面输入空格字符
23+
| Font Size | 显示每个字符的大小,由 **Item Width****Item Height** 自动计算得出,不可编辑
1824

19-
| 属性 | 功能说明
20-
| -------------- | -----------
21-
| SpriteFrame | 设置事先绘制好的包含所需字体样式的图片
22-
| Item Width | 指定每一个字符的宽度
23-
| Item Height | 指定每一个字符的高度
24-
| Start Char | 指定艺术数字字体里面的第一个字符,如果字符是 Space,也需要在这个属性里面输入空格字符
25+
**艺术数字资源** 在使用之前需要先配置包含所需字体样式的 SpriteFrame 贴图,如下图:
2526

26-
配置完成后点击右上方的打勾按钮来保存设置。
27+
![raw_texture_file](label-atlas/raw_texture_file.png)
2728

28-
![save label atlas](label-atlas/save-label-atlas.png)
29+
然后将其拖拽到 **艺术数字资源****SpriteFrame** 属性框中:
30+
31+
![sprite-frame](label-atlas/save-label-atlas.png)
32+
33+
设置完成后请点击右上角的绿色打钩按钮保存。
2934

3035
## 使用艺术数字资源
3136

32-
使用艺术数字资源非常简单,你只需要新建一个 Label 组件,然后将新建好的艺术数字资源拖拽到节点的 Label 组件的 Font 属性上即可。可参考 [Label 组件](../ui-system/components/editor/label.md)
37+
使用艺术数字资源只需要在 **层级管理器** 中新建一个 Label 节点,然后在 **属性检查器** 中将新建好的艺术数字资源拖拽到节点 Label 组件的 Font 属性上即可。详情可参考 [Label 组件](../ui-system/components/editor/label.md)
-388 KB
Loading

zh/asset/label-atlas/label-atlas.png

20.8 KB
Loading
-52 KB
Loading
6.04 KB
Loading

zh/asset/render-texture.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@
22

33
渲染纹理是一张在 GPU 上的纹理。通常我们会把它设置到相机的 **目标纹理** 上,使相机照射的内容通过离屏的 `frambuffer` 绘制到该纹理上。一般可用于制作汽车后视镜,动态阴影等功能。
44

5+
## 创建 RenderTexture
6+
7+
**资源管理器** 中点击左上方的 **+** 按钮,选择 **渲染纹理**,即可创建渲染纹理资源:
8+
9+
![add-render-texture](render-texture/add-render-texture.png)
10+
11+
然后在 **属性检查器** 中便可以设置渲染纹理资源的相关属性:
12+
13+
![render-texture-property](render-texture/render-texture-property.png)
14+
15+
| 属性 | 说明 |
16+
| :--- | :--- |
17+
| **Width** | 设置渲染纹理的宽 |
18+
| **Height** | 设置渲染纹理的高 |
19+
520
## 使用 RenderTexture
621

22+
方法一:将 3D 相机可见范围内的内容绘制到 UI 的精灵帧上
23+
724
```typescript
8-
// 方法一:把 3D 相机照射的内容绘制到 UI 的精灵帧上
925
export class CaptureToWeb extends Component {
1026
@property(Sprite)
1127
sprite: Sprite = null;
@@ -40,8 +56,11 @@ export class CaptureToWeb extends Component {
4056
this.sprite.spriteFrame = sp;
4157
}
4258
}
59+
```
60+
61+
方法二:将 3D 相机可见范围内的内容绘制到 3D 模型上
4362

44-
// 方法二:把 3D 相机照射的内容绘制到 3D 模型上
63+
```ts
4564
export class RenderCameraToModel extends Component {
4665
@property(MeshRenderer)
4766
model: MeshRenderer = null;
8.66 KB
Loading
Loading

0 commit comments

Comments
 (0)