Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GUI Infrastructure #2375

Open
wants to merge 214 commits into
base: dev/1.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 212 commits
Commits
Show all changes
214 commits
Select commit Hold shift + click to select a range
9c1b561
refactor(renderpipeline): refactor framework
singlecoder Aug 21, 2023
a44de9e
refactor(renderpipeline): opt code
singlecoder Aug 22, 2023
d504369
refactor(renderpipeline): fix conflicts
singlecoder Aug 22, 2023
06c8e53
refactor(renderpipeline): opt code
singlecoder Aug 22, 2023
60b240a
refactor(renderpipeline): opt code
singlecoder Aug 29, 2023
123dde4
refactor(renderpipeline): fix conflicts
singlecoder Aug 29, 2023
563bfbe
refactor(renderpipeline): opt code
singlecoder Aug 29, 2023
a2a236b
refactor(rederpipeline): opt code
singlecoder Aug 29, 2023
bfd7435
refactor(renderpipeline): fix conflicts
singlecoder Sep 13, 2023
51de522
refactor(renderpipeline): fix conflicts
singlecoder Sep 13, 2023
88bb053
refactor(renderpipeline): fix conflicts
singlecoder Sep 13, 2023
554b80a
refactor(renderpipeline): fix conflicts
singlecoder Sep 13, 2023
339f7eb
refactor(renderpipeline): opt code
singlecoder Sep 14, 2023
c648e0c
refactor(renderpipeline): merge code from main
singlecoder Sep 20, 2023
26308cf
refactor(renderpipeline): merge code from main
singlecoder Oct 7, 2023
28d9579
refactor(2d): fix conflicts
singlecoder Nov 2, 2023
139f247
refactor(2d-render-pipeline): fix conflicts
singlecoder Nov 22, 2023
a0ed23b
Merge branch 'main' into refactor/2d-render-pipeline
singlecoder Dec 12, 2023
b550930
Merge branch 'main' into refactor/2d-render-pipeline
singlecoder Dec 20, 2023
2d86283
Merge branch 'main' into refactor/2d-render-pipeline
singlecoder Dec 25, 2023
8e028fb
refactor(render-pipeline): opt code
singlecoder Dec 28, 2023
40b1e88
refactor(2d-render-pipeline): fix conflicts
singlecoder Jan 16, 2024
eee57cf
refactor(2d-render-pipeline): opt buffer update data
singlecoder Jan 16, 2024
4be33d5
Merge branch 'main' into refactor/2d-render-pipeline
singlecoder Jan 16, 2024
0d3f67b
refactor(2d-render-pipeline): opt code
singlecoder Jan 16, 2024
61bfb35
refactor(2d-render-pipeline): fix conflicts
singlecoder Feb 4, 2024
9dd5bf1
refactor(2d-render-pipeline): fix conflicts
singlecoder Feb 4, 2024
371550b
refactor(2d-render-pipeline): opt render data api
singlecoder Feb 20, 2024
ed074ff
Merge branch 'main' into refactor/2d-render-pipeline
singlecoder Feb 20, 2024
08214c2
refactor(2d-render-pipeline): add MeshBuffer
singlecoder Feb 22, 2024
094b5e6
refactor(2d-render-pipeline): complete sprite renderer and sprite mask
singlecoder Mar 5, 2024
04eb47c
refactor(2d-render-pipeline): complete sprite renderer draw mode
singlecoder Mar 5, 2024
650b135
refactor(2d-render-pipeline): complete text renderer
singlecoder Mar 5, 2024
3f0cfa0
refactor(2d-render-pipeline): fix conflicts from dev/1.2
singlecoder Mar 15, 2024
7e33812
refactor(2d-render-pipeline): fix conflicts from dev/1.2
singlecoder Mar 15, 2024
c265204
Merge branch 'main' into refactor/2d-render-pipeline
singlecoder Mar 28, 2024
d442be2
refactor(2d-render-pipeline): fix conflicts from dev/1.3
singlecoder Apr 10, 2024
7a09c01
refactor(2d-render-pipeline): delete IBatcher
singlecoder Apr 11, 2024
901ba13
refactor(2d-render-pipeline): move IPoolElement to Pool
singlecoder Apr 11, 2024
b256155
refactor(2d-render-pipeline): replace CharRenderDataPool with Pool
singlecoder Apr 11, 2024
10bb95b
refactor(2d-render-pipeline): create mesh buffer support custom size
singlecoder Apr 12, 2024
b62df3a
refactor(2d-render-pipeline): opt code
singlecoder Apr 18, 2024
0dbad8d
refactor(2d-render-pipeline): opt code
singlecoder Apr 18, 2024
9e50d30
refactor(2d-render-pipeline): opt text renderer upload texture
singlecoder Apr 19, 2024
ebd27df
feat(ui-init): init ui package
singlecoder Apr 24, 2024
c98748f
feat(ui-init): add basic class
singlecoder Apr 24, 2024
7649de4
refactor(2d-render-pipeline): rename the rendering order function of …
singlecoder Apr 25, 2024
68657e8
refactor(2d-render-pipeline): fix test
singlecoder Apr 25, 2024
c95c0c2
refactor(2d-render-pipeline): fix test error
singlecoder Apr 26, 2024
8f36498
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder Apr 26, 2024
10fc066
refactor(2d-render-pipeline): fix chunk error
singlecoder Apr 26, 2024
c9ac2a5
refactor(2d-render-pipeline): opt code
singlecoder Apr 28, 2024
5dc393d
refactor(2d-render-pipeline): opt code
singlecoder Apr 28, 2024
d667d99
refactor(2d-render-pipeline): opt code
singlecoder Apr 29, 2024
caa0a38
refactor(2d-render-pipeline): fix 2d sort error
singlecoder Apr 29, 2024
8f77a72
refactor(2d-render-pipeline): change 2d batch structure
singlecoder Apr 30, 2024
f08d477
refactor(2d-render-pipeline): opt code
singlecoder Apr 30, 2024
7f4a460
refactor(2d-render-pipeline): opt code
singlecoder May 6, 2024
cfe01a5
refactor(2d-render-pipeline): opt code
singlecoder May 6, 2024
83cbf4a
refactor(2d-render-pipeline): fix sprite draw mode tiled error
singlecoder May 6, 2024
c353ee3
refactor(2d-render-pipeline): rename CharRenderData to CharRenderInfo
singlecoder May 6, 2024
fbf6ed1
refactor(2d-render-pipeline): opt code
singlecoder May 6, 2024
997f29f
refactor(2d-render-pipeline): fix render queue sort error
singlecoder May 7, 2024
68f8993
refactor(2d-render-pipeline): fix render queue sort error
singlecoder May 7, 2024
96e9621
refactor(2d-render-pipeline): opt code
singlecoder May 7, 2024
f9e67ec
refactor(2d-render-pipeline): opt performance for render queue sort
singlecoder May 7, 2024
48bcccf
refactor(2d-render-pipeline): opt performance for render queue sort
singlecoder May 7, 2024
c65299a
refactor(2d-render-pipeline): opt performance for 2d
singlecoder May 7, 2024
0acf868
refactor(2d-render-pipeline): opt code
singlecoder May 8, 2024
5871137
refactor(2d-render-pipeline): opt code
singlecoder May 9, 2024
999e348
refactor(2d-render-pipeline): opt code
singlecoder May 9, 2024
fa5a17f
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder May 10, 2024
8fae435
feat(ui): rename resolution adaptation strategy
singlecoder May 10, 2024
332ff64
feat(ui): add ui canvas and ui renderer
singlecoder May 10, 2024
3710d41
Merge branch 'dev/1.3' into refactor/2d-render-pipeline
singlecoder May 10, 2024
1714428
refactor(2d-render-pipeline): fix shadow error
singlecoder May 11, 2024
8bcde48
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder May 13, 2024
a0e2dc5
feat(ui): init ui canvas
singlecoder May 13, 2024
f232172
feat(ui): add get set for ui canvas
singlecoder May 21, 2024
09e975c
refactor(2d-render-pipeline): opt code for simple assembler
singlecoder May 21, 2024
bfb78bc
refactor(2d-render-pipeline): opt code for sprite assemble
singlecoder May 21, 2024
a35fc8f
refactor(2d-render-pipeline): opt code
singlecoder May 21, 2024
169f3eb
refactor(2d-render-pipeline): opt code
singlecoder May 21, 2024
436d4b1
refactor(2d-render-pipeline): opt code
singlecoder May 21, 2024
ae911ae
refactor(2d-render-pipeline): opt code
singlecoder May 22, 2024
2621b7e
refactor(2d-render-pipeline): opt code for batch
singlecoder May 22, 2024
0b2b12d
refactor(2d-render-pipeline): rename SpriteRenderData to RenderData2D
singlecoder May 24, 2024
239feed
refactor(2d-render-pipeline): use primitive to change buffer mesh in …
singlecoder May 31, 2024
8388166
refactor(2d-render-pipeline): opt code
singlecoder Jun 3, 2024
520da7b
refactor(2d-render-pipeline): clean render queue
singlecoder Jun 3, 2024
54ff8f1
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder Jun 4, 2024
d8393e8
refactor(2d-render-pipeline): opt code
singlecoder Jun 4, 2024
836e752
refactor(2d-render-pipeline): opt code
singlecoder Jun 4, 2024
169aa09
refactor(2d-render-pipeline): opt code
singlecoder Jun 4, 2024
c09d5e7
refactor(2d-render-pipeline): opt code
singlecoder Jun 4, 2024
df3b5f8
refactor(2d-render-pipeline): fix conflicts
singlecoder Jun 4, 2024
3ada1f6
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder Jun 4, 2024
6edbf7b
refactor(2d-render-pipeline): opt code
singlecoder Jun 4, 2024
fbaa8aa
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder Jun 4, 2024
26b3b94
refactor(2d-render-pipeline): add comment for export TextUtils
singlecoder Jun 5, 2024
bae7a9a
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder Jun 5, 2024
7f613d9
feat(ui): ui canvas
singlecoder Jun 6, 2024
271a77c
test(primitive): test one-to-one 2D renderer and primitive
singlecoder Jun 7, 2024
9575b36
test(primitive): buffer add alloc and free sub buffer
singlecoder Jun 7, 2024
054ded6
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder Jun 11, 2024
cef8757
feat(ui): add temp code
singlecoder Jun 11, 2024
1772f93
refactor(2d-render-pipeline): opt code
singlecoder Jun 11, 2024
a1969c3
refactor(2d-render-pipeline): opt code
singlecoder Jun 11, 2024
78059b3
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder Jun 11, 2024
7d57894
feat(ui): temp code
singlecoder Jun 11, 2024
59d5c86
refactor(2d-render-pipeline): opt chunk
singlecoder Jun 11, 2024
531e2b3
refactor(2d-render-pipeline): revert code
singlecoder Jun 11, 2024
67eea0f
refactor(2d-render-pipeline): opt code
singlecoder Jun 11, 2024
41401e4
refactor(2d-render-pipeline): opt code
singlecoder Jun 11, 2024
0e48dbb
refactor(2d-render-pipeline): opt object pool
singlecoder Jun 11, 2024
4cb99c8
refactor(2d-render-pipeline): opt code for dynamic geometry data
singlecoder Jun 11, 2024
e2a74ca
refactor(2d-render-pipeline): opt code
singlecoder Jun 11, 2024
ef592f6
refactor(2d-render-pipeline): opt code
singlecoder Jun 11, 2024
80e88c8
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder Jun 12, 2024
edc5953
refactor(2d-render-pipeline): fix import error
singlecoder Jun 12, 2024
6a0962e
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder Jun 12, 2024
b4748af
refactor(2d-render-pipeline): opt code
singlecoder Jun 12, 2024
3d8cbc2
refactor(2d-render-pipeline): fix test error
singlecoder Jun 12, 2024
c880f70
refactor(2d-render-pipeline): refactor mask
singlecoder Jun 12, 2024
0455188
refactor(2d-render-pipeline): opt upload buffer
singlecoder Jun 12, 2024
44447f3
refactor(2d-render-pipeline): opt code
singlecoder Jun 12, 2024
98e7887
refactor(2d-render-pipeline): add sub render element and sub render data
singlecoder Jun 13, 2024
4b5dc36
refactor(2d-render-pipeline): opt dynamic update shader data for rend…
singlecoder Jun 13, 2024
7f6798d
refactor(2d-render-pipeline): fix text render error
singlecoder Jun 13, 2024
7347e62
refactor(2d-render-pipeline): fix mesh renderer error
singlecoder Jun 13, 2024
59ce725
refactor(2d-render-pipeline): opt code
singlecoder Jun 13, 2024
c502f6d
refactor(2d-render-pipeline): delete unused class
singlecoder Jun 13, 2024
e0e85c6
refactor(2d-render-pipeline): clean render element
singlecoder Jun 13, 2024
70cc80d
refactor(2d-render-pipeline): opt code
singlecoder Jun 13, 2024
8ca4efb
refactor(2d-render-pipeline): opt code for push render data
singlecoder Jun 13, 2024
ba35d56
refactor(2d-render-pipeline): opt code
singlecoder Jun 13, 2024
10d4bf5
refactor(2d-render-pipeline): opt code
singlecoder Jun 13, 2024
c100342
refactor(2d-render-pipeline): delete render data usage
singlecoder Jun 13, 2024
e51478c
refactor(2d-render-pipeline): opt code
singlecoder Jun 14, 2024
bbbc3ff
refactor(2d-render-pipeline): opt text renderer
singlecoder Jun 14, 2024
4c9794b
refactor(2d-render-pipeline): add textSubRenderElementPool for text r…
singlecoder Jun 14, 2024
30348f1
refactor(2d-render-pipeline): opt code for mask
singlecoder Jun 14, 2024
8583bf9
refactor(2d-render-pipeline): opt code for mask
singlecoder Jun 14, 2024
43687db
refactor(2d-render-pipeline): opt text renderer
singlecoder Jun 14, 2024
754a7f4
refactor(2d-render-pipeline): opt code
singlecoder Jun 14, 2024
8332c31
refactor(2d-render-pipeline): opt code
singlecoder Jun 14, 2024
6b07a12
refactor(2d-render-pipeline): opt code
singlecoder Jun 14, 2024
1bf8334
refactor(2d-render-pipeline): opt upload buffer
singlecoder Jun 14, 2024
3f46739
refactor(2d-render-pipeline): opt upload buffer
singlecoder Jun 14, 2024
dc293bd
refactor(2d-render-pipeline): rename dynamic geometry data
singlecoder Jun 14, 2024
9860e71
refactor(2d-render-pipeline): rename dynamic geometry data
singlecoder Jun 14, 2024
2ab14d6
refactor(2d-render-pipeline): rename dynamic geometry data
singlecoder Jun 14, 2024
beb3593
refactor(2d-render-pipeline): opt code
singlecoder Jun 14, 2024
aa0d174
refactor(2d-render-pipeline): opt code
singlecoder Jun 14, 2024
af0f2d7
refactor(2d-render-pipeline): opt code
singlecoder Jun 14, 2024
0b45a7f
refactor(2d-render-pipeline): opt code
singlecoder Jun 14, 2024
7cb710c
refactor(2d-render-pipeline): opt code
singlecoder Jun 14, 2024
e4f0d93
refactor(2d-render-pipeline): fix test error
singlecoder Jun 14, 2024
854410d
Test0 (#10)
GuoLei1990 Jun 17, 2024
5cb8b48
refactor(2d-render-pipeline): opt code
singlecoder Jun 17, 2024
ce13c8e
refactor(2d-render-pipeline): fix conflict from dev/1.3
singlecoder Jun 17, 2024
e9f2bee
refactor(2d-render-pipeline): fix upload buffer error
singlecoder Jun 17, 2024
38edcbf
refactor(2d-renderpip): fix show errofffffffffffffffffffffff
singlecoder Jun 17, 2024
9d407d2
feat(ui): merge from refactor 2d render pipeline and fix conflicts
singlecoder Jun 18, 2024
043d9fa
refactor(2d-render-pipeline): opt code
singlecoder Jun 18, 2024
0aa5514
refactor(2d-render-pipeline): opt code
singlecoder Jun 18, 2024
6475f15
fix(e2e): fix e2e error
singlecoder Jun 18, 2024
6a7bf93
refactor(2d-render-pipeline): fix conflicts
singlecoder Jun 18, 2024
0b99f79
refactor(2d-render-pipeline): opt code
singlecoder Jun 18, 2024
75bc0c1
refactor(2d-render-pipeline): fix conflicts
singlecoder Jun 19, 2024
beb506b
refactor(2d-render-pipeline): fix e2e error
singlecoder Jun 19, 2024
fdca466
refactor(2d-render-pipeline): opt code
singlecoder Jun 19, 2024
e3f0aae
refactor(2d-render-pipeline): fix e2e screen shot error
singlecoder Jun 19, 2024
37359f0
refactor(2d-render-pipeline): opt code
singlecoder Jun 19, 2024
31529a9
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder Jun 19, 2024
1203df7
refactor(2d-render-pipeline): opt code
singlecoder Jun 19, 2024
42dcd13
Merge branch 'refactor/2d-render-pipeline' into feature/ui-init
singlecoder Jun 19, 2024
5fef2a1
Merge branch 'dev/1.3' into feature/ui-init
singlecoder Jun 20, 2024
78add14
feat: ui transform (#9)
cptbtptpbcptdtptp Jun 20, 2024
fd2dc9d
Merge remote-tracking branch 'chengkong/feature/ui-init' into feature…
singlecoder Jun 20, 2024
c9177bf
Merge branch 'dev/1.3' into feature/ui-init
singlecoder Jun 25, 2024
e71a6da
feat(ui): fix conflicts from dev/1.3
singlecoder Jul 4, 2024
1457cdd
UI Canvas (#11)
singlecoder Jul 16, 2024
c9b3157
feat(ui): fix conflicts from dev/1.3
singlecoder Jul 16, 2024
477af1f
feat(ui): opt code for ui canvas
singlecoder Jul 17, 2024
7ccffd3
Merge branch 'dev/1.3' into feature/ui-init
singlecoder Jul 17, 2024
11691f6
feat(ui): opt code
singlecoder Jul 18, 2024
4934498
feat(ui): opt code
singlecoder Jul 18, 2024
f0ebdd0
feat(ui): opt cde
singlecoder Jul 18, 2024
fa07ecd
feat(ui): fix conflicts from dev/1.3
singlecoder Jul 23, 2024
7ae6558
Merge branch 'dev/1.3' into feature/ui-init
singlecoder Jul 30, 2024
52c0d28
feat(ui): add overlay camera add and remove when need
singlecoder Jul 30, 2024
5931066
feat(gui): merge main
singlecoder Aug 13, 2024
a197c1e
Merge code (#12)
cptbtptpbcptdtptp Aug 29, 2024
189a1e7
fix: shaderlab code
Aug 9, 2024
aa6aff8
fix: shaderlab code
Aug 9, 2024
077e163
fix: sprite mask clone bug (#2327)
cptbtptpbcptdtptp Aug 12, 2024
40d926f
Fix animator play backwards error and onStateExit not triggered when …
luzhuang Aug 13, 2024
334bd4a
Fix CharactorController move not effect with transform changed in upd…
luzhuang Aug 13, 2024
8d0ee7a
"v1.3.6"
GuoLei1990 Aug 13, 2024
fc9302b
doc: fix english version of canvas
MrKou47 Aug 13, 2024
2dce250
Feat/add spine doc (#2334)
johanzhu Aug 14, 2024
4e83314
Update README.md
GuoLei1990 Aug 18, 2024
012b61e
Update README.md
GuoLei1990 Aug 18, 2024
f7dacdc
Fix particleRenderer enable startFrame (#2333)
JujieX Aug 20, 2024
41075e6
"v1.3.7"
GuoLei1990 Aug 20, 2024
2f4ce0f
fix(demo): fix video demo error in ios, video will show full screen (…
singlecoder Aug 20, 2024
04bb5b3
Change image in spine doc (#2356)
johanzhu Aug 21, 2024
f237f6a
feat(gui): merge code from dev 1.4
singlecoder Aug 29, 2024
20a1d30
Init UI Input (#13)
cptbtptpbcptdtptp Sep 12, 2024
5279a74
Merge branch 'dev/1.4' into feature/ui-init
singlecoder Sep 12, 2024
6a87332
feat(gui): opt code
singlecoder Oct 10, 2024
a5e0642
feat(gui): opt code
singlecoder Oct 11, 2024
d88532f
Add bubble event. (#16)
cptbtptpbcptdtptp Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/core/src/2d/assembler/ISpriteAssembler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { Vector2 } from "@galacean/engine-math";
import { Renderer } from "../../Renderer";

/**
* @internal
*/
export interface ISpriteAssembler {
resetData(renderer: Renderer, vertexCount?: number): void;
updatePositions?(renderer: Renderer): void;
updatePositions?(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After adding parameters like width, height, pivot, and flip, it seems that the function is no longer just updating the position. Should we consider renaming the function, or adding a new method for these updates?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After adding parameters like width, height, pivot, and flip, it seems that the function is no longer just updating the position. Should we consider renaming the function, or adding a new method for these updates?

This method just for update vertex position, can you give a other case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my problem. I saw that the input parameters changed, and I thought the function accusation also changed.
Please revolve this comment.

renderer: Renderer,
width: number,
height: number,
pivot: Vector2,
flipX?: boolean,
flipY?: boolean
): void;
updateUVs?(renderer: Renderer): void;
updateColor?(renderer: Renderer): void;
updateColor?(renderer: Renderer, alpha?: number): void;
updateAlpha?(renderer: Renderer, alpha: number): void;
}
36 changes: 27 additions & 9 deletions packages/core/src/2d/assembler/SimpleSpriteAssembler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BoundingBox, Matrix } from "@galacean/engine-math";
import { BoundingBox, Matrix, Vector2 } from "@galacean/engine-math";
import { StaticInterfaceImplement } from "../../base/StaticInterfaceImplement";
import { UIImage } from "../../ui";
import { SpriteMask } from "../sprite";
import { SpriteRenderer } from "../sprite/SpriteRenderer";
import { ISpriteAssembler } from "./ISpriteAssembler";
Expand All @@ -12,7 +13,7 @@ export class SimpleSpriteAssembler {
static _rectangleTriangles = [0, 1, 2, 2, 1, 3];
static _worldMatrix = new Matrix();

static resetData(renderer: SpriteRenderer | SpriteMask): void {
static resetData(renderer: SpriteRenderer | SpriteMask | UIImage): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that we now have three related types (SpriteRenderer, SpriteMask, and UIImage). To improve readability and maintainability, would it be better to define a single type for these renderable components, such as Renderable? This way, we can avoid redundancy and make future updates easier.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, you should try to pr

const manager = renderer._getChunkManager();
const lastSubChunk = renderer._subChunk;
lastSubChunk && manager.freeSubChunk(lastSubChunk);
Expand All @@ -21,16 +22,23 @@ export class SimpleSpriteAssembler {
renderer._subChunk = subChunk;
}

static updatePositions(renderer: SpriteRenderer | SpriteMask): void {
const { width, height, sprite } = renderer;
const { x: pivotX, y: pivotY } = sprite.pivot;
static updatePositions(
renderer: SpriteRenderer | SpriteMask | UIImage,
width: number,
height: number,
pivot: Vector2,
flipX: boolean = false,
flipY: boolean = false
): void {
const { sprite } = renderer;
const { x: pivotX, y: pivotY } = pivot;
// Renderer's worldMatrix
const worldMatrix = SimpleSpriteAssembler._worldMatrix;
const { elements: wE } = worldMatrix;
// Parent's worldMatrix
const { elements: pWE } = renderer.entity.transform.worldMatrix;
const sx = renderer.flipX ? -width : width;
const sy = renderer.flipY ? -height : height;
const sx = flipX ? -width : width;
const sy = flipY ? -height : height;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran a performance test comparing the ternary operator version and a simplified multiplication version for sx and sy. The results showed that the multiplication approach is consistently faster. Since both versions produce the same output, I recommend switching to the multiplication method to improve performance, especially in cases where this function is called frequently. Here’s the updated version:

const sx = width * (flipX ? -1 : 1);
const sy = height * (flipY ? -1 : 1);

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

理论上 -x 应该是比 -1 * x 性能更好

另外,-1 * x 和 x 对比怎么样呢

(wE[0] = pWE[0] * sx), (wE[1] = pWE[1] * sx), (wE[2] = pWE[2] * sx);
(wE[4] = pWE[4] * sy), (wE[5] = pWE[5] * sy), (wE[6] = pWE[6] * sy);
(wE[8] = pWE[8]), (wE[9] = pWE[9]), (wE[10] = pWE[10]);
Expand Down Expand Up @@ -74,15 +82,25 @@ export class SimpleSpriteAssembler {
vertices[offset + 28] = top;
}

static updateColor(renderer: SpriteRenderer): void {
static updateColor(renderer: SpriteRenderer, alpha: number = 1): void {
const subChunk = renderer._subChunk;
const { r, g, b, a } = renderer.color;
const finalAlpha = a * alpha;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above three lines and following line can be optimized using destructuring to reduce redundancy and improve readability. Here’s an optimized version:

const { _subChunk: { chunk: { vertices } }, color: { r, g, b, a } } = renderer;
const finalAlpha = a * alpha;

const vertices = subChunk.chunk.vertices;
for (let i = 0, o = subChunk.vertexArea.start + 5; i < 4; ++i, o += 9) {
vertices[o] = r;
vertices[o + 1] = g;
vertices[o + 2] = b;
vertices[o + 3] = a;
vertices[o + 3] = finalAlpha;
}
}

static updateAlpha(renderer: SpriteRenderer, alpha: number = 1): void {
const subChunk = renderer._subChunk;
const finalAlpha = renderer.color.a * alpha;
const vertices = subChunk.chunk.vertices;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above three lines can be optimized using destructuring to make it more concise and avoid repeated references to renderer and subChunk. Here's a suggested improvement:
const { _subChunk: { chunk: { vertices } }, color: { a } } = renderer;
const finalAlpha = a * alpha;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think this is not good for readability.

for (let i = 0, o = subChunk.vertexArea.start + 5; i < 4; ++i, o += 9) {
vertices[o + 3] = finalAlpha;
}
}
}
43 changes: 31 additions & 12 deletions packages/core/src/2d/assembler/SlicedSpriteAssembler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Matrix } from "@galacean/engine-math";
import { Matrix, Vector2 } from "@galacean/engine-math";
import { StaticInterfaceImplement } from "../../base/StaticInterfaceImplement";
import { UIImage } from "../../ui";
import { SpriteMask } from "../sprite";
import { SpriteRenderer } from "../sprite/SpriteRenderer";
import { ISpriteAssembler } from "./ISpriteAssembler";

Expand All @@ -14,7 +16,7 @@ export class SlicedSpriteAssembler {
];
static _worldMatrix = new Matrix();

static resetData(renderer: SpriteRenderer): void {
static resetData(renderer: SpriteRenderer | UIImage): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the previous comment regarding SpriteRenderer | SpriteMask | UIImage. To avoid redundancy, consider using the same Renderable type here as well. See the comment in packages/core/src/2d/assembler/SimpleSpriteAssembler.ts

const manager = renderer._getChunkManager();
const lastSubChunk = renderer._subChunk;
lastSubChunk && manager.freeSubChunk(lastSubChunk);
Expand All @@ -23,8 +25,15 @@ export class SlicedSpriteAssembler {
renderer._subChunk = subChunk;
}

static updatePositions(renderer: SpriteRenderer): void {
const { width, height, sprite } = renderer;
static updatePositions(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same observation as mentioned earlier regarding the updatePositions function. Since the added parameters (width, height, pivot, flipX, and flipY) extend its functionality beyond just position updates, I would recommend renaming the function here as well to something like updateTransform or updateDimensionsAndPosition. This will help clarify its current role.

renderer: SpriteRenderer | SpriteMask | UIImage,
width: number,
height: number,
pivot: Vector2,
flipX: boolean = false,
flipY: boolean = false
): void {
const { sprite } = renderer;
const { border } = sprite;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This two lines can be optimized using destructuring to make it more concise and avoid repeated:

const { sprite: { border } } = renderer;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a subjective preference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the destructuring style, it’s indeed a subjective choice that depends on individual coding style and readability. If the original style aligns with project guidelines or personal preference, then let’s keep it as it is.

// Update local positions.
const spritePositions = sprite._getPositions();
Expand Down Expand Up @@ -73,16 +82,16 @@ export class SlicedSpriteAssembler {
}

// Update renderer's worldMatrix.
const { x: pivotX, y: pivotY } = renderer.sprite.pivot;
const localTransX = renderer.width * pivotX;
const localTransY = renderer.height * pivotY;
const { x: pivotX, y: pivotY } = pivot;
const localTransX = width * pivotX;
const localTransY = height * pivotY;
// Renderer's worldMatrix.
const worldMatrix = SlicedSpriteAssembler._worldMatrix;
const { elements: wE } = worldMatrix;
// Parent's worldMatrix.
const { elements: pWE } = renderer.entity.transform.worldMatrix;
const sx = renderer.flipX ? -1 : 1;
const sy = renderer.flipY ? -1 : 1;
const sx = flipX ? -1 : 1;
const sy = flipY ? -1 : 1;
(wE[0] = pWE[0] * sx), (wE[1] = pWE[1] * sx), (wE[2] = pWE[2] * sx);
(wE[4] = pWE[4] * sy), (wE[5] = pWE[5] * sy), (wE[6] = pWE[6] * sy);
(wE[8] = pWE[8]), (wE[9] = pWE[9]), (wE[10] = pWE[10]);
Expand Down Expand Up @@ -118,7 +127,7 @@ export class SlicedSpriteAssembler {
renderer._bounds.transform(worldMatrix);
}

static updateUVs(renderer: SpriteRenderer): void {
static updateUVs(renderer: SpriteRenderer | UIImage): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as commented above.
we have renderer: SpriteRenderer | UIImage, which includes only two classes.
If we anticipate this pattern expanding or being reused in the future, it might still be beneficial to define a type like Renderable for consistency and maintainability, even though there are currently only two classes. However, if this combination is unique to this specific case, leaving it as-is might be more straightforward.

const subChunk = renderer._subChunk;
const vertices = subChunk.chunk.vertices;
const spriteUVs = renderer.sprite._getUVs();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above three lines can be optimized using destructuring to make it more concise and avoid repeated references to renderer and subChunk. Here's a suggested improvement:

const { _subChunk: { chunk: { vertices } }, sprite } = renderer;
const spriteUVs = sprite._getUVs();

Expand All @@ -131,15 +140,25 @@ export class SlicedSpriteAssembler {
}
}

static updateColor(renderer: SpriteRenderer): void {
static updateColor(renderer: SpriteRenderer | UIImage, alpha: number = 1): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as commented above.
we have renderer: SpriteRenderer | UIImage, which includes only two classes.
If we anticipate this pattern expanding or being reused in the future, it might still be beneficial to define a type like Renderable for consistency and maintainability, even though there are currently only two classes. However, if this combination is unique to this specific case, leaving it as-is might be more straightforward.

const subChunk = renderer._subChunk;
const { r, g, b, a } = renderer.color;
const finalAlpha = a * alpha;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above three lines and following line can be optimized using destructuring to reduce redundancy and improve readability. Here’s an optimized version:

const { _subChunk: { chunk: { vertices } }, color: { r, g, b, a } } = renderer;
const finalAlpha = a * alpha;

const vertices = subChunk.chunk.vertices;
for (let i = 0, o = subChunk.vertexArea.start + 5; i < 16; ++i, o += 9) {
vertices[o] = r;
vertices[o + 1] = g;
vertices[o + 2] = b;
vertices[o + 3] = a;
vertices[o + 3] = finalAlpha;
}
}

static updateAlpha(renderer: SpriteRenderer, alpha: number = 1): void {
const subChunk = renderer._subChunk;
const finalAlpha = renderer.color.a * alpha;
const vertices = subChunk.chunk.vertices;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above three lines and following line can be optimized using destructuring to reduce redundancy and improve readability. Here’s an optimized version:

const { _subChunk: { chunk: { vertices } }, color: { a } } = renderer;
const finalAlpha = a * alpha;

for (let i = 0, o = subChunk.vertexArea.start + 5; i < 16; ++i, o += 9) {
vertices[o + 3] = finalAlpha;
}
}
}
43 changes: 31 additions & 12 deletions packages/core/src/2d/assembler/TiledSpriteAssembler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MathUtil, Matrix } from "@galacean/engine-math";
import { MathUtil, Matrix, Vector2 } from "@galacean/engine-math";
import { DisorderedArray } from "../../DisorderedArray";
import { Logger } from "../../base";
import { StaticInterfaceImplement } from "../../base/StaticInterfaceImplement";
import { UIImage } from "../../ui";
import { SpriteTileMode } from "../enums/SpriteTileMode";
import { Sprite } from "../sprite";
import { SpriteRenderer } from "../sprite/SpriteRenderer";
Expand All @@ -18,7 +19,7 @@ export class TiledSpriteAssembler {
static _uvRow = new DisorderedArray<number>();
static _uvColumn = new DisorderedArray<number>();

static resetData(renderer: SpriteRenderer, vertexCount: number): void {
static resetData(renderer: SpriteRenderer | UIImage, vertexCount: number): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as commented above.
we have renderer: SpriteRenderer | UIImage, which includes only two classes.
If we anticipate this pattern expanding or being reused in the future, it might still be beneficial to define a type like Renderable for consistency and maintainability, even though there are currently only two classes. However, if this combination is unique to this specific case, leaving it as-is might be more straightforward.

if (vertexCount) {
const manager = renderer._getChunkManager();
const lastSubChunk = renderer._subChunk;
Expand All @@ -33,8 +34,15 @@ export class TiledSpriteAssembler {
}
}

static updatePositions(renderer: SpriteRenderer): void {
const { width, height, sprite, tileMode, tiledAdaptiveThreshold: threshold } = renderer;
static updatePositions(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same observation as mentioned earlier regarding the updatePositions function. Since the added parameters (width, height, pivot, flipX, and flipY) extend its functionality beyond just position updates, I would recommend renaming the function here as well to something like updateTransform or updateDimensionsAndPosition. This will help clarify its current role.

renderer: SpriteRenderer | UIImage,
width: number,
height: number,
pivot: Vector2,
flipX: boolean = false,
flipY: boolean = false
): void {
const { sprite, tileMode, tiledAdaptiveThreshold: threshold } = renderer;
// Calculate row and column
const { _posRow: posRow, _posColumn: posColumn, _uvRow: uvRow, _uvColumn: uvColumn } = TiledSpriteAssembler;
const maxVertexCount = renderer._getChunkManager().maxVertexCount;
Expand Down Expand Up @@ -64,16 +72,16 @@ export class TiledSpriteAssembler {
);
TiledSpriteAssembler.resetData(renderer, vertexCount);
// Update renderer's worldMatrix
const { x: pivotX, y: pivotY } = renderer.sprite.pivot;
const localTransX = renderer.width * pivotX;
const localTransY = renderer.height * pivotY;
const { x: pivotX, y: pivotY } = pivot;
const localTransX = width * pivotX;
const localTransY = height * pivotY;
// Renderer's worldMatrix
const { _worldMatrix: worldMatrix } = TiledSpriteAssembler;
const { elements: wE } = worldMatrix;
// Parent's worldMatrix
const { elements: pWE } = renderer.entity.transform.worldMatrix;
const sx = renderer.flipX ? -1 : 1;
const sy = renderer.flipY ? -1 : 1;
const sx = flipX ? -1 : 1;
const sy = flipY ? -1 : 1;
let wE0: number, wE1: number, wE2: number;
let wE4: number, wE5: number, wE6: number;
(wE0 = wE[0] = pWE[0] * sx), (wE1 = wE[1] = pWE[1] * sx), (wE2 = wE[2] = pWE[2] * sx);
Expand Down Expand Up @@ -139,7 +147,7 @@ export class TiledSpriteAssembler {
renderer._bounds.transform(worldMatrix);
}

static updateUVs(renderer: SpriteRenderer): void {
static updateUVs(renderer: SpriteRenderer | UIImage): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as commented above.
we have renderer: SpriteRenderer | UIImage, which includes only two classes.
If we anticipate this pattern expanding or being reused in the future, it might still be beneficial to define a type like Renderable for consistency and maintainability, even though there are currently only two classes. However, if this combination is unique to this specific case, leaving it as-is might be more straightforward.

const { _posRow: posRow, _posColumn: posColumn, _uvRow: uvRow, _uvColumn: uvColumn } = TiledSpriteAssembler;
const rowLength = posRow.length - 1;
const columnLength = posColumn.length - 1;
Expand Down Expand Up @@ -173,16 +181,27 @@ export class TiledSpriteAssembler {
}
}

static updateColor(renderer: SpriteRenderer): void {
static updateColor(renderer: SpriteRenderer | UIImage, alpha: number = 1): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as commented above.
we have renderer: SpriteRenderer | UIImage, which includes only two classes.
If we anticipate this pattern expanding or being reused in the future, it might still be beneficial to define a type like Renderable for consistency and maintainability, even though there are currently only two classes. However, if this combination is unique to this specific case, leaving it as-is might be more straightforward.

const subChunk = renderer._subChunk;
const { r, g, b, a } = renderer.color;
const finalAlpha = a * alpha;
const vertices = subChunk.chunk.vertices;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above four lines can be optimized using destructuring to reduce redundancy and improve readability. Here’s an optimized version:

const { _subChunk: { chunk: { vertices } }, color: { r, g, b, a } } = renderer;
const finalAlpha = a * alpha;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destructuring assignment is a concise syntax that is suitable for shallow objects and simple property extraction. It is the recommended approach, especially when dealing with properties that are certain to exist.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 Thanks for the insight! Since destructuring is a subjective choice, let’s keep the original approach as it aligns with your style.

const vertexArea = subChunk.vertexArea;
for (let i = 0, o = vertexArea.start + 5, n = vertexArea.size / 9; i < n; ++i, o += 9) {
vertices[o] = r;
vertices[o + 1] = g;
vertices[o + 2] = b;
vertices[o + 3] = a;
vertices[o + 3] = finalAlpha;
}
}

static updateAlpha(renderer: SpriteRenderer, alpha: number = 1): void {
const subChunk = renderer._subChunk;
const finalAlpha = renderer.color.a * alpha;
const vertices = subChunk.chunk.vertices;
const vertexArea = subChunk.vertexArea;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be optimized using destructuring to reduce redundancy and improve readability. Here’s an optimized version:

const { _subChunk: { chunk: { vertices }, vertexArea }, color: { a } } = renderer;
const finalAlpha = a * alpha;

for (let i = 0, o = vertexArea.start + 5, n = vertexArea.size / 9; i < n; ++i, o += 9) {
vertices[o + 3] = finalAlpha;
}
}

Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/2d/sprite/SpriteMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ export class SpriteMask extends Renderer {
}

protected override _updateBounds(worldBounds: BoundingBox): void {
if (this.sprite) {
SimpleSpriteAssembler.updatePositions(this);
const { sprite } = this;
if (sprite) {
SimpleSpriteAssembler.updatePositions(this, this.width, this.height, sprite.pivot, this._flipX, this._flipY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To improve readability and reduce repeated references to this, I suggest destructuring the properties before calling the method. Here’s an example of how you could simplify it:

const { width, height, _flipX, _flipY } = this;
const { pivot } = sprite;
SimpleSpriteAssembler.updatePositions(this, width, height, pivot, _flipX, _flipY);

This reduces redundancy and makes the code cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destructuring assignment usually takes out the attributes to be reused to avoid repeated reading, which does not exist here.

The code itself is not very complex and can be written in one line, so I don't think it is necessary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 Agreed. We can use this.xx here directly~

} else {
worldBounds.min.set(0, 0, 0);
worldBounds.max.set(0, 0, 0);
Expand All @@ -250,7 +251,8 @@ export class SpriteMask extends Renderer {
* @inheritdoc
*/
protected override _render(context: RenderContext): void {
if (!this.sprite?.texture || !this.width || !this.height) {
const { _sprite: sprite } = this;
if (!sprite?.texture || !this.width || !this.height) {
singlecoder marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand All @@ -266,7 +268,7 @@ export class SpriteMask extends Renderer {

// Update position
if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
SimpleSpriteAssembler.updatePositions(this);
SimpleSpriteAssembler.updatePositions(this, this.width, this.height, sprite.pivot, this._flipX, this._flipY);
singlecoder marked this conversation as resolved.
Show resolved Hide resolved
this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
}

Expand Down
12 changes: 8 additions & 4 deletions packages/core/src/2d/sprite/SpriteRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SpriteMaskInteraction } from "../enums/SpriteMaskInteraction";
import { SpriteModifyFlags } from "../enums/SpriteModifyFlags";
import { SpriteTileMode } from "../enums/SpriteTileMode";
import { Sprite } from "./Sprite";
import { ComponentType } from "../../enums/ComponentType";

/**
* Renders a Sprite for 2D graphics.
Expand Down Expand Up @@ -267,6 +268,7 @@ export class SpriteRenderer extends Renderer {
*/
constructor(entity: Entity) {
super(entity);
this._componentType = ComponentType.SpriteRenderer;
this.drawMode = SpriteDrawMode.Simple;
this._dirtyUpdateFlag |= SpriteRendererUpdateFlags.Color;
this.setMaterial(this._engine._spriteDefaultMaterial);
Expand Down Expand Up @@ -315,16 +317,18 @@ export class SpriteRenderer extends Renderer {
}

protected override _updateBounds(worldBounds: BoundingBox): void {
if (this.sprite) {
this._assembler.updatePositions(this);
const { _sprite: sprite } = this;
if (sprite) {
this._assembler.updatePositions(this, this.width, this.height, sprite.pivot);
singlecoder marked this conversation as resolved.
Show resolved Hide resolved
} else {
worldBounds.min.set(0, 0, 0);
worldBounds.max.set(0, 0, 0);
}
}

protected override _render(context: RenderContext): void {
if (!this.sprite?.texture || !this.width || !this.height) {
const { _sprite: sprite } = this;
if (!sprite?.texture || !this.width || !this.height) {
singlecoder marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand All @@ -339,7 +343,7 @@ export class SpriteRenderer extends Renderer {

// Update position
if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
this._assembler.updatePositions(this);
this._assembler.updatePositions(this, this.width, this.height, sprite.pivot);
singlecoder marked this conversation as resolved.
Show resolved Hide resolved
this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
}

Expand Down
Loading