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 #2375

Open
wants to merge 229 commits into
base: dev/1.4
Choose a base branch
from
Open

Add GUI #2375

Show file tree
Hide file tree
Changes from 223 commits
Commits
Show all changes
229 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
6904c05
Add UI culling. (#17)
cptbtptpbcptdtptp Oct 21, 2024
d6c03fa
Modify the ui logic as suggested. (#18)
cptbtptpbcptdtptp Oct 22, 2024
f702b2b
feat(ui): fix conflicts
singlecoder Oct 22, 2024
bc8a8d4
Update ui code (#19)
cptbtptpbcptdtptp Oct 24, 2024
53d136e
Add `UIImage.alphaHitTestMinimumThreshold` (#20)
cptbtptpbcptdtptp Oct 28, 2024
15b8e6c
feat(ui): add ui text
singlecoder Nov 1, 2024
4b2487d
Add ui button. (#21)
cptbtptpbcptdtptp Nov 5, 2024
ae63b66
Add UI (#22)
cptbtptpbcptdtptp Nov 6, 2024
8094d8a
feat(ui): fix text bug
singlecoder Nov 6, 2024
3a29609
Separate ui package (#23)
cptbtptpbcptdtptp Nov 20, 2024
8a7073a
Merge branch 'dev/1.4' into feature/ui-init
singlecoder Nov 20, 2024
b8bb449
feat(ui): fix package version
singlecoder Nov 20, 2024
5d4af60
feat(ui): fix lint error
singlecoder Nov 20, 2024
c4ace76
Fix lint error (#24)
cptbtptpbcptdtptp Nov 20, 2024
d73f8f5
Fix pnpm lock (#25)
cptbtptpbcptdtptp Nov 20, 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
26 changes: 21 additions & 5 deletions packages/core/src/2d/assembler/ISpriteAssembler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import { Renderer } from "../../Renderer";
import { Vector2, Vector3 } from "@galacean/engine-math";
import { ISpriteRenderer } from "./ISpriteRenderer";

/**
* @internal
*/
export interface ISpriteAssembler {
resetData(renderer: Renderer, vertexCount?: number): void;
updatePositions?(renderer: Renderer): void;
updateUVs?(renderer: Renderer): void;
updateColor?(renderer: Renderer): void;
resetData(renderer: ISpriteRenderer, vertexCount?: number): void;
updatePositions(
renderer: ISpriteRenderer,
width: number,
height: number,
pivot: Vector2,
flipX?: boolean,
flipY?: boolean
): void;
updateUVs(renderer: ISpriteRenderer): void;
updateColor(renderer: ISpriteRenderer, alpha?: number): void;
getUVByLocalPosition(
renderer: ISpriteRenderer,
width: number,
height: number,
pivot: Vector2,
position: Vector3,
out: Vector2
): boolean;
}
16 changes: 16 additions & 0 deletions packages/core/src/2d/assembler/ISpriteRenderer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Color } from "@galacean/engine-math";
import { PrimitiveChunkManager } from "../../RenderPipeline/PrimitiveChunkManager";
import { SubPrimitiveChunk } from "../../RenderPipeline/SubPrimitiveChunk";
import { Transform } from "../../Transform";
import { SpriteTileMode } from "../enums/SpriteTileMode";
import { Sprite } from "../sprite";

export interface ISpriteRenderer {
sprite: Sprite;
color?: Color;
tileMode?: SpriteTileMode;
tiledAdaptiveThreshold?: number;
_transform: Transform;
_subChunk: SubPrimitiveChunk;
_getChunkManager(): PrimitiveChunkManager;
}
66 changes: 49 additions & 17 deletions packages/core/src/2d/assembler/SimpleSpriteAssembler.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { BoundingBox, Matrix } from "@galacean/engine-math";
import { Matrix, Vector2, Vector3 } from "@galacean/engine-math";
import { StaticInterfaceImplement } from "../../base/StaticInterfaceImplement";
import { SpriteMask } from "../sprite";
import { SpriteRenderer } from "../sprite/SpriteRenderer";
import { ISpriteAssembler } from "./ISpriteAssembler";
import { ISpriteRenderer } from "./ISpriteRenderer";

/**
* @internal
*/
@StaticInterfaceImplement<ISpriteAssembler>()
export class SimpleSpriteAssembler {
static _rectangleTriangles = [0, 1, 2, 2, 1, 3];
static _worldMatrix = new Matrix();
private static _rectangleTriangles = [0, 1, 2, 2, 1, 3];
private static _worldMatrix = new Matrix();

static resetData(renderer: SpriteRenderer | SpriteMask): void {
static resetData(renderer: ISpriteRenderer): void {
const manager = renderer._getChunkManager();
const lastSubChunk = renderer._subChunk;
lastSubChunk && manager.freeSubChunk(lastSubChunk);
Expand All @@ -21,16 +20,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: ISpriteRenderer,
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 { elements: pWE } = renderer._transform.worldMatrix;
const sx = flipX ? -width : width;
const sy = flipY ? -height : height;
(wE[0] = pWE[0] * sx), (wE[1] = pWE[1] * sx), (wE[2] = pWE[2] * sx);
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 对比怎么样呢

Copy link
Contributor

Choose a reason for hiding this comment

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

I write a test on hitu. Here is the result.
image

(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 All @@ -53,11 +59,9 @@ export class SimpleSpriteAssembler {
vertices[o + 1] = wE[1] * x + wE[5] * y + wE[13];
vertices[o + 2] = wE[2] * x + wE[6] * y + wE[14];
}

BoundingBox.transform(sprite._getBounds(), worldMatrix, renderer._bounds);
}

static updateUVs(renderer: SpriteRenderer | SpriteMask): void {
static updateUVs(renderer: ISpriteRenderer): void {
const spriteUVs = renderer.sprite._getUVs();
const { x: left, y: bottom } = spriteUVs[0];
const { x: right, y: top } = spriteUVs[3];
Expand All @@ -74,15 +78,43 @@ export class SimpleSpriteAssembler {
vertices[offset + 28] = top;
}

static updateColor(renderer: SpriteRenderer): void {
static updateColor(renderer: ISpriteRenderer, alpha: number = 1): void {
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 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;

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 getUVByLocalPosition(
renderer: ISpriteRenderer,
width: number,
height: number,
pivot: Vector2,
position: Vector3,
out: Vector2
): boolean {
const sprite = renderer.sprite;
const normalizedX = position.x / width + pivot.x;
const normalizedY = position.y / height + pivot.y;
const positions = sprite._getPositions();
const { x: left, y: bottom } = positions[0];
const { x: right, y: top } = positions[3];
if (normalizedX >= left && normalizedX <= right && normalizedY >= bottom && normalizedY <= top) {
const uvs = sprite._getUVs();
const { x: uvLeft, y: uvBottom } = uvs[0];
const { x: uvRight, y: uvTop } = uvs[3];
const factorX = (normalizedX - left) / (right - left);
const factorY = (normalizedY - bottom) / (top - bottom);
out.set(uvLeft + (uvRight - uvLeft) * factorX, uvBottom + (uvTop - uvBottom) * factorY);
return true;
} else {
return false;
}
Comment on lines +94 to +117
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add input validation to prevent potential runtime errors.

The method should validate input parameters to prevent division by zero and null/undefined errors.

 static getUVByLocalPosition(
   renderer: ISpriteRenderer,
   width: number,
   height: number,
   pivot: Vector2,
   position: Vector3,
   out: Vector2
 ): boolean {
+  if (!renderer?.sprite || !position || !pivot || !out) {
+    return false;
+  }
+  if (width === 0 || height === 0) {
+    return false;
+  }
   const sprite = renderer.sprite;
   const normalizedX = position.x / width + pivot.x;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static getUVByLocalPosition(
renderer: ISpriteRenderer,
width: number,
height: number,
pivot: Vector2,
position: Vector3,
out: Vector2
): boolean {
const sprite = renderer.sprite;
const normalizedX = position.x / width + pivot.x;
const normalizedY = position.y / height + pivot.y;
const positions = sprite._getPositions();
const { x: left, y: bottom } = positions[0];
const { x: right, y: top } = positions[3];
if (normalizedX >= left && normalizedX <= right && normalizedY >= bottom && normalizedY <= top) {
const uvs = sprite._getUVs();
const { x: uvLeft, y: uvBottom } = uvs[0];
const { x: uvRight, y: uvTop } = uvs[3];
const factorX = (normalizedX - left) / (right - left);
const factorY = (normalizedY - bottom) / (top - bottom);
out.set(uvLeft + (uvRight - uvLeft) * factorX, uvBottom + (uvTop - uvBottom) * factorY);
return true;
} else {
return false;
static getUVByLocalPosition(
renderer: ISpriteRenderer,
width: number,
height: number,
pivot: Vector2,
position: Vector3,
out: Vector2
): boolean {
if (!renderer?.sprite || !position || !pivot || !out) {
return false;
}
if (width === 0 || height === 0) {
return false;
}
const sprite = renderer.sprite;
const normalizedX = position.x / width + pivot.x;
const normalizedY = position.y / height + pivot.y;
const positions = sprite._getPositions();
const { x: left, y: bottom } = positions[0];
const { x: right, y: top } = positions[3];
if (normalizedX >= left && normalizedX <= right && normalizedY >= bottom && normalizedY <= top) {
const uvs = sprite._getUVs();
const { x: uvLeft, y: uvBottom } = uvs[0];
const { x: uvRight, y: uvTop } = uvs[3];
const factorX = (normalizedX - left) / (right - left);
const factorY = (normalizedY - bottom) / (top - bottom);
out.set(uvLeft + (uvRight - uvLeft) * factorX, uvBottom + (uvTop - uvBottom) * factorY);
return true;
} else {
return false;

}
}
131 changes: 95 additions & 36 deletions packages/core/src/2d/assembler/SlicedSpriteAssembler.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { Matrix } from "@galacean/engine-math";
import { Matrix, Vector2, Vector3 } from "@galacean/engine-math";
import { StaticInterfaceImplement } from "../../base/StaticInterfaceImplement";
import { SpriteRenderer } from "../sprite/SpriteRenderer";
import { ISpriteAssembler } from "./ISpriteAssembler";
import { ISpriteRenderer } from "./ISpriteRenderer";

/**
* @internal
*/
@StaticInterfaceImplement<ISpriteAssembler>()
export class SlicedSpriteAssembler {
static _rectangleTriangles = [
private static _rectangleTriangles = [
0, 1, 4, 1, 5, 4, 1, 2, 5, 2, 6, 5, 2, 3, 6, 3, 7, 6, 4, 5, 8, 5, 9, 8, 5, 6, 9, 6, 10, 9, 6, 7, 10, 7, 11, 10, 8,
9, 12, 9, 13, 12, 9, 10, 13, 10, 14, 13, 10, 11, 14, 11, 15, 14
];
static _worldMatrix = new Matrix();
private static _worldMatrix = new Matrix();
private static _row = new Array<number>(4);
private static _column = new Array<number>(4);

static resetData(renderer: SpriteRenderer): void {
static resetData(renderer: ISpriteRenderer): void {
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(
renderer: ISpriteRenderer,
cptbtptpbcptdtptp marked this conversation as resolved.
Show resolved Hide resolved
width: number,
height: number,
pivot: Vector2,
flipX: boolean = false,
flipY: boolean = false
): void {
const { sprite } = renderer;
const { border } = sprite;
// Update local positions.
cptbtptpbcptdtptp marked this conversation as resolved.
Show resolved Hide resolved
const spritePositions = sprite._getPositions();
Expand All @@ -47,42 +56,36 @@ export class SlicedSpriteAssembler {
// column
// ------------------------
// Calculate row and column.
let row: number[], column: number[];
const { _row: row, _column: column } = SlicedSpriteAssembler;
if (fixedLeft + fixedRight > width) {
const widthScale = width / (fixedLeft + fixedRight);
row = [
expectWidth * left * widthScale,
fixedLeft * widthScale,
fixedLeft * widthScale,
width - expectWidth * (1 - right) * widthScale
];
(row[0] = expectWidth * left * widthScale), (row[1] = row[2] = fixedLeft * widthScale);
row[3] = width - expectWidth * (1 - right) * widthScale;
} else {
row = [expectWidth * left, fixedLeft, width - fixedRight, width - expectWidth * (1 - right)];
(row[0] = expectWidth * left), (row[1] = fixedLeft), (row[2] = width - fixedRight);
row[3] = width - expectWidth * (1 - right);
}
Comment on lines +65 to +69
Copy link

@coderabbitai coderabbitai bot Oct 28, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve readability by simplifying assignment statements

Consider breaking down the combined assignment statements into separate lines for better clarity and maintainability.

Apply this diff to refactor the code:

- (row[0] = expectWidth * left * widthScale), (row[1] = row[2] = fixedLeft * widthScale);
- row[3] = width - expectWidth * (1 - right) * widthScale;
+ row[0] = expectWidth * left * widthScale;
+ row[1] = fixedLeft * widthScale;
+ row[2] = fixedLeft * widthScale;
+ row[3] = width - expectWidth * (1 - right) * widthScale;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(row[0] = expectWidth * left * widthScale), (row[1] = row[2] = fixedLeft * widthScale);
row[3] = width - expectWidth * (1 - right) * widthScale;
} else {
row = [expectWidth * left, fixedLeft, width - fixedRight, width - expectWidth * (1 - right)];
(row[0] = expectWidth * left), (row[1] = fixedLeft), (row[2] = width - fixedRight);
row[3] = width - expectWidth * (1 - right);
row[0] = expectWidth * left * widthScale;
row[1] = fixedLeft * widthScale;
row[2] = fixedLeft * widthScale;
row[3] = width - expectWidth * (1 - right) * widthScale;
} else {
(row[0] = expectWidth * left), (row[1] = fixedLeft), (row[2] = width - fixedRight);
row[3] = width - expectWidth * (1 - right);

Copy link
Member Author

Choose a reason for hiding this comment

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

can not agree more

Copy link

Choose a reason for hiding this comment

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

@singlecoder, glad to hear that you agree! If there's anything else I can assist with, please let me know.

(^ᆺ^)ノ


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!


if (fixedTop + fixedBottom > height) {
const heightScale = height / (fixedTop + fixedBottom);
column = [
expectHeight * bottom * heightScale,
fixedBottom * heightScale,
fixedBottom * heightScale,
height - expectHeight * (1 - top) * heightScale
];
(column[0] = expectHeight * bottom * heightScale), (column[1] = column[2] = fixedBottom * heightScale);
column[3] = height - expectHeight * (1 - top) * heightScale;
} else {
column = [expectHeight * bottom, fixedBottom, height - fixedTop, height - expectHeight * (1 - top)];
(column[0] = expectHeight * bottom), (column[1] = fixedBottom), (column[2] = height - fixedTop);
column[3] = height - expectHeight * (1 - top);
}

// 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 { elements: pWE } = renderer._transform.worldMatrix;
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);
Comment on lines +89 to +91
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Check for potential issues with _transform access

Accessing renderer._transform.worldMatrix directly may violate encapsulation if _transform is intended to be private. Consider providing a public getter if necessary.

If _transform should remain private, modify the class to provide controlled access:

+ // Add in ISpriteRenderer implementation
+ get worldMatrix(): Matrix {
+   return this._transform.worldMatrix;
+ }

Then update the reference:

- const { elements: pWE } = renderer._transform.worldMatrix;
+ const { elements: pWE } = renderer.worldMatrix;

Committable suggestion was skipped due to low confidence.

(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 @@ -111,14 +114,9 @@ export class SlicedSpriteAssembler {
vertices[o + 2] = wE[2] * rowValue + wE[6] * columnValue + wE[14];
}
}

const { min, max } = renderer._bounds;
min.set(row[0], column[0], 0);
max.set(row[3], column[3], 0);
renderer._bounds.transform(worldMatrix);
}

static updateUVs(renderer: SpriteRenderer): void {
static updateUVs(renderer: ISpriteRenderer): void {
const subChunk = renderer._subChunk;
const vertices = subChunk.chunk.vertices;
const spriteUVs = renderer.sprite._getUVs();
Expand All @@ -131,15 +129,76 @@ export class SlicedSpriteAssembler {
}
}

static updateColor(renderer: SpriteRenderer): void {
static updateColor(renderer: ISpriteRenderer, alpha: number = 1): void {
const subChunk = renderer._subChunk;
const { r, g, b, a } = renderer.color;
const finalAlpha = a * alpha;
const vertices = subChunk.chunk.vertices;
cptbtptpbcptdtptp marked this conversation as resolved.
Show resolved Hide resolved
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 getUVByLocalPosition(
renderer: ISpriteRenderer,
width: number,
height: number,
pivot: Vector2,
position: Vector3,
out: Vector2
): boolean {
const sprite = renderer.sprite;
const positions = sprite._getPositions();
const { x: left, y: bottom } = positions[0];
const { x: right, y: top } = positions[3];
const { border } = sprite;
const { width: expectWidth, height: expectHeight } = sprite;
const fixedLeft = expectWidth * border.x;
const fixedBottom = expectHeight * border.y;
const fixedRight = expectWidth * border.z;
const fixedTop = expectHeight * border.w;
const { _row: row, _column: column } = SlicedSpriteAssembler;
if (fixedLeft + fixedRight > width) {
const widthScale = width / (fixedLeft + fixedRight);
(row[0] = expectWidth * left * widthScale), (row[1] = row[2] = fixedLeft * widthScale);
row[3] = width - expectWidth * (1 - right) * widthScale;
} else {
(row[0] = expectWidth * left), (row[1] = fixedLeft), (row[2] = width - fixedRight);
row[3] = width - expectWidth * (1 - right);
}

if (fixedTop + fixedBottom > height) {
const heightScale = height / (fixedTop + fixedBottom);
(column[0] = expectHeight * bottom * heightScale), (column[1] = column[2] = fixedBottom * heightScale);
column[3] = height - expectHeight * (1 - top) * heightScale;
} else {
(column[0] = expectHeight * bottom), (column[1] = fixedBottom), (column[2] = height - fixedTop);
column[3] = height - expectHeight * (1 - top);
}

const x = position.x + width * pivot.x;
const y = position.y + height * pivot.y;
if (x >= row[0] && x <= row[3] && y >= column[0] && y <= column[3]) {
for (let i = row.length - 2; i >= 0; i--) {
if (x >= row[i]) {
for (let j = column.length - 2; j >= 0; j--) {
if (y >= column[j]) {
const uvs = sprite._getUVs();
const factorX = (x - row[i]) / (row[i + 1] - row[i]);
const factorY = (y - column[j]) / (column[j + 1] - column[j]);
const uvLeft = uvs[i].x;
const uvBottom = uvs[j].y;
out.set(uvLeft + (uvs[i + 1].x - uvLeft) * factorX, uvBottom + (uvs[j + 1].y - uvBottom) * factorY);
return true;
}
}
}
}
} else {
return false;
}
}
}
Loading
Loading