From a6bc41ab50138980fb0a4b3bdec88a6c2b9064e4 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 22 Sep 2024 17:39:29 +0800 Subject: [PATCH 1/7] Refactor 2d assembler --- .../graphics/webgl/graphics-assembler.ts | 85 ++++++++------- cocos/2d/assembler/graphics/webgl/index.ts | 4 +- cocos/2d/assembler/label/bmfont.ts | 79 ++------------ cocos/2d/assembler/label/bmfontUtils.ts | 43 ++++---- cocos/2d/assembler/label/index.ts | 6 +- cocos/2d/assembler/label/letter-font.ts | 30 +++--- cocos/2d/assembler/label/letter.ts | 18 ++-- cocos/2d/assembler/label/ttf.ts | 31 +++--- cocos/2d/assembler/label/ttfUtils.ts | 25 +++-- cocos/2d/assembler/sprite/bar-filled.ts | 34 +++--- cocos/2d/assembler/sprite/index.ts | 4 +- cocos/2d/assembler/sprite/radial-filled.ts | 44 ++++---- cocos/2d/assembler/sprite/simple.ts | 34 +++--- cocos/2d/assembler/sprite/sliced.ts | 41 +++---- cocos/2d/assembler/sprite/tiled.ts | 46 ++++---- cocos/2d/components/graphics.ts | 5 +- cocos/2d/renderer/base.ts | 11 +- cocos/dragon-bones/ArmatureDisplay.ts | 5 +- cocos/dragon-bones/assembler/simple.ts | 41 ++++--- .../particle-2d/motion-streak-2d-assembler.ts | 62 +++++------ cocos/particle-2d/motion-streak-2d.ts | 19 ++-- cocos/particle-2d/particle-asset.ts | 2 +- cocos/particle-2d/particle-simulator-2d.ts | 3 +- .../particle-system-2d-assembler.ts | 44 +++++--- cocos/particle-2d/particle-system-2d.ts | 100 +++++++++++++++--- cocos/spine/assembler/simple.ts | 46 +++++--- cocos/spine/skeleton.ts | 6 +- cocos/tiledmap/assembler/simple.ts | 67 ++++++++---- 28 files changed, 516 insertions(+), 419 deletions(-) diff --git a/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts b/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts index 1db293de040..384f2a0a40b 100644 --- a/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts +++ b/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts @@ -24,12 +24,13 @@ import { JSB } from 'internal:constants'; import { Color, Vec3 } from '../../../../core'; import { IAssembler } from '../../../renderer/base'; -import { MeshRenderData } from '../../../renderer/render-data'; +import { BaseRenderData, MeshRenderData } from '../../../renderer/render-data'; import { IBatcher } from '../../../renderer/i-batcher'; import { Graphics } from '../../../components'; import { LineCap, LineJoin, PointFlags } from '../types'; import { earcut as Earcut } from './earcut'; import { Impl, Point } from './impl'; +import { UIRenderer } from '../../../framework'; const MAX_VERTEX = 65535; const MAX_INDICES = MAX_VERTEX * 2; @@ -72,8 +73,18 @@ function clamp (v: number, minNum: number, maxNum: number): number { * graphics 组装器 * 可通过 `UI.graphicsAssembler` 获取该组装器。 */ -export const graphicsAssembler: IAssembler = { - useModel: true, +export class GraphicsAssembler implements IAssembler { + createData (comp: UIRenderer): BaseRenderData { + return null as unknown as BaseRenderData; + } + + updateUVs (comp: UIRenderer, ...args: any[]): void { + + } + + updateColor (comp: UIRenderer): void { + + } updateRenderData (graphics: Graphics): void { if (JSB) { @@ -81,16 +92,16 @@ export const graphicsAssembler: IAssembler = { graphics.renderData.material = graphics.getMaterialInstance(0); } } - }, + } fillBuffers (graphics: Graphics, renderer: IBatcher): void { // this.renderIA!(graphics, renderer); - }, + } renderIA (graphics: Graphics, renderer: IBatcher): void { - }, + } - getRenderData (graphics: Graphics, vertexCount: number): MeshRenderData | null { + private getRenderData (graphics: Graphics, vertexCount: number): MeshRenderData | null { if (!_impl) { return null; } @@ -122,7 +133,7 @@ export const graphicsAssembler: IAssembler = { } return renderData; - }, + } stroke (graphics: Graphics): void { Color.copy(_curColor, graphics.strokeColor); @@ -137,7 +148,7 @@ export const graphicsAssembler: IAssembler = { graphics.impl.updatePathOffset = true; this.end(graphics); - }, + } fill (graphics: Graphics): void { Color.copy(_curColor, graphics.fillColor); @@ -149,13 +160,13 @@ export const graphicsAssembler: IAssembler = { } this.end(graphics); - }, + } end (graphics: Graphics): void { graphics.markForUpdateRenderData(); - }, + } - _expandStroke (graphics: Graphics): void { + private _expandStroke (graphics: Graphics): void { const w = graphics.lineWidth * 0.5; const lineCap = graphics.lineCap; const lineJoin = graphics.lineJoin; @@ -296,9 +307,9 @@ export const graphicsAssembler: IAssembler = { } _renderData = null; _impl = null; - }, + } - _expandFill (graphics: Graphics): void { + private _expandFill (graphics: Graphics): void { _impl = graphics.impl; if (!_impl) { return; @@ -374,9 +385,9 @@ export const graphicsAssembler: IAssembler = { _renderData = null; _impl = null; - }, + } - _calculateJoins (impl: Impl, w: number, lineJoin: LineJoin, miterLimit: number): void { + private _calculateJoins (impl: Impl, w: number, lineJoin: LineJoin, miterLimit: number): void { let iw = 0.0; if (w > 0.0) { @@ -450,9 +461,9 @@ export const graphicsAssembler: IAssembler = { p1 = pts[j + 1]; } } - }, + } - _flattenPaths (impl: Impl): void { + private _flattenPaths (impl: Impl): void { const paths = impl.paths; for (let i = impl.pathOffset, l = impl.pathLength; i < l; i++) { const path = paths[i]; @@ -482,9 +493,9 @@ export const graphicsAssembler: IAssembler = { p1 = pts[j + 1]; } } - }, + } - _chooseBevel (bevel: number, p0: Point, p1: Point, w: number) { + private _chooseBevel (bevel: number, p0: Point, p1: Point, w: number): [number, number, number, number] { const x = p1.x; const y = p1.y; let x0 = 0; @@ -503,9 +514,9 @@ export const graphicsAssembler: IAssembler = { } return [x0, y0, x1, y1]; - }, + } - _buttCapStart (p: Point, dx: number, dy: number, w: number, d: number): void { + private _buttCapStart (p: Point, dx: number, dy: number, w: number, d: number): void { const px = p.x - dx * d; const py = p.y - dy * d; const dlx = dy; @@ -513,9 +524,9 @@ export const graphicsAssembler: IAssembler = { this._vSet(px + dlx * w, py + dly * w, 1); this._vSet(px - dlx * w, py - dly * w, -1); - }, + } - _buttCapEnd (p: Point, dx: number, dy: number, w: number, d: number): void { + private _buttCapEnd (p: Point, dx: number, dy: number, w: number, d: number): void { const px = p.x + dx * d; const py = p.y + dy * d; const dlx = dy; @@ -523,9 +534,9 @@ export const graphicsAssembler: IAssembler = { this._vSet(px + dlx * w, py + dly * w, 1); this._vSet(px - dlx * w, py - dly * w, -1); - }, + } - _roundCapStart (p: Point, dx: number, dy: number, w: number, nCap: number): void { + private _roundCapStart (p: Point, dx: number, dy: number, w: number, nCap: number): void { const px = p.x; const py = p.y; const dlx = dy; @@ -540,9 +551,9 @@ export const graphicsAssembler: IAssembler = { } this._vSet(px + dlx * w, py + dly * w, 1); this._vSet(px - dlx * w, py - dly * w, -1); - }, + } - _roundCapEnd (p: Point, dx: number, dy: number, w: number, nCap: number): void { + private _roundCapEnd (p: Point, dx: number, dy: number, w: number, nCap: number): void { const px = p.x; const py = p.y; const dlx = dy; @@ -557,9 +568,9 @@ export const graphicsAssembler: IAssembler = { this._vSet(px, py, 0); this._vSet(px - dlx * ax + dx * ay, py - dly * ax + dy * ay, 1); } - }, + } - _roundJoin (p0: Point, p1: Point, lw: number, rw: number, nCap: number): void { + private _roundJoin (p0: Point, p1: Point, lw: number, rw: number, nCap: number): void { const dlx0 = p0.dy; const dly0 = -p0.dx; const dlx1 = p1.dy; @@ -621,9 +632,9 @@ export const graphicsAssembler: IAssembler = { this._vSet(p1x + dlx1 * rw, p1y + dly1 * rw, 1); this._vSet(rx1, ry1, -1); } - }, + } - _bevelJoin (p0: Point, p1: Point, lw: number, rw: number): void { + private _bevelJoin (p0: Point, p1: Point, lw: number, rw: number): void { let rx0 = 0; let ry0 = 0; let rx1 = 0; @@ -662,9 +673,9 @@ export const graphicsAssembler: IAssembler = { this._vSet(p1.x + dlx1 * lw, p1.y + dly1 * lw, 1); this._vSet(rx1, ry1, -1); } - }, + } - _vSet (x: number, y: number, distance = 0): void { + private _vSet (x: number, y: number, distance = 0): void { if (!_renderData) { return; } @@ -682,5 +693,7 @@ export const graphicsAssembler: IAssembler = { dataOffset += 4; vData[dataOffset++] = distance; meshBuffer.vertexStart++; - }, -}; + } +} + +export const graphicsAssembler = new GraphicsAssembler(); diff --git a/cocos/2d/assembler/graphics/webgl/index.ts b/cocos/2d/assembler/graphics/webgl/index.ts index 1a060e49757..c6b5de170be 100644 --- a/cocos/2d/assembler/graphics/webgl/index.ts +++ b/cocos/2d/assembler/graphics/webgl/index.ts @@ -23,12 +23,12 @@ */ import { UIRenderer } from '../../../framework/ui-renderer'; -import { IAssemblerManager } from '../../../renderer/base'; +import { IAssembler, IAssemblerManager } from '../../../renderer/base'; import { Graphics } from '../../../components'; import { graphicsAssembler as graphics } from './graphics-assembler'; const graphicsAssemblerManager: IAssemblerManager = { - getAssembler (sprite: UIRenderer) { + getAssembler (sprite: UIRenderer): IAssembler { return graphics; }, }; diff --git a/cocos/2d/assembler/label/bmfont.ts b/cocos/2d/assembler/label/bmfont.ts index 78431f155a0..4ed11d78e2e 100644 --- a/cocos/2d/assembler/label/bmfont.ts +++ b/cocos/2d/assembler/label/bmfont.ts @@ -28,7 +28,8 @@ import { IBatcher } from '../../renderer/i-batcher'; import { Label } from '../../components/label'; import { IAssembler } from '../../renderer/base'; import { fillMeshVertices3D } from '../utils'; -import { bmfontUtils } from './bmfontUtils'; +import { BmfontUtils } from './bmfontUtils'; +import { RenderData } from '../../renderer/render-data'; const tempColor = new Color(255, 255, 255, 255); @@ -36,82 +37,20 @@ const tempColor = new Color(255, 255, 255, 255); * bmfont 组装器 * 可通过 `UI.bmfont` 获取该组装器。 */ -export const bmfont: IAssembler = { - createData (comp: Label) { +class Bmfont extends BmfontUtils implements IAssembler { + createData (comp: Label): RenderData { const renderData = comp.requestRenderData(); renderData.resize(0, 0); return renderData; - }, + } - fillBuffers (comp: Label, renderer: IBatcher) { + fillBuffers (comp: Label, renderer: IBatcher): void { const node = comp.node; tempColor.set(comp.color); tempColor.a = node._uiProps.opacity * 255; // Fill All fillMeshVertices3D(node, renderer, comp.renderData!, tempColor); - }, + } +} - appendQuad (comp: Label, spriteFrame: SpriteFrame, rect: Rect, rotated: boolean, x: number, y: number, scale: number) { - const renderData = comp.renderData; - if (!renderData) { - return; - } - - const dataOffset = renderData.dataLength; - - renderData.dataLength += 4; - renderData.resize(renderData.dataLength, renderData.dataLength / 2 * 3); - - const dataList = renderData.data; - const texW = spriteFrame.width; - const texH = spriteFrame.height; - - const rectWidth = rect.width; - const rectHeight = rect.height; - - let l = 0; - let b = 0; - let t = 0; - let r = 0; - if (!rotated) { - l = (rect.x) / texW; - r = (rect.x + rectWidth) / texW; - b = (rect.y + rectHeight) / texH; - t = (rect.y) / texH; - - dataList[dataOffset].u = l; - dataList[dataOffset].v = b; - dataList[dataOffset + 1].u = r; - dataList[dataOffset + 1].v = b; - dataList[dataOffset + 2].u = l; - dataList[dataOffset + 2].v = t; - dataList[dataOffset + 3].u = r; - dataList[dataOffset + 3].v = t; - } else { - l = (rect.x) / texW; - r = (rect.x + rectHeight) / texW; - b = (rect.y + rectWidth) / texH; - t = (rect.y) / texH; - - dataList[dataOffset].u = l; - dataList[dataOffset].v = t; - dataList[dataOffset + 1].u = l; - dataList[dataOffset + 1].v = b; - dataList[dataOffset + 2].u = r; - dataList[dataOffset + 2].v = t; - dataList[dataOffset + 3].u = r; - dataList[dataOffset + 3].v = b; - } - - dataList[dataOffset].x = x; - dataList[dataOffset].y = y - rectHeight * scale; - dataList[dataOffset + 1].x = x + rectWidth * scale; - dataList[dataOffset + 1].y = y - rectHeight * scale; - dataList[dataOffset + 2].x = x; - dataList[dataOffset + 2].y = y; - dataList[dataOffset + 3].x = x + rectWidth * scale; - dataList[dataOffset + 3].y = y; - }, -}; - -js.addon(bmfont, bmfontUtils); +export const bmfont = new Bmfont(); diff --git a/cocos/2d/assembler/label/bmfontUtils.ts b/cocos/2d/assembler/label/bmfontUtils.ts index e1b604d2df7..c30c82fa73d 100644 --- a/cocos/2d/assembler/label/bmfontUtils.ts +++ b/cocos/2d/assembler/label/bmfontUtils.ts @@ -23,7 +23,7 @@ */ import { JSB } from 'internal:constants'; -import { IConfig, FontAtlas } from '../../assets/bitmap-font'; +import { IConfig, FontAtlas, BitmapFont } from '../../assets/bitmap-font'; import { SpriteFrame } from '../../assets/sprite-frame'; import { Rect, errorID } from '../../../core'; import { Label, Overflow, CacheMode } from '../../components/label'; @@ -46,8 +46,7 @@ let _fntConfig: IConfig | null = null; let _spriteFrame: SpriteFrame|null = null; let QUAD_INDICES: Uint16Array | null = null; -export const bmfontUtils = { - +export class BmfontUtils { updateProcessingData ( style: TextStyle, layout: TextLayout, @@ -91,7 +90,7 @@ export const bmfontUtils = { style.fontFamily = shareLabelInfo.fontFamily; style.color.set(comp.color); - }, + } updateRenderData (comp: Label): void { if (!comp.renderData) { @@ -170,7 +169,7 @@ export const bmfontUtils = { const renderData = comp.renderData; renderData.updateRenderData(comp, comp.spriteFrame); } - }, + } updateUVs (label: Label): void { const renderData = label.renderData!; @@ -184,7 +183,7 @@ export const bmfontUtils = { vData[vertexOffset + 1] = vert.v; vertexOffset += 9; } - }, + } updateColor (label: Label): void { if (JSB) { @@ -207,16 +206,16 @@ export const bmfontUtils = { colorOffset += stride; } } - }, + } - resetRenderData (comp: Label): void { + protected resetRenderData (comp: Label): void { const renderData = comp.renderData!; renderData.dataLength = 0; renderData.resize(0, 0); - }, + } // callBack function - generateVertexData ( + protected generateVertexData ( style: TextStyle, outputLayoutData: TextOutputLayoutData, outputRenderData: TextOutputRenderData, @@ -279,10 +278,10 @@ export const bmfontUtils = { dataList[dataOffset + 2].y = y; dataList[dataOffset + 3].x = x + rectWidth * scale; dataList[dataOffset + 3].y = y; - }, + } - _updateFontFamily (comp): void { - const fontAsset = comp.font; + protected _updateFontFamily (comp: Label): void { + const fontAsset = comp.font as BitmapFont; _spriteFrame = fontAsset.spriteFrame; _fntConfig = fontAsset.fntConfig; shareLabelInfo.fontAtlas = fontAsset.fontDefDictionary; @@ -296,22 +295,22 @@ export const bmfontUtils = { dynamicAtlasManager.packToDynamicAtlas(comp, _spriteFrame); // TODO update material and uv - }, + } - _updateLabelInfo (comp): void { + protected _updateLabelInfo (comp: Label): void { // clear shareLabelInfo.hash = ''; shareLabelInfo.margin = 0; - }, + } - _resetProperties (): void { + protected _resetProperties (): void { _fntConfig = null; _spriteFrame = null; shareLabelInfo.hash = ''; shareLabelInfo.margin = 0; - }, + } - createQuadIndices (indexCount: number): void { + protected createQuadIndices (indexCount: number): void { if (indexCount % 6 !== 0) { errorID(16308); return; @@ -327,7 +326,5 @@ export const bmfontUtils = { QUAD_INDICES[offset++] = 3 + i * 4; QUAD_INDICES[offset++] = 2 + i * 4; } - }, -}; - -export default bmfontUtils; + } +} diff --git a/cocos/2d/assembler/label/index.ts b/cocos/2d/assembler/label/index.ts index 1c36681072a..1b50a26d6c3 100644 --- a/cocos/2d/assembler/label/index.ts +++ b/cocos/2d/assembler/label/index.ts @@ -24,15 +24,15 @@ import { BitmapFont } from '../../assets'; import { Label } from '../../components'; -import { IAssemblerManager } from '../../renderer/base'; +import { IAssembler, IAssemblerManager } from '../../renderer/base'; import { bmfont } from './bmfont'; import { letter } from './letter'; import { ttf } from './ttf'; import { TextProcessing } from './text-processing'; const labelAssembler: IAssemblerManager = { - getAssembler (comp: Label) { - let assembler = ttf; + getAssembler (comp: Label): IAssembler { + let assembler: IAssembler = ttf; if (comp.font instanceof BitmapFont) { assembler = bmfont; diff --git a/cocos/2d/assembler/label/letter-font.ts b/cocos/2d/assembler/label/letter-font.ts index 733ae2223aa..e46ba5e6de0 100644 --- a/cocos/2d/assembler/label/letter-font.ts +++ b/cocos/2d/assembler/label/letter-font.ts @@ -22,9 +22,9 @@ THE SOFTWARE. */ -import { js } from '../../../core'; +import { Color } from '../../../core/math/color'; import { Label } from '../../components'; -import { bmfontUtils } from './bmfontUtils'; +import { BmfontUtils } from './bmfontUtils'; import { shareLabelInfo, LetterAtlas, computeHash, LetterRenderTexture } from './font-utils'; const _atlasWidth = 1024; @@ -33,16 +33,16 @@ const _isBold = false; let _shareAtlas: LetterAtlas | null = null; -export const letterFont = js.mixin(bmfontUtils, { - getAssemblerData () { +export class LetterFont extends BmfontUtils { + getAssemblerData (): LetterRenderTexture | null { if (!_shareAtlas) { _shareAtlas = new LetterAtlas(_atlasWidth, _atlasHeight); } return _shareAtlas.getTexture() as LetterRenderTexture | null; - }, + } - _updateFontFamily (comp) { + protected _updateFontFamily (comp: Label): void { shareLabelInfo.fontAtlas = _shareAtlas; shareLabelInfo.fontFamily = this._getFontFamily(comp); @@ -57,9 +57,9 @@ export const letterFont = js.mixin(bmfontUtils, { shareLabelInfo.isOutlined = false; shareLabelInfo.margin = 0; } - }, + } - _getFontFamily (comp: Label) { + protected _getFontFamily (comp: Label): string { let fontFamily = 'Arial'; if (!comp.useSystemFont) { if (comp.font) { @@ -70,15 +70,15 @@ export const letterFont = js.mixin(bmfontUtils, { } return fontFamily; - }, + } - _updateLabelInfo (comp) { + protected _updateLabelInfo (comp: Label): void { shareLabelInfo.fontDesc = this._getFontDesc(); - shareLabelInfo.color = comp.color; + Color.copy(shareLabelInfo.color, comp.color); shareLabelInfo.hash = computeHash(shareLabelInfo); - }, + } - _getFontDesc () { + protected _getFontDesc (): string { let fontDesc = `${shareLabelInfo.fontSize.toString()}px `; fontDesc += shareLabelInfo.fontFamily; if (_isBold) { @@ -86,5 +86,5 @@ export const letterFont = js.mixin(bmfontUtils, { } return fontDesc; - }, -}); + } +} diff --git a/cocos/2d/assembler/label/letter.ts b/cocos/2d/assembler/label/letter.ts index 24388e2dd5b..290436c7532 100644 --- a/cocos/2d/assembler/label/letter.ts +++ b/cocos/2d/assembler/label/letter.ts @@ -23,12 +23,14 @@ */ import { JSB } from 'internal:constants'; -import { js, Color } from '../../../core'; +import { Color } from '../../../core'; import { IBatcher } from '../../renderer/i-batcher'; import { Label } from '../../components/label'; import { fillMeshVertices3D } from '../utils'; -import { letterFont } from './letter-font'; +import { LetterFont } from './letter-font'; import type { RenderData } from '../../renderer/render-data'; +import { IAssembler } from '../../renderer/base'; +import { UIRenderer } from '../../framework'; const tempColor = new Color(255, 255, 255, 255); @@ -36,12 +38,12 @@ const tempColor = new Color(255, 255, 255, 255); * letter 组装器 * 可通过 `UI.letter` 获取该组装器。 */ -export const letter = { +class Letter extends LetterFont implements IAssembler { createData (comp: Label): RenderData { const renderData = comp.requestRenderData(); renderData.resize(0, 0); return renderData; - }, + } fillBuffers (comp: Label, renderer: IBatcher): void { if (!comp.renderData) { @@ -52,7 +54,7 @@ export const letter = { tempColor.a = node._uiProps.opacity * 255; // Fill All fillMeshVertices3D(node, renderer, comp.renderData, tempColor); - }, + } updateColor (label: Label): void { if (JSB) { @@ -70,7 +72,7 @@ export const letter = { colorOffset += stride; } } - }, -}; + } +} -js.addon(letter, letterFont); +export const letter = new Letter(); diff --git a/cocos/2d/assembler/label/ttf.ts b/cocos/2d/assembler/label/ttf.ts index 68e3a4580fc..a8653ad651d 100644 --- a/cocos/2d/assembler/label/ttf.ts +++ b/cocos/2d/assembler/label/ttf.ts @@ -31,8 +31,9 @@ import { Color, js } from '../../../core'; import { IBatcher } from '../../renderer/i-batcher'; import { Label } from '../../components/label'; import { IAssembler } from '../../renderer/base'; -import { ttfUtils } from './ttfUtils'; -import { IRenderData } from '../../renderer/render-data'; +import { TTFUtils } from './ttfUtils'; +import { IRenderData, RenderData } from '../../renderer/render-data'; +import { UIRenderer } from '../../framework'; const WHITE = Color.WHITE.clone(); const QUAD_INDICES = Uint16Array.from([0, 1, 2, 1, 3, 2]); @@ -41,8 +42,8 @@ const QUAD_INDICES = Uint16Array.from([0, 1, 2, 1, 3, 2]); * ttf 组装器 * 可通过 `UI.ttf` 获取该组装器。 */ -export const ttf: IAssembler = { - createData (comp: Label) { +class TTF extends TTFUtils implements IAssembler { + createData (comp: Label): RenderData { const renderData = comp.requestRenderData()!; renderData.dataLength = 4; @@ -62,9 +63,9 @@ export const ttf: IAssembler = { } renderData.chunk.setIndexBuffer(QUAD_INDICES); return renderData; - }, + } - fillBuffers (comp: Label, renderer: IBatcher) { + fillBuffers (comp: Label, renderer: IBatcher): void { const renderData = comp.renderData!; const chunk = renderData.chunk; const dataList: IRenderData[] = renderData.data; @@ -105,9 +106,9 @@ export const ttf: IAssembler = { // slow version // const chunk = renderData.chunk; // renderer.getBufferAccessor().appendIndices(chunk); - }, + } - updateVertexData (comp: Label) { + updateVertexData (comp: Label): void { const renderData = comp.renderData; if (!renderData) { return; @@ -127,9 +128,9 @@ export const ttf: IAssembler = { data[2].y = height - appY; // t data[3].x = width - appX; // r data[3].y = height - appY; // t - }, + } - updateUVs (comp: Label) { + updateUVs (comp: Label): void { const renderData = comp.renderData; if (!renderData || !comp.ttfSpriteFrame) { return; @@ -144,11 +145,11 @@ export const ttf: IAssembler = { vData[22] = uv[5]; vData[30] = uv[6]; vData[31] = uv[7]; - }, + } - updateColor (comp: Label) { + updateColor (comp: Label): void { // no needs to update color - }, -}; + } +} -js.addon(ttf, ttfUtils); +export const ttf = new TTF(); diff --git a/cocos/2d/assembler/label/ttfUtils.ts b/cocos/2d/assembler/label/ttfUtils.ts index c4ff09c4aa0..7571f3bbd13 100644 --- a/cocos/2d/assembler/label/ttfUtils.ts +++ b/cocos/2d/assembler/label/ttfUtils.ts @@ -34,8 +34,7 @@ import { approx } from '../../../core'; const Overflow = Label.Overflow; -export const ttfUtils = { - +export class TTFUtils { updateProcessingData ( style: TextStyle, layout: TextLayout, @@ -98,19 +97,19 @@ export const ttfUtils = { layout.horizontalAlign = comp.horizontalAlign; // render Only layout.verticalAlign = comp.verticalAlign; // render Only - }, + } getAssemblerData (): ISharedLabelData { const sharedLabelData = Label._canvasPool.get(); sharedLabelData.canvas.width = sharedLabelData.canvas.height = 1; return sharedLabelData; - }, + } resetAssemblerData (assemblerData: ISharedLabelData): void { if (assemblerData) { Label._canvasPool.put(assemblerData); } - }, + } updateRenderData (comp: Label): void { if (!comp.renderData) { return; } @@ -163,7 +162,7 @@ export const ttfUtils = { const renderData = comp.renderData; renderData.updateRenderData(comp, comp.spriteFrame); } - }, + } // callBack function generateVertexData (style: TextStyle, outputLayoutData: TextOutputLayoutData, outputRenderData: TextOutputRenderData): void { @@ -182,15 +181,15 @@ export const ttfUtils = { data[2].y = height - appY; // t data[3].x = width - appX; // r data[3].y = height - appY; // t - }, + } updateVertexData (comp: Label): void { // no needs to update vertex data - }, + } updateUVs (comp: Label): void { // no needs to update uv data - }, + } _updateFontFamily (comp: Label): string { let _fontFamily = ''; @@ -204,19 +203,19 @@ export const ttfUtils = { _fontFamily = comp.fontFamily || 'Arial'; } return _fontFamily; - }, + } _calDynamicAtlas (comp: Label, outputLayoutData: TextOutputLayoutData): void { if (comp.cacheMode !== Label.CacheMode.BITMAP || outputLayoutData.canvasSize.width <= 0 || outputLayoutData.canvasSize.height <= 0) return; const frame = comp.ttfSpriteFrame!; dynamicAtlasManager.packToDynamicAtlas(comp, frame); // TODO update material and uv - }, + } _resetDynamicAtlas (comp: Label): void { if (comp.cacheMode !== Label.CacheMode.BITMAP) return; const frame = comp.ttfSpriteFrame!; dynamicAtlasManager.deleteAtlasSpriteFrame(frame); frame._resetDynamicAtlasFrame(); - }, -}; + } +} diff --git a/cocos/2d/assembler/sprite/bar-filled.ts b/cocos/2d/assembler/sprite/bar-filled.ts index 31e164023ad..333e2235ef6 100644 --- a/cocos/2d/assembler/sprite/bar-filled.ts +++ b/cocos/2d/assembler/sprite/bar-filled.ts @@ -38,8 +38,8 @@ const QUAD_INDICES = Uint16Array.from([0, 1, 2, 1, 3, 2]); * barFilled 组装器 * 可通过 `UI.barFilled` 获取该组装器。 */ -export const barFilled: IAssembler = { - updateRenderData (sprite: Sprite) { +class BarFilled implements IAssembler { + updateRenderData (sprite: Sprite): void { const frame = sprite.spriteFrame; dynamicAtlasManager.packToDynamicAtlas(sprite, frame); // TODO update material and uv @@ -72,9 +72,9 @@ export const barFilled: IAssembler = { this.updateVertexData(sprite, fillStart, fillEnd); renderData.updateRenderData(sprite, frame); } - }, + } - updateUVs (sprite: Sprite, fillStart: number, fillEnd: number) { + updateUVs (sprite: Sprite, fillStart: number, fillEnd: number): void { const spriteFrame = sprite.spriteFrame!; const renderData = sprite.renderData!; const vData = renderData.chunk.vb; @@ -143,9 +143,9 @@ export const barFilled: IAssembler = { errorID(2626); break; } - }, + } - updateVertexData (sprite: Sprite, fillStart: number, fillEnd: number) { + private updateVertexData (sprite: Sprite, fillStart: number, fillEnd: number): void { const renderData: RenderData|null = sprite.renderData; const dataList: IRenderData[] = renderData!.data; const uiTrans = sprite.node._uiProps.uiTransformComp!; @@ -189,9 +189,9 @@ export const barFilled: IAssembler = { dataList[2].y = t; dataList[3].x = r; dataList[3].y = t; - }, + } - createData (sprite: Sprite) { + createData (sprite: Sprite): RenderData { const renderData: RenderData|null = sprite.requestRenderData(); // 0-4 for local vertex renderData.dataLength = 4; @@ -205,9 +205,9 @@ export const barFilled: IAssembler = { } return renderData; - }, + } - updateWorldVertexData (sprite: Sprite, chunk: StaticVBChunk) { + private updateWorldVertexData (sprite: Sprite, chunk: StaticVBChunk): void { const node = sprite.node; node.getWorldMatrix(m); @@ -229,9 +229,9 @@ export const barFilled: IAssembler = { vData[offset + 1] = (m.m01 * x + m.m05 * y + m.m13) * rhw; vData[offset + 2] = (m.m02 * x + m.m06 * y + m.m14) * rhw; } - }, + } - fillBuffers (sprite: Sprite, renderer: IBatcher) { + fillBuffers (sprite: Sprite, renderer: IBatcher): void { const renderData: RenderData = sprite.renderData!; const chunk = renderData.chunk; if (sprite._flagChangedVersion !== sprite.node.flagChangedVersion || renderData.vertDirty) { @@ -252,9 +252,9 @@ export const barFilled: IAssembler = { ib[indexOffset++] = vid + 1; ib[indexOffset++] = vid + 3; meshBuffer.indexOffset += 6; - }, + } - updateColor (sprite: Sprite) { + updateColor (sprite: Sprite): void { const renderData = sprite.renderData!; const vData = renderData.chunk.vb; const stride = renderData.floatStride; @@ -272,5 +272,7 @@ export const barFilled: IAssembler = { colorOffset += stride; } - }, -}; + } +} + +export const barFilled = new BarFilled(); diff --git a/cocos/2d/assembler/sprite/index.ts b/cocos/2d/assembler/sprite/index.ts index 024db3aea74..c590632cfbe 100644 --- a/cocos/2d/assembler/sprite/index.ts +++ b/cocos/2d/assembler/sprite/index.ts @@ -23,7 +23,7 @@ */ import { UIRenderer } from '../../framework/ui-renderer'; -import { IAssemblerManager } from '../../renderer/base'; +import { IAssembler, IAssemblerManager } from '../../renderer/base'; import { Sprite } from '../../components'; import { barFilled } from './bar-filled'; import { radialFilled } from './radial-filled'; @@ -38,7 +38,7 @@ const FillType = Sprite.FillType; const spriteAssembler: IAssemblerManager = { getAssembler (spriteComp: UIRenderer) { - let util = simple; + let util: IAssembler = simple; const comp = spriteComp as Sprite; switch (comp.type) { diff --git a/cocos/2d/assembler/sprite/radial-filled.ts b/cocos/2d/assembler/sprite/radial-filled.ts index aa869b0ee17..14a7b7fc3f9 100644 --- a/cocos/2d/assembler/sprite/radial-filled.ts +++ b/cocos/2d/assembler/sprite/radial-filled.ts @@ -232,14 +232,12 @@ function _generateUV (progressX: number, progressY: number, data: IRenderData[], * radialFilled 组装器 * 可通过 `UI.radialFilled` 获取该组装器。 */ -export const radialFilled: IAssembler = { - useModel: false, - - createData (sprite: Sprite) { +class RadialFilled implements IAssembler { + createData (sprite: Sprite): RenderData { return sprite.requestRenderData(); - }, + } - updateRenderData (sprite: Sprite) { + updateRenderData (sprite: Sprite): void { const frame = sprite.spriteFrame; dynamicAtlasManager.packToDynamicAtlas(sprite, frame); // TODO update material and uv @@ -380,18 +378,18 @@ export const radialFilled: IAssembler = { } renderData.updateRenderData(sprite, frame); } - }, + } - createQuadIndices (indexCount: number) { + private createQuadIndices (indexCount: number): void { QUAD_INDICES = null; QUAD_INDICES = new Uint16Array(indexCount); let offset = 0; for (let i = 0; i < indexCount; i++) { QUAD_INDICES[offset++] = i; } - }, + } - fillBuffers (comp: Sprite, renderer: IBatcher) { + fillBuffers (comp: Sprite, renderer: IBatcher): void { const node = comp.node; const renderData: RenderData = comp.renderData!; const chunk = renderData.chunk; @@ -414,9 +412,9 @@ export const radialFilled: IAssembler = { } meshBuffer.indexOffset += renderData.indexCount; meshBuffer.setDirty(); - }, + } - updateWorldUVData (sprite: Sprite, chunk: StaticVBChunk) { + private updateWorldUVData (sprite: Sprite): void { const renderData = sprite.renderData!; const stride = renderData.floatStride; const dataList: IRenderData[] = renderData.data; @@ -426,10 +424,10 @@ export const radialFilled: IAssembler = { vData[offset + 3] = dataList[i].u; vData[offset + 4] = dataList[i].v; } - }, + } // only for TS - updateWorldVertexAndUVData (sprite: Sprite, chunk: StaticVBChunk) { + private updateWorldVertexAndUVData (sprite: Sprite, chunk: StaticVBChunk): void { const node = sprite.node; node.getWorldMatrix(m); @@ -454,18 +452,18 @@ export const radialFilled: IAssembler = { vData[vertexOffset + 4] = vert.v; vertexOffset += stride; } - }, + } // dirty Mark // the real update uv is on updateWorldUVData - updateUVs (sprite: Sprite) { + updateUVs (sprite: Sprite): void { const renderData = sprite.renderData!; renderData.vertDirty = true; sprite.markForUpdateRenderData(); - }, + } // fill color here - updateColorLate (sprite: Sprite) { + private updateColorLate (sprite: Sprite): void { const renderData = sprite.renderData!; const vData = renderData.chunk.vb; const stride = renderData.floatStride; @@ -484,10 +482,12 @@ export const radialFilled: IAssembler = { vData[colorOffset + 3] = colorA; colorOffset += stride; } - }, + } // Too early - updateColor (sprite: Sprite) { + updateColor (sprite: Sprite): void { // Update color by updateColorLate - }, -}; + } +} + +export const radialFilled = new RadialFilled(); diff --git a/cocos/2d/assembler/sprite/simple.ts b/cocos/2d/assembler/sprite/simple.ts index c41a612a7d9..941e3676e42 100644 --- a/cocos/2d/assembler/sprite/simple.ts +++ b/cocos/2d/assembler/sprite/simple.ts @@ -40,16 +40,16 @@ const QUAD_INDICES = Uint16Array.from([0, 1, 2, 1, 3, 2]); * simple 组装器 * 可通过 `UI.simple` 获取该组装器。 */ -export const simple: IAssembler = { - createData (sprite: Sprite) { +class Simple implements IAssembler { + createData (sprite: Sprite): RenderData { const renderData = sprite.requestRenderData(); renderData.dataLength = 4; renderData.resize(4, 6); renderData.chunk.setIndexBuffer(QUAD_INDICES); return renderData; - }, + } - updateRenderData (sprite: Sprite) { + updateRenderData (sprite: Sprite): void { const frame = sprite.spriteFrame; dynamicAtlasManager.packToDynamicAtlas(sprite, frame); @@ -63,9 +63,9 @@ export const simple: IAssembler = { } renderData.updateRenderData(sprite, frame); } - }, + } - updateWorldVerts (sprite: Sprite, chunk: StaticVBChunk) { + private updateWorldVerts (sprite: Sprite, chunk: StaticVBChunk): void { const renderData = sprite.renderData!; const vData = chunk.vb; @@ -92,9 +92,9 @@ export const simple: IAssembler = { vData[offset + 1] = (m01 * x + m05 * y + m13) * rhw; vData[offset + 2] = (m02 * x + m06 * y + m14) * rhw; } - }, + } - fillBuffers (sprite: Sprite, renderer: IBatcher) { + fillBuffers (sprite: Sprite, renderer: IBatcher): void { if (sprite === null) { return; } @@ -134,9 +134,9 @@ export const simple: IAssembler = { meshBuffer.indexOffset += 6; // slow version // renderer.switchBufferAccessor().appendIndices(chunk); - }, + } - updateVertexData (sprite: Sprite) { + private updateVertexData (sprite: Sprite): void { const renderData: RenderData | null = sprite.renderData; if (!renderData) { return; @@ -184,9 +184,9 @@ export const simple: IAssembler = { dataList[3].y = t; renderData.vertDirty = true; - }, + } - updateUVs (sprite: Sprite) { + updateUVs (sprite: Sprite): void { if (!sprite.spriteFrame) return; const renderData = sprite.renderData!; const vData = renderData.chunk.vb; @@ -199,9 +199,9 @@ export const simple: IAssembler = { vData[22] = uv[5]; vData[30] = uv[6]; vData[31] = uv[7]; - }, + } - updateColor (sprite: Sprite) { + updateColor (sprite: Sprite): void { const renderData = sprite.renderData!; const vData = renderData.chunk.vb; let colorOffset = 5; @@ -216,5 +216,7 @@ export const simple: IAssembler = { vData[colorOffset + 2] = colorB; vData[colorOffset + 3] = colorA; } - }, -}; + } +} + +export const simple = new Simple(); diff --git a/cocos/2d/assembler/sprite/sliced.ts b/cocos/2d/assembler/sprite/sliced.ts index 61ed371554d..09d13a25c72 100644 --- a/cocos/2d/assembler/sprite/sliced.ts +++ b/cocos/2d/assembler/sprite/sliced.ts @@ -39,20 +39,21 @@ for (let i = 0; i < 4; i++) { * sliced 组装器 * 可通过 `UI.sliced` 获取该组装器。 */ -export const sliced: IAssembler = { +class Sliced implements IAssembler { + private QUAD_INDICES!: Uint16Array; - createData (sprite: Sprite) { + createData (sprite: Sprite): RenderData { const renderData: RenderData | null = sprite.requestRenderData()!; // 0-4 for local vertex renderData.dataLength = 16; renderData.resize(16, 54); this.QUAD_INDICES = new Uint16Array(54); this.createQuadIndices(4, 4); - renderData.chunk.setIndexBuffer(this.QUAD_INDICES as Uint16Array); + renderData.chunk.setIndexBuffer(this.QUAD_INDICES); return renderData; - }, + } - createQuadIndices (vertexRow: number, vertexCol: number) { + private createQuadIndices (vertexRow: number, vertexCol: number): void { let offset = 0; for (let curRow = 0; curRow < vertexRow - 1; curRow++) { for (let curCol = 0; curCol < vertexCol - 1; curCol++) { @@ -74,9 +75,9 @@ export const sliced: IAssembler = { this.QUAD_INDICES[offset++] = vid + vertexCol; } } - }, + } - updateRenderData (sprite: Sprite) { + updateRenderData (sprite: Sprite): void { const frame = sprite.spriteFrame; // TODO: Material API design and export from editor could affect the material activation process @@ -102,9 +103,9 @@ export const sliced: IAssembler = { } renderData.updateRenderData(sprite, frame); } - }, + } - updateVertexData (sprite: Sprite) { + private updateVertexData (sprite: Sprite): void { const renderData: RenderData = sprite.renderData!; const dataList: IRenderData[] = renderData.data; const uiTrans = sprite.node._uiProps.uiTransformComp!; @@ -148,9 +149,9 @@ export const sliced: IAssembler = { } } } - }, + } - fillBuffers (sprite: Sprite, renderer: IBatcher) { + fillBuffers (sprite: Sprite, renderer: IBatcher): void { const renderData: RenderData = sprite.renderData!; const chunk = renderData.chunk; if (sprite._flagChangedVersion !== sprite.node.flagChangedVersion || renderData.vertDirty) { @@ -176,9 +177,9 @@ export const sliced: IAssembler = { } } meshBuffer.indexOffset = indexOffset; - }, + } - updateWorldVertexData (sprite: Sprite, chunk: StaticVBChunk) { + private updateWorldVertexData (sprite: Sprite, chunk: StaticVBChunk): void { const renderData = sprite.renderData!; const stride = renderData.floatStride; const dataList: IRenderData[] = renderData.data; @@ -206,9 +207,9 @@ export const sliced: IAssembler = { vData[offset + 2] = (m02 * x + m06 * y + m14) * rhw; } } - }, + } - updateUVs (sprite: Sprite) { + updateUVs (sprite: Sprite): void { if (!sprite.spriteFrame) return; const renderData = sprite.renderData!; const vData = renderData.chunk.vb; @@ -220,9 +221,9 @@ export const sliced: IAssembler = { vData[uvOffset + 1] = uv[i].v; uvOffset += stride; } - }, + } - updateColor (sprite: Sprite) { + updateColor (sprite: Sprite): void { const renderData = sprite.renderData!; const vData = renderData.chunk.vb; const stride = renderData.floatStride; @@ -240,5 +241,7 @@ export const sliced: IAssembler = { vData[colorOffset + 3] = colorA; colorOffset += stride; } - }, -}; + } +} + +export const sliced = new Sliced(); diff --git a/cocos/2d/assembler/sprite/tiled.ts b/cocos/2d/assembler/sprite/tiled.ts index 8608456f5d8..ed0722310b3 100644 --- a/cocos/2d/assembler/sprite/tiled.ts +++ b/cocos/2d/assembler/sprite/tiled.ts @@ -57,12 +57,12 @@ function has9SlicedOffsetVertexCount (spriteFrame: SpriteFrame): number { return 0; } -export const tiled: IAssembler = { - createData (sprite: UIRenderer) { +class Tiled implements IAssembler { + createData (sprite: UIRenderer): RenderData { return sprite.requestRenderData(); - }, + } - updateRenderData (sprite: Sprite) { + updateRenderData (sprite: Sprite): void { const renderData = sprite.renderData!; const frame = sprite.spriteFrame!; if (!frame || !renderData) { @@ -117,9 +117,9 @@ export const tiled: IAssembler = { } renderData.updateRenderData(sprite, frame); - }, + } - createQuadIndices (indexCount: number) { + private createQuadIndices (indexCount: number): void { if (indexCount % 6 !== 0) { errorID(16308); return; @@ -135,17 +135,17 @@ export const tiled: IAssembler = { QUAD_INDICES[offset++] = 3 + i * 4; QUAD_INDICES[offset++] = 2 + i * 4; } - }, + } // dirty Mark // the real update uv is on updateWorldUVData - updateUVs (sprite: Sprite) { + updateUVs (sprite: Sprite): void { const renderData = sprite.renderData!; renderData.vertDirty = true; sprite.markForUpdateRenderData(); - }, + } - fillBuffers (sprite: Sprite, renderer: IBatcher) { + fillBuffers (sprite: Sprite, renderer: IBatcher): void { const node = sprite.node; const renderData: RenderData = sprite.renderData!; const chunk = renderData.chunk; @@ -179,9 +179,9 @@ export const tiled: IAssembler = { meshBuffer.indexOffset += 6; } meshBuffer.setDirty(); - }, + } - updateWorldUVData (sprite: Sprite) { + private updateWorldUVData (sprite: Sprite): void { const renderData = sprite.renderData!; const stride = renderData.floatStride; const dataList: IRenderData[] = renderData.data; @@ -191,10 +191,10 @@ export const tiled: IAssembler = { vData[offset + 3] = dataList[i].u; vData[offset + 4] = dataList[i].v; } - }, + } // only for TS - updateWorldVertexAndUVData (sprite: Sprite, chunk: StaticVBChunk) { + private updateWorldVertexAndUVData (sprite: Sprite, chunk: StaticVBChunk): void { const node = sprite.node; node.getWorldMatrix(m); @@ -218,9 +218,9 @@ export const tiled: IAssembler = { } this.updateWorldUVData(sprite); - }, + } - updateVerts (sprite: Sprite, sizableWidth: number, sizableHeight: number, row: number, col: number) { + private updateVerts (sprite: Sprite, sizableWidth: number, sizableHeight: number, row: number, col: number): void { const uiTrans = sprite.node._uiProps.uiTransformComp!; const renderData: RenderData = sprite.renderData!; const dataList: IRenderData[] = renderData.data; @@ -490,10 +490,10 @@ export const tiled: IAssembler = { dataList[curIndex + 3].v = tempYVerts[3]; } } - }, + } // fill color here - updateColorLate (sprite: Sprite) { + private updateColorLate (sprite: Sprite): void { const renderData = sprite.renderData!; const vData = renderData.chunk.vb; const stride = renderData.floatStride; @@ -512,10 +512,12 @@ export const tiled: IAssembler = { vData[colorOffset + 3] = colorA; colorOffset += stride; } - }, + } // Too early - updateColor (sprite: Sprite) { + updateColor (sprite: Sprite): void { // Update color by updateColorLate - }, -}; + } +} + +export const tiled = new Tiled(); diff --git a/cocos/2d/components/graphics.ts b/cocos/2d/components/graphics.ts index 08248a4b935..61732590707 100644 --- a/cocos/2d/components/graphics.ts +++ b/cocos/2d/components/graphics.ts @@ -39,6 +39,7 @@ import { Format, PrimitiveMode, Attribute, Device, BufferUsageBit, BufferInfo, M import { vfmtPosColor, getAttributeStride, getComponentPerVertex } from '../renderer/vertex-format'; import { NativeUIModelProxy } from '../renderer/native-2d'; import { RenderEntity, RenderEntityType } from '../renderer/render-entity'; +import { GraphicsAssembler } from '../assembler/graphics/webgl/graphics-assembler'; const attributes = vfmtPosColor.concat([ new Attribute('a_dist', Format.R32F), @@ -589,7 +590,7 @@ export class Graphics extends UIRenderer { this._isDrawing = true; this._isNeedUploadData = true; - (this._assembler as IAssembler).stroke!(this); + (this._assembler as GraphicsAssembler).stroke(this); } /** @@ -606,7 +607,7 @@ export class Graphics extends UIRenderer { this._isDrawing = true; this._isNeedUploadData = true; - (this._assembler as IAssembler).fill!(this); + (this._assembler as GraphicsAssembler).fill(this); } private _updateMtlForGraphics (): void { diff --git a/cocos/2d/renderer/base.ts b/cocos/2d/renderer/base.ts index 20312364a90..2f0ab474080 100644 --- a/cocos/2d/renderer/base.ts +++ b/cocos/2d/renderer/base.ts @@ -28,12 +28,21 @@ */ import { UIRenderer } from '../framework/ui-renderer'; +import type { IBatcher } from './i-batcher'; +import type { BaseRenderData, RenderData } from './render-data'; /** * @internal */ export interface IAssembler { - [key: string]: any; + createData(comp: UIRenderer): BaseRenderData; + fillBuffers(comp: UIRenderer, renderer: IBatcher): void; + updateUVs (comp: UIRenderer, ...args: any[]): void; + updateColor (comp: UIRenderer): void; + updateRenderData (comp: UIRenderer): void; + update? (comp: UIRenderer, dt: number): void; + resetAssemblerData? (data: any): void; + removeData? (data: BaseRenderData): void; } /** diff --git a/cocos/dragon-bones/ArmatureDisplay.ts b/cocos/dragon-bones/ArmatureDisplay.ts index 3a301c02ff9..5244d977e8b 100644 --- a/cocos/dragon-bones/ArmatureDisplay.ts +++ b/cocos/dragon-bones/ArmatureDisplay.ts @@ -43,6 +43,7 @@ import { Material, Texture2D } from '../asset/assets'; import { Node } from '../scene-graph'; import { builtinResMgr } from '../asset/asset-manager'; import { setPropertyEnumType } from '../core/internal-index'; +import { RenderData } from '../2d/renderer/render-data'; enum DefaultArmaturesEnum { default = -1, @@ -582,7 +583,7 @@ export class ArmatureDisplay extends UIRenderer { */ public maxIndexCount = 0; - protected _materialCache: { [key: string]: MaterialInstance } = {} as any; + protected _materialCache: { [key: string]: MaterialInstance } = {}; protected _enumArmatures: any = Enum({}); protected _enumAnimations: any = Enum({}); @@ -1471,7 +1472,7 @@ export class ArmatureDisplay extends UIRenderer { this._assembler = assembler; } if (this._armature && this._assembler) { - this._renderData = this._assembler.createData(this); + this._renderData = this._assembler.createData(this) as RenderData; if (this._renderData) { this.maxVertexCount = this._renderData.vertexCount; this.maxIndexCount = this._renderData.indexCount; diff --git a/cocos/dragon-bones/assembler/simple.ts b/cocos/dragon-bones/assembler/simple.ts index ba26668e978..621f7e6d75e 100644 --- a/cocos/dragon-bones/assembler/simple.ts +++ b/cocos/dragon-bones/assembler/simple.ts @@ -28,16 +28,17 @@ import { BlendFactor } from '../../gfx'; import { vfmtPosUvColor } from '../../2d/renderer/vertex-format'; import { MaterialInstance } from '../../render-scene/core/material-instance'; import { IAssembler } from '../../2d/renderer/base'; -import { Batcher2D } from '../../2d/renderer/batcher-2d'; import { ArmatureFrame } from '../ArmatureCache'; import { ArmatureDisplay } from '../ArmatureDisplay'; import { CCSlot } from '../CCSlot'; import { StaticVBAccessor } from '../../2d/renderer/static-vb-accessor'; -import { RenderData } from '../../2d/renderer/render-data'; +import { BaseRenderData, RenderData } from '../../2d/renderer/render-data'; import { Texture2D } from '../../asset/assets'; import { TextureBase } from '../../asset/assets/texture-base'; import { Node } from '../../scene-graph'; import { director } from '../../game'; +import { IBatcher } from '../../2d/renderer/i-batcher'; +import { UIRenderer } from '../../2d'; const NEED_COLOR = 0x01; const NEED_BATCH = 0x10; @@ -128,9 +129,16 @@ let _accessor: StaticVBAccessor = null!; * simple 组装器 * 可通过 `UI.simple` 获取该组装器。 */ -export const simple: IAssembler = { - accessor: _accessor, - vCount: 32767, +class Simple implements IAssembler { + fillBuffers (comp: ArmatureDisplay, renderer: IBatcher): void { + + } + updateUVs (comp: ArmatureDisplay): void { + + } + + private accessor = _accessor; + private vCount = 32767; ensureAccessor (): StaticVBAccessor { if (!_accessor) { const device = director.root!.device; @@ -140,13 +148,13 @@ export const simple: IAssembler = { // Register to batcher so that batcher can upload buffers after batching process batcher.registerBufferAccessor(Number.parseInt('DRAGONBONES', 36), _accessor); } - return this.accessor as StaticVBAccessor; - }, + return this.accessor; + } createData (comp: ArmatureDisplay): RenderData { let rd = comp.renderData; if (!rd) { - this.ensureAccessor() as StaticVBAccessor; + this.ensureAccessor(); const slots = comp._armature!._slots; let vCount = 0; let iCount = 0; @@ -168,22 +176,25 @@ export const simple: IAssembler = { } } return rd; - }, + } - updateRenderData (comp: ArmatureDisplay, batcher: Batcher2D): void { + updateRenderData (comp: ArmatureDisplay): void { _comp = comp; const armature = comp._armature; if (armature) { - updateComponentRenderData(comp, batcher); + updateComponentRenderData(comp); } - }, + } updateColor (comp: ArmatureDisplay): void { if (!comp) return; _comp = comp; _comp.markForUpdateRenderData(); - }, -}; + } +} + +export const simple = new Simple(); + function realTimeTraverse (armature: Armature, parentOpacity: number, worldMat?: Mat4): void { const rd = _renderData!; _vbuf = rd.chunk.vb; @@ -406,7 +417,7 @@ function cacheTraverse (frame: ArmatureFrame | null, parentMat?: Mat4): void { } } -function updateComponentRenderData (comp: ArmatureDisplay, batcher: Batcher2D): void { +function updateComponentRenderData (comp: ArmatureDisplay): void { // comp.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA; const armature = comp._armature; diff --git a/cocos/particle-2d/motion-streak-2d-assembler.ts b/cocos/particle-2d/motion-streak-2d-assembler.ts index 9879601ed7e..7c23a0fc73b 100644 --- a/cocos/particle-2d/motion-streak-2d-assembler.ts +++ b/cocos/particle-2d/motion-streak-2d-assembler.ts @@ -25,16 +25,15 @@ import { JSB } from 'internal:constants'; import { IAssembler, IAssemblerManager } from '../2d/renderer/base'; -import { MotionStreak } from './motion-streak-2d'; +import { MotionStreak, MotionStreakPoint } from './motion-streak-2d'; import { Vec2, Color } from '../core'; import { IBatcher } from '../2d/renderer/i-batcher'; import { RenderData } from '../2d/renderer/render-data'; +import { UIRenderer } from '../2d'; -const _tangent = new Vec2(); -// const _miter = new Vec2(); const _normal = new Vec2(); const _vec2 = new Vec2(); -let QUAD_INDICES; +let QUAD_INDICES: Uint16Array | null = null; function normal (out: Vec2, dir: Vec2): Vec2 { // get perpendicular @@ -43,32 +42,17 @@ function normal (out: Vec2, dir: Vec2): Vec2 { return out; } -function computeMiter (miter, lineA, lineB, halfThick, maxMultiple): number { - // get tangent line - lineA.add(lineB, _tangent); - _tangent.normalize(); - - // get miter as a unit vector - miter.x = -_tangent.y; - miter.y = _tangent.x; - _vec2.x = -lineA.y; - _vec2.y = lineA.x; - - // get the necessary length of our miter - let multiple = 1 / miter.dot(_vec2); - if (maxMultiple) { - multiple = Math.min(multiple, maxMultiple); +class MotionStreakAssembler implements IAssembler { + updateUVs (comp: UIRenderer, ...args: any[]): void { + throw new Error('Method not implemented.'); } - return halfThick * multiple; -} -export const MotionStreakAssembler: IAssembler = { createData (comp: MotionStreak): RenderData { const renderData = comp.requestRenderData(); renderData.dataLength = 4; renderData.resize(16, (16 - 2) * 3); return renderData; - }, + } update (comp: MotionStreak, dt: number): void { const stroke = comp.stroke / 2; @@ -80,7 +64,7 @@ export const MotionStreakAssembler: IAssembler = { const points = comp.points; - let cur; + let cur: MotionStreakPoint | undefined; if (points.length > 1) { const point = points[0]; const difx = point.point.x - tx; @@ -91,7 +75,7 @@ export const MotionStreakAssembler: IAssembler = { } if (!cur) { - cur = new MotionStreak.Point(); + cur = new MotionStreakPoint(); points.unshift(cur); } @@ -178,7 +162,7 @@ export const MotionStreakAssembler: IAssembler = { if (JSB) { const indexCount = renderData.indexCount; this.createQuadIndices(comp, indexCount); - renderData.chunk.setIndexBuffer(QUAD_INDICES); + renderData.chunk.setIndexBuffer(QUAD_INDICES!); // Fill all dataList to vData this.updateWorldVertexAllData(comp); @@ -186,9 +170,9 @@ export const MotionStreakAssembler: IAssembler = { renderData.updateRenderData(comp, comp.texture!); comp.markForUpdateRenderData(); } - }, + } - updateWorldVertexAllData (comp: MotionStreak): void { + private updateWorldVertexAllData (comp: MotionStreak): void { const renderData = comp.renderData!; const stride = renderData.floatStride; const dataList = renderData.data; @@ -202,9 +186,9 @@ export const MotionStreakAssembler: IAssembler = { vData[offset + 4] = dataList[i].v; Color.toArray(vData, dataList[i].color, offset + 5); } - }, + } - createQuadIndices (comp: MotionStreak, indexCount: number): void { + private createQuadIndices (comp: MotionStreak, indexCount: number): void { const renderData = comp.renderData!; const chunk = renderData.chunk; const vid = 0; @@ -221,9 +205,9 @@ export const MotionStreakAssembler: IAssembler = { QUAD_INDICES[indexOffset++] = start + 2; QUAD_INDICES[indexOffset++] = start + 3; } - }, + } - updateRenderDataCache (comp: MotionStreak, renderData: RenderData): void { + private updateRenderDataCache (comp: MotionStreak, renderData: RenderData): void { if (renderData.passDirty) { renderData.updatePass(comp); } @@ -237,7 +221,7 @@ export const MotionStreakAssembler: IAssembler = { if (renderData.hashDirty) { renderData.updateHash(); } - }, + } updateRenderData (comp: MotionStreak): void { if (JSB) { @@ -247,11 +231,11 @@ export const MotionStreakAssembler: IAssembler = { comp.renderData!.renderDrawInfo.setVertDirty(false); comp.node.hasChangedFlags = 0; } - }, + } updateColor (comp: MotionStreak): void { // do nothing - }, + } fillBuffers (comp: MotionStreak, renderer: IBatcher): void { const renderData = comp.renderData!; @@ -292,12 +276,14 @@ export const MotionStreakAssembler: IAssembler = { meshBuffer.indexOffset += renderData.indexCount; meshBuffer.setDirty(); - }, -}; + } +} + +const motionStreakAssembler = new MotionStreakAssembler(); export const MotionStreakAssemblerManager: IAssemblerManager = { getAssembler (comp: MotionStreak): IAssembler { - return MotionStreakAssembler; + return motionStreakAssembler; }, }; diff --git a/cocos/particle-2d/motion-streak-2d.ts b/cocos/particle-2d/motion-streak-2d.ts index e63ba96557d..eed1a8a5516 100644 --- a/cocos/particle-2d/motion-streak-2d.ts +++ b/cocos/particle-2d/motion-streak-2d.ts @@ -29,8 +29,9 @@ import { UIRenderer } from '../2d/framework'; import { Texture2D } from '../asset/assets/texture-2d'; import { IBatcher } from '../2d/renderer/i-batcher'; import { Vec2 } from '../core'; +import { RenderData } from '../2d/renderer/render-data'; -class Point { +export class MotionStreakPoint { public point = new Vec2(); public dir = new Vec2(); public distance = 0; @@ -69,7 +70,7 @@ class Point { @menu('Effects/MotionStreak') @help('i18n:COMPONENT.help_url.motionStreak') export class MotionStreak extends UIRenderer { - public static Point = Point; + public static Point = MotionStreakPoint; /** * @en Preview the trailing effect in editor mode. @@ -156,7 +157,7 @@ export class MotionStreak extends UIRenderer { this._fastMode = val; } - public get points (): Point[] { + public get points (): MotionStreakPoint[] { return this._points; } @@ -172,7 +173,7 @@ export class MotionStreak extends UIRenderer { private _texture: Texture2D | null = null; @serializable private _fastMode = false; - private _points: Point[] = []; + private _points: MotionStreakPoint[] = []; public onEnable (): void { super.onEnable(); @@ -188,8 +189,8 @@ export class MotionStreak extends UIRenderer { if (!this._renderData) { if (this._assembler && this._assembler.createData) { - this._renderData = this._assembler.createData(this); - this._renderData!.material = this.material; + this._renderData = this._assembler.createData(this) as RenderData; + this._renderData.material = this.material; this._updateColor(); } } @@ -219,9 +220,11 @@ export class MotionStreak extends UIRenderer { if (this._renderData) this._renderData.clear(); } - public lateUpdate (dt): void { + public lateUpdate (dt: number): void { if (EDITOR_NOT_IN_PREVIEW && !this._preview) return; - if (this._assembler) this._assembler.update(this, dt); + if (this._assembler && this._assembler.update) { + this._assembler.update(this, dt); + } } /** diff --git a/cocos/particle-2d/particle-asset.ts b/cocos/particle-2d/particle-asset.ts index 9b75d43b85d..ba345761451 100644 --- a/cocos/particle-2d/particle-asset.ts +++ b/cocos/particle-2d/particle-asset.ts @@ -39,7 +39,7 @@ const { ccclass, serializable, editable } = _decorator; export class ParticleAsset extends Asset { @serializable @editable - public spriteFrame: SpriteFrame | null= null; + public spriteFrame: SpriteFrame | null = null; } cclegacy.ParticleAsset = ParticleAsset; diff --git a/cocos/particle-2d/particle-simulator-2d.ts b/cocos/particle-2d/particle-simulator-2d.ts index 501ef233ece..3c304566a7e 100644 --- a/cocos/particle-2d/particle-simulator-2d.ts +++ b/cocos/particle-2d/particle-simulator-2d.ts @@ -27,6 +27,7 @@ import { vfmtPosUvColor, getComponentPerVertex } from '../2d/renderer/vertex-for import { PositionType, EmitterMode, START_SIZE_EQUAL_TO_END_SIZE, START_RADIUS_EQUAL_TO_END_RADIUS } from './define'; import { ParticleSystem2D } from './particle-system-2d'; import { MeshRenderData } from '../2d/renderer/render-data'; +import type { Particle2DAssembler } from './particle-system-2d-assembler'; const _pos = new Vec2(); const _tpa = new Vec2(); @@ -329,7 +330,7 @@ export class Simulator { } public step (dt: number): void { - const assembler = this.sys.assembler!; + const assembler = this.sys.assembler as Particle2DAssembler; const psys = this.sys; const node = psys.node; const particles = this.particles; diff --git a/cocos/particle-2d/particle-system-2d-assembler.ts b/cocos/particle-2d/particle-system-2d-assembler.ts index bb8032428d7..440120f0924 100644 --- a/cocos/particle-2d/particle-system-2d-assembler.ts +++ b/cocos/particle-2d/particle-system-2d-assembler.ts @@ -29,26 +29,40 @@ import { MeshRenderData } from '../2d/renderer/render-data'; import { IBatcher } from '../2d/renderer/i-batcher'; import { cclegacy } from '../core'; -export const ParticleAssembler: IAssembler = { - maxParticleDeltaTime: 0, - createData (comp: ParticleSystem2D) { +export class Particle2DAssembler implements IAssembler { + maxParticleDeltaTime = 0; + + updateUVs (comp: ParticleSystem2D): void { + + } + + updateColor (comp: ParticleSystem2D): void { + + } + + createData (comp: ParticleSystem2D): MeshRenderData { return MeshRenderData.add(); - }, - removeData (data) { + } + + removeData (data: MeshRenderData): void { MeshRenderData.remove(data); - }, - updateRenderData () { - }, - fillBuffers (comp: ParticleSystem2D, renderer: IBatcher) { - }, -}; + } + + updateRenderData (): void { + } + + fillBuffers (comp: ParticleSystem2D, renderer: IBatcher): void { + } +} + +export const particle2DAssembler = new Particle2DAssembler(); export const ParticleSystem2DAssembler: IAssemblerManager = { - getAssembler (comp: ParticleSystem2D) { - if (!ParticleAssembler.maxParticleDeltaTime) { - ParticleAssembler.maxParticleDeltaTime = cclegacy.game.frameTime / 1000 * 2; + getAssembler (comp: ParticleSystem2D): IAssembler { + if (!particle2DAssembler.maxParticleDeltaTime) { + particle2DAssembler.maxParticleDeltaTime = cclegacy.game.frameTime / 1000 * 2; } - return ParticleAssembler; + return particle2DAssembler; }, }; diff --git a/cocos/particle-2d/particle-system-2d.ts b/cocos/particle-2d/particle-system-2d.ts index 2b40985c812..c70dfb2d2c7 100644 --- a/cocos/particle-2d/particle-system-2d.ts +++ b/cocos/particle-2d/particle-system-2d.ts @@ -42,7 +42,7 @@ import { IBatcher } from '../2d/renderer/i-batcher'; import { assetManager, builtinResMgr } from '../asset/asset-manager'; import { PositionType, EmitterMode, DURATION_INFINITY, START_RADIUS_EQUAL_TO_END_RADIUS, START_SIZE_EQUAL_TO_END_SIZE } from './define'; import { ccwindow } from '../core/global-exports'; -import type { IAssembler } from '../2d'; +import type { IAssembler, MeshRenderData } from '../2d'; import type { TextureBase } from '../asset/assets/texture-base'; /** @@ -138,6 +138,80 @@ function getParticleComponents (node): ParticleSystem2D[] { return getParticleComponents(parent); } +interface IParticle2DParameters { + maxParticles?: string; + particleLifespan?: string; + particleLifespanVariance?: string; + emissionRate?: string; + duration?: string; + blendFuncSource?: string; + blendFuncDestination?: string; + startColorRed?: string; + startColorGreen?: string; + startColorBlue?: string; + startColorAlpha?: string; + + startColorVarianceRed?: string; + startColorVarianceGreen?: string; + startColorVarianceBlue?: string; + startColorVarianceAlpha?: string; + + finishColorRed?: string; + finishColorGreen?: string; + finishColorBlue?: string; + finishColorAlpha?: string; + + finishColorVarianceRed?: string; + finishColorVarianceGreen?: string; + finishColorVarianceBlue?: string; + finishColorVarianceAlpha?: string; + + startParticleSize?: string; + startParticleSizeVariance?: string; + finishParticleSize?: string; + finishParticleSizeVariance?: string; + + positionType?: string; + + sourcePositionVariancex?: string; + sourcePositionVariancey?: string; + + angle?: string; + angleVariance?: string; + + rotationStart?: string; + rotationStartVariance?: string; + rotationEnd?: string; + rotationEndVariance?: string; + + emitterType?: string; + + gravityx?: string; + gravityy?: string; + + speed?: string; + speedVariance?: string; + + radialAcceleration?: string; + radialAccelVariance?: string; + + tangentialAcceleration?: string; + tangentialAccelVariance?: string; + + rotationIsDir?: string; + + maxRadius?: string; + maxRadiusVariance?: string; + minRadius?: string; + minRadiusVariance?: string; + rotatePerSecond?: string; + rotatePerSecondVariance?: string; + + spriteFrameUuid?: string; + textureFileName?: string; + textureImageData?: string; +} + /** * @en Particle System base class. * cocos2d also supports particles generated by Particle Designer (http://particledesigner.71squared.com/). @@ -740,10 +814,10 @@ export class ParticleSystem2D extends UIRenderer { private _positionType = PositionType.FREE; private _stopped = true; - private declare _previewTimer; + private declare _previewTimer: number | null; private declare _focused: boolean; - private declare _plistFile; - private declare _tiffReader; + private declare _plistFile: string; + private declare _tiffReader: TiffReader; private _useFile: boolean; constructor () { @@ -768,7 +842,7 @@ export class ParticleSystem2D extends UIRenderer { // reset uv data so next time simulator will refill buffer uv info when exit edit mode from prefab. this._simulator.uvFilled = 0; - if (this._simulator.renderData && this._assembler) { + if (this._simulator.renderData && this._assembler && this._assembler.removeData) { this._assembler.removeData(this._simulator.renderData); } } @@ -843,13 +917,13 @@ export class ParticleSystem2D extends UIRenderer { this._assembler = assembler; } if (this._assembler && this._assembler.createData) { - this._simulator.renderData = this._assembler.createData(this); + this._simulator.renderData = this._assembler.createData(this) as MeshRenderData; this._simulator.renderData.particleInitRenderDrawInfo(this.renderEntity); // 确保 renderEntity 和 renderData 都是 simulator 上的 this._simulator.initDrawInfo(); } } - protected lateUpdate (dt): void { + protected lateUpdate (dt: number): void { if (!this._simulator.finished) { this._simulator.step(dt); } @@ -917,14 +991,14 @@ export class ParticleSystem2D extends UIRenderer { if (!this._custom) { const isDiffFrame = this._spriteFrame !== file.spriteFrame; if (isDiffFrame) this.spriteFrame = file.spriteFrame; - this._initWithDictionary(file._nativeAsset); + this._initWithDictionary(file._nativeAsset as IParticle2DParameters); } if (!this._spriteFrame) { if (file.spriteFrame) { this.spriteFrame = file.spriteFrame; } else if (this._custom) { - this._initTextureWithDictionary(file._nativeAsset); + this._initTextureWithDictionary(file._nativeAsset as IParticle2DParameters); } } else if (!this._renderSpriteFrame && this._spriteFrame) { this._applySpriteFrame(); @@ -935,7 +1009,7 @@ export class ParticleSystem2D extends UIRenderer { /** * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ - public _initTextureWithDictionary (dict: any): boolean { + public _initTextureWithDictionary (dict: IParticle2DParameters): boolean { if (dict.spriteFrameUuid) { const spriteFrameUuid = dict.spriteFrameUuid; assetManager.loadAny(spriteFrameUuid, (err: Error, spriteFrame: SpriteFrame): void => { @@ -1023,7 +1097,9 @@ export class ParticleSystem2D extends UIRenderer { /** * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ - public _initWithDictionary (dict: any): boolean { + public _initWithDictionary (dict: IParticle2DParameters): boolean { + const parseInt = globalThis.parseInt as (v: string | number) => number; + const parseFloat = globalThis.parseFloat as (v: string | number) => number; this._useFile = true; this.totalParticles = parseInt(dict.maxParticles || 0); @@ -1034,7 +1110,7 @@ export class ParticleSystem2D extends UIRenderer { // emission Rate const _tempEmissionRate = dict.emissionRate; if (_tempEmissionRate) { - this.emissionRate = _tempEmissionRate; + this.emissionRate = parseFloat(_tempEmissionRate); } else { this.emissionRate = Math.min(this.totalParticles / this.life, Number.MAX_VALUE); } diff --git a/cocos/spine/assembler/simple.ts b/cocos/spine/assembler/simple.ts index 660ae7a5ca6..6abbc7950f7 100644 --- a/cocos/spine/assembler/simple.ts +++ b/cocos/spine/assembler/simple.ts @@ -24,17 +24,18 @@ import { IAssembler } from '../../2d/renderer/base'; -import { Batcher2D } from '../../2d/renderer/batcher-2d'; import { StaticVBAccessor } from '../../2d/renderer/static-vb-accessor'; import { vfmtPosUvColor4B, vfmtPosUvTwoColor4B, getAttributeStride } from '../../2d/renderer/vertex-format'; import { Skeleton, SpineMaterialType } from '../skeleton'; import { BlendFactor } from '../../gfx'; import { legacyCC } from '../../core/global-exports'; -import { RenderData } from '../../2d/renderer/render-data'; +import { BaseRenderData, RenderData } from '../../2d/renderer/render-data'; import { director } from '../../game'; import spine from '../lib/spine-core.js'; import { Color, EPSILON, Vec3 } from '../../core'; import { MaterialInstance } from '../../render-scene'; +import { IBatcher } from '../../2d/renderer/i-batcher'; +import { UIRenderer } from '../../2d'; const _slotColor = new Color(0, 0, 255, 255); const _boneColor = new Color(255, 0, 0, 255); @@ -84,46 +85,59 @@ function _getSlotMaterial (blendMode: number, comp: Skeleton): MaterialInstance return comp.getMaterialForBlendAndTint(src, dst, _useTint ? SpineMaterialType.TWO_COLORED : SpineMaterialType.COLORED_TEXTURED); } -export const simple: IAssembler = { - vCount: 32767, - ensureAccessor (useTint: boolean) { +class Simple implements IAssembler { + fillBuffers (comp: Skeleton, renderer: IBatcher): void { + + } + updateUVs (comp: Skeleton): void { + + } + + updateColor (comp: Skeleton): void { + + } + + vCount = 32767; + private ensureAccessor (useTint: boolean): StaticVBAccessor { let accessor = useTint ? _tintAccessor : _accessor; if (!accessor) { const device = director.root!.device; const batcher = director.root!.batcher2D; const attributes = useTint ? vfmtPosUvTwoColor4B : vfmtPosUvColor4B; if (useTint) { - accessor = _tintAccessor = new StaticVBAccessor(device, attributes, this.vCount as number); + accessor = _tintAccessor = new StaticVBAccessor(device, attributes, this.vCount); // Register to batcher so that batcher can upload buffers after batching process batcher.registerBufferAccessor(Number.parseInt('SPINETINT', 36), _tintAccessor); } else { - accessor = _accessor = new StaticVBAccessor(device, attributes, this.vCount as number); + accessor = _accessor = new StaticVBAccessor(device, attributes, this.vCount); // Register to batcher so that batcher can upload buffers after batching process batcher.registerBufferAccessor(Number.parseInt('SPINE', 36), _accessor); } } return accessor; - }, + } - createData (comp: Skeleton) { + createData (comp: Skeleton): RenderData { let rd = comp.renderData; if (!rd) { const useTint = comp.useTint || comp.isAnimationCached(); - const accessor = this.ensureAccessor(useTint) as StaticVBAccessor; + const accessor = this.ensureAccessor(useTint); rd = RenderData.add(useTint ? vfmtPosUvTwoColor4B : vfmtPosUvColor4B, accessor); } return rd; - }, + } - updateRenderData (comp: Skeleton, batcher: Batcher2D) { + updateRenderData (comp: Skeleton): void { const skeleton = comp._skeleton; if (skeleton && comp.node.active && comp.skeletonData?.isValid) { - updateComponentRenderData(comp, batcher); + updateComponentRenderData(comp); } - }, -}; + } +} + +export const simple = new Simple(); -function updateComponentRenderData (comp: Skeleton, batcher: Batcher2D): void { +function updateComponentRenderData (comp: Skeleton): void { comp.drawList.reset(); if (comp.color.a === 0) return; comp._updateColor(); diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 27daeb4fd32..1a665d44f3b 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -29,7 +29,7 @@ import { Enum, EnumType, ccenum } from '../core/value-types/enum'; import { Node, NodeEventType } from '../scene-graph'; import { CCObject, Color, RecyclePool, js } from '../core'; import { SkeletonData } from './skeleton-data'; -import { Graphics, UIRenderer } from '../2d'; +import { Graphics, RenderData, UIRenderer } from '../2d'; import { Batcher2D } from '../2d/renderer/batcher-2d'; import { BlendFactor, BlendOp } from '../gfx'; import { MaterialInstance } from '../render-scene'; @@ -1130,7 +1130,7 @@ export class Skeleton extends UIRenderer { this._assembler = assembler; } if (this._skeleton && this._assembler) { - this._renderData = this._assembler.createData(this); + this._renderData = this._assembler.createData(this) as RenderData; this.markForUpdateRenderData(); this._updateColor(); } @@ -1588,7 +1588,7 @@ export class Skeleton extends UIRenderer { } } if (this._assembler && this._skeleton) { - this._renderData = this._assembler.createData(this); + this._renderData = this._assembler.createData(this) as RenderData; this.markForUpdateRenderData(); } } diff --git a/cocos/tiledmap/assembler/simple.ts b/cocos/tiledmap/assembler/simple.ts index ab5269a6900..1e039a38407 100644 --- a/cocos/tiledmap/assembler/simple.ts +++ b/cocos/tiledmap/assembler/simple.ts @@ -31,10 +31,11 @@ import { GID, MixedGID, RenderOrder, TiledGrid, TileFlag } from '../tiled-types' import { director, Director } from '../../game'; import { StaticVBAccessor } from '../../2d/renderer/static-vb-accessor'; import { vfmtPosUvColor } from '../../2d/renderer/vertex-format'; -import { RenderData } from '../../2d/renderer/render-data'; +import { BaseRenderData, RenderData } from '../../2d/renderer/render-data'; import { RenderDrawInfoType } from '../../2d/renderer/render-draw-info'; import { Texture2D } from '../../asset/assets'; import { Node } from '../../scene-graph'; +import { UIRenderer } from '../../2d'; const MaxGridsLimit = Math.ceil(65535 / 6); @@ -56,8 +57,8 @@ let _moveX = 0; let _moveY = 0; let _fillCount = 0; -let _curTexture : Texture2D | null = null; -let _tempBuffers : Float32Array; +let _curTexture: Texture2D | null = null; +let _tempBuffers: Float32Array; let _curLayer: TiledLayer; let flipTexture: (grid: TiledGrid, gid: MixedGID) => void; @@ -67,26 +68,31 @@ let _accessor: StaticVBAccessor = null!; * simple 组装器 * 可通过 `UI.simple` 获取该组装器。 */ -export const simple: IAssembler = { - ensureAccessor () { +class Simple implements IAssembler { + updateUVs (comp: TiledLayer): void { + } + + private ensureAccessor (): void { if (!_accessor) { const device = director.root!.device; const batcher = director.root!.batcher2D; - _accessor = new StaticVBAccessor(device, vfmtPosUvColor, this.vCount); + _accessor = new StaticVBAccessor(device, vfmtPosUvColor); //batcher.registerBufferAccessor(Number.parseInt('TILED-MAP', 36), _accessor); director.on(Director.EVENT_BEFORE_DRAW, () => { _accessor.reset(); }); } - }, + } - createData (layer: TiledLayer) { + createData (layer: TiledLayer): BaseRenderData { if (JSB) { this.ensureAccessor(); } - }, - fillBuffers (layer: TiledLayer, renderer: IBatcher) { + return null as unknown as BaseRenderData; + } + + fillBuffers (layer: TiledLayer, renderer: IBatcher): void { if (!layer || layer.tiledDataArray.length === 0) return; const dataArray = layer.tiledDataArray; @@ -110,9 +116,9 @@ export const simple: IAssembler = { vertexId += 4; } renderData.chunk.meshBuffer.indexOffset = indexOffset; - }, + } - updateRenderData (comp: TiledLayer) { + updateRenderData (comp: TiledLayer): void { comp.updateCulling(); _moveX = comp.leftDownToCenterX; _moveY = comp.leftDownToCenterY; @@ -157,9 +163,9 @@ export const simple: IAssembler = { if (JSB) { comp.prepareDrawData(); } - }, + } - updateColor (tiled: TiledLayer) { + updateColor (tiled: TiledLayer): void { const color = tiled.color; const colorV = new Float32Array(4); colorV[0] = color.r / 255; @@ -175,8 +181,10 @@ export const simple: IAssembler = { vs.set(colorV, i * 9 + 5); } } - }, -}; + } +} + +export const simple = new Simple(); /* texture coordinate @@ -276,7 +284,7 @@ function _flipDiamondTileTexture (inGrid: TiledGrid, gid: MixedGID): void { let tempVal; // vice - if (((gid as unknown as number) & TileFlag.DIAGONAL) >>> 0) { + if ((gid & TileFlag.DIAGONAL) >>> 0) { tempVal = _uva; _uva = _uvb; _uvb = tempVal; @@ -287,14 +295,14 @@ function _flipDiamondTileTexture (inGrid: TiledGrid, gid: MixedGID): void { } // flip x - if (((gid as unknown as number) & TileFlag.HORIZONTAL) >>> 0) { + if ((gid & TileFlag.HORIZONTAL) >>> 0) { tempVal = _uvb; _uvb = _uvc; _uvc = tempVal; } // flip y - if (((gid as unknown as number) & TileFlag.VERTICAL) >>> 0) { + if ((gid & TileFlag.VERTICAL) >>> 0) { tempVal = _uva; _uva = _uvd; _uvd = tempVal; @@ -325,8 +333,13 @@ function packRenderData (): void { // rowMoveDir is -1 or 1, -1 means decrease, 1 means increase // colMoveDir is -1 or 1, -1 means decrease, 1 means increase -function traverseGrids (leftDown: { col: number, row: number }, rightTop: { col: number, row: number }, - rowMoveDir: number, colMoveDir: number, comp: TiledLayer): void { +function traverseGrids ( + leftDown: { col: number, row: number }, + rightTop: { col: number, row: number }, + rowMoveDir: number, + colMoveDir: number, + comp: TiledLayer, +): void { // show nothing if (rightTop.row < 0 || rightTop.col < 0) return; @@ -535,8 +548,16 @@ function traverseGrids (leftDown: { col: number, row: number }, rightTop: { col: packRenderData(); } -function fillByTiledNode (tiledNode: Node, color: Float32Array, vbuf: Float32Array, - left: number, right: number, top: number, bottom: number, diamondTile: boolean): void { +function fillByTiledNode ( + tiledNode: Node, + color: Float32Array, + vbuf: Float32Array, + left: number, + right: number, + top: number, + bottom: number, + diamondTile: boolean, +): void { const vertStep = 9; const vertStep2 = vertStep * 2; const vertStep3 = vertStep * 3; From 632b7e988b6971c9af38f54c60791cd439bd3874 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 20 Oct 2024 12:50:03 +0800 Subject: [PATCH 2/7] Update --- .../graphics/webgl/graphics-assembler.ts | 23 +------------------ cocos/2d/assembler/label/bmfont.ts | 11 ++++----- cocos/2d/assembler/label/bmfontUtils.ts | 2 +- cocos/2d/assembler/label/index.ts | 2 +- cocos/2d/assembler/label/letter-font.ts | 2 +- cocos/2d/assembler/label/letter.ts | 7 +++--- cocos/2d/assembler/label/ttf.ts | 13 +++++------ cocos/2d/assembler/label/ttfUtils.ts | 10 ++++---- cocos/2d/assembler/sprite/bar-filled.ts | 8 +++---- cocos/2d/assembler/sprite/radial-filled.ts | 12 +++++----- cocos/2d/assembler/sprite/simple.ts | 10 ++++---- cocos/2d/assembler/sprite/sliced.ts | 10 ++++---- cocos/2d/assembler/sprite/tiled.ts | 14 +++++------ cocos/2d/components/graphics.ts | 5 ++-- cocos/2d/components/label.ts | 11 +++++---- cocos/2d/framework/ui-renderer.ts | 7 ++++-- cocos/2d/renderer/base.ts | 12 +++++----- cocos/dragon-bones/ArmatureDisplay.ts | 4 ++-- cocos/dragon-bones/assembler/simple.ts | 13 +++++------ .../particle-2d/motion-streak-2d-assembler.ts | 8 +++---- cocos/particle-2d/motion-streak-2d.ts | 4 ++-- cocos/particle-2d/particle-asset.ts | 2 +- cocos/particle-2d/particle-simulator-2d.ts | 4 ++-- .../particle-system-2d-assembler.ts | 4 ++-- cocos/particle-2d/particle-system-2d.ts | 2 +- cocos/spine/assembler/simple.ts | 9 ++++---- cocos/spine/skeleton.ts | 7 +++--- cocos/tiledmap/assembler/simple.ts | 9 ++++---- 28 files changed, 102 insertions(+), 123 deletions(-) diff --git a/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts b/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts index 384f2a0a40b..1c57e5a8ced 100644 --- a/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts +++ b/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts @@ -24,13 +24,11 @@ import { JSB } from 'internal:constants'; import { Color, Vec3 } from '../../../../core'; import { IAssembler } from '../../../renderer/base'; -import { BaseRenderData, MeshRenderData } from '../../../renderer/render-data'; -import { IBatcher } from '../../../renderer/i-batcher'; +import { MeshRenderData } from '../../../renderer/render-data'; import { Graphics } from '../../../components'; import { LineCap, LineJoin, PointFlags } from '../types'; import { earcut as Earcut } from './earcut'; import { Impl, Point } from './impl'; -import { UIRenderer } from '../../../framework'; const MAX_VERTEX = 65535; const MAX_INDICES = MAX_VERTEX * 2; @@ -74,18 +72,6 @@ function clamp (v: number, minNum: number, maxNum: number): number { * 可通过 `UI.graphicsAssembler` 获取该组装器。 */ export class GraphicsAssembler implements IAssembler { - createData (comp: UIRenderer): BaseRenderData { - return null as unknown as BaseRenderData; - } - - updateUVs (comp: UIRenderer, ...args: any[]): void { - - } - - updateColor (comp: UIRenderer): void { - - } - updateRenderData (graphics: Graphics): void { if (JSB) { if (graphics.renderData) { @@ -94,13 +80,6 @@ export class GraphicsAssembler implements IAssembler { } } - fillBuffers (graphics: Graphics, renderer: IBatcher): void { - // this.renderIA!(graphics, renderer); - } - - renderIA (graphics: Graphics, renderer: IBatcher): void { - } - private getRenderData (graphics: Graphics, vertexCount: number): MeshRenderData | null { if (!_impl) { return null; diff --git a/cocos/2d/assembler/label/bmfont.ts b/cocos/2d/assembler/label/bmfont.ts index 4ed11d78e2e..2d6eb769a72 100644 --- a/cocos/2d/assembler/label/bmfont.ts +++ b/cocos/2d/assembler/label/bmfont.ts @@ -22,14 +22,13 @@ THE SOFTWARE. */ -import { SpriteFrame } from '../../assets/sprite-frame'; -import { Color, Rect, js } from '../../../core'; -import { IBatcher } from '../../renderer/i-batcher'; -import { Label } from '../../components/label'; -import { IAssembler } from '../../renderer/base'; +import { Color } from '../../../core'; +import type { IBatcher } from '../../renderer/i-batcher'; +import type { Label } from '../../components/label'; +import type { IAssembler } from '../../renderer/base'; import { fillMeshVertices3D } from '../utils'; import { BmfontUtils } from './bmfontUtils'; -import { RenderData } from '../../renderer/render-data'; +import type { RenderData } from '../../renderer/render-data'; const tempColor = new Color(255, 255, 255, 255); diff --git a/cocos/2d/assembler/label/bmfontUtils.ts b/cocos/2d/assembler/label/bmfontUtils.ts index c30c82fa73d..26c503910e2 100644 --- a/cocos/2d/assembler/label/bmfontUtils.ts +++ b/cocos/2d/assembler/label/bmfontUtils.ts @@ -23,7 +23,7 @@ */ import { JSB } from 'internal:constants'; -import { IConfig, FontAtlas, BitmapFont } from '../../assets/bitmap-font'; +import { IConfig, FontAtlas, type BitmapFont } from '../../assets/bitmap-font'; import { SpriteFrame } from '../../assets/sprite-frame'; import { Rect, errorID } from '../../../core'; import { Label, Overflow, CacheMode } from '../../components/label'; diff --git a/cocos/2d/assembler/label/index.ts b/cocos/2d/assembler/label/index.ts index 6b806cfc45f..adbf007d533 100644 --- a/cocos/2d/assembler/label/index.ts +++ b/cocos/2d/assembler/label/index.ts @@ -24,7 +24,7 @@ import { BitmapFont } from '../../assets'; import { CacheMode, Label } from '../../components'; -import { IAssembler, IAssemblerManager } from '../../renderer/base'; +import type { IAssembler, IAssemblerManager } from '../../renderer/base'; import { bmfont } from './bmfont'; import { letter } from './letter'; import { ttf } from './ttf'; diff --git a/cocos/2d/assembler/label/letter-font.ts b/cocos/2d/assembler/label/letter-font.ts index e46ba5e6de0..e73df3c4ebc 100644 --- a/cocos/2d/assembler/label/letter-font.ts +++ b/cocos/2d/assembler/label/letter-font.ts @@ -23,7 +23,7 @@ */ import { Color } from '../../../core/math/color'; -import { Label } from '../../components'; +import type { Label } from '../../components'; import { BmfontUtils } from './bmfontUtils'; import { shareLabelInfo, LetterAtlas, computeHash, LetterRenderTexture } from './font-utils'; diff --git a/cocos/2d/assembler/label/letter.ts b/cocos/2d/assembler/label/letter.ts index 290436c7532..81619c21544 100644 --- a/cocos/2d/assembler/label/letter.ts +++ b/cocos/2d/assembler/label/letter.ts @@ -24,13 +24,12 @@ import { JSB } from 'internal:constants'; import { Color } from '../../../core'; -import { IBatcher } from '../../renderer/i-batcher'; -import { Label } from '../../components/label'; +import type { IBatcher } from '../../renderer/i-batcher'; +import type { Label } from '../../components/label'; import { fillMeshVertices3D } from '../utils'; import { LetterFont } from './letter-font'; import type { RenderData } from '../../renderer/render-data'; -import { IAssembler } from '../../renderer/base'; -import { UIRenderer } from '../../framework'; +import type { IAssembler } from '../../renderer/base'; const tempColor = new Color(255, 255, 255, 255); diff --git a/cocos/2d/assembler/label/ttf.ts b/cocos/2d/assembler/label/ttf.ts index a8653ad651d..1f1c5cf227d 100644 --- a/cocos/2d/assembler/label/ttf.ts +++ b/cocos/2d/assembler/label/ttf.ts @@ -27,13 +27,12 @@ * @module ui-assembler */ -import { Color, js } from '../../../core'; -import { IBatcher } from '../../renderer/i-batcher'; -import { Label } from '../../components/label'; -import { IAssembler } from '../../renderer/base'; +import { Color } from '../../../core'; +import type { IBatcher } from '../../renderer/i-batcher'; +import type { Label } from '../../components/label'; +import type { IAssembler } from '../../renderer/base'; import { TTFUtils } from './ttfUtils'; -import { IRenderData, RenderData } from '../../renderer/render-data'; -import { UIRenderer } from '../../framework'; +import type { IRenderData, RenderData } from '../../renderer/render-data'; const WHITE = Color.WHITE.clone(); const QUAD_INDICES = Uint16Array.from([0, 1, 2, 1, 3, 2]); @@ -42,7 +41,7 @@ const QUAD_INDICES = Uint16Array.from([0, 1, 2, 1, 3, 2]); * ttf 组装器 * 可通过 `UI.ttf` 获取该组装器。 */ -class TTF extends TTFUtils implements IAssembler { +export class TTF extends TTFUtils implements IAssembler { createData (comp: Label): RenderData { const renderData = comp.requestRenderData()!; diff --git a/cocos/2d/assembler/label/ttfUtils.ts b/cocos/2d/assembler/label/ttfUtils.ts index b4627001cca..4b148ee0596 100644 --- a/cocos/2d/assembler/label/ttfUtils.ts +++ b/cocos/2d/assembler/label/ttfUtils.ts @@ -22,13 +22,13 @@ THE SOFTWARE. */ import { CacheMode, Label } from '../../components'; -import { ISharedLabelData } from './font-utils'; -import { UITransform } from '../../framework/ui-transform'; +import type { ISharedLabelData } from './font-utils'; +import type { UITransform } from '../../framework/ui-transform'; import { dynamicAtlasManager } from '../../utils/dynamic-atlas/atlas-manager'; import { TextProcessing } from './text-processing'; -import { TextOutputLayoutData, TextOutputRenderData } from './text-output-data'; -import { TextStyle } from './text-style'; -import { TextLayout } from './text-layout'; +import type { TextOutputLayoutData, TextOutputRenderData } from './text-output-data'; +import type { TextStyle } from './text-style'; +import type { TextLayout } from './text-layout'; import { view } from '../../../ui/view'; import { approx } from '../../../core'; diff --git a/cocos/2d/assembler/sprite/bar-filled.ts b/cocos/2d/assembler/sprite/bar-filled.ts index 333e2235ef6..e0a54669e92 100644 --- a/cocos/2d/assembler/sprite/bar-filled.ts +++ b/cocos/2d/assembler/sprite/bar-filled.ts @@ -23,12 +23,12 @@ */ import { Mat4, errorID } from '../../../core'; -import { IRenderData, RenderData } from '../../renderer/render-data'; -import { IBatcher } from '../../renderer/i-batcher'; +import type { IRenderData, RenderData } from '../../renderer/render-data'; +import type { IBatcher } from '../../renderer/i-batcher'; import { Sprite } from '../../components'; -import { IAssembler } from '../../renderer/base'; +import type { IAssembler } from '../../renderer/base'; import { dynamicAtlasManager } from '../../utils/dynamic-atlas/atlas-manager'; -import { StaticVBChunk } from '../../renderer/static-vb-accessor'; +import type { StaticVBChunk } from '../../renderer/static-vb-accessor'; const FillType = Sprite.FillType; const m = new Mat4(); diff --git a/cocos/2d/assembler/sprite/radial-filled.ts b/cocos/2d/assembler/sprite/radial-filled.ts index 14a7b7fc3f9..123ba5a878e 100644 --- a/cocos/2d/assembler/sprite/radial-filled.ts +++ b/cocos/2d/assembler/sprite/radial-filled.ts @@ -23,14 +23,14 @@ */ import { JSB } from 'internal:constants'; -import { SpriteFrame } from '../../assets'; +import type { SpriteFrame } from '../../assets'; import { Mat4, Vec2 } from '../../../core'; -import { IRenderData, RenderData } from '../../renderer/render-data'; -import { IBatcher } from '../../renderer/i-batcher'; -import { Sprite } from '../../components'; -import { IAssembler } from '../../renderer/base'; +import type { IRenderData, RenderData } from '../../renderer/render-data'; +import type { IBatcher } from '../../renderer/i-batcher'; +import type { Sprite } from '../../components'; +import type { IAssembler } from '../../renderer/base'; import { dynamicAtlasManager } from '../../utils/dynamic-atlas/atlas-manager'; -import { StaticVBChunk } from '../../renderer/static-vb-accessor'; +import type { StaticVBChunk } from '../../renderer/static-vb-accessor'; const PI_2 = Math.PI * 2; const EPSILON = 1e-6; diff --git a/cocos/2d/assembler/sprite/simple.ts b/cocos/2d/assembler/sprite/simple.ts index 941e3676e42..3938c21245d 100644 --- a/cocos/2d/assembler/sprite/simple.ts +++ b/cocos/2d/assembler/sprite/simple.ts @@ -27,12 +27,12 @@ * @module ui-assembler */ -import { IAssembler } from '../../renderer/base'; -import { IRenderData, RenderData } from '../../renderer/render-data'; -import { IBatcher } from '../../renderer/i-batcher'; -import { Sprite } from '../../components'; +import type { IAssembler } from '../../renderer/base'; +import type { IRenderData, RenderData } from '../../renderer/render-data'; +import type { IBatcher } from '../../renderer/i-batcher'; +import type { Sprite } from '../../components'; import { dynamicAtlasManager } from '../../utils/dynamic-atlas/atlas-manager'; -import { StaticVBChunk } from '../../renderer/static-vb-accessor'; +import type { StaticVBChunk } from '../../renderer/static-vb-accessor'; const QUAD_INDICES = Uint16Array.from([0, 1, 2, 1, 3, 2]); diff --git a/cocos/2d/assembler/sprite/sliced.ts b/cocos/2d/assembler/sprite/sliced.ts index 09d13a25c72..8ecbd0ecfba 100644 --- a/cocos/2d/assembler/sprite/sliced.ts +++ b/cocos/2d/assembler/sprite/sliced.ts @@ -23,12 +23,12 @@ */ import { Color } from '../../../core'; -import { IRenderData, RenderData } from '../../renderer/render-data'; -import { IBatcher } from '../../renderer/i-batcher'; -import { Sprite } from '../../components'; -import { IAssembler } from '../../renderer/base'; +import type { IRenderData, RenderData } from '../../renderer/render-data'; +import type { IBatcher } from '../../renderer/i-batcher'; +import type { Sprite } from '../../components'; +import type { IAssembler } from '../../renderer/base'; import { dynamicAtlasManager } from '../../utils/dynamic-atlas/atlas-manager'; -import { StaticVBChunk } from '../../renderer/static-vb-accessor'; +import type { StaticVBChunk } from '../../renderer/static-vb-accessor'; const tempRenderData: IRenderData[] = []; for (let i = 0; i < 4; i++) { diff --git a/cocos/2d/assembler/sprite/tiled.ts b/cocos/2d/assembler/sprite/tiled.ts index ed0722310b3..5ed5d5520ed 100644 --- a/cocos/2d/assembler/sprite/tiled.ts +++ b/cocos/2d/assembler/sprite/tiled.ts @@ -23,14 +23,14 @@ */ import { JSB } from 'internal:constants'; -import { IUV, SpriteFrame } from '../../assets/sprite-frame'; +import type { IUV, SpriteFrame } from '../../assets/sprite-frame'; import { Mat4, Color, errorID } from '../../../core'; -import { IRenderData, RenderData } from '../../renderer/render-data'; -import { IBatcher } from '../../renderer/i-batcher'; -import { Sprite } from '../../components/sprite'; -import { UIRenderer } from '../../framework/ui-renderer'; -import { IAssembler } from '../../renderer/base'; -import { StaticVBChunk } from '../../renderer/static-vb-accessor'; +import type { IRenderData, RenderData } from '../../renderer/render-data'; +import type { IBatcher } from '../../renderer/i-batcher'; +import type { Sprite } from '../../components/sprite'; +import type { UIRenderer } from '../../framework/ui-renderer'; +import type { IAssembler } from '../../renderer/base'; +import type { StaticVBChunk } from '../../renderer/static-vb-accessor'; const m = new Mat4(); diff --git a/cocos/2d/components/graphics.ts b/cocos/2d/components/graphics.ts index 61732590707..ff96c514ea0 100644 --- a/cocos/2d/components/graphics.ts +++ b/cocos/2d/components/graphics.ts @@ -30,8 +30,7 @@ import { InstanceMaterialType, UIRenderer } from '../framework/ui-renderer'; import { director } from '../../game/director'; import { Color, warnID, cclegacy } from '../../core'; import { scene } from '../../render-scene'; -import { IAssembler } from '../renderer/base'; -import { IBatcher } from '../renderer/i-batcher'; +import type { IBatcher } from '../renderer/i-batcher'; import { LineCap, LineJoin } from '../assembler/graphics/types'; import { Impl } from '../assembler/graphics/webgl/impl'; import { Material, RenderingSubMesh } from '../../asset/assets'; @@ -39,7 +38,7 @@ import { Format, PrimitiveMode, Attribute, Device, BufferUsageBit, BufferInfo, M import { vfmtPosColor, getAttributeStride, getComponentPerVertex } from '../renderer/vertex-format'; import { NativeUIModelProxy } from '../renderer/native-2d'; import { RenderEntity, RenderEntityType } from '../renderer/render-entity'; -import { GraphicsAssembler } from '../assembler/graphics/webgl/graphics-assembler'; +import type { GraphicsAssembler } from '../assembler/graphics/webgl/graphics-assembler'; const attributes = vfmtPosColor.concat([ new Attribute('a_dist', Format.R32F), diff --git a/cocos/2d/components/label.ts b/cocos/2d/components/label.ts index fbee4f14d19..67e2b1ae6e6 100644 --- a/cocos/2d/components/label.ts +++ b/cocos/2d/components/label.ts @@ -39,6 +39,9 @@ import { BlendFactor } from '../../gfx'; import { TextStyle } from '../assembler/label/text-style'; import { TextLayout } from '../assembler/label/text-layout'; import { TextOutputLayoutData, TextOutputRenderData } from '../assembler/label/text-output-data'; +import type { RenderData } from '../renderer/render-data'; +import type { LetterFont } from '../assembler/label/letter-font'; +import type { TTF } from '../assembler/label/ttf'; const tempColor = Color.WHITE.clone(); /** @@ -1011,7 +1014,7 @@ export class Label extends UIRenderer { if (!this.renderData) { if (this._assembler && this._assembler.createData) { - this._renderData = this._assembler.createData(this); + this._renderData = this._assembler.createData(this) as RenderData; this.renderData!.material = this.material; this._updateColor(); } @@ -1035,12 +1038,12 @@ export class Label extends UIRenderer { } } else { if (this.cacheMode === CacheMode.CHAR) { - this._letterTexture = this._assembler!.getAssemblerData(); + this._letterTexture = (this._assembler as LetterFont).getAssemblerData(); this._texture = this._letterTexture; } else if (!this._ttfSpriteFrame) { this._ttfSpriteFrame = new SpriteFrame(); - this._assemblerData = this._assembler!.getAssemblerData(); - const image = new ImageAsset(this._assemblerData!.canvas); + this._assemblerData = (this._assembler as TTF).getAssemblerData(); + const image = new ImageAsset(this._assemblerData.canvas); const texture = new Texture2D(); texture.image = image; this._ttfSpriteFrame.texture = texture; diff --git a/cocos/2d/framework/ui-renderer.ts b/cocos/2d/framework/ui-renderer.ts index c4e1cd1d32f..ac77ca94025 100644 --- a/cocos/2d/framework/ui-renderer.ts +++ b/cocos/2d/framework/ui-renderer.ts @@ -476,8 +476,11 @@ export class UIRenderer extends Renderer { this.setEntityColor(this._color); this.setEntityOpacity(this.node._uiProps.localOpacity); - if (this._assembler) { - this._assembler.updateColor(this); + const assembler = this._assembler; + if (assembler) { + if (assembler.updateColor) { + assembler.updateColor(this); + } // Need update rendFlag when opacity changes from 0 to !0 or 0 to !0 const renderFlag = this._renderFlag; this._renderFlag = this._canRender(); diff --git a/cocos/2d/renderer/base.ts b/cocos/2d/renderer/base.ts index 2f0ab474080..7d3df91d73d 100644 --- a/cocos/2d/renderer/base.ts +++ b/cocos/2d/renderer/base.ts @@ -27,18 +27,18 @@ * @module ui */ -import { UIRenderer } from '../framework/ui-renderer'; +import type { UIRenderer } from '../framework/ui-renderer'; import type { IBatcher } from './i-batcher'; -import type { BaseRenderData, RenderData } from './render-data'; +import type { BaseRenderData } from './render-data'; /** * @internal */ export interface IAssembler { - createData(comp: UIRenderer): BaseRenderData; - fillBuffers(comp: UIRenderer, renderer: IBatcher): void; - updateUVs (comp: UIRenderer, ...args: any[]): void; - updateColor (comp: UIRenderer): void; + createData? (comp: UIRenderer): BaseRenderData; + fillBuffers? (comp: UIRenderer, renderer: IBatcher): void; + updateUVs? (comp: UIRenderer, ...args: any[]): void; + updateColor? (comp: UIRenderer): void; updateRenderData (comp: UIRenderer): void; update? (comp: UIRenderer, dt: number): void; resetAssemblerData? (data: any): void; diff --git a/cocos/dragon-bones/ArmatureDisplay.ts b/cocos/dragon-bones/ArmatureDisplay.ts index 77bfc708206..f101a768462 100644 --- a/cocos/dragon-bones/ArmatureDisplay.ts +++ b/cocos/dragon-bones/ArmatureDisplay.ts @@ -43,7 +43,7 @@ import { Material, Texture2D } from '../asset/assets'; import { Node } from '../scene-graph'; import { builtinResMgr } from '../asset/asset-manager'; import { setPropertyEnumType } from '../core/internal-index'; -import { RenderData } from '../2d/renderer/render-data'; +import type { RenderData } from '../2d/renderer/render-data'; enum DefaultArmaturesEnum { default = -1, @@ -1472,7 +1472,7 @@ export class ArmatureDisplay extends UIRenderer { this._assembler = assembler; } if (this._armature && this._assembler) { - this._renderData = this._assembler.createData(this) as RenderData; + this._renderData = this._assembler.createData!(this) as RenderData; if (this._renderData) { this.maxVertexCount = this._renderData.vertexCount; this.maxIndexCount = this._renderData.indexCount; diff --git a/cocos/dragon-bones/assembler/simple.ts b/cocos/dragon-bones/assembler/simple.ts index 621f7e6d75e..3486f2e31ab 100644 --- a/cocos/dragon-bones/assembler/simple.ts +++ b/cocos/dragon-bones/assembler/simple.ts @@ -27,18 +27,17 @@ import { Color, Mat4, Vec3, cclegacy } from '../../core'; import { BlendFactor } from '../../gfx'; import { vfmtPosUvColor } from '../../2d/renderer/vertex-format'; import { MaterialInstance } from '../../render-scene/core/material-instance'; -import { IAssembler } from '../../2d/renderer/base'; +import type { IAssembler } from '../../2d/renderer/base'; import { ArmatureFrame } from '../ArmatureCache'; import { ArmatureDisplay } from '../ArmatureDisplay'; import { CCSlot } from '../CCSlot'; import { StaticVBAccessor } from '../../2d/renderer/static-vb-accessor'; -import { BaseRenderData, RenderData } from '../../2d/renderer/render-data'; -import { Texture2D } from '../../asset/assets'; -import { TextureBase } from '../../asset/assets/texture-base'; -import { Node } from '../../scene-graph'; +import { RenderData } from '../../2d/renderer/render-data'; +import type { Texture2D } from '../../asset/assets'; +import type { TextureBase } from '../../asset/assets/texture-base'; +import type { Node } from '../../scene-graph'; import { director } from '../../game'; -import { IBatcher } from '../../2d/renderer/i-batcher'; -import { UIRenderer } from '../../2d'; +import type { IBatcher } from '../../2d/renderer/i-batcher'; const NEED_COLOR = 0x01; const NEED_BATCH = 0x10; diff --git a/cocos/particle-2d/motion-streak-2d-assembler.ts b/cocos/particle-2d/motion-streak-2d-assembler.ts index 7c23a0fc73b..b074fa73011 100644 --- a/cocos/particle-2d/motion-streak-2d-assembler.ts +++ b/cocos/particle-2d/motion-streak-2d-assembler.ts @@ -24,12 +24,12 @@ */ import { JSB } from 'internal:constants'; -import { IAssembler, IAssemblerManager } from '../2d/renderer/base'; +import type { IAssembler, IAssemblerManager } from '../2d/renderer/base'; import { MotionStreak, MotionStreakPoint } from './motion-streak-2d'; import { Vec2, Color } from '../core'; -import { IBatcher } from '../2d/renderer/i-batcher'; -import { RenderData } from '../2d/renderer/render-data'; -import { UIRenderer } from '../2d'; +import type { IBatcher } from '../2d/renderer/i-batcher'; +import type { RenderData } from '../2d/renderer/render-data'; +import type { UIRenderer } from '../2d'; const _normal = new Vec2(); const _vec2 = new Vec2(); diff --git a/cocos/particle-2d/motion-streak-2d.ts b/cocos/particle-2d/motion-streak-2d.ts index eed1a8a5516..cb11e5818b4 100644 --- a/cocos/particle-2d/motion-streak-2d.ts +++ b/cocos/particle-2d/motion-streak-2d.ts @@ -27,9 +27,9 @@ import { ccclass, executeInEditMode, serializable, playOnFocus, menu, help, edit import { EDITOR_NOT_IN_PREVIEW } from 'internal:constants'; import { UIRenderer } from '../2d/framework'; import { Texture2D } from '../asset/assets/texture-2d'; -import { IBatcher } from '../2d/renderer/i-batcher'; +import type { IBatcher } from '../2d/renderer/i-batcher'; import { Vec2 } from '../core'; -import { RenderData } from '../2d/renderer/render-data'; +import type { RenderData } from '../2d/renderer/render-data'; export class MotionStreakPoint { public point = new Vec2(); diff --git a/cocos/particle-2d/particle-asset.ts b/cocos/particle-2d/particle-asset.ts index ba345761451..b9c1b1be718 100644 --- a/cocos/particle-2d/particle-asset.ts +++ b/cocos/particle-2d/particle-asset.ts @@ -24,7 +24,7 @@ */ import { Asset } from '../asset/assets/asset'; -import { SpriteFrame } from '../2d/assets/sprite-frame'; +import type { SpriteFrame } from '../2d/assets/sprite-frame'; import { cclegacy, _decorator } from '../core'; const { ccclass, serializable, editable } = _decorator; diff --git a/cocos/particle-2d/particle-simulator-2d.ts b/cocos/particle-2d/particle-simulator-2d.ts index 3c304566a7e..8031085876c 100644 --- a/cocos/particle-2d/particle-simulator-2d.ts +++ b/cocos/particle-2d/particle-simulator-2d.ts @@ -25,8 +25,8 @@ import { Vec2, Color, js, random, IColorLike, Vec4, clamp, toRadian, toDegree } from '../core'; import { vfmtPosUvColor, getComponentPerVertex } from '../2d/renderer/vertex-format'; import { PositionType, EmitterMode, START_SIZE_EQUAL_TO_END_SIZE, START_RADIUS_EQUAL_TO_END_RADIUS } from './define'; -import { ParticleSystem2D } from './particle-system-2d'; -import { MeshRenderData } from '../2d/renderer/render-data'; +import type { ParticleSystem2D } from './particle-system-2d'; +import type { MeshRenderData } from '../2d/renderer/render-data'; import type { Particle2DAssembler } from './particle-system-2d-assembler'; const _pos = new Vec2(); diff --git a/cocos/particle-2d/particle-system-2d-assembler.ts b/cocos/particle-2d/particle-system-2d-assembler.ts index 440120f0924..69d5f999903 100644 --- a/cocos/particle-2d/particle-system-2d-assembler.ts +++ b/cocos/particle-2d/particle-system-2d-assembler.ts @@ -23,10 +23,10 @@ THE SOFTWARE. */ -import { IAssembler, IAssemblerManager } from '../2d/renderer/base'; +import type { IAssembler, IAssemblerManager } from '../2d/renderer/base'; import { ParticleSystem2D } from './particle-system-2d'; import { MeshRenderData } from '../2d/renderer/render-data'; -import { IBatcher } from '../2d/renderer/i-batcher'; +import type { IBatcher } from '../2d/renderer/i-batcher'; import { cclegacy } from '../core'; export class Particle2DAssembler implements IAssembler { diff --git a/cocos/particle-2d/particle-system-2d.ts b/cocos/particle-2d/particle-system-2d.ts index c70dfb2d2c7..584977b4679 100644 --- a/cocos/particle-2d/particle-system-2d.ts +++ b/cocos/particle-2d/particle-system-2d.ts @@ -38,7 +38,7 @@ import { BlendFactor } from '../gfx'; import { PNGReader } from './png-reader'; import { TiffReader } from './tiff-reader'; import codec from '../../external/compression/ZipUtils'; -import { IBatcher } from '../2d/renderer/i-batcher'; +import type { IBatcher } from '../2d/renderer/i-batcher'; import { assetManager, builtinResMgr } from '../asset/asset-manager'; import { PositionType, EmitterMode, DURATION_INFINITY, START_RADIUS_EQUAL_TO_END_RADIUS, START_SIZE_EQUAL_TO_END_SIZE } from './define'; import { ccwindow } from '../core/global-exports'; diff --git a/cocos/spine/assembler/simple.ts b/cocos/spine/assembler/simple.ts index 675901e69c6..32385543cf6 100644 --- a/cocos/spine/assembler/simple.ts +++ b/cocos/spine/assembler/simple.ts @@ -26,16 +26,15 @@ import { IAssembler } from '../../2d/renderer/base'; import { StaticVBAccessor } from '../../2d/renderer/static-vb-accessor'; import { vfmtPosUvColor4B, vfmtPosUvTwoColor4B, getAttributeStride } from '../../2d/renderer/vertex-format'; -import { Skeleton, SpineMaterialType } from '../skeleton'; +import { type Skeleton, SpineMaterialType } from '../skeleton'; import { BlendFactor } from '../../gfx'; import { legacyCC } from '../../core/global-exports'; -import { BaseRenderData, RenderData } from '../../2d/renderer/render-data'; +import { RenderData } from '../../2d/renderer/render-data'; import { director } from '../../game'; import spine from '../lib/spine-core'; import { Color, EPSILON, Vec3 } from '../../core'; -import { MaterialInstance } from '../../render-scene'; -import { IBatcher } from '../../2d/renderer/i-batcher'; -import { UIRenderer } from '../../2d'; +import type { MaterialInstance } from '../../render-scene'; +import type { IBatcher } from '../../2d/renderer/i-batcher'; const _slotColor = new Color(0, 0, 255, 255); const _boneColor = new Color(255, 0, 0, 255); diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index d58d4702323..b62f6d38bfc 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -1136,7 +1136,7 @@ export class Skeleton extends UIRenderer { if (this._assembler !== assembler) { this._assembler = assembler; } - if (this._skeleton && this._assembler) { + if (this._skeleton && this._assembler && this._assembler.createData) { this._renderData = this._assembler.createData(this) as RenderData; this.markForUpdateRenderData(); this._updateColor(); @@ -1594,8 +1594,9 @@ export class Skeleton extends UIRenderer { this._instance!.setUseTint(this._useTint); } } - if (this._assembler && this._skeleton) { - this._renderData = this._assembler.createData(this) as RenderData; + const assembler = this._assembler; + if (assembler && assembler.createData && this._skeleton) { + this._renderData = assembler.createData(this) as RenderData; this.markForUpdateRenderData(); } } diff --git a/cocos/tiledmap/assembler/simple.ts b/cocos/tiledmap/assembler/simple.ts index a4d34d17e2f..83ad6e5bbf3 100644 --- a/cocos/tiledmap/assembler/simple.ts +++ b/cocos/tiledmap/assembler/simple.ts @@ -24,8 +24,8 @@ import { JSB } from 'internal:constants'; import { Mat4, Size, Vec3 } from '../../core/math'; -import { IAssembler } from '../../2d/renderer/base'; -import { IBatcher } from '../../2d/renderer/i-batcher'; +import type { IAssembler } from '../../2d/renderer/base'; +import type { IBatcher } from '../../2d/renderer/i-batcher'; import { TiledLayer, TiledRenderData, TiledTile } from '..'; import { GID, MixedGID, RenderOrder, TiledGrid, TileFlag } from '../tiled-types'; import { director, DirectorEvent } from '../../game'; @@ -33,9 +33,8 @@ import { StaticVBAccessor } from '../../2d/renderer/static-vb-accessor'; import { vfmtPosUvColor } from '../../2d/renderer/vertex-format'; import { BaseRenderData, RenderData } from '../../2d/renderer/render-data'; import { RenderDrawInfoType } from '../../2d/renderer/render-draw-info'; -import { Texture2D } from '../../asset/assets'; -import { Node } from '../../scene-graph'; -import { UIRenderer } from '../../2d'; +import type { Texture2D } from '../../asset/assets'; +import type { Node } from '../../scene-graph'; const MaxGridsLimit = Math.ceil(65535 / 6); From 5eb3040436a831c7852349f9145d188ad7223bed Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 20 Oct 2024 13:21:42 +0800 Subject: [PATCH 3/7] Update --- cocos/2d/components/label.ts | 4 ++-- cocos/2d/components/sprite.ts | 9 +++++---- cocos/2d/framework/ui-renderer.ts | 5 +++-- cocos/2d/renderer/base.ts | 2 +- cocos/2d/renderer/batcher-2d.ts | 2 +- cocos/dragon-bones/assembler/simple.ts | 7 ------- cocos/particle-2d/motion-streak-2d-assembler.ts | 4 ---- cocos/particle-2d/particle-system-2d-assembler.ts | 15 --------------- 8 files changed, 12 insertions(+), 36 deletions(-) diff --git a/cocos/2d/components/label.ts b/cocos/2d/components/label.ts index 67e2b1ae6e6..c32f2c5158c 100644 --- a/cocos/2d/components/label.ts +++ b/cocos/2d/components/label.ts @@ -955,7 +955,7 @@ export class Label extends UIRenderer { this._applyFontTexture(); } if (this._assembler) { - this._assembler.updateRenderData(this); + this._assembler.updateRenderData!(this); } } @@ -1033,7 +1033,7 @@ export class Label extends UIRenderer { } this.changeMaterialForDefine(); if (this._assembler) { - this._assembler.updateRenderData(this); + this._assembler.updateRenderData!(this); } } } else { diff --git a/cocos/2d/components/sprite.ts b/cocos/2d/components/sprite.ts index d1c4155cbf6..6c0d20108f5 100644 --- a/cocos/2d/components/sprite.ts +++ b/cocos/2d/components/sprite.ts @@ -34,6 +34,7 @@ import { PixelFormat } from '../../asset/assets/asset-enum'; import { TextureBase } from '../../asset/assets/texture-base'; import { Material, RenderTexture } from '../../asset/assets'; import { NodeEventType } from '../../scene-graph/node-event'; +import { RenderData } from '../renderer/render-data'; /** * @en @@ -604,11 +605,11 @@ export class Sprite extends UIRenderer { if (!this._renderData) { if (this._assembler && this._assembler.createData) { - this._renderData = this._assembler.createData(this); - this._renderData!.material = this.getRenderMaterial(0); + this._renderData = this._assembler.createData(this) as RenderData; + this._renderData.material = this.getRenderMaterial(0); this.markForUpdateRenderData(); if (this.spriteFrame) { - this._assembler.updateUVs(this); + this._assembler.updateUVs!(this); } this._updateColor(); } @@ -679,7 +680,7 @@ export class Sprite extends UIRenderer { private _updateUVs (): void { if (this._assembler) { - this._assembler.updateUVs(this); + this._assembler.updateUVs!(this); } } diff --git a/cocos/2d/framework/ui-renderer.ts b/cocos/2d/framework/ui-renderer.ts index ac77ca94025..16ffe16ae2f 100644 --- a/cocos/2d/framework/ui-renderer.ts +++ b/cocos/2d/framework/ui-renderer.ts @@ -401,8 +401,9 @@ export class UIRenderer extends Renderer { * @deprecated Since v3.7.0, this is an engine private interface that will be removed in the future. */ public updateRenderer (): void { - if (this._assembler) { - this._assembler.updateRenderData(this); + const assembler = this._assembler; + if (assembler && assembler.updateRenderData) { + assembler.updateRenderData(this); } this._renderFlag = this._canRender(); this._renderEntity.enabled = this._renderFlag; diff --git a/cocos/2d/renderer/base.ts b/cocos/2d/renderer/base.ts index 7d3df91d73d..5880d2587c9 100644 --- a/cocos/2d/renderer/base.ts +++ b/cocos/2d/renderer/base.ts @@ -39,7 +39,7 @@ export interface IAssembler { fillBuffers? (comp: UIRenderer, renderer: IBatcher): void; updateUVs? (comp: UIRenderer, ...args: any[]): void; updateColor? (comp: UIRenderer): void; - updateRenderData (comp: UIRenderer): void; + updateRenderData? (comp: UIRenderer): void; update? (comp: UIRenderer, dt: number): void; resetAssemblerData? (data: any): void; removeData? (data: BaseRenderData): void; diff --git a/cocos/2d/renderer/batcher-2d.ts b/cocos/2d/renderer/batcher-2d.ts index 3a272c470ce..8ce50f3b2f7 100644 --- a/cocos/2d/renderer/batcher-2d.ts +++ b/cocos/2d/renderer/batcher-2d.ts @@ -436,7 +436,7 @@ export class Batcher2D implements IBatcher { } } - assembler.fillBuffers(comp, this); + if (assembler.fillBuffers) assembler.fillBuffers(comp, this); } /** diff --git a/cocos/dragon-bones/assembler/simple.ts b/cocos/dragon-bones/assembler/simple.ts index 3486f2e31ab..8417ad11d0f 100644 --- a/cocos/dragon-bones/assembler/simple.ts +++ b/cocos/dragon-bones/assembler/simple.ts @@ -129,13 +129,6 @@ let _accessor: StaticVBAccessor = null!; * 可通过 `UI.simple` 获取该组装器。 */ class Simple implements IAssembler { - fillBuffers (comp: ArmatureDisplay, renderer: IBatcher): void { - - } - updateUVs (comp: ArmatureDisplay): void { - - } - private accessor = _accessor; private vCount = 32767; ensureAccessor (): StaticVBAccessor { diff --git a/cocos/particle-2d/motion-streak-2d-assembler.ts b/cocos/particle-2d/motion-streak-2d-assembler.ts index b074fa73011..2aa48e9a6b6 100644 --- a/cocos/particle-2d/motion-streak-2d-assembler.ts +++ b/cocos/particle-2d/motion-streak-2d-assembler.ts @@ -233,10 +233,6 @@ class MotionStreakAssembler implements IAssembler { } } - updateColor (comp: MotionStreak): void { - // do nothing - } - fillBuffers (comp: MotionStreak, renderer: IBatcher): void { const renderData = comp.renderData!; const chunk = renderData.chunk; diff --git a/cocos/particle-2d/particle-system-2d-assembler.ts b/cocos/particle-2d/particle-system-2d-assembler.ts index 69d5f999903..898deb4b921 100644 --- a/cocos/particle-2d/particle-system-2d-assembler.ts +++ b/cocos/particle-2d/particle-system-2d-assembler.ts @@ -26,20 +26,11 @@ import type { IAssembler, IAssemblerManager } from '../2d/renderer/base'; import { ParticleSystem2D } from './particle-system-2d'; import { MeshRenderData } from '../2d/renderer/render-data'; -import type { IBatcher } from '../2d/renderer/i-batcher'; import { cclegacy } from '../core'; export class Particle2DAssembler implements IAssembler { maxParticleDeltaTime = 0; - updateUVs (comp: ParticleSystem2D): void { - - } - - updateColor (comp: ParticleSystem2D): void { - - } - createData (comp: ParticleSystem2D): MeshRenderData { return MeshRenderData.add(); } @@ -47,12 +38,6 @@ export class Particle2DAssembler implements IAssembler { removeData (data: MeshRenderData): void { MeshRenderData.remove(data); } - - updateRenderData (): void { - } - - fillBuffers (comp: ParticleSystem2D, renderer: IBatcher): void { - } } export const particle2DAssembler = new Particle2DAssembler(); From 422aec11d219d02195269fad9fc7043788e2a952 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 20 Oct 2024 13:33:39 +0800 Subject: [PATCH 4/7] Update tilemap. --- cocos/tiledmap/assembler/simple.ts | 3 --- cocos/tiledmap/tiled-layer.ts | 7 ++++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cocos/tiledmap/assembler/simple.ts b/cocos/tiledmap/assembler/simple.ts index 83ad6e5bbf3..f80bbb31423 100644 --- a/cocos/tiledmap/assembler/simple.ts +++ b/cocos/tiledmap/assembler/simple.ts @@ -68,9 +68,6 @@ let _accessor: StaticVBAccessor = null!; * 可通过 `UI.simple` 获取该组装器。 */ class Simple implements IAssembler { - updateUVs (comp: TiledLayer): void { - } - private ensureAccessor (): void { if (!_accessor) { const device = director.root!.device; diff --git a/cocos/tiledmap/tiled-layer.ts b/cocos/tiledmap/tiled-layer.ts index a7266900982..e4133b720e6 100644 --- a/cocos/tiledmap/tiled-layer.ts +++ b/cocos/tiledmap/tiled-layer.ts @@ -1463,9 +1463,10 @@ export class TiledLayer extends UIRenderer { protected _flushAssembler (): void { const assembler = TiledLayer.Assembler.getAssembler(this); - if (this._assembler !== assembler) { - this._assembler = assembler; - this._assembler.createData(this); + let curAssembler = this._assembler; + if (curAssembler !== assembler) { + curAssembler = assembler; + curAssembler.createData!(this); } if (this._tiledDataArray.length === 0) { this.markForUpdateRenderData(); From e5d8769fbba338a267e65cafe7c5f110acf8a16f Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 20 Oct 2024 13:37:18 +0800 Subject: [PATCH 5/7] Update spine assembler. --- cocos/spine/assembler/simple.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/cocos/spine/assembler/simple.ts b/cocos/spine/assembler/simple.ts index 32385543cf6..8f0611f324a 100644 --- a/cocos/spine/assembler/simple.ts +++ b/cocos/spine/assembler/simple.ts @@ -85,17 +85,6 @@ function _getSlotMaterial (blendMode: number, comp: Skeleton): MaterialInstance } class Simple implements IAssembler { - fillBuffers (comp: Skeleton, renderer: IBatcher): void { - - } - updateUVs (comp: Skeleton): void { - - } - - updateColor (comp: Skeleton): void { - - } - vCount = 32767; private ensureAccessor (useTint: boolean): StaticVBAccessor { let accessor = useTint ? _tintAccessor : _accessor; From ee77f2371cdf940d87a2cb48d5845a1ec16551e2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 20 Oct 2024 13:46:19 +0800 Subject: [PATCH 6/7] Use import type --- cocos/2d/assembler/label/bmfontUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/assembler/label/bmfontUtils.ts b/cocos/2d/assembler/label/bmfontUtils.ts index 26c503910e2..34f42a24a9a 100644 --- a/cocos/2d/assembler/label/bmfontUtils.ts +++ b/cocos/2d/assembler/label/bmfontUtils.ts @@ -24,7 +24,7 @@ import { JSB } from 'internal:constants'; import { IConfig, FontAtlas, type BitmapFont } from '../../assets/bitmap-font'; -import { SpriteFrame } from '../../assets/sprite-frame'; +import type { SpriteFrame } from '../../assets/sprite-frame'; import { Rect, errorID } from '../../../core'; import { Label, Overflow, CacheMode } from '../../components/label'; import { UITransform } from '../../framework/ui-transform'; From 5c4920c3bf9e6ef9b4da4077a437540b3b45cf3a Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 20 Oct 2024 15:24:29 +0800 Subject: [PATCH 7/7] Revert "Use import type" This reverts commit ee77f2371cdf940d87a2cb48d5845a1ec16551e2. --- cocos/2d/assembler/label/bmfontUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/assembler/label/bmfontUtils.ts b/cocos/2d/assembler/label/bmfontUtils.ts index 34f42a24a9a..26c503910e2 100644 --- a/cocos/2d/assembler/label/bmfontUtils.ts +++ b/cocos/2d/assembler/label/bmfontUtils.ts @@ -24,7 +24,7 @@ import { JSB } from 'internal:constants'; import { IConfig, FontAtlas, type BitmapFont } from '../../assets/bitmap-font'; -import type { SpriteFrame } from '../../assets/sprite-frame'; +import { SpriteFrame } from '../../assets/sprite-frame'; import { Rect, errorID } from '../../../core'; import { Label, Overflow, CacheMode } from '../../components/label'; import { UITransform } from '../../framework/ui-transform';