Skip to content

Commit f12cbf4

Browse files
committed
feat(publish:docs:3.8)添加 sorting2D 组件文档
1 parent 2698929 commit f12cbf4

File tree

23 files changed

+189
-22
lines changed

23 files changed

+189
-22
lines changed

versions/3.8/en/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@
257257
- [VSCode Extension - Cocos Effect](shader/vscode-plugin.md)
258258
- [Compute Shader](shader/compute-shader.md)
259259

260-
- [3D Sorting](engine/rendering/sorting.md)
260+
- [2D Rendering Sorting](engine/rendering/sorting-2d.md)
261+
- [3D Rendering Sorting](engine/rendering/sorting.md)
261262
- [Effects](module-map/effects/index.md)
262263
- [Billboard](particle-system/billboard-component.md)
263264
- [Line](particle-system/line-component.md)

versions/3.8/en/editor/project/index.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,22 @@ The render pipeline is used to control the rendering process of the scene, curre
4646

4747
![sorting-layer](index/sorting-layer.png)
4848

49-
Used to define the sorting capability when rendering translucent objects.
49+
Customize the rendering order for both 2D UI and 3D objects.
5050

51-
- Click the **Delete** button on the right to delete the corresponding layer.
52-
- All layers can be edited manually, except for the `default` layer, which cannot be edited.
53-
- Click the Add Button to add a different layer.
54-
- The layers can be sorted manually by dragging the gray striped button to the left of the sorting layers using the mouse.
51+
* Operation Instructions
52+
- Click the delete button on the right to remove the corresponding layer.
53+
- Except for the `default` layer which cannot be edited, all other layers can have their names manually edited.
54+
- Click the plus button to add different layers.
55+
- Drag and drop the gray striped button on the left side of layers to manually rearrange them.
5556

5657
![drag](index/drag-to-sort.gif)
5758

58-
Once added, [Sorting](../../engine/rendering/sorting.md) can be added to any node that has a MeshRenderer or SpriteRenderer component. And with [Sorting](../../engine/rendering/sorting.md) component to control the manual sorting of these nodes.
59+
* **(2D UI Rendering Order)** After adding render layers, attach the [Sorting2D](../../engine/rendering/sorting-2d.md) component to any 2D render component node and configure the sorting layer and in-layer order to customize the 2D UI rendering sequence.
60+
![sorting-2d](../../../zh/engine/rendering/sorting-2d/sorting2D-component.png)
5961

62+
* **(3D Object Rendering Order)** After adding render layers, attach the [Sorting](../../engine/rendering/sorting.md) component to any node with MeshRenderer or SpriteRenderer components and configure the sorting layer and in-layer order to customize the 3D object rendering sequence.
6063
![sorting](index/sorting.png)
6164

62-
> **Note**: Can only be used for nodes that hold **MeshRenderer** and **SpriteRenderer** components.
63-
6465
## Physics
6566

6667
![physics](./index/physics.png)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# 2D Rendering Sorting Component
2+
3+
The Sorting2D component allows customizing the rendering order of 2D objects without affecting the original node hierarchy. It can help solve the issue of increased DrawCalls caused by adjacent render objects using different materials.
4+
5+
![sorting2D-component](../../../zh/engine/rendering/sorting-2d/sorting2D-component.png)
6+
7+
## Sorting2D Properties
8+
9+
| Property | Description |
10+
| :-------------- | :----------- |
11+
| sortingLayer | Sets the sorting layer for render objects. [**Modify project's sorting layer configuration**](../../editor/project/index.md#sorting-layers). Lower layers are rendered first. Default layer is "Default". |
12+
| sortingOrder | Sets the order of render objects within the same sorting layer. Objects with lower values are rendered first. If values are equal, nodes with lower hierarchy are rendered first. |
13+
14+
**Note**: When recursively collecting render elements from a 2D node tree encounters a Mask renderer, it will use custom sorting rules to render the recorded 2D UI, reset the render state, recollect render elements, and continue using custom sorting rules for the remaining 2D UI after collection is complete.
15+
16+
## Optimization Example
17+
18+
1. Configure sorting layers in your project
19+
20+
![](./sorting-2d/sorting2D-layers.jpg)
21+
22+
2. Enable the `2D Rendering Sorting` module in `Project Settings -> Feature Cropping`
23+
24+
![](./sorting-2d/sorting2D-open.jpg)
25+
26+
3. Add Sorting2D component to 2D UI nodes and set sorting layers and orders.
27+
28+
![](./sorting-2d/sorting2D-setProperty.jpg)
29+
30+
4. Build the project, run and observe optimization results
31+
32+
* Before optimization
33+
![](../../../zh/engine/rendering/sorting-2d/sorting2D-no-optimize.jpg)
34+
35+
* After optimization
36+
![](../../../zh/engine/rendering/sorting-2d/sorting2D-optimized.jpg)
37+
38+
## Modifying Sorting2D Component's Layer and Order in Code
39+
40+
```typescript
41+
import { _decorator, Component, find, Node, settings, Sorting2D } from 'cc';
42+
const { ccclass, property } = _decorator;
43+
44+
const sortingLayers = settings.querySettings("engine", "sortingLayers");
45+
const default_layer = sortingLayers[0].value;
46+
const autoAtlas_1_layer = sortingLayers[1].value;
47+
const autoAtlas_2_layer = sortingLayers[2].value;
48+
const autoAtlas_1_1_layer = sortingLayers[3].value;
49+
const label_layer = sortingLayers[4].value;
50+
51+
@ccclass('NewComponent')
52+
export class NewComponent extends Component {
53+
54+
start() {
55+
var testNode = find("Canvas/test");
56+
if (testNode) {
57+
this.changeUISortingLayer(testNode, autoAtlas_1_layer, 0);
58+
}
59+
}
60+
61+
changeUISortingLayer(sortingNode: Node, sortingLayer: number, sortingOrder?: number) {
62+
if (sortingNode.getComponent(Sorting2D)) {
63+
sortingNode.getComponent(Sorting2D).sortingLayer = sortingLayer;
64+
if (sortingOrder !== undefined) {
65+
sortingNode.getComponent(Sorting2D).sortingOrder = sortingOrder;
66+
}
67+
}
68+
}
69+
}
70+
```
71+
72+
## API Reference and Examples
73+
74+
[Sorting2D API](https://docs.cocos.com/creator/3.8/api/en/class/Sorting2D)
75+
76+
[Sorting2D Demo](https://github.com/zhefengzhang/test-cases-3d/tree/v3.8.7-add-sorting2d-testCase/assets/cases/ui/other/sorting2D)
56.6 KB
Loading
29.7 KB
Loading
38.7 KB
Loading
69.1 KB
Loading

versions/3.8/en/summary.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,11 @@
10951095
"collapsed": true
10961096
},
10971097
{
1098-
"text": "3D Sorting",
1098+
"text": "2D Rendering Sorting",
1099+
"link": "engine/rendering/sorting-2d.md"
1100+
},
1101+
{
1102+
"text": "3D Rendering Sorting",
10991103
"link": "engine/rendering/sorting.md"
11001104
},
11011105
{

versions/3.8/en/ui-system/components/engine/priority.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
2D rendering nodes can be divided into nodes under Canvas and nodes that are not under Canvas:
66

7-
- The nodes under Canvas can be found in **UI node ordering** below.
7+
- - Nodes under Canvas use **[UI node ordering](#ui-node-ordering)** by default. Use the [Sorting2D component](./sorting-2d.md) for custom rendering order.
88

99
- The nodes that are not under Canvas, the user can choose to enable depth detection and occlusion display of 3D objects through [custom materials](ui-material.md), which will render the occlusion according to the Z-axis coordinates of the object when enabled (see example [2d-rendering-in-3d](https://github.com/cocos/cocos-test-projects/tree/v3.8/assets/cases/2D)).
1010

versions/3.8/zh/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@
263263
- [VSCode 着色器插件](shader/vscode-plugin.md)
264264
- [计算着色器](shader/compute-shader.md)
265265

266+
- [2D 渲染排序](engine/rendering/sorting-2d.md)
266267
- [3D 渲染排序](engine/rendering/sorting.md)
267-
268268
- [特效组件](module-map/effects/index.md)
269269
- [广告牌](particle-system/billboard-component.md)
270270
- [线段组件](particle-system/line-component.md)

0 commit comments

Comments
 (0)