mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
Reduce the generated javascript code size (#17491)
This commit is contained in:
@@ -126,6 +126,8 @@ rules:
|
||||
'@typescript-eslint/no-unsafe-call': off
|
||||
'@typescript-eslint/no-unsafe-member-access': off
|
||||
|
||||
'@typescript-eslint/no-unsafe-enum-comparison': off
|
||||
|
||||
'@typescript-eslint/unbound-method': off # we exploit prototype methods sometimes to acheive better performace
|
||||
'@typescript-eslint/no-explicit-any': off # still relevant for some heavily templated usages
|
||||
|
||||
|
||||
Vendored
+6
-6
@@ -56,11 +56,11 @@ declare module 'pal/input' {
|
||||
/**
|
||||
* @engineInternal
|
||||
*/
|
||||
public static _init ();
|
||||
public static _init (): void;
|
||||
/**
|
||||
* @engineInternal
|
||||
*/
|
||||
public static _on (eventType: import('cocos/input/types/event-enum').InputEventType, cb: GamepadCallback, target?: any);
|
||||
public static _on (eventType: import('cocos/input/types/event-enum').InputEventType, cb: GamepadCallback, target?: any): void;
|
||||
|
||||
public static all: GamepadInputDevice[];
|
||||
public static xr: (GamepadInputDevice | null);
|
||||
@@ -225,22 +225,22 @@ declare module 'pal/input' {
|
||||
* Asynchronously start the accelerometer.
|
||||
* TODO: return a promise.
|
||||
*/
|
||||
public start ();
|
||||
public start (): void;
|
||||
/**
|
||||
* Stop the accelerometer.
|
||||
* TODO: return a promise.
|
||||
*/
|
||||
public stop ();
|
||||
public stop (): void;
|
||||
/**
|
||||
* Set interval of the accelerometer callback.
|
||||
* The interval is in mile seconds.
|
||||
* @param intervalInMileSeconds interval in mile seconds.
|
||||
*/
|
||||
public setInterval (intervalInMileSeconds: number);
|
||||
public setInterval (intervalInMileSeconds: number): void;
|
||||
/**
|
||||
* Register the acceleration event callback.
|
||||
*/
|
||||
public on (eventType: import('cocos/input/types/event-enum').InputEventType, callback: AccelerometerCallback, target?: any);
|
||||
public on (eventType: import('cocos/input/types/event-enum').InputEventType, callback: AccelerometerCallback, target?: any): void;
|
||||
}
|
||||
|
||||
type HandleCallback = (res: import('cocos/input/types').EventHandle) => void;
|
||||
|
||||
+381
-1
@@ -573,6 +573,10 @@ Private node's zIndex can't be set, it will keep cc.macro.MIN_ZINDEX as its valu
|
||||
<!-- DEPRECATED -->
|
||||
cc.Action is deprecated, please use cc.Tween instead
|
||||
|
||||
### 1640
|
||||
|
||||
Node %s(%s) has not attached to a scene.
|
||||
|
||||
### 1700
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
@@ -3451,4 +3455,380 @@ Skin material needs floating-point render target, please check ENABLE_FLOAT_OUTP
|
||||
|
||||
### 16304
|
||||
|
||||
Skin material may need more accurate calculations, please select a head model of standard size, check the isGlobalStandardSkinObject option in the MeshRender component.
|
||||
Skin material may need more accurate calculations, please select a head model of standard size, check the isGlobalStandardSkinObject option in the MeshRender component.
|
||||
|
||||
### 16305
|
||||
|
||||
failed to stop accelerometer
|
||||
|
||||
### 16306
|
||||
|
||||
The data must have positions field
|
||||
|
||||
### 16307
|
||||
|
||||
please change type to sprite_stencil first
|
||||
|
||||
### 16308
|
||||
|
||||
illegal index count!
|
||||
|
||||
### 16309
|
||||
|
||||
Unsupported Format, convert to WebGL internal format failed.
|
||||
|
||||
### 16310
|
||||
|
||||
Unsupported Format, convert to WebGL format failed.
|
||||
|
||||
### 16311
|
||||
|
||||
Unsupported GLType, convert to GL type failed.
|
||||
|
||||
### 16312
|
||||
|
||||
Unsupported GLType, convert to TypedArrayConstructor failed.
|
||||
|
||||
### 16313
|
||||
|
||||
Unsupported GLType, convert to Type failed.
|
||||
|
||||
### 16314
|
||||
|
||||
Unsupported GLType, get type failed.
|
||||
|
||||
### 16315
|
||||
|
||||
Unsupported BufferType, create buffer failed.
|
||||
|
||||
### 16316
|
||||
|
||||
Unsupported BufferType, update buffer failed.
|
||||
|
||||
### 16317
|
||||
|
||||
Unsupported TextureType, create texture failed.
|
||||
|
||||
### 16318
|
||||
|
||||
glCheckFramebufferStatus() - FRAMEBUFFER_INCOMPLETE_ATTACHMENT
|
||||
|
||||
### 16319
|
||||
|
||||
glCheckFramebufferStatus() - FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
|
||||
|
||||
### 16320
|
||||
|
||||
glCheckFramebufferStatus() - FRAMEBUFFER_INCOMPLETE_DIMENSIONS
|
||||
|
||||
### 16321
|
||||
|
||||
glCheckFramebufferStatus() - FRAMEBUFFER_UNSUPPORTED
|
||||
|
||||
### 16322
|
||||
|
||||
Unsupported ShaderType.
|
||||
|
||||
### 16323
|
||||
|
||||
%s in '%s' compilation failed.
|
||||
|
||||
### 16324
|
||||
|
||||
Shader source dump: %s
|
||||
|
||||
### 16325
|
||||
|
||||
Shader '%s' compilation succeeded.
|
||||
|
||||
### 16326
|
||||
|
||||
Failed to link shader: %s
|
||||
|
||||
### 16327
|
||||
|
||||
Unsupported GL texture type, copy buffer to texture failed.
|
||||
|
||||
### 16328
|
||||
|
||||
Command 'draw' must be recorded inside a render pass.
|
||||
|
||||
### 16329
|
||||
|
||||
Command 'updateBuffer' must be recorded outside a render pass.
|
||||
|
||||
### 16330
|
||||
|
||||
Command 'copyBufferToTexture' must be recorded outside a render pass.
|
||||
|
||||
### 16331
|
||||
|
||||
InputAssemblerInfo.vertexBuffers is null.
|
||||
|
||||
### 16332
|
||||
|
||||
Illegal index buffer stride.
|
||||
|
||||
### 16333
|
||||
|
||||
This device does not support WebGL.
|
||||
|
||||
### 16334
|
||||
|
||||
A Class already exists with the same %s : %s. %s
|
||||
|
||||
### 16335
|
||||
|
||||
"%s" has already been set as name or alias of another class.
|
||||
|
||||
### 16336
|
||||
|
||||
"%s" has already been set as id or alias of another class.
|
||||
|
||||
### 16337
|
||||
|
||||
can not support canvas rendering in 3D
|
||||
|
||||
### 16338
|
||||
|
||||
The '_$erialized' prop in MissingScript is missing. Please contact jare.
|
||||
|
||||
### 16339
|
||||
|
||||
Error props: ['%s']
|
||||
|
||||
### 16340
|
||||
|
||||
Error when checking MissingScript 5, %s
|
||||
|
||||
### 16341
|
||||
|
||||
The '_$erialized' prop of MissingScript is missing. Will force the raw data to be save.
|
||||
|
||||
### 16342
|
||||
|
||||
Error props: ['%s']. Please contact jare.
|
||||
|
||||
### 16343
|
||||
|
||||
Unable to stash previously serialized data. %s
|
||||
|
||||
### 16344
|
||||
|
||||
Error when checking MissingScript 6, %s
|
||||
|
||||
### 16345
|
||||
|
||||
uniform '%s' must have a count
|
||||
|
||||
### 16346
|
||||
|
||||
Invalid GFX API!
|
||||
|
||||
### 16347
|
||||
|
||||
The number of mipmaps of each face is different.
|
||||
|
||||
### 16348
|
||||
|
||||
builtin UBO '%s' not available!
|
||||
|
||||
### 16349
|
||||
|
||||
builtin samplerTexture '%s' not available!
|
||||
|
||||
### 16350
|
||||
|
||||
The asset %s is missing!
|
||||
|
||||
### 16351
|
||||
|
||||
the native asset of %s is missing!
|
||||
|
||||
### 16352
|
||||
|
||||
The asset %s is invalid for some reason, detail message: %s, stack: %s
|
||||
|
||||
### 16353
|
||||
|
||||
Can't find letter in this bitmap-font
|
||||
|
||||
### 16354
|
||||
|
||||
Can't find letter definition in texture atlas %s for letter:%s
|
||||
|
||||
### 16355
|
||||
|
||||
Can't find letter definition in font family %s for letter: %s
|
||||
|
||||
### 16356
|
||||
|
||||
wrong format of version when compare version
|
||||
|
||||
### 16357
|
||||
|
||||
should use Vec3.multiply for vector * vector operation
|
||||
|
||||
### 16358
|
||||
|
||||
should use Vec3.scale for vector * scalar operation
|
||||
|
||||
### 16359
|
||||
|
||||
should use Vec2.multiply for vector * vector operation
|
||||
|
||||
### 16360
|
||||
|
||||
should use Vec2.scale for vector * scalar operation
|
||||
|
||||
### 16361
|
||||
|
||||
should use Vec4.multiply for vector * vector operation
|
||||
|
||||
### 16362
|
||||
|
||||
should use Vec4.scale for vector * scalar operation
|
||||
|
||||
### 16363
|
||||
|
||||
Unable to get device
|
||||
|
||||
### 16364
|
||||
|
||||
bitNum can't be undefined
|
||||
|
||||
### 16365
|
||||
|
||||
maximum layers reached.
|
||||
|
||||
### 16366
|
||||
|
||||
do not change buildin layers.
|
||||
|
||||
### 16367
|
||||
|
||||
name can't be undefined
|
||||
|
||||
### 16368
|
||||
|
||||
Unable to access unknown layer.
|
||||
|
||||
### 16369
|
||||
|
||||
unknown define type '%s'
|
||||
|
||||
### 16370
|
||||
|
||||
Shaders in material asset '%s' cannot be modified at runtime, please instantiate the material first.
|
||||
|
||||
### 16371
|
||||
|
||||
Pipeline states in material asset '%s' cannot be modified at runtime, please instantiate the material first.
|
||||
|
||||
### 16372
|
||||
|
||||
illegal pass index: %s.
|
||||
|
||||
### 16373
|
||||
|
||||
illegal property name: %s.
|
||||
|
||||
### 16374
|
||||
|
||||
Unexpected attribute!
|
||||
|
||||
### 16375
|
||||
|
||||
Unexpected: failed to create morph texture?
|
||||
|
||||
### 16376
|
||||
|
||||
The fnt config is not exists!
|
||||
|
||||
### 16377
|
||||
|
||||
SpriteAtlas is null.
|
||||
|
||||
### 16378
|
||||
|
||||
node '%s' doesn't have any renderable component
|
||||
|
||||
### 16379
|
||||
|
||||
cannot resize buffer views!
|
||||
|
||||
### 16380
|
||||
|
||||
cannot update through buffer views!
|
||||
|
||||
### 16381
|
||||
|
||||
Profiler._stats is deprecated, please use Profiler.stats instead.
|
||||
|
||||
### 16382
|
||||
|
||||
reverse: could not reverse a non-relative action
|
||||
|
||||
### 16383
|
||||
|
||||
Need 'clone' for custom prop '%s'
|
||||
|
||||
### 16384
|
||||
|
||||
Need 'add' for custom prop '%s'
|
||||
|
||||
### 16385
|
||||
|
||||
Need 'sub' for custom prop '%s' in reverse mode
|
||||
|
||||
### 16386
|
||||
|
||||
TweenAction: '%s' can't be converted to number
|
||||
|
||||
### 16387
|
||||
|
||||
Wrong return type for 'progress', number or string needed
|
||||
|
||||
### 16388
|
||||
|
||||
reverse: current tween could not be reversed, empty actions
|
||||
|
||||
### 16389
|
||||
|
||||
pause: tween wasn't started, can't pause
|
||||
|
||||
### 16390
|
||||
|
||||
resume: tween wasn't started, can't resume
|
||||
|
||||
### 16391
|
||||
|
||||
reverse: could not find action id %s
|
||||
|
||||
### 16392
|
||||
|
||||
Please set target to tween first
|
||||
|
||||
### 16393
|
||||
|
||||
start: no actions in Tween
|
||||
|
||||
### 16394
|
||||
|
||||
repeatForever: the last action is not ActionInterval
|
||||
|
||||
### 16395
|
||||
|
||||
reverseTime: the last action is not ActionInterval
|
||||
|
||||
### 16396
|
||||
|
||||
tweenUtil' is deprecated, please use 'tween' instead
|
||||
|
||||
### 16397
|
||||
|
||||
ProgressBar FILLED mode only works when barSprite's Type is FILLED!
|
||||
|
||||
### 16398
|
||||
|
||||
ProgressBar non-FILLED mode only works when barSprite's Type is non-FILLED!
|
||||
|
||||
@@ -127,11 +127,17 @@ export function roundRect (ctx: Impl, x: number, y: number, w: number, h: number
|
||||
}
|
||||
|
||||
export function tesselateBezier (
|
||||
ctx: Impl, x1: number, y1: number,
|
||||
x2: number, y2: number,
|
||||
x3: number, y3: number,
|
||||
x4: number, y4: number,
|
||||
level: number, type: number,
|
||||
ctx: Impl,
|
||||
x1: number,
|
||||
y1: number,
|
||||
x2: number,
|
||||
y2: number,
|
||||
x3: number,
|
||||
y3: number,
|
||||
x4: number,
|
||||
y4: number,
|
||||
level: number,
|
||||
type: number,
|
||||
): void {
|
||||
let x12 = 0;
|
||||
let y12 = 0;
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
|
||||
class Aim {
|
||||
// vertex index in coordinates array
|
||||
public i: number;
|
||||
public declare i: number;
|
||||
|
||||
// vertex coordinates
|
||||
public x: number;
|
||||
public y: number;
|
||||
public declare x: number;
|
||||
public declare y: number;
|
||||
|
||||
// previous and next vertex nodes in a polygon ring
|
||||
public prev: Aim | null = null;
|
||||
@@ -182,7 +182,7 @@ function isEar (ear: Aim): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
function isEarHashed (ear: Aim, minX: number, minY: number, size): boolean {
|
||||
function isEarHashed (ear: Aim, minX: number, minY: number, size: number): boolean {
|
||||
const a = ear.prev!;
|
||||
const b = ear;
|
||||
const c = ear.next!;
|
||||
|
||||
@@ -75,7 +75,7 @@ function clamp (v: number, minNum: number, maxNum: number): number {
|
||||
export const graphicsAssembler: IAssembler = {
|
||||
useModel: true,
|
||||
|
||||
updateRenderData (graphics: Graphics) {
|
||||
updateRenderData (graphics: Graphics): void {
|
||||
if (JSB) {
|
||||
if (graphics.renderData) {
|
||||
graphics.renderData.material = graphics.getMaterialInstance(0);
|
||||
@@ -83,14 +83,14 @@ export const graphicsAssembler: IAssembler = {
|
||||
}
|
||||
},
|
||||
|
||||
fillBuffers (graphics: Graphics, renderer: IBatcher) {
|
||||
fillBuffers (graphics: Graphics, renderer: IBatcher): void {
|
||||
// this.renderIA!(graphics, renderer);
|
||||
},
|
||||
|
||||
renderIA (graphics: Graphics, renderer: IBatcher) {
|
||||
renderIA (graphics: Graphics, renderer: IBatcher): void {
|
||||
},
|
||||
|
||||
getRenderData (graphics: Graphics, vertexCount: number) {
|
||||
getRenderData (graphics: Graphics, vertexCount: number): MeshRenderData | null {
|
||||
if (!_impl) {
|
||||
return null;
|
||||
}
|
||||
@@ -124,26 +124,26 @@ export const graphicsAssembler: IAssembler = {
|
||||
return renderData;
|
||||
},
|
||||
|
||||
stroke (graphics: Graphics) {
|
||||
stroke (graphics: Graphics): void {
|
||||
Color.copy(_curColor, graphics.strokeColor);
|
||||
// graphics.node.getWorldMatrix(_currMatrix);
|
||||
if (!graphics.impl) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._flattenPaths!(graphics.impl);
|
||||
this._expandStroke!(graphics);
|
||||
this._flattenPaths(graphics.impl);
|
||||
this._expandStroke(graphics);
|
||||
|
||||
graphics.impl.updatePathOffset = true;
|
||||
|
||||
this.end(graphics);
|
||||
},
|
||||
|
||||
fill (graphics: Graphics) {
|
||||
fill (graphics: Graphics): void {
|
||||
Color.copy(_curColor, graphics.fillColor);
|
||||
// graphics.node.getWorldMatrix(_currMatrix);
|
||||
|
||||
this._expandFill!(graphics);
|
||||
this._expandFill(graphics);
|
||||
if (graphics.impl) {
|
||||
graphics.impl.updatePathOffset = true;
|
||||
}
|
||||
@@ -151,11 +151,11 @@ export const graphicsAssembler: IAssembler = {
|
||||
this.end(graphics);
|
||||
},
|
||||
|
||||
end (graphics: Graphics) {
|
||||
end (graphics: Graphics): void {
|
||||
graphics.markForUpdateRenderData();
|
||||
},
|
||||
|
||||
_expandStroke (graphics: Graphics) {
|
||||
_expandStroke (graphics: Graphics): void {
|
||||
const w = graphics.lineWidth * 0.5;
|
||||
const lineCap = graphics.lineCap;
|
||||
const lineJoin = graphics.lineJoin;
|
||||
@@ -195,7 +195,7 @@ export const graphicsAssembler: IAssembler = {
|
||||
}
|
||||
}
|
||||
|
||||
const meshBuffer: MeshRenderData | null = _renderData = this.getRenderData!(graphics, vertexCount);
|
||||
const meshBuffer: MeshRenderData | null = _renderData = this.getRenderData(graphics, vertexCount);
|
||||
if (!meshBuffer) {
|
||||
return;
|
||||
}
|
||||
@@ -239,11 +239,11 @@ export const graphicsAssembler: IAssembler = {
|
||||
const dy = dPos.y;
|
||||
|
||||
if (lineCap === LineCap.BUTT) {
|
||||
this._buttCapStart!(p0, dx, dy, w, 0);
|
||||
this._buttCapStart(p0, dx, dy, w, 0);
|
||||
} else if (lineCap === LineCap.SQUARE) {
|
||||
this._buttCapStart!(p0, dx, dy, w, w);
|
||||
this._buttCapStart(p0, dx, dy, w, w);
|
||||
} else if (lineCap === LineCap.ROUND) {
|
||||
this._roundCapStart!(p0, dx, dy, w, nCap);
|
||||
this._roundCapStart(p0, dx, dy, w, nCap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,8 +253,8 @@ export const graphicsAssembler: IAssembler = {
|
||||
} else if ((p1.flags & (PointFlags.PT_BEVEL | PointFlags.PT_INNERBEVEL)) !== 0) {
|
||||
this._bevelJoin(p0, p1, w, w);
|
||||
} else {
|
||||
this._vSet!(p1.x + p1.dmx * w, p1.y + p1.dmy * w, 1);
|
||||
this._vSet!(p1.x - p1.dmx * w, p1.y - p1.dmy * w, -1);
|
||||
this._vSet(p1.x + p1.dmx * w, p1.y + p1.dmy * w, 1);
|
||||
this._vSet(p1.x - p1.dmx * w, p1.y - p1.dmy * w, -1);
|
||||
}
|
||||
|
||||
p0 = p1;
|
||||
@@ -276,11 +276,11 @@ export const graphicsAssembler: IAssembler = {
|
||||
const dy = dPos.y;
|
||||
|
||||
if (lineCap === LineCap.BUTT) {
|
||||
this._buttCapEnd!(p1, dx, dy, w, 0);
|
||||
this._buttCapEnd(p1, dx, dy, w, 0);
|
||||
} else if (lineCap === LineCap.SQUARE) {
|
||||
this._buttCapEnd!(p1, dx, dy, w, w);
|
||||
this._buttCapEnd(p1, dx, dy, w, w);
|
||||
} else if (lineCap === LineCap.ROUND) {
|
||||
this._roundCapEnd!(p1, dx, dy, w, nCap);
|
||||
this._roundCapEnd(p1, dx, dy, w, nCap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ export const graphicsAssembler: IAssembler = {
|
||||
_impl = null;
|
||||
},
|
||||
|
||||
_expandFill (graphics: Graphics) {
|
||||
_expandFill (graphics: Graphics): void {
|
||||
_impl = graphics.impl;
|
||||
if (!_impl) {
|
||||
return;
|
||||
@@ -315,7 +315,7 @@ export const graphicsAssembler: IAssembler = {
|
||||
vertexCount += pointsLength;
|
||||
}
|
||||
|
||||
const renderData: MeshRenderData | null = _renderData = this.getRenderData!(graphics, vertexCount);
|
||||
const renderData: MeshRenderData | null = _renderData = this.getRenderData(graphics, vertexCount);
|
||||
if (!renderData) {
|
||||
return;
|
||||
}
|
||||
@@ -337,7 +337,7 @@ export const graphicsAssembler: IAssembler = {
|
||||
const vertexOffset = renderData.vertexStart;
|
||||
|
||||
for (let j = 0; j < pointsLength; ++j) {
|
||||
this._vSet!(pts[j].x, pts[j].y);
|
||||
this._vSet(pts[j].x, pts[j].y);
|
||||
}
|
||||
|
||||
let indicesOffset = renderData.indexStart;
|
||||
@@ -376,7 +376,7 @@ export const graphicsAssembler: IAssembler = {
|
||||
_impl = null;
|
||||
},
|
||||
|
||||
_calculateJoins (impl: Impl, w: number, lineJoin: LineJoin, miterLimit: number) {
|
||||
_calculateJoins (impl: Impl, w: number, lineJoin: LineJoin, miterLimit: number): void {
|
||||
let iw = 0.0;
|
||||
|
||||
if (w > 0.0) {
|
||||
@@ -452,7 +452,7 @@ export const graphicsAssembler: IAssembler = {
|
||||
}
|
||||
},
|
||||
|
||||
_flattenPaths (impl: Impl) {
|
||||
_flattenPaths (impl: Impl): void {
|
||||
const paths = impl.paths;
|
||||
for (let i = impl.pathOffset, l = impl.pathLength; i < l; i++) {
|
||||
const path = paths[i];
|
||||
@@ -505,27 +505,27 @@ export const graphicsAssembler: IAssembler = {
|
||||
return [x0, y0, x1, y1];
|
||||
},
|
||||
|
||||
_buttCapStart (p: Point, dx: number, dy: number, w: number, d: number) {
|
||||
_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;
|
||||
const dly = -dx;
|
||||
|
||||
this._vSet!(px + dlx * w, py + dly * w, 1);
|
||||
this._vSet!(px - dlx * w, py - dly * w, -1);
|
||||
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) {
|
||||
_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;
|
||||
const dly = -dx;
|
||||
|
||||
this._vSet!(px + dlx * w, py + dly * w, 1);
|
||||
this._vSet!(px - dlx * w, py - dly * w, -1);
|
||||
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) {
|
||||
_roundCapStart (p: Point, dx: number, dy: number, w: number, nCap: number): void {
|
||||
const px = p.x;
|
||||
const py = p.y;
|
||||
const dlx = dy;
|
||||
@@ -535,31 +535,31 @@ export const graphicsAssembler: IAssembler = {
|
||||
const a = i / (nCap - 1) * PI;
|
||||
const ax = cos(a) * w;
|
||||
const ay = sin(a) * w;
|
||||
this._vSet!(px - dlx * ax - dx * ay, py - dly * ax - dy * ay, 1);
|
||||
this._vSet!(px, py, 0);
|
||||
this._vSet(px - dlx * ax - dx * ay, py - dly * ax - dy * ay, 1);
|
||||
this._vSet(px, py, 0);
|
||||
}
|
||||
this._vSet!(px + dlx * w, py + dly * w, 1);
|
||||
this._vSet!(px - dlx * w, py - dly * w, -1);
|
||||
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) {
|
||||
_roundCapEnd (p: Point, dx: number, dy: number, w: number, nCap: number): void {
|
||||
const px = p.x;
|
||||
const py = p.y;
|
||||
const dlx = dy;
|
||||
const dly = -dx;
|
||||
|
||||
this._vSet!(px + dlx * w, py + dly * w, 1);
|
||||
this._vSet!(px - dlx * w, py - dly * w, -1);
|
||||
this._vSet(px + dlx * w, py + dly * w, 1);
|
||||
this._vSet(px - dlx * w, py - dly * w, -1);
|
||||
for (let i = 0; i < nCap; i++) {
|
||||
const a = i / (nCap - 1) * PI;
|
||||
const ax = cos(a) * w;
|
||||
const ay = sin(a) * w;
|
||||
this._vSet!(px, py, 0);
|
||||
this._vSet!(px - dlx * ax + dx * ay, py - dly * ax + dy * ay, 1);
|
||||
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) {
|
||||
_roundJoin (p0: Point, p1: Point, lw: number, rw: number, nCap: number): void {
|
||||
const dlx0 = p0.dy;
|
||||
const dly0 = -p0.dx;
|
||||
const dlx1 = p1.dy;
|
||||
@@ -569,7 +569,7 @@ export const graphicsAssembler: IAssembler = {
|
||||
const p1y = p1.y;
|
||||
|
||||
if ((p1.flags & PointFlags.PT_LEFT) !== 0) {
|
||||
const out = this._chooseBevel!(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, lw);
|
||||
const out = this._chooseBevel(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, lw);
|
||||
const lx0 = out[0];
|
||||
const ly0 = out[1];
|
||||
const lx1 = out[2];
|
||||
@@ -579,8 +579,8 @@ export const graphicsAssembler: IAssembler = {
|
||||
let a1 = atan2(-dly1, -dlx1);
|
||||
if (a1 > a0) { a1 -= PI * 2; }
|
||||
|
||||
this._vSet!(lx0, ly0, 1);
|
||||
this._vSet!(p1x - dlx0 * rw, p1.y - dly0 * rw, -1);
|
||||
this._vSet(lx0, ly0, 1);
|
||||
this._vSet(p1x - dlx0 * rw, p1.y - dly0 * rw, -1);
|
||||
|
||||
const n = clamp(ceil((a0 - a1) / PI) * nCap, 2, nCap);
|
||||
for (let i = 0; i < n; i++) {
|
||||
@@ -588,14 +588,14 @@ export const graphicsAssembler: IAssembler = {
|
||||
const a = a0 + u * (a1 - a0);
|
||||
const rx = p1x + cos(a) * rw;
|
||||
const ry = p1y + sin(a) * rw;
|
||||
this._vSet!(p1x, p1y, 0);
|
||||
this._vSet!(rx, ry, -1);
|
||||
this._vSet(p1x, p1y, 0);
|
||||
this._vSet(rx, ry, -1);
|
||||
}
|
||||
|
||||
this._vSet!(lx1, ly1, 1);
|
||||
this._vSet!(p1x - dlx1 * rw, p1y - dly1 * rw, -1);
|
||||
this._vSet(lx1, ly1, 1);
|
||||
this._vSet(p1x - dlx1 * rw, p1y - dly1 * rw, -1);
|
||||
} else {
|
||||
const out = this._chooseBevel!(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, -rw);
|
||||
const out = this._chooseBevel(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, -rw);
|
||||
const rx0 = out[0];
|
||||
const ry0 = out[1];
|
||||
const rx1 = out[2];
|
||||
@@ -605,8 +605,8 @@ export const graphicsAssembler: IAssembler = {
|
||||
let a1 = atan2(dly1, dlx1);
|
||||
if (a1 < a0) { a1 += PI * 2; }
|
||||
|
||||
this._vSet!(p1x + dlx0 * rw, p1y + dly0 * rw, 1);
|
||||
this._vSet!(rx0, ry0, -1);
|
||||
this._vSet(p1x + dlx0 * rw, p1y + dly0 * rw, 1);
|
||||
this._vSet(rx0, ry0, -1);
|
||||
|
||||
const n = clamp(ceil((a1 - a0) / PI) * nCap, 2, nCap);
|
||||
for (let i = 0; i < n; i++) {
|
||||
@@ -614,16 +614,16 @@ export const graphicsAssembler: IAssembler = {
|
||||
const a = a0 + u * (a1 - a0);
|
||||
const lx = p1x + cos(a) * lw;
|
||||
const ly = p1y + sin(a) * lw;
|
||||
this._vSet!(lx, ly, 1);
|
||||
this._vSet!(p1x, p1y, 0);
|
||||
this._vSet(lx, ly, 1);
|
||||
this._vSet(p1x, p1y, 0);
|
||||
}
|
||||
|
||||
this._vSet!(p1x + dlx1 * rw, p1y + dly1 * rw, 1);
|
||||
this._vSet!(rx1, ry1, -1);
|
||||
this._vSet(p1x + dlx1 * rw, p1y + dly1 * rw, 1);
|
||||
this._vSet(rx1, ry1, -1);
|
||||
}
|
||||
},
|
||||
|
||||
_bevelJoin (p0: Point, p1: Point, lw: number, rw: number) {
|
||||
_bevelJoin (p0: Point, p1: Point, lw: number, rw: number): void {
|
||||
let rx0 = 0;
|
||||
let ry0 = 0;
|
||||
let rx1 = 0;
|
||||
@@ -638,33 +638,33 @@ export const graphicsAssembler: IAssembler = {
|
||||
const dly1 = -p1.dx;
|
||||
|
||||
if (p1.flags & PointFlags.PT_LEFT) {
|
||||
const out = this._chooseBevel!(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, lw);
|
||||
const out = this._chooseBevel(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, lw);
|
||||
lx0 = out[0];
|
||||
ly0 = out[1];
|
||||
lx1 = out[2];
|
||||
ly1 = out[3];
|
||||
|
||||
this._vSet!(lx0, ly0, 1);
|
||||
this._vSet!(p1.x - dlx0 * rw, p1.y - dly0 * rw, -1);
|
||||
this._vSet(lx0, ly0, 1);
|
||||
this._vSet(p1.x - dlx0 * rw, p1.y - dly0 * rw, -1);
|
||||
|
||||
this._vSet!(lx1, ly1, 1);
|
||||
this._vSet!(p1.x - dlx1 * rw, p1.y - dly1 * rw, -1);
|
||||
this._vSet(lx1, ly1, 1);
|
||||
this._vSet(p1.x - dlx1 * rw, p1.y - dly1 * rw, -1);
|
||||
} else {
|
||||
const out = this._chooseBevel!(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, -rw);
|
||||
const out = this._chooseBevel(p1.flags & PointFlags.PT_INNERBEVEL, p0, p1, -rw);
|
||||
rx0 = out[0];
|
||||
ry0 = out[1];
|
||||
rx1 = out[2];
|
||||
ry1 = out[3];
|
||||
|
||||
this._vSet!(p1.x + dlx0 * lw, p1.y + dly0 * lw, 1);
|
||||
this._vSet!(rx0, ry0, -1);
|
||||
this._vSet(p1.x + dlx0 * lw, p1.y + dly0 * lw, 1);
|
||||
this._vSet(rx0, ry0, -1);
|
||||
|
||||
this._vSet!(p1.x + dlx1 * lw, p1.y + dly1 * lw, 1);
|
||||
this._vSet!(rx1, ry1, -1);
|
||||
this._vSet(p1.x + dlx1 * lw, p1.y + dly1 * lw, 1);
|
||||
this._vSet(rx1, ry1, -1);
|
||||
}
|
||||
},
|
||||
|
||||
_vSet (x: number, y: number, distance = 0) {
|
||||
_vSet (x: number, y: number, distance = 0): void {
|
||||
if (!_renderData) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ export class Point extends Vec2 {
|
||||
public flags = 0;
|
||||
public len = 0;
|
||||
|
||||
constructor (x: number, y: number) {
|
||||
super(x, y);
|
||||
}
|
||||
|
||||
public reset (): void {
|
||||
this.dx = 0;
|
||||
this.dy = 0;
|
||||
@@ -86,7 +90,7 @@ export class Impl {
|
||||
private _points: Point[] = [];
|
||||
private _renderDataList: MeshRenderData[] = [];
|
||||
private _curPath: Path | null = null;
|
||||
private _comp: Graphics;
|
||||
private declare _comp: Graphics;
|
||||
|
||||
constructor (comp: Graphics) {
|
||||
this._comp = comp;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
import { JSB } from 'internal:constants';
|
||||
import { IConfig, FontAtlas } from '../../assets/bitmap-font';
|
||||
import { SpriteFrame } from '../../assets/sprite-frame';
|
||||
import { Rect } from '../../../core';
|
||||
import { Rect, errorID } from '../../../core';
|
||||
import { Label, Overflow, CacheMode } from '../../components/label';
|
||||
import { UITransform } from '../../framework/ui-transform';
|
||||
import { LetterAtlas, shareLabelInfo } from './font-utils';
|
||||
@@ -44,13 +44,18 @@ let _uiTrans: UITransform | null = null;
|
||||
|
||||
let _fntConfig: IConfig | null = null;
|
||||
let _spriteFrame: SpriteFrame|null = null;
|
||||
let QUAD_INDICES;
|
||||
let QUAD_INDICES: Uint16Array | null = null;
|
||||
|
||||
export const bmfontUtils = {
|
||||
|
||||
updateProcessingData (style: TextStyle, layout: TextLayout,
|
||||
outputLayoutData: TextOutputLayoutData, outputRenderData: TextOutputRenderData,
|
||||
comp: Label, trans: UITransform): void {
|
||||
updateProcessingData (
|
||||
style: TextStyle,
|
||||
layout: TextLayout,
|
||||
outputLayoutData: TextOutputLayoutData,
|
||||
outputRenderData: TextOutputRenderData,
|
||||
comp: Label,
|
||||
trans: UITransform,
|
||||
): void {
|
||||
style.fontSize = comp.fontSize;
|
||||
style.actualFontSize = comp.fontSize;
|
||||
style.originFontSize = _fntConfig ? _fntConfig.fontSize : comp.fontSize;
|
||||
@@ -118,8 +123,15 @@ export const bmfontUtils = {
|
||||
processing.processingString(true, style, layout, outputLayoutData, comp.string);
|
||||
// generateVertex
|
||||
outputRenderData.quadCount = 0;
|
||||
processing.generateRenderInfo(true, style, layout, outputLayoutData, outputRenderData,
|
||||
comp.string, this.generateVertexData);
|
||||
processing.generateRenderInfo(
|
||||
true,
|
||||
style,
|
||||
layout,
|
||||
outputLayoutData,
|
||||
outputRenderData,
|
||||
comp.string,
|
||||
this.generateVertexData,
|
||||
);
|
||||
let isResized = false;
|
||||
if (renderData.dataLength !== outputRenderData.quadCount) {
|
||||
this.resetRenderData(comp);
|
||||
@@ -134,7 +146,7 @@ export const bmfontUtils = {
|
||||
|
||||
const indexCount = renderData.indexCount;
|
||||
this.createQuadIndices(indexCount);
|
||||
renderData.chunk.setIndexBuffer(QUAD_INDICES);
|
||||
renderData.chunk.setIndexBuffer(QUAD_INDICES!);
|
||||
|
||||
_comp.actualFontSize = style.actualFontSize;
|
||||
_uiTrans.setContentSize(outputLayoutData.nodeContentSize);
|
||||
@@ -204,8 +216,17 @@ export const bmfontUtils = {
|
||||
},
|
||||
|
||||
// callBack function
|
||||
generateVertexData (style: TextStyle, outputLayoutData: TextOutputLayoutData, outputRenderData: TextOutputRenderData, offset: number,
|
||||
spriteFrame: SpriteFrame, rect: Rect, rotated: boolean, x: number, y: number): void {
|
||||
generateVertexData (
|
||||
style: TextStyle,
|
||||
outputLayoutData: TextOutputLayoutData,
|
||||
outputRenderData: TextOutputRenderData,
|
||||
offset: number,
|
||||
spriteFrame: SpriteFrame,
|
||||
rect: Rect,
|
||||
rotated: boolean,
|
||||
x: number,
|
||||
y: number,
|
||||
): void {
|
||||
const dataOffset = offset;
|
||||
const scale = style.bmfontScale;
|
||||
|
||||
@@ -290,13 +311,12 @@ export const bmfontUtils = {
|
||||
shareLabelInfo.margin = 0;
|
||||
},
|
||||
|
||||
createQuadIndices (indexCount): void {
|
||||
createQuadIndices (indexCount: number): void {
|
||||
if (indexCount % 6 !== 0) {
|
||||
console.error('illegal index count!');
|
||||
errorID(16308);
|
||||
return;
|
||||
}
|
||||
const quadCount = indexCount / 6;
|
||||
QUAD_INDICES = null;
|
||||
QUAD_INDICES = new Uint16Array(indexCount);
|
||||
let offset = 0;
|
||||
for (let i = 0; i < quadCount; i++) {
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { FontAtlas } from '../../assets/bitmap-font';
|
||||
import { Color, macro, log, warnID } from '../../../core';
|
||||
import { FontAtlas, FontLetterDefinition } from '../../assets/bitmap-font';
|
||||
import { Color, macro, warnID } from '../../../core';
|
||||
import { ImageAsset, Texture2D } from '../../../asset/assets';
|
||||
import { PixelFormat } from '../../../asset/assets/asset-enum';
|
||||
import { BufferTextureCopy } from '../../../gfx';
|
||||
@@ -104,32 +104,20 @@ const WHITE = Color.WHITE.clone();
|
||||
const space = 0;
|
||||
const bleed = 2;
|
||||
|
||||
class FontLetterDefinition {
|
||||
public u = 0;
|
||||
public v = 0;
|
||||
public w = 0;
|
||||
public h = 0;
|
||||
public texture: LetterRenderTexture | null = null;
|
||||
public offsetX = 0;
|
||||
public offsetY = 0;
|
||||
public valid = false;
|
||||
public xAdvance = 0;
|
||||
}
|
||||
|
||||
const _backgroundStyle = `rgba(255, 255, 255, ${(1 / 255).toFixed(3)})`;
|
||||
const BASELINE_OFFSET = getBaselineOffset();
|
||||
|
||||
class LetterTexture {
|
||||
public image: ImageAsset | null = null;
|
||||
public labelInfo: ILabelInfo;
|
||||
public char: string;
|
||||
public declare labelInfo: ILabelInfo;
|
||||
public declare char: string;
|
||||
public data: ISharedLabelData | null = null;
|
||||
public canvas: HTMLCanvasElement | null = null;
|
||||
public context: CanvasRenderingContext2D | null = null;
|
||||
public width = 0;
|
||||
public height = 0;
|
||||
public offsetY = 0;
|
||||
public hash: string;
|
||||
public declare hash: string;
|
||||
constructor (char: string, labelInfo: ILabelInfo) {
|
||||
this.char = char;
|
||||
this.labelInfo = labelInfo;
|
||||
@@ -251,7 +239,7 @@ export class LetterRenderTexture extends Texture2D {
|
||||
|
||||
const gfxDevice = this._getGFXDevice();
|
||||
if (!gfxDevice) {
|
||||
log('Unable to get device');
|
||||
warnID(16363);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -294,14 +282,14 @@ export class LetterAtlas {
|
||||
}
|
||||
|
||||
public insertLetterTexture (letterTexture: LetterTexture): FontLetterDefinition | null {
|
||||
const texture = letterTexture.image;
|
||||
const img = letterTexture.image;
|
||||
const device = director.root!.device;
|
||||
if (!texture || !this.fontDefDictionary || !device) {
|
||||
if (!img || !this.fontDefDictionary || !device) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const width = texture.width;
|
||||
const height = texture.height;
|
||||
const width = img.width;
|
||||
const height = img.height;
|
||||
|
||||
if ((this._x + width + space) > this._width) {
|
||||
this._x = space;
|
||||
@@ -317,14 +305,18 @@ export class LetterAtlas {
|
||||
return null;
|
||||
}
|
||||
|
||||
this.fontDefDictionary.texture.drawTextureAt(texture, this._x, this._y);
|
||||
if (!this.fontDefDictionary.texture) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const rt = this.fontDefDictionary.texture as LetterRenderTexture;
|
||||
rt.drawTextureAt(img, this._x, this._y);
|
||||
|
||||
this._dirty = true;
|
||||
|
||||
const letterDefinition = new FontLetterDefinition();
|
||||
letterDefinition.u = this._x + this._halfBleed;
|
||||
letterDefinition.v = this._y + this._halfBleed;
|
||||
letterDefinition.texture = this.fontDefDictionary.texture;
|
||||
letterDefinition.valid = true;
|
||||
letterDefinition.w = letterTexture.width - bleed;
|
||||
letterDefinition.h = letterTexture.height - bleed;
|
||||
@@ -372,9 +364,10 @@ export class LetterAtlas {
|
||||
|
||||
public destroy (): void {
|
||||
this.reset();
|
||||
if (this.fontDefDictionary) {
|
||||
this.fontDefDictionary.texture.destroy();
|
||||
this.fontDefDictionary.texture = null;
|
||||
const dict = this.fontDefDictionary;
|
||||
if (dict && dict.texture) {
|
||||
dict.texture.destroy();
|
||||
dict.texture = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,13 +388,13 @@ export class LetterAtlas {
|
||||
this.fontDefDictionary.texture = texture;
|
||||
}
|
||||
|
||||
public getLetter (key: string): any {
|
||||
public getLetter (key: string): FontLetterDefinition {
|
||||
return this.fontDefDictionary.letterDefinitions[key];
|
||||
}
|
||||
|
||||
public getLetterDefinitionForChar (char: string, labelInfo: ILabelInfo): any {
|
||||
public getLetterDefinitionForChar (char: string, labelInfo: ILabelInfo): FontLetterDefinition | null {
|
||||
const hash = getSymbolCodeAt(char, 0) + labelInfo.hash;
|
||||
let letter = this.fontDefDictionary.letterDefinitions[hash];
|
||||
let letter: FontLetterDefinition | null = this.fontDefDictionary.letterDefinitions[hash];
|
||||
if (!letter) {
|
||||
const temp = new LetterTexture(char, labelInfo);
|
||||
temp.updateRenderData();
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
*/
|
||||
|
||||
import { js } from '../../../core';
|
||||
import { Label, LabelOutline } from '../../components';
|
||||
import { Label } from '../../components';
|
||||
import { bmfontUtils } from './bmfontUtils';
|
||||
import { shareLabelInfo, LetterAtlas, computeHash, LetterRenderTexture } from './font-utils';
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
import { ANDROID, JSB } from 'internal:constants';
|
||||
import { Texture2D } from '../../../asset/assets';
|
||||
import { WrapMode } from '../../../asset/assets/asset-enum';
|
||||
import { cclegacy, Color, Pool, Rect, Vec2 } from '../../../core';
|
||||
import { log, logID, warn } from '../../../core/platform';
|
||||
import { cclegacy, Color, Rect, Vec2 } from '../../../core';
|
||||
import { logID, warnID } from '../../../core/platform';
|
||||
import { SpriteFrame } from '../../assets';
|
||||
import { FontLetterDefinition } from '../../assets/bitmap-font';
|
||||
import { HorizontalTextAlignment, Overflow, VerticalTextAlignment } from '../../components/label';
|
||||
@@ -447,9 +447,9 @@ export class TextProcessing {
|
||||
|
||||
private _calculateFillTextStartPosition (style: TextStyle, layout: TextLayout, outputLayoutData: TextOutputLayoutData): void {
|
||||
let labelX = 0;
|
||||
if (layout.horizontalAlign === HorizontalTextAlignment.RIGHT) {
|
||||
if (layout.horizontalAlign === HorizontalTextAlignment.RIGHT as number) {
|
||||
labelX = outputLayoutData.canvasSize.width - outputLayoutData.canvasPadding.width;
|
||||
} else if (layout.horizontalAlign === HorizontalTextAlignment.CENTER) {
|
||||
} else if (layout.horizontalAlign === HorizontalTextAlignment.CENTER as number) {
|
||||
labelX = (outputLayoutData.canvasSize.width - outputLayoutData.canvasPadding.width) / 2;
|
||||
}
|
||||
|
||||
@@ -457,10 +457,10 @@ export class TextProcessing {
|
||||
const drawStartY = lineHeight * (outputLayoutData.parsedString.length - 1);
|
||||
// TOP
|
||||
let firstLinelabelY = style.actualFontSize * (1 - BASELINE_RATIO / 2);
|
||||
if (layout.verticalAlign !== VerticalTextAlignment.TOP) {
|
||||
if (layout.verticalAlign !== VerticalTextAlignment.TOP as number) {
|
||||
// free space in vertical direction
|
||||
let blank = drawStartY + outputLayoutData.canvasPadding.height + style.actualFontSize - outputLayoutData.canvasSize.height;
|
||||
if (layout.verticalAlign === VerticalTextAlignment.BOTTOM) {
|
||||
if (layout.verticalAlign === VerticalTextAlignment.BOTTOM as number) {
|
||||
// Unlike BMFont, needs to reserve space below.
|
||||
blank += BASELINE_RATIO / 2 * style.actualFontSize;
|
||||
// BOTTOM
|
||||
@@ -618,9 +618,9 @@ export class TextProcessing {
|
||||
if (style.isUnderline) {
|
||||
const _drawUnderlineWidth = measureText(outputLayoutData.parsedString[i]);
|
||||
const _drawUnderlinePos = new Vec2();
|
||||
if (layout.horizontalAlign === HorizontalTextAlignment.RIGHT) {
|
||||
if (layout.horizontalAlign === HorizontalTextAlignment.RIGHT as number) {
|
||||
_drawUnderlinePos.x = startPosition.x - _drawUnderlineWidth;
|
||||
} else if (layout.horizontalAlign === HorizontalTextAlignment.CENTER) {
|
||||
} else if (layout.horizontalAlign === HorizontalTextAlignment.CENTER as number) {
|
||||
_drawUnderlinePos.x = startPosition.x - (_drawUnderlineWidth / 2);
|
||||
} else {
|
||||
_drawUnderlinePos.x = startPosition.x;
|
||||
@@ -697,11 +697,11 @@ export class TextProcessing {
|
||||
let newWidth = outputLayoutData.nodeContentSize.width;
|
||||
let newHeight = outputLayoutData.nodeContentSize.height;
|
||||
|
||||
if (layout.overFlow === Overflow.RESIZE_HEIGHT) {
|
||||
if (layout.overFlow === Overflow.RESIZE_HEIGHT as number) {
|
||||
newHeight = 0;
|
||||
}
|
||||
|
||||
if (layout.overFlow === Overflow.NONE) {
|
||||
if (layout.overFlow === Overflow.NONE as number) {
|
||||
newWidth = 0;
|
||||
newHeight = 0;
|
||||
}
|
||||
@@ -746,7 +746,7 @@ export class TextProcessing {
|
||||
this._multilineTextWrap(style, layout, outputLayoutData, inputString, this._getFirstWordLen);
|
||||
|
||||
// shrink
|
||||
if (layout.overFlow === Overflow.SHRINK) {
|
||||
if (layout.overFlow === Overflow.SHRINK as number) {
|
||||
if (style.fontSize > 0 && this._isVerticalClamp(style, layout, outputLayoutData, inputString, this)) {
|
||||
this._shrinkLabelToContentSize(style, layout, outputLayoutData, inputString, this._isVerticalClamp);
|
||||
}
|
||||
@@ -832,9 +832,9 @@ export class TextProcessing {
|
||||
if (!letterDef) {
|
||||
this._recordPlaceholderInfo(letterIndex, character);
|
||||
if (style.fntConfig != null) {
|
||||
log(`Can't find letter definition in texture atlas ${style.fntConfig.atlasName} for letter:${character}`);
|
||||
logID(16354, style.fntConfig.atlasName as string, character);
|
||||
} else {
|
||||
log(`Can't find letter definition in font family ${style.fontFamily} for letter:${character}`);
|
||||
logID(16355, style.fontFamily, character);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -1019,10 +1019,10 @@ export class TextProcessing {
|
||||
|
||||
// TOP
|
||||
layout.letterOffsetY = outputLayoutData.nodeContentSize.height;
|
||||
if (layout.verticalAlign !== VerticalTextAlignment.TOP) {
|
||||
if (layout.verticalAlign !== VerticalTextAlignment.TOP as number) {
|
||||
const blank = outputLayoutData.nodeContentSize.height - layout.textDesiredHeight
|
||||
+ layout.lineHeight * this._getFontScale(style, layout) - style.originFontSize * this._fontScale * style.bmfontScale;
|
||||
if (layout.verticalAlign === VerticalTextAlignment.BOTTOM) {
|
||||
if (layout.verticalAlign === VerticalTextAlignment.BOTTOM as number) {
|
||||
// BOTTOM
|
||||
layout.letterOffsetY -= blank;
|
||||
} else {
|
||||
@@ -1033,7 +1033,7 @@ export class TextProcessing {
|
||||
}
|
||||
|
||||
private _getFontScale (style: TextStyle, layout: TextLayout): number {
|
||||
return layout.overFlow === Overflow.SHRINK ? style.bmfontScale : 1;
|
||||
return layout.overFlow === (Overflow.SHRINK as number) ? style.bmfontScale : 1;
|
||||
}
|
||||
|
||||
private _isVerticalClamp (
|
||||
@@ -1178,7 +1178,7 @@ export class TextProcessing {
|
||||
if (!letterInfo.valid) { continue; }
|
||||
const letterDef = shareLabelInfo.fontAtlas!.getLetter(letterInfo.hash);
|
||||
if (!letterDef) {
|
||||
warn('Can\'t find letter in this bitmap-font');
|
||||
warnID(16353);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1197,7 +1197,7 @@ export class TextProcessing {
|
||||
py -= clipTop;
|
||||
}
|
||||
|
||||
if ((py - this._tmpRect.height * style.bmfontScale < layout.tailoredBottomY) && layout.overFlow === Overflow.CLAMP) {
|
||||
if ((py - this._tmpRect.height * style.bmfontScale < layout.tailoredBottomY) && layout.overFlow === Overflow.CLAMP as number) {
|
||||
this._tmpRect.height = (py < layout.tailoredBottomY) ? 0 : (py - layout.tailoredBottomY) / style.bmfontScale;
|
||||
}
|
||||
}
|
||||
@@ -1207,7 +1207,7 @@ export class TextProcessing {
|
||||
|
||||
if (layout.textWidthTemp > 0) {
|
||||
if (this._isHorizontalClamped(layout, outputLayoutData, px, lineIndex)) {
|
||||
if (layout.overFlow === Overflow.CLAMP) {
|
||||
if (layout.overFlow === Overflow.CLAMP as number) {
|
||||
this._tmpRect.width = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
let mesh = {
|
||||
useModel: false,
|
||||
|
||||
createData(sprite) {
|
||||
return sprite.requestRenderData();
|
||||
},
|
||||
|
||||
updateRenderData(sprite) {
|
||||
let frame = sprite.spriteFrame;
|
||||
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
// if (frame) {
|
||||
// if (!frame._original && dynamicAtlasManager) {
|
||||
// dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
// }
|
||||
// if (sprite._material._texture !== frame._texture) {
|
||||
// sprite._activateMaterial();
|
||||
// }
|
||||
// }
|
||||
|
||||
let renderData = sprite._renderData;
|
||||
if (renderData && frame) {
|
||||
let vertices = frame.vertices;
|
||||
if (vertices) {
|
||||
if (renderData.vertexCount !== vertices.x.length) {
|
||||
renderData.vertexCount = vertices.x.length;
|
||||
|
||||
// 1 for world vertices, 2 for local vertices
|
||||
renderData.dataLength = renderData.vertexCount * 2;
|
||||
|
||||
renderData.uvDirty = renderData.vertDirty = true;
|
||||
}
|
||||
renderData.indiceCount = vertices.triangles.length;
|
||||
|
||||
if (renderData.uvDirty) {
|
||||
this.updateUVs(sprite);
|
||||
}
|
||||
let vertDirty = renderData.vertDirty;
|
||||
if (vertDirty) {
|
||||
this.updateVerts(sprite);
|
||||
this.updateWorldVerts(sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
updateUVs(sprite) {
|
||||
let vertices = sprite.spriteFrame.vertices,
|
||||
u = vertices.nu,
|
||||
v = vertices.nv;
|
||||
|
||||
let renderData = sprite._renderData;
|
||||
let data = renderData._data;
|
||||
for (let i = 0, l = u.length; i < l; i++) {
|
||||
let vertice = data[i];
|
||||
vertice.u = u[i];
|
||||
vertice.v = v[i];
|
||||
}
|
||||
|
||||
renderData.uvDirty = false;
|
||||
},
|
||||
|
||||
updateVerts(sprite) {
|
||||
let node = sprite.node,
|
||||
contentWidth = Math.abs(node.width),
|
||||
contentHeight = Math.abs(node.height),
|
||||
appx = node.anchorX * contentWidth,
|
||||
appy = node.anchorY * contentHeight;
|
||||
|
||||
let frame = sprite.spriteFrame,
|
||||
vertices = frame.vertices,
|
||||
x = vertices.x,
|
||||
y = vertices.y,
|
||||
originalWidth = frame._originalSize.width,
|
||||
originalHeight = frame._originalSize.height,
|
||||
rectWidth = frame._rect.width,
|
||||
rectHeight = frame._rect.height,
|
||||
offsetX = frame._offset.x,
|
||||
offsetY = frame._offset.y,
|
||||
trimX = offsetX + (originalWidth - rectWidth) / 2,
|
||||
trimY = offsetY + (originalHeight - rectHeight) / 2;
|
||||
|
||||
let scaleX = contentWidth / (sprite.trim ? rectWidth : originalWidth),
|
||||
scaleY = contentHeight / (sprite.trim ? rectHeight : originalHeight);
|
||||
|
||||
let renderData = sprite._renderData;
|
||||
let data = renderData._data;
|
||||
|
||||
if (!sprite.trim) {
|
||||
for (let i = 0, l = x.length; i < l; i++) {
|
||||
let vertice = data[i + l];
|
||||
vertice.x = (x[i]) * scaleX - appx;
|
||||
vertice.y = (originalHeight - y[i]) * scaleY - appy;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let i = 0, l = x.length; i < l; i++) {
|
||||
let vertice = data[i + l];
|
||||
vertice.x = (x[i] - trimX) * scaleX - appx;
|
||||
vertice.y = (originalHeight - y[i] - trimY) * scaleY - appy;
|
||||
}
|
||||
}
|
||||
|
||||
renderData.vertDirty = false;
|
||||
},
|
||||
|
||||
updateWorldVerts(sprite) {
|
||||
let node = sprite.node,
|
||||
renderData = sprite._renderData,
|
||||
data = renderData._data;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
for (let i = 0, l = renderData.vertexCount; i < l; i++) {
|
||||
let local = data[i + l];
|
||||
let world = data[i];
|
||||
vec3.set(vec3_temp, local.x, local.y, 0);
|
||||
vec3.transformMat4(world, vec3_temp, matrix);
|
||||
}
|
||||
},
|
||||
|
||||
fillBuffers(sprite, /*renderer*/buffer) {
|
||||
let vertices = sprite.spriteFrame.vertices;
|
||||
if (!vertices) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update world verts
|
||||
// if (renderer.worldMatDirty) {
|
||||
this.updateWorldVerts(sprite);
|
||||
// }
|
||||
|
||||
// buffer
|
||||
let /*buffer = renderer._meshBuffer3D,*/
|
||||
indiceOffset = buffer.indiceOffset,
|
||||
vertexId = buffer.vertexOffset;
|
||||
|
||||
let node = sprite.node;
|
||||
fillVerticesWithoutCalc3D(node, buffer, sprite._renderData, sprite._color._val);
|
||||
|
||||
// buffer data may be realloc, need get reference after request.
|
||||
let ibuf = buffer._iData;
|
||||
let triangles = vertices.triangles;
|
||||
for (let i = 0, l = triangles.length; i < l; i++) {
|
||||
ibuf[indiceOffset++] = vertexId + triangles[i];
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default mesh;
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
import { JSB } from 'internal:constants';
|
||||
import { IUV, SpriteFrame } from '../../assets/sprite-frame';
|
||||
import { Mat4, Vec3, Color, error } from '../../../core';
|
||||
import { Mat4, Color, errorID } from '../../../core';
|
||||
import { IRenderData, RenderData } from '../../renderer/render-data';
|
||||
import { IBatcher } from '../../renderer/i-batcher';
|
||||
import { Sprite } from '../../components/sprite';
|
||||
@@ -121,11 +121,10 @@ export const tiled: IAssembler = {
|
||||
|
||||
createQuadIndices (indexCount: number) {
|
||||
if (indexCount % 6 !== 0) {
|
||||
error('illegal index count!');
|
||||
errorID(16308);
|
||||
return;
|
||||
}
|
||||
const quadCount = indexCount / 6;
|
||||
QUAD_INDICES = null;
|
||||
QUAD_INDICES = new Uint16Array(indexCount);
|
||||
let offset = 0;
|
||||
for (let i = 0; i < quadCount; i++) {
|
||||
|
||||
@@ -26,8 +26,10 @@
|
||||
import { ccclass, type, serializable, editable } from 'cc.decorator';
|
||||
import { Font } from './font';
|
||||
import { SpriteFrame } from './sprite-frame';
|
||||
import { cclegacy, js, warn } from '../../core';
|
||||
import { cclegacy, js, warnID } from '../../core';
|
||||
import { getSymbolCodeAt } from '../utils';
|
||||
import { IShareLabelInfo } from '../assembler/label/font-utils';
|
||||
import { TextureBase } from '../../asset/assets/texture-base';
|
||||
|
||||
export interface IConfig {
|
||||
[key: string]: any;
|
||||
@@ -40,7 +42,6 @@ export class FontLetterDefinition {
|
||||
public h = 0;
|
||||
public offsetX = 0;
|
||||
public offsetY = 0;
|
||||
public textureID = 0;
|
||||
public valid = false;
|
||||
public xAdvance = 0;
|
||||
}
|
||||
@@ -50,15 +51,14 @@ export interface ILetterDefinition {
|
||||
}
|
||||
|
||||
export class FontAtlas {
|
||||
public declare letterDefinitions;
|
||||
public declare texture;
|
||||
public letterDefinitions: ILetterDefinition = {};
|
||||
public declare texture: TextureBase | null;
|
||||
|
||||
constructor (texture) {
|
||||
this.letterDefinitions = {};
|
||||
constructor (texture: TextureBase | null) {
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public addLetterDefinitions (letter, letterDefinition): void {
|
||||
public addLetterDefinitions (letter: string, letterDefinition: FontLetterDefinition): void {
|
||||
this.letterDefinitions[letter] = letterDefinition;
|
||||
}
|
||||
|
||||
@@ -72,22 +72,20 @@ export class FontAtlas {
|
||||
return copyLetterDefinitions;
|
||||
}
|
||||
|
||||
public getTexture (): any {
|
||||
public getTexture (): TextureBase | null {
|
||||
return this.texture;
|
||||
}
|
||||
|
||||
public getLetter (key): any {
|
||||
public getLetter (key: string): FontLetterDefinition {
|
||||
return this.letterDefinitions[key];
|
||||
}
|
||||
|
||||
public getLetterDefinitionForChar (char, labelInfo?): any {
|
||||
const key = getSymbolCodeAt(char as string, 0);
|
||||
const hasKey = this.letterDefinitions.hasOwnProperty(key);
|
||||
let letter;
|
||||
public getLetterDefinitionForChar (char: string, labelInfo?: IShareLabelInfo): FontLetterDefinition | null {
|
||||
const key = getSymbolCodeAt(char, 0);
|
||||
const hasKey = Object.prototype.hasOwnProperty.call(this.letterDefinitions, key);
|
||||
let letter: FontLetterDefinition | null = null;
|
||||
if (hasKey) {
|
||||
letter = this.letterDefinitions[key];
|
||||
} else {
|
||||
letter = null;
|
||||
}
|
||||
return letter;
|
||||
}
|
||||
@@ -138,6 +136,10 @@ export class BitmapFont extends Font {
|
||||
*/
|
||||
public declare fontDefDictionary: FontAtlas;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
onLoaded (): void {
|
||||
const spriteFrame = this.spriteFrame;
|
||||
if (!this.fontDefDictionary && spriteFrame) {
|
||||
@@ -146,24 +148,23 @@ export class BitmapFont extends Font {
|
||||
|
||||
const fntConfig = this.fntConfig;
|
||||
if (!fntConfig) {
|
||||
warn('The fnt config is not exists!');
|
||||
warnID(16376);
|
||||
return;
|
||||
}
|
||||
|
||||
const fontDict = fntConfig.fontDefDictionary;
|
||||
for (const fontDef in fontDict) {
|
||||
const info = fontDict[fontDef];
|
||||
const letter = new FontLetterDefinition();
|
||||
const rect = fontDict[fontDef].rect;
|
||||
letter.offsetX = fontDict[fontDef].xOffset;
|
||||
letter.offsetY = fontDict[fontDef].yOffset;
|
||||
const rect = info.rect;
|
||||
letter.offsetX = info.xOffset;
|
||||
letter.offsetY = info.yOffset;
|
||||
letter.w = rect.width;
|
||||
letter.h = rect.height;
|
||||
letter.u = rect.x;
|
||||
letter.v = rect.y;
|
||||
// FIXME: only one texture supported for now
|
||||
letter.textureID = 0;
|
||||
letter.valid = true;
|
||||
letter.xAdvance = fontDict[fontDef].xAdvance;
|
||||
letter.xAdvance = info.xAdvance;
|
||||
|
||||
this.fontDefDictionary.addLetterDefinitions(fontDef, letter);
|
||||
}
|
||||
|
||||
@@ -55,6 +55,10 @@ export class SpriteAtlas extends Asset {
|
||||
@editable
|
||||
public spriteFrames: ISpriteFrameList = js.createMap();
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get the [[Texture2D]] asset of the atlas.
|
||||
* @zh 获取精灵图集的贴图。
|
||||
@@ -125,6 +129,7 @@ export class SpriteAtlas extends Asset {
|
||||
spriteFrames: frames,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
import { ccclass } from 'cc.decorator';
|
||||
import { EDITOR, TEST, BUILD } from 'internal:constants';
|
||||
import { Mat4, Rect, Size, Vec2, Vec3, Vec4, cclegacy, errorID, warnID, js } from '../../core';
|
||||
import { Rect, Size, Vec2, Vec3, Vec4, cclegacy, errorID, warnID, js, v3, mat4, rect, v4, v2, size } from '../../core';
|
||||
import { Asset } from '../../asset/assets/asset';
|
||||
import { TextureBase } from '../../asset/assets/texture-base';
|
||||
import { ImageAsset, ImageSource } from '../../asset/assets/image-asset';
|
||||
@@ -42,8 +42,8 @@ const INSET_LEFT = 0;
|
||||
const INSET_TOP = 1;
|
||||
const INSET_RIGHT = 2;
|
||||
const INSET_BOTTOM = 3;
|
||||
const temp_vec3 = new Vec3();
|
||||
const temp_matrix = new Mat4();
|
||||
const temp_vec3 = v3();
|
||||
const temp_matrix = mat4();
|
||||
|
||||
enum MeshType {
|
||||
RECT = 0,
|
||||
@@ -586,15 +586,15 @@ export class SpriteFrame extends Asset {
|
||||
public uvSliced: IUV[] = [];
|
||||
|
||||
// the location of the sprite on rendering texture
|
||||
protected _rect = new Rect();
|
||||
protected _rect = rect();
|
||||
|
||||
protected _trimmedBorder = new Vec4();
|
||||
protected _trimmedBorder = v4();
|
||||
|
||||
// for trimming
|
||||
protected _offset = new Vec2();
|
||||
protected _offset = v2();
|
||||
|
||||
// for trimming
|
||||
protected _originalSize = new Size();
|
||||
protected _originalSize = size();
|
||||
|
||||
protected _rotated = false;
|
||||
|
||||
@@ -619,7 +619,7 @@ export class SpriteFrame extends Asset {
|
||||
|
||||
protected _pixelsToUnit = 100;
|
||||
|
||||
protected _pivot = new Vec2(0.5, 0.5); // center
|
||||
protected _pivot = v2(0.5, 0.5); // center
|
||||
|
||||
// Todo: Some features need add
|
||||
protected _meshType = MeshType.RECT;
|
||||
@@ -635,9 +635,9 @@ export class SpriteFrame extends Asset {
|
||||
// (updated after attribute value changes in the editor, adjusting vertices/re-generation)
|
||||
|
||||
// Mesh api
|
||||
protected declare _mesh: Mesh | null;
|
||||
protected _minPos = new Vec3();
|
||||
protected _maxPos = new Vec3();
|
||||
protected _mesh: Mesh | null = null;
|
||||
protected _minPos = v3();
|
||||
protected _maxPos = v3();
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
@@ -1351,12 +1351,12 @@ export class SpriteFrame extends Asset {
|
||||
|
||||
const offset = data.offset;
|
||||
if (data.offset) {
|
||||
this._offset = new Vec2(offset.x, offset.y);
|
||||
this._offset = v2(offset.x, offset.y);
|
||||
}
|
||||
|
||||
const originalSize = data.originalSize;
|
||||
if (data.originalSize) {
|
||||
this._originalSize = new Size(originalSize.width, originalSize.height);
|
||||
this._originalSize = size(originalSize.width, originalSize.height);
|
||||
}
|
||||
this._rotated = !!data.rotated;
|
||||
this._name = data.name;
|
||||
@@ -1365,7 +1365,7 @@ export class SpriteFrame extends Asset {
|
||||
this._pixelsToUnit = data.pixelsToUnit;
|
||||
const pivot = data.pivot;
|
||||
if (pivot) {
|
||||
this._pivot = new Vec2(pivot.x, pivot.y);
|
||||
this._pivot = v2(pivot.x, pivot.y);
|
||||
}
|
||||
this._meshType = data.meshType;
|
||||
|
||||
@@ -1397,14 +1397,14 @@ export class SpriteFrame extends Asset {
|
||||
indexes: vertices.indexes,
|
||||
uv: vertices.uv,
|
||||
nuv: vertices.nuv,
|
||||
minPos: new Vec3(vertices.minPos.x, vertices.minPos.y, vertices.minPos.z),
|
||||
maxPos: new Vec3(vertices.maxPos.x, vertices.maxPos.y, vertices.maxPos.z),
|
||||
minPos: v3(vertices.minPos.x, vertices.minPos.y, vertices.minPos.z),
|
||||
maxPos: v3(vertices.maxPos.x, vertices.maxPos.y, vertices.maxPos.z),
|
||||
};
|
||||
}
|
||||
this.vertices.rawPosition.length = 0;
|
||||
const rawPosition = vertices.rawPosition;
|
||||
for (let i = 0; i < rawPosition.length; i += 3) {
|
||||
this.vertices.rawPosition.push(new Vec3(rawPosition[i], rawPosition[i + 1], rawPosition[i + 2]));
|
||||
this.vertices.rawPosition.push(v3(rawPosition[i], rawPosition[i + 1], rawPosition[i + 2]));
|
||||
}
|
||||
this._updateMeshVertices();
|
||||
}
|
||||
@@ -1470,7 +1470,7 @@ export class SpriteFrame extends Asset {
|
||||
const config: ISpriteFrameInitInfo = {};
|
||||
let isReset = false;
|
||||
if (this._rect.width === 0 || this._rect.height === 0 || !this.checkRect(tex)) {
|
||||
config.rect = new Rect(0, 0, tex.width, tex.height);
|
||||
config.rect = rect(0, 0, tex.width, tex.height);
|
||||
isReset = true;
|
||||
}
|
||||
|
||||
@@ -1479,7 +1479,7 @@ export class SpriteFrame extends Asset {
|
||||
|| this._originalSize.height === 0
|
||||
|| isReset
|
||||
) {
|
||||
config.originalSize = new Size(tex.width, tex.height);
|
||||
config.originalSize = size(tex.width, tex.height);
|
||||
isReset = true;
|
||||
}
|
||||
|
||||
@@ -1534,8 +1534,8 @@ export class SpriteFrame extends Asset {
|
||||
indexes: [],
|
||||
uv: [],
|
||||
nuv: [],
|
||||
minPos: new Vec3(),
|
||||
maxPos: new Vec3(),
|
||||
minPos: v3(),
|
||||
maxPos: v3(),
|
||||
};
|
||||
} else {
|
||||
this.vertices.rawPosition.length = 0;
|
||||
@@ -1614,7 +1614,7 @@ export class SpriteFrame extends Asset {
|
||||
const units = 1 / this._pixelsToUnit;
|
||||
const PosX = -(this._pivot.x - 0.5) * this.rect.width * units;
|
||||
const PosY = -(this._pivot.y - 0.5) * this.rect.height * units;
|
||||
const temp_vec3 = new Vec3(PosX, PosY, 0);
|
||||
const temp_vec3 = v3(PosX, PosY, 0);
|
||||
temp_matrix.transform(temp_vec3);
|
||||
temp_vec3.set(units, units, 1);
|
||||
temp_matrix.scale(temp_vec3);
|
||||
|
||||
@@ -39,6 +39,10 @@ export class TTFFont extends Font {
|
||||
@serializable
|
||||
public _fontFamily: string | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
|
||||
*/
|
||||
@@ -60,7 +64,7 @@ export class TTFFont extends Font {
|
||||
__nativeName__: string;
|
||||
ext: string;
|
||||
__isNative__: boolean;
|
||||
} {
|
||||
} {
|
||||
return { uuid: this._uuid, __nativeName__: this._native, ext: path.extname(this._native), __isNative__: true };
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
import { ccclass, help, executionOrder, menu, tooltip, displayOrder,
|
||||
type, visible, serializable, range, slide, executeInEditMode } from 'cc.decorator';
|
||||
import { JSB } from 'internal:constants';
|
||||
import { clamp, Color, Mat4, Vec2, Vec3, warnID, cclegacy, ccenum, error } from '../../core';
|
||||
import { clamp, Color, Mat4, Vec2, Vec3, warnID, cclegacy, ccenum, errorID } from '../../core';
|
||||
import { Graphics } from './graphics';
|
||||
import { TransformBit } from '../../scene-graph/node-enum';
|
||||
import { Stage } from '../renderer/stencil-manager';
|
||||
@@ -121,6 +121,10 @@ export class Mask extends Component {
|
||||
*/
|
||||
public static Type = MaskType;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The mask type.
|
||||
@@ -230,7 +234,7 @@ export class Mask extends Component {
|
||||
if (this._sprite) {
|
||||
this._sprite.spriteFrame = value;
|
||||
} else {
|
||||
error('please change type to sprite_stencil first');
|
||||
errorID(16307);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -508,14 +508,11 @@ export class RichText extends Component {
|
||||
protected _labelHeight = 0;
|
||||
protected _layoutDirty = true;
|
||||
protected _lineOffsetX = 0;
|
||||
protected _updateRichTextStatus: () => void;
|
||||
protected declare _updateRichTextStatus: () => void;
|
||||
protected _labelChildrenNum = 0; // only ISegment
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
if (EDITOR) {
|
||||
this._userDefinedFont = null;
|
||||
}
|
||||
this._updateRichTextStatus = this._updateRichText;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import { ccclass, help, executionOrder, menu, tooltip, displayOrder, type, range
|
||||
import { BUILD, EDITOR } from 'internal:constants';
|
||||
import { SpriteAtlas } from '../assets/sprite-atlas';
|
||||
import { SpriteFrame } from '../assets/sprite-frame';
|
||||
import { Vec2, cclegacy, ccenum, clamp, warn } from '../../core';
|
||||
import { Vec2, cclegacy, ccenum, clamp, warnID } from '../../core';
|
||||
import { IBatcher } from '../renderer/i-batcher';
|
||||
import { UIRenderer, InstanceMaterialType } from '../framework/ui-renderer';
|
||||
import { PixelFormat } from '../../asset/assets/asset-enum';
|
||||
@@ -167,6 +167,10 @@ enum EventType {
|
||||
@executionOrder(110)
|
||||
@menu('2D/Sprite')
|
||||
export class Sprite extends UIRenderer {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The sprite atlas where the sprite is.
|
||||
@@ -526,7 +530,7 @@ export class Sprite extends UIRenderer {
|
||||
*/
|
||||
public changeSpriteFrameFromAtlas (name: string): void {
|
||||
if (!this._atlas) {
|
||||
warn('SpriteAtlas is null.');
|
||||
warnID(16377);
|
||||
return;
|
||||
}
|
||||
const sprite = this._atlas.getSpriteFrame(name);
|
||||
|
||||
@@ -34,7 +34,7 @@ import { NativeUIModelProxy } from '../renderer/native-2d';
|
||||
import { uiRendererManager } from '../framework/ui-renderer-manager';
|
||||
import { RenderEntity, RenderEntityType } from '../renderer/render-entity';
|
||||
import { MeshRenderData, RenderData } from '../renderer/render-data';
|
||||
import { assert, cclegacy, warn } from '../../core';
|
||||
import { assert, cclegacy, warnID } from '../../core';
|
||||
import { RenderDrawInfoType } from '../renderer/render-draw-info';
|
||||
import type { UIRenderer } from '../framework/ui-renderer';
|
||||
|
||||
@@ -101,7 +101,7 @@ export class UIMeshRenderer extends Component {
|
||||
|
||||
this._modelComponent = this.getComponent('cc.ModelRenderer') as ModelRenderer;
|
||||
if (!this._modelComponent) {
|
||||
warn(`node '${this.node && this.node.name}' doesn't have any renderable component`);
|
||||
warnID(16378, this.node ? this.node.name : '');
|
||||
return;
|
||||
}
|
||||
if (JSB) {
|
||||
|
||||
@@ -46,6 +46,10 @@ import { NodeEventType } from '../../scene-graph/node-event';
|
||||
@executeInEditMode
|
||||
@disallowMultiple
|
||||
export class UIOpacity extends Component {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The parent node's opacity.
|
||||
|
||||
@@ -55,6 +55,10 @@ import type { Batcher2D } from '../renderer/batcher-2d';
|
||||
@menu('2D/UIStaticBatch')
|
||||
@executionOrder(110)
|
||||
export class UIStaticBatch extends UIRenderer {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
@override
|
||||
@visible(false)
|
||||
get color (): Readonly<Color> {
|
||||
|
||||
@@ -132,7 +132,7 @@ class PointerEventDispatcher implements IEventDispatcher {
|
||||
for (let i = 0; i < length; ++i) {
|
||||
const pointerEventProcessor = pointerEventProcessorList[i];
|
||||
if (pointerEventProcessor.isEnabled && pointerEventProcessor.shouldHandleEventTouch) {
|
||||
if (eventTouch.type === InputEventType.TOUCH_START) {
|
||||
if (eventTouch.type === InputEventType.TOUCH_START as string) {
|
||||
if (pointerEventProcessor._handleEventTouch(eventTouch)) {
|
||||
// pointerEventProcessor may be disabled in handling touch event above.
|
||||
if (pointerEventProcessor.isEnabled) {
|
||||
@@ -155,7 +155,7 @@ class PointerEventDispatcher implements IEventDispatcher {
|
||||
const index = pointerEventProcessor.claimedTouchIdList.indexOf(touch.getID());
|
||||
if (index !== -1) {
|
||||
pointerEventProcessor._handleEventTouch(eventTouch);
|
||||
if (eventTouch.type === InputEventType.TOUCH_END || eventTouch.type === InputEventType.TOUCH_CANCEL) {
|
||||
if (eventTouch.type === (InputEventType.TOUCH_END as string) || eventTouch.type === (InputEventType.TOUCH_CANCEL as string)) {
|
||||
js.array.removeAt(pointerEventProcessor.claimedTouchIdList, index);
|
||||
// The event is handled, so should remove other EventProcessor's claimedTouchIdList.
|
||||
this._removeClaimedTouch(i + 1, index);
|
||||
|
||||
@@ -31,7 +31,6 @@ import { Widget } from '../../ui/widget';
|
||||
import { Vec3, screen, Enum, cclegacy, visibleRect } from '../../core';
|
||||
import { view } from '../../ui/view';
|
||||
import { RenderRoot2D } from './render-root-2d';
|
||||
import { NodeEventType } from '../../scene-graph/node-event';
|
||||
|
||||
const _worldPos = new Vec3();
|
||||
|
||||
@@ -122,9 +121,9 @@ export class Canvas extends RenderRoot2D {
|
||||
@serializable
|
||||
protected _alignCanvasWithScreen = true;
|
||||
|
||||
protected _thisOnCameraResized: () => void;
|
||||
protected declare _thisOnCameraResized: () => void;
|
||||
// fit canvas node to design resolution
|
||||
protected fitDesignResolution_EDITOR: (() => void) | undefined;
|
||||
protected declare fitDesignResolution_EDITOR: (() => void) | undefined;
|
||||
|
||||
private _pos = new Vec3();
|
||||
private _renderMode = RenderMode.OVERLAY;
|
||||
|
||||
@@ -49,6 +49,10 @@ enum SpriteMode {
|
||||
@menu('2D/SpriteRenderer')
|
||||
@executeInEditMode
|
||||
export class SpriteRenderer extends ModelRenderer {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The spriteFrame that the component should render.
|
||||
* @zh 该组件应渲染的 spriteFrame。
|
||||
|
||||
@@ -44,6 +44,10 @@ import { Stage } from '../renderer/stencil-manager';
|
||||
export class UIComponent extends Component {
|
||||
protected _lastParent: Node | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public __preload (): void {
|
||||
// TODO: UIComponent should not be assigned to UIMeshRenderer | UIRenderer @holycanvas
|
||||
// workaround: mark this as any
|
||||
|
||||
@@ -262,7 +262,7 @@ export class UIRenderer extends Renderer {
|
||||
protected _renderDataFlag = true;
|
||||
protected _renderFlag = true;
|
||||
|
||||
protected _renderEntity: RenderEntity;
|
||||
protected declare _renderEntity: RenderEntity;
|
||||
|
||||
protected _instanceMaterialType = -1;
|
||||
protected _srcBlendFactorCache = BlendFactor.SRC_ALPHA;
|
||||
|
||||
@@ -53,6 +53,10 @@ const _rect = new Rect();
|
||||
@disallowMultiple
|
||||
@executeInEditMode
|
||||
export class UITransform extends Component {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Size of the UI node.
|
||||
|
||||
@@ -28,7 +28,8 @@ import type { UIStaticBatch } from '../components/ui-static-batch';
|
||||
import { Material } from '../../asset/assets/material';
|
||||
import { RenderRoot2D, UIRenderer } from '../framework';
|
||||
import { Texture, Device, Attribute, Sampler, DescriptorSetInfo, Buffer,
|
||||
BufferInfo, BufferUsageBit, MemoryUsageBit, DescriptorSet, InputAssembler, deviceManager, PrimitiveMode } from '../../gfx';
|
||||
BufferInfo, BufferUsageBit, MemoryUsageBit, DescriptorSet, InputAssembler, deviceManager, PrimitiveMode,
|
||||
DepthStencilState } from '../../gfx';
|
||||
import { CachedArray, Pool, Mat4, cclegacy, assertIsTrue, assert, approx, EPSILON } from '../../core';
|
||||
import { Root } from '../../root';
|
||||
import { Node } from '../../scene-graph';
|
||||
@@ -82,13 +83,13 @@ export class Batcher2D implements IBatcher {
|
||||
this._currIsStatic = value;
|
||||
}
|
||||
|
||||
public device: Device;
|
||||
public declare device: Device;
|
||||
private _screens: RenderRoot2D[] = [];
|
||||
private _staticVBBuffer: StaticVBAccessor | null = null;
|
||||
private _bufferAccessors: Map<number, StaticVBAccessor> = new Map();
|
||||
|
||||
private _drawBatchPool: Pool<DrawBatch2D>;
|
||||
private _batches: CachedArray<DrawBatch2D>;
|
||||
private declare _drawBatchPool: Pool<DrawBatch2D>;
|
||||
private declare _batches: CachedArray<DrawBatch2D>;
|
||||
private _currBID = -1;
|
||||
private _indexStart = 0;
|
||||
|
||||
@@ -457,7 +458,7 @@ export class Batcher2D implements IBatcher {
|
||||
this.autoMergeBatches(this._currComponent!);
|
||||
this.resetRenderStates();
|
||||
}
|
||||
let depthStencil;
|
||||
let depthStencil: DepthStencilState | null = null;
|
||||
let dssHash = 0;
|
||||
if (renderComp) {
|
||||
renderComp.stencilStage = StencilManager.sharedManager!.stage;
|
||||
@@ -557,7 +558,7 @@ export class Batcher2D implements IBatcher {
|
||||
this.resetRenderStates();
|
||||
}
|
||||
|
||||
let depthStencil;
|
||||
let depthStencil: DepthStencilState | null = null;
|
||||
let dssHash = 0;
|
||||
if (mat) {
|
||||
// Notice: A little hack, if it is for mask, not need update here, while control by stencilManger
|
||||
@@ -672,7 +673,7 @@ export class Batcher2D implements IBatcher {
|
||||
return;
|
||||
}
|
||||
|
||||
let depthStencil;
|
||||
let depthStencil: DepthStencilState | null = null;
|
||||
let dssHash = 0;
|
||||
if (renderComp) {
|
||||
if (renderComp.customMaterial !== null) {
|
||||
@@ -697,7 +698,7 @@ export class Batcher2D implements IBatcher {
|
||||
}
|
||||
|
||||
private mergeBatchesForMiddleware (renderComp: UIRenderer): void {
|
||||
let depthStencil;
|
||||
let depthStencil: DepthStencilState | null = null;
|
||||
let dssHash = 0;
|
||||
renderComp.stencilStage = StencilManager.sharedManager!.stage;
|
||||
if (renderComp.customMaterial !== null) {
|
||||
@@ -915,7 +916,7 @@ export class Batcher2D implements IBatcher {
|
||||
_stencilManager.pushMask(1);//not need object,only use length
|
||||
const stage = _stencilManager.clear(comp); //invert
|
||||
|
||||
let depthStencil;
|
||||
let depthStencil: DepthStencilState | null = null;
|
||||
let dssHash = 0;
|
||||
const mat = this._maskClearMtl;
|
||||
if (mat) {
|
||||
@@ -1062,7 +1063,7 @@ class DescriptorSetCache {
|
||||
private _descriptorSetCache = new Map<number, DescriptorSet>();
|
||||
private _dsCacheHashByTexture = new Map<number, number>();
|
||||
private _localDescriptorSetCache: LocalDescriptorSet[] = [];
|
||||
private _localCachePool: Pool<LocalDescriptorSet>;
|
||||
private declare _localCachePool: Pool<LocalDescriptorSet>;
|
||||
|
||||
constructor () {
|
||||
this._localCachePool = new Pool(() => new LocalDescriptorSet(), 16, (obj) => obj.destroy());
|
||||
|
||||
@@ -31,10 +31,10 @@ export class BufferAccessor {
|
||||
public get vertexFormatBytes (): number { return this._vertexFormatBytes; }
|
||||
public get floatsPerVertex (): number { return this._floatsPerVertex; }
|
||||
|
||||
protected _device: Device = null!
|
||||
protected _attributes: Attribute[] = null!;
|
||||
protected _vertexFormatBytes: number;
|
||||
protected _floatsPerVertex: number;
|
||||
protected declare _device: Device;
|
||||
protected declare _attributes: Attribute[];
|
||||
protected declare _vertexFormatBytes: number;
|
||||
protected declare _floatsPerVertex: number;
|
||||
protected _buffers: MeshBuffer[] = [];
|
||||
|
||||
constructor (device: Device, attributes: Attribute[]) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import { DrawBatch2D } from './draw-batch';
|
||||
import { markAsWarning, replaceProperty, removeProperty, warnID } from '../../core';
|
||||
import { MeshBuffer } from './mesh-buffer';
|
||||
import { MeshRenderData } from './render-data';
|
||||
import { Attribute } from '../../gfx/base/define';
|
||||
|
||||
export { VertexFormat as UIVertexFormat };
|
||||
|
||||
@@ -42,7 +43,9 @@ export { UIDrawBatch };
|
||||
class UIDrawBatch extends DrawBatch2D {
|
||||
}
|
||||
|
||||
markAsWarning(MeshBuffer.prototype, 'MeshBuffer',
|
||||
markAsWarning(
|
||||
MeshBuffer.prototype,
|
||||
'MeshBuffer',
|
||||
[
|
||||
'byteStart',
|
||||
'vertexStart',
|
||||
@@ -51,7 +54,8 @@ markAsWarning(MeshBuffer.prototype, 'MeshBuffer',
|
||||
].map((item) => ({
|
||||
name: item,
|
||||
suggest: `please use meshBuffer.accessor.${item} instead`,
|
||||
})));
|
||||
})),
|
||||
);
|
||||
|
||||
replaceProperty(MeshBuffer.prototype, 'MeshBuffer', [
|
||||
{
|
||||
@@ -100,7 +104,7 @@ replaceProperty(MeshRenderData.prototype, 'MeshRenderData', [
|
||||
]);
|
||||
|
||||
export class QuadRenderData extends MeshRenderData {
|
||||
constructor (vertexFormat) {
|
||||
constructor (vertexFormat: Attribute[]) {
|
||||
super(vertexFormat);
|
||||
warnID(9006);
|
||||
}
|
||||
|
||||
@@ -23,13 +23,14 @@
|
||||
*/
|
||||
|
||||
import { Material } from '../../asset/assets/material';
|
||||
import { Texture, Sampler, InputAssembler, DescriptorSet, Shader } from '../../gfx';
|
||||
import { Texture, Sampler, InputAssembler, DescriptorSet, Shader, DepthStencilState } from '../../gfx';
|
||||
import { Node } from '../../scene-graph';
|
||||
import { Model } from '../../render-scene/scene/model';
|
||||
import { Layers } from '../../scene-graph/layers';
|
||||
import { cclegacy } from '../../core';
|
||||
import { Pass } from '../../render-scene/core/pass';
|
||||
import { IMacroPatch, Pass } from '../../render-scene/core/pass';
|
||||
import { IBatcher } from './i-batcher';
|
||||
import type { Root } from '../../root';
|
||||
|
||||
const UI_VIS_FLAG = Layers.Enum.NONE | Layers.Enum.UI_3D;
|
||||
export class DrawBatch2D {
|
||||
@@ -102,7 +103,7 @@ export class DrawBatch2D {
|
||||
}
|
||||
|
||||
// object version
|
||||
public fillPasses (mat: Material | null, dss, dssHash, patches): void {
|
||||
public fillPasses (mat: Material | null, dss: DepthStencilState | null, dssHash: number, patches: Readonly<IMacroPatch[] | null>): void {
|
||||
if (mat) {
|
||||
const passes = mat.passes;
|
||||
if (!passes) { return; }
|
||||
@@ -114,7 +115,7 @@ export class DrawBatch2D {
|
||||
|
||||
for (let i = 0; i < passes.length; i++) {
|
||||
if (!this._passes[i]) {
|
||||
this._passes[i] = new Pass(cclegacy.director.root);
|
||||
this._passes[i] = new Pass(cclegacy.director.root as Root);
|
||||
}
|
||||
const mtlPass = passes[i];
|
||||
const passInUse = this._passes[i];
|
||||
|
||||
@@ -558,8 +558,8 @@ export class MeshRenderData extends BaseRenderData {
|
||||
get vDataOffset (): number { return this._byteLength >>> 2; }
|
||||
|
||||
public _isMeshBuffer = true;
|
||||
public vData: Float32Array;
|
||||
public iData: Uint16Array;
|
||||
public declare vData: Float32Array;
|
||||
public declare iData: Uint16Array;
|
||||
/**
|
||||
* First vertex used in the current IA
|
||||
*/
|
||||
|
||||
@@ -81,13 +81,13 @@ export class RenderDrawInfo {
|
||||
protected _useLocal = false;
|
||||
|
||||
protected _model: Model | null = null;
|
||||
protected _drawInfoType :RenderDrawInfoType = RenderDrawInfoType.COMP;
|
||||
protected _drawInfoType: RenderDrawInfoType = RenderDrawInfoType.COMP;
|
||||
protected _subNode: Node | null = null;
|
||||
|
||||
protected declare _nativeObj: NativeRenderDrawInfo;
|
||||
protected _uint8SharedBuffer: Uint8Array;
|
||||
protected _uint16SharedBuffer: Uint16Array;
|
||||
protected _uint32SharedBuffer: Uint32Array;
|
||||
protected declare _uint8SharedBuffer: Uint8Array;
|
||||
protected declare _uint16SharedBuffer: Uint16Array;
|
||||
protected declare _uint32SharedBuffer: Uint32Array;
|
||||
|
||||
// SharedBuffer of pos/uv/color
|
||||
protected declare _render2dBuffer: Float32Array;
|
||||
@@ -276,7 +276,7 @@ export class RenderDrawInfo {
|
||||
this._drawInfoType = drawInfoType;
|
||||
}
|
||||
|
||||
public setSubNode (node : Node): void {
|
||||
public setSubNode (node: Node): void {
|
||||
if (JSB) {
|
||||
if (this._subNode !== node) {
|
||||
this._nativeObj.subNode = node;
|
||||
|
||||
@@ -47,7 +47,7 @@ export class StaticVBChunk {
|
||||
public get ib (): Readonly<Uint16Array> {
|
||||
return this._ib;
|
||||
}
|
||||
private _ib: Uint16Array;
|
||||
private declare _ib: Uint16Array;
|
||||
|
||||
constructor (
|
||||
public vertexAccessor: StaticVBAccessor,
|
||||
|
||||
@@ -112,7 +112,7 @@ export class StencilManager {
|
||||
zFailOp: StencilOp;
|
||||
passOp: StencilOp;
|
||||
ref: number;
|
||||
} {
|
||||
} {
|
||||
return this._stencilPattern;
|
||||
}
|
||||
|
||||
@@ -236,13 +236,13 @@ export class StencilManager {
|
||||
let depthWriteValue = 0;
|
||||
if (dss.depthTest) depthTestValue = 1;
|
||||
if (dss.depthWrite) depthWriteValue = 1;
|
||||
key = (depthTestValue) | (depthWriteValue << 1) | (dss.depthFunc << 2) | (stage << 6) | (this._maskStack.length << 9);
|
||||
key = (depthTestValue) | (depthWriteValue << 1) | ((dss.depthFunc as number) << 2) | ((stage as number) << 6) | (this._maskStack.length << 9);
|
||||
depthTest = dss.depthTest;
|
||||
depthWrite = dss.depthWrite;
|
||||
depthFunc = dss.depthFunc;
|
||||
cacheMap = this.stencilStateMapWithDepth;
|
||||
} else {
|
||||
key = (stage << 16) | this._maskStack.length;
|
||||
key = ((stage as number) << 16) | this._maskStack.length;
|
||||
}
|
||||
if (cacheMap && cacheMap.has(key)) {
|
||||
return cacheMap.get(key) as DepthStencilState;
|
||||
|
||||
@@ -23,11 +23,13 @@
|
||||
*/
|
||||
|
||||
import { EDITOR_NOT_IN_PREVIEW } from 'internal:constants';
|
||||
import { System, macro, js, cclegacy } from '../../../core';
|
||||
import { System, macro, cclegacy } from '../../../core';
|
||||
import { Atlas, DynamicAtlasTexture } from './atlas';
|
||||
import { director } from '../../../game';
|
||||
import { SpriteFrame } from '../../assets';
|
||||
import { Filter } from '../../../gfx/base/define';
|
||||
import { Filter } from '../../../gfx/base/define';
|
||||
import { TextureBase } from '../../../asset/assets/texture-base';
|
||||
import { Texture2D } from '../../../asset/assets';
|
||||
|
||||
/**
|
||||
* @en The dynamic atlas manager which manages all runtime dynamic packed atlas texture for UI rendering.
|
||||
@@ -53,6 +55,10 @@ export class DynamicAtlasManager extends System {
|
||||
|
||||
private _enabled = false;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Enable or disable the dynamic atlas.
|
||||
@@ -231,15 +237,15 @@ export class DynamicAtlasManager extends System {
|
||||
* @method deleteAtlasSpriteFrame
|
||||
* @param spriteFrame the sprite frame that will be removed from the atlas.
|
||||
*/
|
||||
public deleteAtlasSpriteFrame (spriteFrame): void {
|
||||
if (!spriteFrame._original) return;
|
||||
public deleteAtlasSpriteFrame (spriteFrame: SpriteFrame): void {
|
||||
if (!spriteFrame.original) return;
|
||||
|
||||
let atlas;
|
||||
let atlas: Atlas;
|
||||
for (let i = this._atlases.length - 1; i >= 0; i--) {
|
||||
atlas = this._atlases[i];
|
||||
js.array.fastRemove(atlas._innerSpriteFrames, spriteFrame);
|
||||
atlas.removeSpriteFrame(spriteFrame);
|
||||
}
|
||||
const texture = spriteFrame._original._texture;
|
||||
const texture = spriteFrame.original._texture;
|
||||
this.deleteAtlasTexture(texture);
|
||||
}
|
||||
|
||||
@@ -253,10 +259,10 @@ export class DynamicAtlasManager extends System {
|
||||
* @method deleteAtlasTexture
|
||||
* @param texture the texture that will be removed from the atlas.
|
||||
*/
|
||||
public deleteAtlasTexture (texture): void {
|
||||
public deleteAtlasTexture (texture: TextureBase): void {
|
||||
if (texture) {
|
||||
for (let i = this._atlases.length - 1; i >= 0; i--) {
|
||||
this._atlases[i].deleteInnerTexture(texture);
|
||||
this._atlases[i].deleteInnerTexture(texture as Texture2D);
|
||||
|
||||
if (this._atlases[i].isEmpty()) {
|
||||
this._atlases[i].destroy();
|
||||
@@ -277,10 +283,10 @@ export class DynamicAtlasManager extends System {
|
||||
* @method packToDynamicAtlas
|
||||
* @param frame the sprite frame that will be packed in the dynamic atlas.
|
||||
*/
|
||||
public packToDynamicAtlas (comp, frame): void {
|
||||
public packToDynamicAtlas (comp, frame: SpriteFrame | null): void {
|
||||
if (EDITOR_NOT_IN_PREVIEW || !this._enabled) return;
|
||||
|
||||
if (frame && !frame._original && frame.packable && frame.texture && frame.texture.width > 0 && frame.texture.height > 0) {
|
||||
if (frame && !frame.original && frame.packable && frame.texture && frame.texture.width > 0 && frame.texture.height > 0) {
|
||||
const packedFrame = this.insertSpriteFrame(frame);
|
||||
if (packedFrame) {
|
||||
frame._setDynamicAtlasFrame(packedFrame);
|
||||
|
||||
@@ -26,21 +26,25 @@ import { PixelFormat } from '../../../asset/assets/asset-enum';
|
||||
import { ImageAsset } from '../../../asset/assets/image-asset';
|
||||
import { Texture2D } from '../../../asset/assets/texture-2d';
|
||||
import { BufferTextureCopy } from '../../../gfx';
|
||||
import { cclegacy, warn } from '../../../core';
|
||||
import { cclegacy, js, warnID } from '../../../core';
|
||||
import { SpriteFrame } from '../../assets/sprite-frame';
|
||||
|
||||
const space = 2;
|
||||
|
||||
export class Atlas {
|
||||
private _texture: DynamicAtlasTexture;
|
||||
private _width: any;
|
||||
private _height: any;
|
||||
private _x: number;
|
||||
private _y: number;
|
||||
private _nextY: number;
|
||||
private _innerTextureInfos = {};
|
||||
private _innerSpriteFrames: SpriteFrame[];
|
||||
private _count: number;
|
||||
private declare _texture: DynamicAtlasTexture;
|
||||
private declare _width: number;
|
||||
private declare _height: number;
|
||||
private declare _x: number;
|
||||
private declare _y: number;
|
||||
private declare _nextY: number;
|
||||
private _innerTextureInfos: Record<string, {
|
||||
x: number,
|
||||
y: number,
|
||||
texture: Texture2D,
|
||||
}> = {};
|
||||
private _innerSpriteFrames: SpriteFrame[] = [];
|
||||
private _count: number = 0;
|
||||
|
||||
constructor (width: number, height: number) {
|
||||
const texture = new DynamicAtlasTexture();
|
||||
@@ -53,11 +57,6 @@ export class Atlas {
|
||||
this._x = space;
|
||||
this._y = space;
|
||||
this._nextY = space;
|
||||
|
||||
this._innerTextureInfos = {};
|
||||
this._innerSpriteFrames = [];
|
||||
|
||||
this._count = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,6 +144,10 @@ export class Atlas {
|
||||
return frame;
|
||||
}
|
||||
|
||||
public removeSpriteFrame (spriteFrame: SpriteFrame): void {
|
||||
js.array.fastRemove(this._innerSpriteFrames, spriteFrame);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Delete a texture from the atlas.
|
||||
@@ -254,7 +257,7 @@ export class DynamicAtlasTexture extends Texture2D {
|
||||
|
||||
const gfxDevice = this._getGFXDevice();
|
||||
if (!gfxDevice) {
|
||||
warn('Unable to get device');
|
||||
warnID(16363);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import { ImageAsset } from '../../asset/assets/image-asset';
|
||||
import { UBOMorph, UNIFORM_NORMAL_MORPH_TEXTURE_BINDING,
|
||||
UNIFORM_POSITION_MORPH_TEXTURE_BINDING, UNIFORM_TANGENT_MORPH_TEXTURE_BINDING } from '../../rendering/define';
|
||||
import { Morph, SubMeshMorph } from './morph';
|
||||
import { assertIsNonNullable, assertIsTrue, warn, bits, nextPow2, cclegacy } from '../../core';
|
||||
import { assertIsNonNullable, assertIsTrue, warn, bits, nextPow2, cclegacy, warnID } from '../../core';
|
||||
import { IMacroPatch } from '../../render-scene';
|
||||
import { PixelFormat } from '../../asset/assets/asset-enum';
|
||||
|
||||
@@ -100,7 +100,7 @@ export function createMorphRendering (mesh: Mesh, gfxDevice: Device): MorphRende
|
||||
* 每个子网格形变都使用自己独立的 [[MorphRenderingInstance]],它的形变目标权重、渲染管线状态和形变混合计算策略都是独立控制的。
|
||||
*/
|
||||
export class StdMorphRendering implements MorphRendering {
|
||||
private _mesh: Mesh;
|
||||
private declare _mesh: Mesh;
|
||||
private _subMeshRenderings: (SubMeshMorphRendering | null)[] = [];
|
||||
|
||||
constructor (mesh: Mesh, gfxDevice: Device) {
|
||||
@@ -230,17 +230,17 @@ interface SubMeshMorphRenderingInstance {
|
||||
* Target displacements of each attribute are transferred through vertex texture, say, morph texture.
|
||||
*/
|
||||
class GpuComputing implements SubMeshMorphRendering {
|
||||
private _gfxDevice: Device;
|
||||
private _subMeshMorph: SubMeshMorph;
|
||||
private _textureInfo: {
|
||||
private declare _gfxDevice: Device;
|
||||
private declare _subMeshMorph: SubMeshMorph;
|
||||
private declare _textureInfo: {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
private _attributes: {
|
||||
private declare _attributes: {
|
||||
name: string;
|
||||
morphTexture: MorphTexture;
|
||||
}[];
|
||||
private _verticesCount: number;
|
||||
private declare _verticesCount: number;
|
||||
|
||||
constructor (mesh: Mesh, subMeshIndex: number, morph: Morph, gfxDevice: Device) {
|
||||
this._gfxDevice = gfxDevice;
|
||||
@@ -299,7 +299,7 @@ class GpuComputing implements SubMeshMorphRendering {
|
||||
requiredPatches: () => IMacroPatch[];
|
||||
adaptPipelineState: (descriptorSet: DescriptorSet) => void;
|
||||
destroy: () => void;
|
||||
} {
|
||||
} {
|
||||
const morphUniforms = new MorphUniforms(this._gfxDevice, this._subMeshMorph.targets.length);
|
||||
morphUniforms.setMorphTextureInfo(this._textureInfo.width, this._textureInfo.height);
|
||||
morphUniforms.setVerticesCount(this._verticesCount);
|
||||
@@ -320,7 +320,7 @@ class GpuComputing implements SubMeshMorphRendering {
|
||||
case AttributeName.ATTR_NORMAL: binding = UNIFORM_NORMAL_MORPH_TEXTURE_BINDING; break;
|
||||
case AttributeName.ATTR_TANGENT: binding = UNIFORM_TANGENT_MORPH_TEXTURE_BINDING; break;
|
||||
default:
|
||||
warn('Unexpected attribute!'); break;
|
||||
warnID(16374); break;
|
||||
}
|
||||
if (binding !== undefined) {
|
||||
descriptorSet.bindSampler(binding, attribute.morphTexture.sampler);
|
||||
@@ -344,7 +344,7 @@ class GpuComputing implements SubMeshMorphRendering {
|
||||
* The displacements, then, are passed to GPU.
|
||||
*/
|
||||
class CpuComputing implements SubMeshMorphRendering {
|
||||
private _gfxDevice: Device;
|
||||
private declare _gfxDevice: Device;
|
||||
private _attributes: {
|
||||
name: string;
|
||||
targets: {
|
||||
@@ -390,12 +390,12 @@ class CpuComputing implements SubMeshMorphRendering {
|
||||
}
|
||||
}
|
||||
class CpuComputingRenderingInstance implements SubMeshMorphRenderingInstance {
|
||||
private _attributes: {
|
||||
private declare _attributes: {
|
||||
attributeName: string;
|
||||
morphTexture: MorphTexture;
|
||||
}[];
|
||||
private _owner: CpuComputing;
|
||||
private _morphUniforms: MorphUniforms;
|
||||
private declare _owner: CpuComputing;
|
||||
private declare _morphUniforms: MorphUniforms;
|
||||
|
||||
public constructor (owner: CpuComputing, nVertices: number, gfxDevice: Device) {
|
||||
this._owner = owner;
|
||||
@@ -459,7 +459,7 @@ class CpuComputingRenderingInstance implements SubMeshMorphRenderingInstance {
|
||||
case AttributeName.ATTR_NORMAL: binding = UNIFORM_NORMAL_MORPH_TEXTURE_BINDING; break;
|
||||
case AttributeName.ATTR_TANGENT: binding = UNIFORM_TANGENT_MORPH_TEXTURE_BINDING; break;
|
||||
default:
|
||||
warn('Unexpected attribute!'); break;
|
||||
warnID(16374); break;
|
||||
}
|
||||
if (binding !== undefined) {
|
||||
descriptorSet.bindSampler(binding, attribute.morphTexture.sampler);
|
||||
@@ -483,9 +483,9 @@ class CpuComputingRenderingInstance implements SubMeshMorphRenderingInstance {
|
||||
* Provides the access to morph related uniforms.
|
||||
*/
|
||||
class MorphUniforms {
|
||||
private _targetCount: number;
|
||||
private _localBuffer: DataView;
|
||||
private _remoteBuffer: Buffer;
|
||||
private declare _targetCount: number;
|
||||
private declare _localBuffer: DataView;
|
||||
private declare _remoteBuffer: Buffer;
|
||||
|
||||
constructor (gfxDevice: Device, targetCount: number) {
|
||||
this._targetCount = targetCount;
|
||||
@@ -508,18 +508,21 @@ class MorphUniforms {
|
||||
|
||||
public setWeights (weights: number[]): void {
|
||||
assertIsTrue(weights.length === this._targetCount);
|
||||
const isLittleEndian = cclegacy.sys.isLittleEndian as boolean;
|
||||
for (let iWeight = 0; iWeight < weights.length; ++iWeight) {
|
||||
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_WEIGHTS + 4 * iWeight, weights[iWeight], cclegacy.sys.isLittleEndian);
|
||||
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_WEIGHTS + 4 * iWeight, weights[iWeight], isLittleEndian);
|
||||
}
|
||||
}
|
||||
|
||||
public setMorphTextureInfo (width: number, height: number): void {
|
||||
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_DISPLACEMENT_TEXTURE_WIDTH, width, cclegacy.sys.isLittleEndian);
|
||||
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_DISPLACEMENT_TEXTURE_HEIGHT, height, cclegacy.sys.isLittleEndian);
|
||||
const isLittleEndian = cclegacy.sys.isLittleEndian as boolean;
|
||||
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_DISPLACEMENT_TEXTURE_WIDTH, width, isLittleEndian);
|
||||
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_DISPLACEMENT_TEXTURE_HEIGHT, height, isLittleEndian);
|
||||
}
|
||||
|
||||
public setVerticesCount (count: number): void {
|
||||
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_VERTICES_COUNT, count, cclegacy.sys.isLittleEndian);
|
||||
const isLittleEndian = cclegacy.sys.isLittleEndian as boolean;
|
||||
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_VERTICES_COUNT, count, isLittleEndian);
|
||||
}
|
||||
|
||||
public commit (): void {
|
||||
@@ -585,7 +588,7 @@ function createVec4TextureFactory (gfxDevice: Device, vec4Capacity: number): {
|
||||
textureAsset.setWrapMode(Texture2D.WrapMode.CLAMP_TO_EDGE, Texture2D.WrapMode.CLAMP_TO_EDGE, Texture2D.WrapMode.CLAMP_TO_EDGE);
|
||||
textureAsset.image = image;
|
||||
if (!textureAsset.getGFXTexture()) {
|
||||
warn('Unexpected: failed to create morph texture?');
|
||||
warnID(16375);
|
||||
}
|
||||
const sampler = gfxDevice.getSampler(textureAsset.getSamplerInfo());
|
||||
return {
|
||||
|
||||
@@ -146,6 +146,10 @@ class ModelBakeSettings extends EventTarget {
|
||||
public probeBlendCubemap: TextureCube | null = null;
|
||||
public probePlanarmap: Texture | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Whether the model is static and bake-able with light map.
|
||||
* Notice: the model's vertex data must have the second UV attribute to enable light map baking.
|
||||
@@ -304,7 +308,7 @@ export class MeshRenderer extends ModelRenderer {
|
||||
@editable
|
||||
@disallowAnimation
|
||||
@displayOrder(3)
|
||||
public bakeSettings = new ModelBakeSettings(this);
|
||||
public bakeSettings = new ModelBakeSettings();
|
||||
|
||||
@serializable
|
||||
protected _mesh: Mesh | null = null;
|
||||
@@ -527,7 +531,7 @@ export class MeshRenderer extends ModelRenderer {
|
||||
this._enabledGlobalStandardSkinObject = false;
|
||||
}
|
||||
|
||||
protected _modelType: typeof scene.Model;
|
||||
protected _modelType: typeof scene.Model = scene.Model;
|
||||
|
||||
protected _model: scene.Model | null = null;
|
||||
|
||||
@@ -538,7 +542,6 @@ export class MeshRenderer extends ModelRenderer {
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
this._modelType = scene.Model;
|
||||
|
||||
const highQualityMode = settings.querySettings(Settings.Category.RENDERING, 'highQualityMode');
|
||||
if (highQualityMode) {
|
||||
|
||||
@@ -39,13 +39,17 @@ export class MorphModel extends Model {
|
||||
private _morphRenderingInstance: MorphRenderingInstance | null = null;
|
||||
private _usedMaterials = new Set<Material>();
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Acquire the material's macro patches for the given sub model.
|
||||
* @zh 获取指定子模型的材质宏组合。
|
||||
* @param subModelIndex @en The index for the requested sub model. @zh 子模型的序号。
|
||||
* @returns @en The macro patches. @zh 材质宏组合
|
||||
*/
|
||||
public getMacroPatches (subModelIndex: number) : IMacroPatch[] | null {
|
||||
public getMacroPatches (subModelIndex: number): IMacroPatch[] | null {
|
||||
const superMacroPatches = super.getMacroPatches(subModelIndex);
|
||||
if (this._morphRenderingInstance) {
|
||||
const morphInstanceMacroPatches = this._morphRenderingInstance.requiredPatches(subModelIndex);
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
*/
|
||||
import { BUILD, EDITOR, PREVIEW } from 'internal:constants';
|
||||
import { Asset } from '../assets/asset';
|
||||
import { error, cclegacy } from '../../core';
|
||||
import { error, cclegacy, errorID } from '../../core';
|
||||
import packManager from './pack-manager';
|
||||
import parser from './parser';
|
||||
import { Pipeline } from './pipeline';
|
||||
@@ -183,7 +183,7 @@ function loadDepends (task: Task, asset: Asset, done: ((err?: Error | null) => v
|
||||
if (asset.addRef) {
|
||||
asset.addRef();
|
||||
}
|
||||
getDepends(uuid, asset, Object.create(null), depends, config!);
|
||||
getDepends(uuid, asset, Object.create(null) as Record<string, any>, depends, config!);
|
||||
if (progress.canInvoke) {
|
||||
task.dispatch('progress', ++progress.finish, progress.total += depends.length, item);
|
||||
}
|
||||
@@ -218,7 +218,7 @@ function loadDepends (task: Task, asset: Asset, done: ((err?: Error | null) => v
|
||||
onLoadedInvokedMap.add(asset);
|
||||
}
|
||||
} catch (e) {
|
||||
error(`The asset ${uuid} is invalid for some reason, detail message: ${(e as Error).message}, stack: ${(e as Error).stack!}`);
|
||||
errorID(16352, uuid, (e as Error).message, (e as Error).stack!);
|
||||
if (EDITOR || PREVIEW) {
|
||||
if (asset instanceof Asset) {
|
||||
asset.initDefault();
|
||||
@@ -235,7 +235,7 @@ function loadDepends (task: Task, asset: Asset, done: ((err?: Error | null) => v
|
||||
error(`The asset ${uuid} is invalid for some reason and will be reverted to default asset, please check it out!`);
|
||||
asset.initDefault();
|
||||
}
|
||||
cache(uuid, asset, cacheAsset);
|
||||
cache(uuid, asset, cacheAsset as boolean);
|
||||
subTask.recycle();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { Asset } from '../assets/asset';
|
||||
import { cclegacy, error, js, misc } from '../../core';
|
||||
import { cclegacy, error, errorID, js, misc } from '../../core';
|
||||
import Config from './config';
|
||||
import { dependMap, nativeDependMap } from './depend-maps';
|
||||
import dependUtil from './depend-util';
|
||||
@@ -67,9 +67,15 @@ export function urlAppendTimestamp (url: string, append: boolean): string {
|
||||
return url;
|
||||
}
|
||||
|
||||
export type RetryFunction = (times: number, done: ((err: Error | null, data?: any | null) => void)) => void;
|
||||
export type RetryFunction = (times: number, done: ((err: Error | null, data?: any) => void)) => void;
|
||||
|
||||
export function retry (process: RetryFunction, times: number, wait: number, onComplete: ((err: Error | null, data?: any | null) => void), index = 0): void {
|
||||
export function retry (
|
||||
process: RetryFunction,
|
||||
times: number,
|
||||
wait: number,
|
||||
onComplete: ((err: Error | null, data?: any) => void),
|
||||
index = 0,
|
||||
): void {
|
||||
process(index, (err, result): void => {
|
||||
index++;
|
||||
if (!err || index > times) {
|
||||
@@ -84,8 +90,13 @@ export function retry (process: RetryFunction, times: number, wait: number, onCo
|
||||
});
|
||||
}
|
||||
|
||||
export function getDepends (uuid: string, data: Asset | Record<string, any>, exclude: Record<string, any>,
|
||||
depends: any[], config: Config): void {
|
||||
export function getDepends (
|
||||
uuid: string,
|
||||
data: Asset | Record<string, any>,
|
||||
exclude: Record<string, any>,
|
||||
depends: any[],
|
||||
config: Config,
|
||||
): void {
|
||||
try {
|
||||
const info = dependUtil.parse(uuid, data);
|
||||
for (let i = 0, l = info.deps.length; i < l; i++) {
|
||||
@@ -130,7 +141,7 @@ export function setProperties (uuid: string, asset: Asset, assetsMap: Record<str
|
||||
}
|
||||
missingAssetReporter.stashByOwner(depend.owner, depend.prop, EditorExtends.serialize.asAsset(depend.uuid));
|
||||
} else {
|
||||
error(`The asset ${depend.uuid} is missing!`);
|
||||
errorID(16350, depend.uuid);
|
||||
}
|
||||
cclegacy.assetManager.dispatchAssetMissing(asset, depend.owner, depend.prop, depend.uuid);
|
||||
if (depend.type && depend.type !== Asset) {
|
||||
@@ -143,7 +154,7 @@ export function setProperties (uuid: string, asset: Asset, assetsMap: Record<str
|
||||
} else {
|
||||
depend.owner[depend.prop] = dependAsset.addRef();
|
||||
if (EDITOR) {
|
||||
let reference = references!.get(dependAsset);
|
||||
let reference = references!.get(dependAsset as string);
|
||||
if (!reference || isScene(asset)) {
|
||||
reference = [];
|
||||
references!.add(depend.uuid, reference);
|
||||
@@ -164,7 +175,7 @@ export function setProperties (uuid: string, asset: Asset, assetsMap: Record<str
|
||||
asset._nativeAsset = assetsMap[`${uuid}@native`];
|
||||
} else {
|
||||
missingAsset = true;
|
||||
console.error(`the native asset of ${uuid} is missing!`);
|
||||
errorID(16351, uuid);
|
||||
}
|
||||
nativeDependMap.delete(asset);
|
||||
}
|
||||
@@ -192,7 +203,7 @@ export function forEach<T = any> (array: T[], process: ForEachFunction<T>, onCom
|
||||
if (length === 0 && onComplete) {
|
||||
onComplete(errs);
|
||||
}
|
||||
const cb = (err): void => {
|
||||
const cb = (err?: Error | null): void => {
|
||||
if (err) {
|
||||
errs.push(err);
|
||||
}
|
||||
@@ -220,10 +231,12 @@ interface ILoadResArgs<T> {
|
||||
onComplete: T | null;
|
||||
}
|
||||
|
||||
export function parseParameters<T extends (...args) => void> (
|
||||
export function parseParameters<T extends (
|
||||
...args) => void> (
|
||||
options: Record<string, any> | ((finished: number, total: number, item: RequestItem) => void) | T | null | undefined,
|
||||
onProgress: ((finished: number, total: number, item: RequestItem) => void) | T | null | undefined,
|
||||
onComplete: T | null | undefined): IParameters<T> {
|
||||
onComplete: T | null | undefined,
|
||||
): IParameters<T> {
|
||||
let optionsOut: any = options;
|
||||
let onProgressOut: any = onProgress;
|
||||
let onCompleteOut: any = onComplete;
|
||||
@@ -248,10 +261,12 @@ export function parseParameters<T extends (...args) => void> (
|
||||
return { options: optionsOut || Object.create(null), onProgress: onProgressOut, onComplete: onCompleteOut };
|
||||
}
|
||||
|
||||
export function parseLoadResArgs<T extends (...args) => void> (
|
||||
export function parseLoadResArgs<T extends (
|
||||
...args) => void> (
|
||||
type: Constructor<Asset> | ((finished: number, total: number, item: RequestItem) => void) | T | null | undefined,
|
||||
onProgress: ((finished: number, total: number, item: RequestItem) => void) | T | null | undefined,
|
||||
onComplete: T | null | undefined): ILoadResArgs<T> {
|
||||
onComplete: T | null | undefined,
|
||||
): ILoadResArgs<T> {
|
||||
let typeOut: any = type;
|
||||
let onProgressOut: any = onProgress;
|
||||
let onCompleteOut: any = onComplete;
|
||||
|
||||
@@ -37,6 +37,10 @@ import { Asset } from './asset';
|
||||
export class BufferAsset extends Asset {
|
||||
private _buffer: ArrayBuffer | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
|
||||
*/
|
||||
|
||||
@@ -325,6 +325,10 @@ export class EffectAsset extends Asset {
|
||||
@editorOnly
|
||||
public hideInEditor = false;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The loaded callback which should be invoked by the [[AssetManager]], will automatically register the effect.
|
||||
* @zh 通过 [[AssetManager]] 加载完成时的回调,将自动注册 effect 资源。
|
||||
|
||||
@@ -40,6 +40,10 @@ export default class JsonAsset extends Asset {
|
||||
@serializable
|
||||
@editable
|
||||
public json: Record<string, any> | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
cclegacy.JsonAsset = JsonAsset;
|
||||
|
||||
@@ -29,7 +29,7 @@ import { Texture, Type } from '../../gfx';
|
||||
import { TextureBase } from './texture-base';
|
||||
import { IPassInfoFull, Pass, PassOverrides } from '../../render-scene/core/pass';
|
||||
import { MacroRecord, MaterialProperty } from '../../render-scene/core/pass-utils';
|
||||
import { Color, warnID, Vec4, cclegacy, warn } from '../../core';
|
||||
import { Color, warnID, Vec4, cclegacy } from '../../core';
|
||||
import { SRGBToLinear } from '../../rendering/pipeline-funcs';
|
||||
import { Renderer } from '../../misc/renderer';
|
||||
import type { Root } from '../../root';
|
||||
@@ -251,7 +251,7 @@ export class Material extends Asset {
|
||||
* @param passIdx @en The pass to apply to. Will apply to all passes if not specified. @zh 要重编的 pass 索引,如果没有指定,则重编所有 pass。
|
||||
*/
|
||||
public recompileShaders (overrides: MacroRecord, passIdx?: number): void {
|
||||
warn(`Shaders in material asset '${this.name}' cannot be modified at runtime, please instantiate the material first.`);
|
||||
warnID(16370, this.name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,7 +261,7 @@ export class Material extends Asset {
|
||||
* @param passIdx The pass to apply to. Will apply to all passes if not specified.
|
||||
*/
|
||||
public overridePipelineStates (overrides: PassOverrides, passIdx?: number): void {
|
||||
warn(`Pipeline states in material asset '${this.name}' cannot be modified at runtime, please instantiate the material first.`);
|
||||
warnID(16371, this.name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -313,7 +313,9 @@ export class Material extends Asset {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (passIdx >= this._passes.length) { warn(`illegal pass index: ${passIdx}.`); return; }
|
||||
if (passIdx >= this._passes.length) {
|
||||
warnID(16372, passIdx);
|
||||
}
|
||||
const pass = this._passes[passIdx];
|
||||
if (this._uploadProperty(pass, name, val)) {
|
||||
this._props[pass.propertyIndex][name] = val;
|
||||
@@ -321,7 +323,7 @@ export class Material extends Asset {
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
warn(`illegal property name: ${name}.`);
|
||||
warnID(16373, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,7 +351,10 @@ export class Material extends Asset {
|
||||
if (name in props) { return props[name]; }
|
||||
}
|
||||
} else {
|
||||
if (passIdx >= this._passes.length) { warn(`illegal pass index: ${passIdx}.`); return null; }
|
||||
if (passIdx >= this._passes.length) {
|
||||
warnID(16372, passIdx);
|
||||
return null;
|
||||
}
|
||||
const props = this._props[this._passes[passIdx].propertyIndex];
|
||||
if (name in props) { return props[name]; }
|
||||
}
|
||||
|
||||
@@ -61,6 +61,9 @@ const _windowInfo: IRenderWindowInfo = {
|
||||
@ccclass('cc.RenderTexture')
|
||||
export class RenderTexture extends TextureBase {
|
||||
private _window: RenderWindow | null = null;
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The render window for the render pipeline, it's created internally and cannot be modified.
|
||||
@@ -221,7 +224,9 @@ export class RenderTexture extends TextureBase {
|
||||
* @param height @en The pixel height. @zh 像素高度。
|
||||
* @param buffer @en The buffer to hold pixel data. @zh 像素缓存。
|
||||
*/
|
||||
public readPixels (x = 0, y = 0, width?: number, height?: number, buffer?: Uint8Array): Uint8Array | null {
|
||||
public readPixels (x?: number, y?: number, width?: number, height?: number, buffer?: Uint8Array): Uint8Array | null {
|
||||
x = x || 0;
|
||||
y = y || 0;
|
||||
width = width || this.width;
|
||||
height = height || this.height;
|
||||
const gfxTexture = this.getGFXTexture();
|
||||
|
||||
@@ -110,17 +110,17 @@ export class RenderingSubMesh {
|
||||
|
||||
private _vertexBuffers: Buffer[];
|
||||
|
||||
private _attributes: Attribute[];
|
||||
private declare _attributes: Attribute[];
|
||||
|
||||
private _indexBuffer: Buffer | null = null;
|
||||
private declare _indexBuffer: Buffer | null;
|
||||
|
||||
private _indirectBuffer: Buffer | null = null;
|
||||
private declare _indirectBuffer: Buffer | null;
|
||||
|
||||
private _primitiveMode: PrimitiveMode;
|
||||
private declare _primitiveMode: PrimitiveMode;
|
||||
|
||||
private _iaInfo: InputAssemblerInfo;
|
||||
private declare _iaInfo: InputAssemblerInfo;
|
||||
|
||||
private _isOwnerOfIndexBuffer = true;
|
||||
private declare _isOwnerOfIndexBuffer: boolean;
|
||||
|
||||
private _drawInfo?: DrawInfo | null = null;
|
||||
|
||||
|
||||
@@ -43,6 +43,10 @@ export class SceneAsset extends Asset {
|
||||
@serializable
|
||||
public scene: Scene | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initDefault (uuid?: string): void {
|
||||
super.initDefault(uuid);
|
||||
this.scene = new Scene('New Scene');
|
||||
|
||||
@@ -81,6 +81,10 @@ export class SimpleTexture extends TextureBase {
|
||||
*/
|
||||
protected _maxLevel = 1000;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The mipmap level of the texture.
|
||||
* @zh 贴图中的 Mipmap 层级数量。
|
||||
|
||||
@@ -44,6 +44,10 @@ export class TextAsset extends Asset {
|
||||
public toString (): string {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
cclegacy.TextAsset = TextAsset;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
import { EDITOR, TEST } from 'internal:constants';
|
||||
import { ccclass, type } from 'cc.decorator';
|
||||
import { TextureType, TextureInfo, TextureViewInfo } from '../../gfx';
|
||||
import { Filter, PixelFormat } from './asset-enum';
|
||||
import { PixelFormat } from './asset-enum';
|
||||
import { ImageAsset } from './image-asset';
|
||||
import { PresumedGFXTextureInfo, PresumedGFXTextureViewInfo, SimpleTexture } from './simple-texture';
|
||||
import { js, cclegacy } from '../../core';
|
||||
@@ -83,6 +83,10 @@ export interface ITexture2DCreateInfo {
|
||||
*/
|
||||
@ccclass('cc.Texture2D')
|
||||
export class Texture2D extends SimpleTexture {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en All levels of mipmap images, be noted, automatically generated mipmaps are not included.
|
||||
* When setup mipmap, the size of the texture and pixel format could be modified.
|
||||
|
||||
@@ -139,7 +139,7 @@ export class TextureBase extends Asset {
|
||||
*/
|
||||
protected _height = 1;
|
||||
|
||||
private _id: string;
|
||||
private declare _id: string;
|
||||
private _samplerInfo = new SamplerInfo();
|
||||
private _gfxSampler: Sampler | null = null;
|
||||
private _gfxDevice: Device | null = null;
|
||||
|
||||
@@ -29,7 +29,7 @@ import { ImageAsset } from './image-asset';
|
||||
import { PresumedGFXTextureInfo, PresumedGFXTextureViewInfo, SimpleTexture } from './simple-texture';
|
||||
import { ITexture2DCreateInfo, Texture2D } from './texture-2d';
|
||||
import { legacyCC, ccwindow } from '../../core/global-exports';
|
||||
import { error, js, sys } from '../../core';
|
||||
import { errorID, js, sys } from '../../core';
|
||||
import { OS } from '../../../pal/system-info/enum-type';
|
||||
|
||||
export type ITextureCubeCreateInfo = ITexture2DCreateInfo;
|
||||
@@ -128,6 +128,10 @@ export class TextureCube extends SimpleTexture {
|
||||
@serializable
|
||||
_mipmapMode = MipmapMode.NONE;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en All levels of mipmap images, be noted, automatically generated mipmaps are not included.
|
||||
* When setup mipmap, the size of the texture and pixel format could be modified.
|
||||
@@ -156,7 +160,7 @@ export class TextureCube extends SimpleTexture {
|
||||
|| front.length !== right.length
|
||||
|| front.length !== top.length
|
||||
|| front.length !== bottom.length) {
|
||||
error('The number of mipmaps of each face is different.');
|
||||
errorID(16347);
|
||||
this._setMipmapParams([]);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,9 @@ const REAL_KEYFRAME_VALUE_DEFAULT_FLAGS = (RealInterpolationMode.LINEAR << REAL_
|
||||
* 注意,该视图可能因关键帧的添加、改变、移除而失效。
|
||||
*/
|
||||
class RealKeyframeValue extends EditorExtendable {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* @en
|
||||
* When perform interpolation, the interpolation method should be taken
|
||||
@@ -164,7 +167,8 @@ class RealKeyframeValue extends EditorExtendable {
|
||||
|
||||
CCClass.fastDefine(
|
||||
'cc.RealKeyframeValue',
|
||||
RealKeyframeValue, {
|
||||
RealKeyframeValue,
|
||||
{
|
||||
interpolationMode: RealInterpolationMode.LINEAR,
|
||||
tangentWeightMode: TangentWeightMode.NONE,
|
||||
value: 0.0,
|
||||
@@ -314,6 +318,10 @@ function createRealKeyframeValue (params: RealKeyframeValueParameters): RealKeyf
|
||||
* 无意义意味着这些值可能不会被存储或序列化。
|
||||
*/
|
||||
export class RealCurve extends KeyframeCurve<RealKeyframeValue> {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets or sets the pre-extrapolation-mode of this curve.
|
||||
@@ -556,8 +564,10 @@ export class RealCurve extends KeyframeCurve<RealKeyframeValue> {
|
||||
const nKeyframes = dataView.getUint32(currentOffset, true); currentOffset += FRAME_COUNT_BYTES;
|
||||
|
||||
// Times
|
||||
const times = Array.from({ length: nKeyframes },
|
||||
(_, index) => dataView.getFloat32(currentOffset + TIME_BYTES * index, true));
|
||||
const times = Array.from(
|
||||
{ length: nKeyframes },
|
||||
(_, index) => dataView.getFloat32(currentOffset + TIME_BYTES * index, true),
|
||||
);
|
||||
currentOffset += TIME_BYTES * nKeyframes;
|
||||
|
||||
// Frame values
|
||||
|
||||
@@ -140,6 +140,9 @@ function createQuatKeyframeValue (params: QuatKeyframeValueParameters): QuatKeyf
|
||||
*/
|
||||
@ccclass('cc.QuatCurve')
|
||||
export class QuatCurve extends KeyframeCurve<QuatKeyframeValue> {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* @en
|
||||
* Gets or sets the pre-extrapolation-mode of this curve.
|
||||
@@ -320,11 +323,9 @@ export class QuatCurve extends KeyframeCurve<QuatKeyframeValue> {
|
||||
|
||||
const nFrames = nKeyframes;
|
||||
const interpolationModesSize = INTERPOLATION_MODE_BYTES * (interpolationModeRepeated ? 1 : nFrames);
|
||||
const easingMethodsSize = keyframeValues.reduce(
|
||||
(result, { easingMethod }) => result += (Array.isArray(easingMethod)
|
||||
? EASING_METHOD_BYTES + (EASING_METHOD_BEZIER_COMPONENT_BYTES * 4)
|
||||
: EASING_METHOD_BYTES), 0,
|
||||
);
|
||||
const easingMethodsSize = keyframeValues.reduce((result, { easingMethod }) => result += (Array.isArray(easingMethod)
|
||||
? EASING_METHOD_BYTES + (EASING_METHOD_BEZIER_COMPONENT_BYTES * 4)
|
||||
: EASING_METHOD_BYTES), 0);
|
||||
|
||||
let dataSize = 0;
|
||||
dataSize += (
|
||||
@@ -413,13 +414,16 @@ export class QuatCurve extends KeyframeCurve<QuatKeyframeValue> {
|
||||
const nFrames = dataView.getUint32(P, true); P += FRAME_COUNT_BYTES;
|
||||
|
||||
// Times
|
||||
const times = Array.from({ length: nFrames },
|
||||
(_, index) => dataView.getFloat32(P + TIME_BYTES * index, true));
|
||||
const times = Array.from(
|
||||
{ length: nFrames },
|
||||
(_, index) => dataView.getFloat32(P + TIME_BYTES * index, true),
|
||||
);
|
||||
P += TIME_BYTES * nFrames;
|
||||
|
||||
// Frame values
|
||||
const P_VALUES = P; P += VALUE_BYTES * 4 * nFrames;
|
||||
const keyframeValues = Array.from({ length: nFrames },
|
||||
const keyframeValues = Array.from(
|
||||
{ length: nFrames },
|
||||
(_, index) => {
|
||||
const pQuat = P_VALUES + VALUE_BYTES * 4 * index;
|
||||
const x = dataView.getFloat32(pQuat + VALUE_BYTES * 0, true);
|
||||
@@ -443,7 +447,8 @@ export class QuatCurve extends KeyframeCurve<QuatKeyframeValue> {
|
||||
P += EASING_METHOD_BEZIER_COMPONENT_BYTES * 4;
|
||||
}
|
||||
return keyframeValue;
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
if (interpolationModeRepeated) {
|
||||
const interpolationMode = dataView.getUint8(P);
|
||||
|
||||
@@ -193,8 +193,8 @@ class CCObject implements EditorExtendableObject {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public _objFlags: number;
|
||||
protected _name: string;
|
||||
public _objFlags: number = 0;
|
||||
protected declare _name: string;
|
||||
|
||||
constructor (name = '') {
|
||||
/**
|
||||
@@ -203,12 +203,6 @@ class CCObject implements EditorExtendableObject {
|
||||
*/
|
||||
this._name = name;
|
||||
|
||||
/**
|
||||
* @default 0
|
||||
* @private
|
||||
*/
|
||||
this._objFlags = 0;
|
||||
|
||||
if (EDITOR) {
|
||||
// See cocos/cocos-engine#15392
|
||||
this[editorExtrasTag] = {};
|
||||
|
||||
@@ -95,9 +95,9 @@ export function setClassAttr (ctor, propName, key, value): void {
|
||||
}
|
||||
|
||||
export class PrimitiveType<T> {
|
||||
public name: string;
|
||||
public declare name: string;
|
||||
|
||||
public default: T;
|
||||
public declare default: T;
|
||||
|
||||
constructor (name: string, defaultValue: T) {
|
||||
this.name = name;
|
||||
@@ -264,8 +264,12 @@ export function getObjTypeChecker_ET (typeCtor) {
|
||||
const defaultVal = legacyCC.Class.getDefault(defaultDef);
|
||||
if (!Array.isArray(defaultVal) && isChildClassOf(typeCtor, legacyCC.ValueType)) {
|
||||
const typename = getClassName(typeCtor);
|
||||
const info = formatStr('No need to specify the "type" of "%s.%s" because %s is a child class of ValueType.',
|
||||
getClassName(classCtor), mainPropName, typename);
|
||||
const info = formatStr(
|
||||
'No need to specify the "type" of "%s.%s" because %s is a child class of ValueType.',
|
||||
getClassName(classCtor),
|
||||
mainPropName,
|
||||
typename,
|
||||
);
|
||||
if (defaultDef) {
|
||||
log(info);
|
||||
} else {
|
||||
|
||||
@@ -164,7 +164,7 @@ export function Eventify<TBase> (base: Constructor<TBase>): Constructor<TBase &
|
||||
|
||||
// Mixin with `CallbacksInvokers`'s prototype
|
||||
const callbacksInvokerPrototype = CallbacksInvoker.prototype;
|
||||
const propertyKeys: (string | symbol)[] = (Object.getOwnPropertyNames(callbacksInvokerPrototype) as (string | symbol)[]).concat(
|
||||
const propertyKeys: (string | symbol)[] = (Object.getOwnPropertyNames(callbacksInvokerPrototype) as (string | symbol)[]).concat(
|
||||
Object.getOwnPropertySymbols(callbacksInvokerPrototype),
|
||||
);
|
||||
for (let iPropertyKey = 0; iPropertyKey < propertyKeys.length; ++iPropertyKey) {
|
||||
|
||||
@@ -167,7 +167,7 @@ export class Plane {
|
||||
* @zh
|
||||
* 法线向量。
|
||||
*/
|
||||
public n: Vec3;
|
||||
public declare n: Vec3;
|
||||
|
||||
/**
|
||||
* @en
|
||||
|
||||
@@ -61,8 +61,12 @@ export class Ray {
|
||||
*/
|
||||
public static clone (a: Ray): Ray {
|
||||
return new Ray(
|
||||
a.o.x, a.o.y, a.o.z,
|
||||
a.d.x, a.d.y, a.d.z,
|
||||
a.o.x,
|
||||
a.o.y,
|
||||
a.o.z,
|
||||
a.d.x,
|
||||
a.d.y,
|
||||
a.d.z,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -129,7 +133,7 @@ export class Ray {
|
||||
* @zh
|
||||
* 起点。
|
||||
*/
|
||||
public o: Vec3;
|
||||
public declare o: Vec3;
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -137,7 +141,7 @@ export class Ray {
|
||||
* @zh
|
||||
* 方向。
|
||||
*/
|
||||
public d: Vec3;
|
||||
public declare d: Vec3;
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -149,7 +153,7 @@ export class Ray {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
protected readonly _type: number;
|
||||
protected readonly _type: number = enums.SHAPE_RAY;
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -163,9 +167,14 @@ export class Ray {
|
||||
* @param dy @en The y component of direction point. @zh 方向的 y 部分。
|
||||
* @param dz @en The z component of direction point. @zh 方向的 z 部分。
|
||||
*/
|
||||
constructor (ox = 0, oy = 0, oz = 0,
|
||||
dx = 0, dy = 0, dz = -1) {
|
||||
this._type = enums.SHAPE_RAY;
|
||||
constructor (
|
||||
ox = 0,
|
||||
oy = 0,
|
||||
oz = 0,
|
||||
dx = 0,
|
||||
dy = 0,
|
||||
dz = -1,
|
||||
) {
|
||||
this.o = new Vec3(ox, oy, oz);
|
||||
this.d = new Vec3(dx, dy, dz);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ export class Sphere {
|
||||
* @zh
|
||||
* 当前球在本地坐标中的中心点。
|
||||
*/
|
||||
protected _center: Vec3 = new Vec3(0, 0, 0);
|
||||
protected declare _center: Vec3;
|
||||
get center (): Vec3 {
|
||||
return this._center;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ export class Sphere {
|
||||
this._center = val;
|
||||
}
|
||||
|
||||
private _radius = 0;
|
||||
private declare _radius: number;
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -162,7 +162,7 @@ export class Sphere {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
protected readonly _type: number;
|
||||
protected readonly _type: number = enums.SHAPE_SPHERE;
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -175,7 +175,6 @@ export class Sphere {
|
||||
* @param r @en The radius of the sphere. @zh 球的半径。
|
||||
*/
|
||||
constructor (cx = 0, cy = 0, cz = 0, r = 1) {
|
||||
this._type = enums.SHAPE_SPHERE;
|
||||
this._center = new Vec3(cx, cy, cz);
|
||||
this._radius = r;
|
||||
}
|
||||
|
||||
@@ -38,20 +38,28 @@ export class Triangle {
|
||||
* Creates a new triangle instance.
|
||||
* @zh
|
||||
* 创建一个新的三角形。
|
||||
* @param {number} ax @en The x component of point a @zh a 点的 x 部分。
|
||||
* @param {number} ay @en The y component of point a @zh a 点的 y 部分。
|
||||
* @param {number} az @en The z component of point a @zh a 点的 z 部分。
|
||||
* @param {number} bx @en The x component of point b @zh b 点的 x 部分。
|
||||
* @param {number} by @en The y component of point b @zh b 点的 y 部分。
|
||||
* @param {number} bz @en The z component of point b @zh b 点的 z 部分。
|
||||
* @param {number} cx @en The x component of point c @zh c 点的 x 部分。
|
||||
* @param {number} cy @en The y component of point c @zh c 点的 y 部分。
|
||||
* @param {number} cz @en The z component of point c @zh c 点的 z 部分。
|
||||
* @returns {Triangle} @en The created Triangle instance. @zh 创建出的三角形实例。
|
||||
* @param ax @en The x component of point a @zh a 点的 x 部分。
|
||||
* @param ay @en The y component of point a @zh a 点的 y 部分。
|
||||
* @param az @en The z component of point a @zh a 点的 z 部分。
|
||||
* @param bx @en The x component of point b @zh b 点的 x 部分。
|
||||
* @param by @en The y component of point b @zh b 点的 y 部分。
|
||||
* @param bz @en The z component of point b @zh b 点的 z 部分。
|
||||
* @param cx @en The x component of point c @zh c 点的 x 部分。
|
||||
* @param cy @en The y component of point c @zh c 点的 y 部分。
|
||||
* @param cz @en The z component of point c @zh c 点的 z 部分。
|
||||
* @returns @en The created Triangle instance. @zh 创建出的三角形实例。
|
||||
*/
|
||||
public static create (ax = 1, ay = 0, az = 0,
|
||||
bx = 0, by = 0, bz = 0,
|
||||
cx = 0, cy = 0, cz = 1): Triangle {
|
||||
public static create (
|
||||
ax = 1,
|
||||
ay = 0,
|
||||
az = 0,
|
||||
bx = 0,
|
||||
by = 0,
|
||||
bz = 0,
|
||||
cx = 0,
|
||||
cy = 0,
|
||||
cz = 1,
|
||||
): Triangle {
|
||||
return new Triangle(ax, ay, az, bx, by, bz, cx, cy, cz);
|
||||
}
|
||||
|
||||
@@ -65,9 +73,15 @@ export class Triangle {
|
||||
*/
|
||||
public static clone (t: Triangle): Triangle {
|
||||
return new Triangle(
|
||||
t.a.x, t.a.y, t.a.z,
|
||||
t.b.x, t.b.y, t.b.z,
|
||||
t.c.x, t.c.y, t.c.z,
|
||||
t.a.x,
|
||||
t.a.y,
|
||||
t.a.z,
|
||||
t.b.x,
|
||||
t.b.y,
|
||||
t.b.z,
|
||||
t.c.x,
|
||||
t.c.y,
|
||||
t.c.z,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -123,10 +137,18 @@ export class Triangle {
|
||||
* @param cz @en The value to set out.c.z. @zh c 点的 z 部分。
|
||||
* @returns @en The Triangle object to be set, same as the `out` parameter. @zh 接受操作的三角形,与 `out` 参数相同。
|
||||
*/
|
||||
public static set (out: Triangle,
|
||||
ax: number, ay: number, az: number,
|
||||
bx: number, by: number, bz: number,
|
||||
cx: number, cy: number, cz: number): Triangle {
|
||||
public static set (
|
||||
out: Triangle,
|
||||
ax: number,
|
||||
ay: number,
|
||||
az: number,
|
||||
bx: number,
|
||||
by: number,
|
||||
bz: number,
|
||||
cx: number,
|
||||
cy: number,
|
||||
cz: number,
|
||||
): Triangle {
|
||||
out.a.x = ax;
|
||||
out.a.y = ay;
|
||||
out.a.z = az;
|
||||
@@ -148,7 +170,7 @@ export class Triangle {
|
||||
* @zh
|
||||
* 点 a。
|
||||
*/
|
||||
public a: Vec3;
|
||||
public declare a: Vec3;
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -156,7 +178,7 @@ export class Triangle {
|
||||
* @zh
|
||||
* 点 b。
|
||||
*/
|
||||
public b: Vec3;
|
||||
public declare b: Vec3;
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -164,7 +186,7 @@ export class Triangle {
|
||||
* @zh
|
||||
* 点 c。
|
||||
*/
|
||||
public c: Vec3;
|
||||
public declare c: Vec3;
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -176,27 +198,34 @@ export class Triangle {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
protected readonly _type: number;
|
||||
protected readonly _type: number = enums.SHAPE_TRIANGLE;
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Constructs a triangle.
|
||||
* @zh
|
||||
* 构造一个三角形。
|
||||
* @param {number} ax @en x component of point a. @zh a 点的 x 部分。
|
||||
* @param {number} ay @en y component of point a. @zh a 点的 y 部分。
|
||||
* @param {number} az @en z component of point a. @zh a 点的 z 部分。
|
||||
* @param {number} bx @en x component of point b. @zh b 点的 x 部分。
|
||||
* @param {number} by @en y component of point b. @zh b 点的 y 部分。
|
||||
* @param {number} bz @en z component of point b. @zh b 点的 z 部分。
|
||||
* @param {number} cx @en x component of point c. @zh c 点的 x 部分。
|
||||
* @param {number} cy @en y component of point c. @zh c 点的 y 部分。
|
||||
* @param {number} cz @en z component of point c. @zh c 点的 z 部分。
|
||||
* @param ax @en x component of point a. @zh a 点的 x 部分。
|
||||
* @param ay @en y component of point a. @zh a 点的 y 部分。
|
||||
* @param az @en z component of point a. @zh a 点的 z 部分。
|
||||
* @param bx @en x component of point b. @zh b 点的 x 部分。
|
||||
* @param by @en y component of point b. @zh b 点的 y 部分。
|
||||
* @param bz @en z component of point b. @zh b 点的 z 部分。
|
||||
* @param cx @en x component of point c. @zh c 点的 x 部分。
|
||||
* @param cy @en y component of point c. @zh c 点的 y 部分。
|
||||
* @param cz @en z component of point c. @zh c 点的 z 部分。
|
||||
*/
|
||||
constructor (ax = 0, ay = 0, az = 0,
|
||||
bx = 1, by = 0, bz = 0,
|
||||
cx = 0, cy = 1, cz = 0) {
|
||||
this._type = enums.SHAPE_TRIANGLE;
|
||||
constructor (
|
||||
ax = 0,
|
||||
ay = 0,
|
||||
az = 0,
|
||||
bx = 1,
|
||||
by = 0,
|
||||
bz = 0,
|
||||
cx = 0,
|
||||
cy = 1,
|
||||
cz = 0,
|
||||
) {
|
||||
this.a = new Vec3(ax, ay, az);
|
||||
this.b = new Vec3(bx, by, bz);
|
||||
this.c = new Vec3(cx, cy, cz);
|
||||
|
||||
@@ -31,7 +31,7 @@ import { clamp, EPSILON, random } from './utils';
|
||||
|
||||
import { Vec3 } from './vec3';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { warn } from '../platform/debug';
|
||||
import { warnID } from '../platform/debug';
|
||||
|
||||
/**
|
||||
* @en Representation of 2D vectors and points.
|
||||
@@ -638,7 +638,9 @@ export class Vec2 extends ValueType {
|
||||
* @param scalar scalar number
|
||||
*/
|
||||
public multiplyScalar (scalar: number): Vec2 {
|
||||
if (typeof scalar === 'object') { warn('should use Vec2.multiply for vector * vector operation'); }
|
||||
if (typeof scalar === 'object') {
|
||||
warnID(16359);
|
||||
}
|
||||
this.x *= scalar;
|
||||
this.y *= scalar;
|
||||
return this;
|
||||
@@ -650,7 +652,9 @@ export class Vec2 extends ValueType {
|
||||
* @param other specified vector
|
||||
*/
|
||||
public multiply (other: Vec2): Vec2 {
|
||||
if (typeof other !== 'object') { warn('should use Vec2.scale for vector * scalar operation'); }
|
||||
if (typeof other !== 'object') {
|
||||
warnID(16360);
|
||||
}
|
||||
this.x *= other.x;
|
||||
this.y *= other.y;
|
||||
return this;
|
||||
|
||||
@@ -30,7 +30,7 @@ import { Mat4 } from './mat4';
|
||||
import { IMat3Like, IMat4Like, IQuatLike, IVec3Like } from './type-define';
|
||||
import { clamp, EPSILON, lerp, random } from './utils';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { warn } from '../platform/debug';
|
||||
import { warnID } from '../platform/debug';
|
||||
|
||||
/**
|
||||
* @en Representation of 3D vectors and points.
|
||||
@@ -1071,8 +1071,9 @@ export class Vec3 extends ValueType {
|
||||
* @param scalar scalar number
|
||||
*/
|
||||
public multiplyScalar (scalar: number): Vec3 {
|
||||
// TODO: can not use cc.warn, or will cause circular dependency.
|
||||
if (typeof scalar === 'object') { warn('should use Vec3.multiply for vector * vector operation'); }
|
||||
if (typeof scalar === 'object') {
|
||||
warnID(16357);
|
||||
}
|
||||
this.x *= scalar;
|
||||
this.y *= scalar;
|
||||
this.z *= scalar;
|
||||
@@ -1085,8 +1086,9 @@ export class Vec3 extends ValueType {
|
||||
* @param other specified vector
|
||||
*/
|
||||
public multiply (other: Vec3): Vec3 {
|
||||
// TODO: can not use cc.warn, or will cause circular dependency.
|
||||
if (typeof other !== 'object') { warn('should use Vec3.scale for vector * scalar operation'); }
|
||||
if (typeof other !== 'object') {
|
||||
warnID(16358);
|
||||
}
|
||||
this.x *= other.x;
|
||||
this.y *= other.y;
|
||||
this.z *= other.z;
|
||||
|
||||
@@ -29,7 +29,7 @@ import { Mat4 } from './mat4';
|
||||
import { IMat4Like, IQuatLike, IVec4Like, IColorLike } from './type-define';
|
||||
import { clamp, EPSILON, random } from './utils';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { warn } from '../platform/debug';
|
||||
import { warnID } from '../platform/debug';
|
||||
|
||||
/**
|
||||
* @en Representation of four-dimensional vectors.
|
||||
@@ -775,7 +775,9 @@ export class Vec4 extends ValueType {
|
||||
* @param scalar scalar number
|
||||
*/
|
||||
public multiplyScalar (scalar: number): Vec4 {
|
||||
if (typeof scalar === 'object') { warn('should use Vec4.multiply for vector * vector operation'); }
|
||||
if (typeof scalar === 'object') {
|
||||
warnID(16361);
|
||||
}
|
||||
this.x *= scalar;
|
||||
this.y *= scalar;
|
||||
this.z *= scalar;
|
||||
@@ -789,7 +791,9 @@ export class Vec4 extends ValueType {
|
||||
* @param other specified vector
|
||||
*/
|
||||
public multiply (other: Vec4): Vec4 {
|
||||
if (typeof other !== 'object') { warn('should use Vec4.scale for vector * scalar operation'); }
|
||||
if (typeof other !== 'object') {
|
||||
warnID(16362);
|
||||
}
|
||||
this.x *= other.x;
|
||||
this.y *= other.y;
|
||||
this.z *= other.z;
|
||||
|
||||
@@ -39,7 +39,7 @@ export class CachedArray<T> extends ScalableContainer {
|
||||
* @zh
|
||||
* 实际存储数据内容的数组。
|
||||
*/
|
||||
public array: T[];
|
||||
public declare array: T[];
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -49,7 +49,7 @@ export class CachedArray<T> extends ScalableContainer {
|
||||
*/
|
||||
public length = 0;
|
||||
|
||||
private _compareFn?: (a: T, b: T) => number;
|
||||
private declare _compareFn?: (a: T, b: T) => number;
|
||||
private _initSize = 0;
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,6 @@ export class CachedArray<T> extends ScalableContainer {
|
||||
super();
|
||||
this.array = new Array(length);
|
||||
this._initSize = length;
|
||||
this.length = 0;
|
||||
this._compareFn = compareFn;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,12 +33,12 @@ import { ScalableContainer } from './scalable-container';
|
||||
* @see [[RecyclePool]]
|
||||
*/
|
||||
export class Pool<T> extends ScalableContainer {
|
||||
private _ctor: () => T;
|
||||
private _elementsPerBatch: number;
|
||||
private _shrinkThreshold: number;
|
||||
private _nextAvail: number;
|
||||
private declare _ctor: () => T;
|
||||
private declare _elementsPerBatch: number;
|
||||
private declare _shrinkThreshold: number;
|
||||
private declare _nextAvail: number;
|
||||
private _freePool: T[] = [];
|
||||
private _dtor: ((obj: T) => void) | null;
|
||||
private declare _dtor: ((obj: T) => void) | null;
|
||||
|
||||
/**
|
||||
* @en Constructor with the allocator of elements and initial pool size.
|
||||
|
||||
@@ -36,11 +36,11 @@ import { ScalableContainer } from './scalable-container';
|
||||
* @see [[Pool]]
|
||||
*/
|
||||
export class RecyclePool<T = any> extends ScalableContainer {
|
||||
private _fn: () => T;
|
||||
private _dtor: ((obj: T) => void) | null = null;
|
||||
private declare _fn: () => T;
|
||||
private declare _dtor: ((obj: T) => void) | null;
|
||||
private _count = 0;
|
||||
private _data: T[];
|
||||
private _initSize = 0;
|
||||
private declare _data: T[];
|
||||
private declare _initSize: number;
|
||||
|
||||
/**
|
||||
* @en Constructor with the allocator of elements and initial pool size, all elements will be pre-allocated.
|
||||
|
||||
@@ -261,7 +261,7 @@ export function _throw (error_: any): any {
|
||||
}
|
||||
}
|
||||
|
||||
function getTypedFormatter (type: 'Log' | 'Warning' | 'Error' | 'Assert'): (id: number, ...args: StringSubstitution[]) => string {
|
||||
function getTypedFormatter (type: 'Log' | 'Debug' | 'Warning' | 'Error' | 'Assert'): (id: number, ...args: StringSubstitution[]) => string {
|
||||
return (id: number, ...args: StringSubstitution[]): string => {
|
||||
const msg = DEBUG ? (debugInfos[id] || 'unknown id') : `${type} ${id}, please go to ${ERROR_MAP_URL}#${id} to see details.`;
|
||||
if (args.length === 0) {
|
||||
@@ -276,6 +276,11 @@ export function logID (id: number, ...optionalParams: StringSubstitution[]): voi
|
||||
log(logFormatter(id, ...optionalParams));
|
||||
}
|
||||
|
||||
const debugFormatter = getTypedFormatter('Debug');
|
||||
export function debugID (id: number, ...optionalParams: StringSubstitution[]): void {
|
||||
debug(debugFormatter(id, ...optionalParams));
|
||||
}
|
||||
|
||||
const warnFormatter = getTypedFormatter('Warning');
|
||||
export function warnID (id: number, ...optionalParams: StringSubstitution[]): void {
|
||||
warn(warnFormatter(id, ...optionalParams));
|
||||
|
||||
@@ -34,6 +34,7 @@ export {
|
||||
error,
|
||||
warn,
|
||||
assert,
|
||||
debugID,
|
||||
logID,
|
||||
errorID,
|
||||
warnID,
|
||||
|
||||
@@ -41,17 +41,17 @@ export class System implements ISchedulable {
|
||||
protected _priority = 0;
|
||||
protected _executeInEditMode = false;
|
||||
|
||||
set priority (value:number) {
|
||||
set priority (value: number) {
|
||||
this._priority = value;
|
||||
}
|
||||
get priority ():number {
|
||||
get priority (): number {
|
||||
return this._priority;
|
||||
}
|
||||
|
||||
set id (id:string) {
|
||||
set id (id: string) {
|
||||
this._id = id;
|
||||
}
|
||||
get id ():string {
|
||||
get id (): string {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ export class System implements ISchedulable {
|
||||
* @param a System a
|
||||
* @param b System b
|
||||
*/
|
||||
public static sortByPriority (a:System, b:System): number {
|
||||
public static sortByPriority (a: System, b: System): number {
|
||||
if (a._priority < b._priority) {
|
||||
return 1;
|
||||
} else if (a._priority > b.priority) {
|
||||
|
||||
@@ -174,6 +174,7 @@ export function removeIf<T> (array: T[], predicate: (value: T) => boolean): T |
|
||||
removeAt(array, index);
|
||||
return value;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,14 +49,14 @@ export class IDGenerator {
|
||||
* `getNewId()` to get a unique id.
|
||||
* @zh 记录当前 id 值。调用 `getNewId()` 时,它可能被加1。应该使用 `getNewId()` 获取唯一的 id。
|
||||
*/
|
||||
public id: number;
|
||||
public declare id: number;
|
||||
|
||||
/**
|
||||
* @en A string value indicates the category this IDGenerator belongs to. It will be an empty
|
||||
* string if not be assigned by passed parameter in constructor.
|
||||
* @zh 用于标识该 IDGenerator 所属的类别。如果构造函数没有传参数对它赋值的话,它将是一个空字符串。
|
||||
*/
|
||||
public prefix: string;
|
||||
public declare prefix: string;
|
||||
|
||||
/**
|
||||
* @en Construct a new id generator.
|
||||
|
||||
@@ -630,14 +630,14 @@ function setup (tag: string, table: Record<string | number, any>, allowExist: bo
|
||||
if (id) {
|
||||
const registered = table[id];
|
||||
if (!allowExist && registered && registered !== constructor) {
|
||||
let err = `A Class already exists with the same ${tag} : "${id}".`;
|
||||
let detail = '';
|
||||
if (TEST) {
|
||||
// eslint-disable-next-line no-multi-str
|
||||
err += ' (This may be caused by error of unit test.) \
|
||||
detail += ' (This may be caused by error of unit test.) \
|
||||
If you dont need serialization, you can set class id to "". You can also call \
|
||||
js.unregisterClass to remove the id of unused class';
|
||||
}
|
||||
error(err);
|
||||
errorID(16334, tag, id, detail);
|
||||
} else {
|
||||
table[id] = constructor;
|
||||
}
|
||||
@@ -697,11 +697,11 @@ export function setClassAlias (target: Constructor, alias: string): void {
|
||||
const idRegistry = _idToClass[alias];
|
||||
let ok = true;
|
||||
if (nameRegistry && nameRegistry !== target) {
|
||||
error(`"${alias}" has already been set as name or alias of another class.`);
|
||||
errorID(16335, alias);
|
||||
ok = false;
|
||||
}
|
||||
if (idRegistry && idRegistry !== target) {
|
||||
error(`"${alias}" has already been set as id or alias of another class.`);
|
||||
errorID(16336, alias);
|
||||
ok = false;
|
||||
}
|
||||
if (ok) {
|
||||
|
||||
@@ -168,10 +168,10 @@ export function isDomNode (node): boolean {
|
||||
* @param p1 @en The first parameter passed to `callback`. @zh 传给回调函数的第一个参数。
|
||||
* @param p2 @en The seconde parameter passed to `callback`. @zh 传给回调函数的第二个参数。
|
||||
*/
|
||||
export function callInNextTick (callback, p1?: any, p2?: any): void {
|
||||
export function callInNextTick<T extends any[]> (callback: (...args: T) => void, ...args: T): void {
|
||||
if (callback) {
|
||||
setTimeoutRAF((): void => {
|
||||
callback(p1, p2);
|
||||
callback(...args);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ export class Pool<T> {
|
||||
* 当前可用对象数量,一开始默认是 0,随着对象的回收会逐渐增大,最大不会超过调用构造函数时指定的 size。
|
||||
* @default 0
|
||||
*/
|
||||
public count: number;
|
||||
public count: number = 0;
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -98,8 +98,8 @@ export class Pool<T> {
|
||||
return this._get();
|
||||
}
|
||||
|
||||
private _pool: Array<T | null>;
|
||||
private _cleanup: CleanUpFunction<T> | null;
|
||||
private declare _pool: Array<T | null>;
|
||||
private declare _cleanup: CleanUpFunction<T> | null;
|
||||
|
||||
/**
|
||||
* @en Constructor. @zh 构造函数。
|
||||
@@ -125,7 +125,6 @@ export class Pool<T> {
|
||||
constructor (_0: CleanUpFunction<T> | number, _1?: number) {
|
||||
const size = (_1 === undefined) ? (_0 as number) : _1;
|
||||
const cleanupFunc = (_1 === undefined) ? null : (_0 as CleanUpFunction<T>);
|
||||
this.count = 0;
|
||||
this._pool = new Array(size);
|
||||
this._cleanup = cleanupFunc;
|
||||
}
|
||||
|
||||
+10
-33
@@ -178,46 +178,23 @@ export class Director extends EventTarget {
|
||||
/**
|
||||
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
|
||||
*/
|
||||
public _compScheduler: ComponentScheduler;
|
||||
public _compScheduler: ComponentScheduler = new ComponentScheduler(); // Scheduler for life-cycle methods in component
|
||||
/**
|
||||
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
|
||||
*/
|
||||
public _nodeActivator: NodeActivator;
|
||||
private _invalid: boolean;
|
||||
private _paused: boolean;
|
||||
private _root: Root | null;
|
||||
private _loadingScene: string;
|
||||
private _scene: Scene | null;
|
||||
private _totalFrames: number;
|
||||
private _scheduler: Scheduler;
|
||||
private _systems: System[];
|
||||
public _nodeActivator: NodeActivator = new NodeActivator();
|
||||
private _invalid: boolean = false;
|
||||
private _paused: boolean = false;
|
||||
private _root: Root | null = null;
|
||||
private _loadingScene: string = '';
|
||||
private _scene: Scene | null = null;
|
||||
private _totalFrames: number = 0; // FPS
|
||||
private _scheduler: Scheduler = new Scheduler(); // Scheduler for user registration update
|
||||
private _systems: System[] = [];
|
||||
private _persistRootNodes: Record<string, Node> = {};
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
|
||||
this._invalid = false;
|
||||
// paused?
|
||||
this._paused = false;
|
||||
|
||||
// root
|
||||
this._root = null;
|
||||
|
||||
// scenes
|
||||
this._loadingScene = '';
|
||||
this._scene = null;
|
||||
|
||||
// FPS
|
||||
this._totalFrames = 0;
|
||||
|
||||
// Scheduler for user registration update
|
||||
this._scheduler = new Scheduler();
|
||||
// Scheduler for life-cycle methods in component
|
||||
this._compScheduler = new ComponentScheduler();
|
||||
// Node activator
|
||||
this._nodeActivator = new NodeActivator();
|
||||
|
||||
this._systems = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -389,6 +389,10 @@ export class Game extends EventTarget {
|
||||
*/
|
||||
public onStart: Game.OnStart | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Indicates whether the engine and the renderer has been initialized
|
||||
* @zh 引擎和渲染器是否以完成初始化
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { EDITOR, TAOBAO } from 'internal:constants';
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { Material } from '../asset/assets/material';
|
||||
import { clamp01, Mat4, Vec2, Settings, settings, sys, cclegacy, easing, preTransforms } from '../core';
|
||||
import {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
import { EDITOR, JSB, WEBGPU } from 'internal:constants';
|
||||
import { cclegacy, error, getError, sys, screen, Settings, settings } from '../core';
|
||||
import { cclegacy, getError, sys, screen, Settings, settings, errorID } from '../core';
|
||||
import { BindingMappingInfo, DeviceInfo, SwapchainInfo } from './base/define';
|
||||
import { Device } from './base/device';
|
||||
import { Swapchain } from './base/swapchain';
|
||||
@@ -186,7 +186,7 @@ export class DeviceManager {
|
||||
|
||||
if (!this._gfxDevice) {
|
||||
// todo fix here for wechat game
|
||||
error('can not support canvas rendering in 3D');
|
||||
errorID(16337);
|
||||
this._renderType = RenderType.UNKNOWN;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import {
|
||||
} from './webgl-commands';
|
||||
import { IWebGLGPUBuffer, IWebGLGPUBufferView, WebGLIndirectDrawInfos } from './webgl-gpu-objects';
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
import { warn } from '../../core';
|
||||
import { warnID } from '../../core';
|
||||
|
||||
export class WebGLBuffer extends Buffer {
|
||||
get gpuBuffer (): IWebGLGPUBuffer {
|
||||
@@ -48,6 +48,10 @@ export class WebGLBuffer extends Buffer {
|
||||
private _gpuBufferView: IWebGLGPUBufferView | null = null;
|
||||
private _uniformBuffer: Uint8Array | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initialize (info: Readonly<BufferInfo> | Readonly<BufferViewInfo>): void {
|
||||
if ('buffer' in info) { // buffer view
|
||||
this._isBufferView = true;
|
||||
@@ -113,7 +117,7 @@ export class WebGLBuffer extends Buffer {
|
||||
|
||||
public resize (size: number): void {
|
||||
if (this._isBufferView) {
|
||||
warn('cannot resize buffer views!');
|
||||
warnID(16379);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -143,7 +147,7 @@ export class WebGLBuffer extends Buffer {
|
||||
|
||||
public update (buffer: Readonly<BufferSource>, size?: number): void {
|
||||
if (this._isBufferView) {
|
||||
warn('cannot update through buffer views!');
|
||||
warnID(16380);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ import {
|
||||
} from './webgl-commands';
|
||||
|
||||
export class WebGLCommandPool<T extends WebGLCmdObject> {
|
||||
private _frees: (T|null)[];
|
||||
private declare _frees: (T|null)[];
|
||||
private _freeIdx = 0;
|
||||
private _freeCmds: CachedArray<T>;
|
||||
private declare _freeCmds: CachedArray<T>;
|
||||
|
||||
constructor (Clazz: new() => T, count: number) {
|
||||
this._frees = new Array(count);
|
||||
@@ -104,12 +104,12 @@ export class WebGLCommandPool<T extends WebGLCmdObject> {
|
||||
}
|
||||
|
||||
export class WebGLCommandAllocator {
|
||||
public beginRenderPassCmdPool: WebGLCommandPool<WebGLCmdBeginRenderPass>;
|
||||
public bindStatesCmdPool: WebGLCommandPool<WebGLCmdBindStates>;
|
||||
public drawCmdPool: WebGLCommandPool<WebGLCmdDraw>;
|
||||
public updateBufferCmdPool: WebGLCommandPool<WebGLCmdUpdateBuffer>;
|
||||
public copyBufferToTextureCmdPool: WebGLCommandPool<WebGLCmdCopyBufferToTexture>;
|
||||
public blitTextureCmdPool: WebGLCommandPool<WebGLCmdBlitTexture>;
|
||||
public declare beginRenderPassCmdPool: WebGLCommandPool<WebGLCmdBeginRenderPass>;
|
||||
public declare bindStatesCmdPool: WebGLCommandPool<WebGLCmdBindStates>;
|
||||
public declare drawCmdPool: WebGLCommandPool<WebGLCmdDraw>;
|
||||
public declare updateBufferCmdPool: WebGLCommandPool<WebGLCmdUpdateBuffer>;
|
||||
public declare copyBufferToTextureCmdPool: WebGLCommandPool<WebGLCmdCopyBufferToTexture>;
|
||||
public declare blitTextureCmdPool: WebGLCommandPool<WebGLCmdBlitTexture>;
|
||||
|
||||
constructor () {
|
||||
this.beginRenderPassCmdPool = new WebGLCommandPool(WebGLCmdBeginRenderPass, 1);
|
||||
|
||||
@@ -47,7 +47,7 @@ import { GeneralBarrier } from '../base/states/general-barrier';
|
||||
import { TextureBarrier } from '../base/states/texture-barrier';
|
||||
import { BufferBarrier } from '../base/states/buffer-barrier';
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
import { error } from '../../core';
|
||||
import { error, errorID } from '../../core';
|
||||
|
||||
export class WebGLCommandBuffer extends CommandBuffer {
|
||||
public cmdPackage: WebGLCmdPackage = new WebGLCmdPackage();
|
||||
@@ -61,6 +61,10 @@ export class WebGLCommandBuffer extends CommandBuffer {
|
||||
protected _curDynamicStates: DynamicStates = new DynamicStates();
|
||||
protected _isStateInvalied = false;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initialize (info: Readonly<CommandBufferInfo>): void {
|
||||
this._type = info.type;
|
||||
this._queue = info.queue;
|
||||
@@ -296,7 +300,7 @@ export class WebGLCommandBuffer extends CommandBuffer {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error('Command \'draw\' must be recorded inside a render pass.');
|
||||
errorID(16328);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +336,7 @@ export class WebGLCommandBuffer extends CommandBuffer {
|
||||
this.cmdPackage.cmds.push(WebGLCmd.UPDATE_BUFFER);
|
||||
}
|
||||
} else {
|
||||
error('Command \'updateBuffer\' must be recorded outside a render pass.');
|
||||
errorID(16329);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +358,7 @@ export class WebGLCommandBuffer extends CommandBuffer {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error('Command \'copyBufferToTexture\' must be recorded outside a render pass.');
|
||||
errorID(16330);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { debug, error, errorID, CachedArray, cclegacy, assertID } from '../../core';
|
||||
import { debugID, error, errorID, CachedArray, cclegacy, assertID } from '../../core';
|
||||
import { WebGLCommandAllocator } from './webgl-command-allocator';
|
||||
import { WebGLEXT } from './webgl-define';
|
||||
import { WebGLDevice } from './webgl-device';
|
||||
@@ -179,7 +179,7 @@ export function GFXFormatToWebGLInternalFormat (format: Format, gl: WebGLRenderi
|
||||
case Format.DEPTH_STENCIL: return gl.DEPTH_STENCIL;
|
||||
|
||||
default: {
|
||||
error('Unsupported Format, convert to WebGL internal format failed.');
|
||||
errorID(16309);
|
||||
return gl.RGBA;
|
||||
}
|
||||
}
|
||||
@@ -261,7 +261,7 @@ export function GFXFormatToWebGLFormat (format: Format, gl: WebGLRenderingContex
|
||||
case Format.ASTC_SRGBA_12X12: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
|
||||
|
||||
default: {
|
||||
error('Unsupported Format, convert to WebGL format failed.');
|
||||
errorID(16310);
|
||||
return gl.RGBA;
|
||||
}
|
||||
}
|
||||
@@ -288,7 +288,7 @@ function GFXTypeToWebGLType (type: Type, gl: WebGLRenderingContext): GLenum {
|
||||
case Type.SAMPLER2D: return gl.SAMPLER_2D;
|
||||
case Type.SAMPLER_CUBE: return gl.SAMPLER_CUBE;
|
||||
default: {
|
||||
error('Unsupported GLType, convert to GL type failed.');
|
||||
errorID(16311);
|
||||
return Type.UNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -315,7 +315,7 @@ function GFXTypeToTypedArrayCtor (type: Type): Int32ArrayConstructor | Float32Ar
|
||||
case Type.MAT4:
|
||||
return Float32Array;
|
||||
default: {
|
||||
error('Unsupported GLType, convert to TypedArrayConstructor failed.');
|
||||
errorID(16312);
|
||||
return Float32Array;
|
||||
}
|
||||
}
|
||||
@@ -342,7 +342,7 @@ function WebGLTypeToGFXType (glType: GLenum, gl: WebGLRenderingContext): Type {
|
||||
case gl.SAMPLER_2D: return Type.SAMPLER2D;
|
||||
case gl.SAMPLER_CUBE: return Type.SAMPLER_CUBE;
|
||||
default: {
|
||||
error('Unsupported GLType, convert to Type failed.');
|
||||
errorID(16313);
|
||||
return Type.UNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -369,7 +369,7 @@ function WebGLGetTypeSize (glType: GLenum, gl: WebGLRenderingContext): number {
|
||||
case gl.SAMPLER_2D: return 4;
|
||||
case gl.SAMPLER_CUBE: return 4;
|
||||
default: {
|
||||
error('Unsupported GLType, get type failed.');
|
||||
errorID(16314);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -446,7 +446,7 @@ export enum WebGLCmd {
|
||||
}
|
||||
|
||||
export abstract class WebGLCmdObject {
|
||||
public cmdType: WebGLCmd;
|
||||
public declare cmdType: WebGLCmd;
|
||||
public refCount = 0;
|
||||
|
||||
constructor (type: WebGLCmd) {
|
||||
@@ -664,7 +664,7 @@ export function WebGLCmdFuncCreateBuffer (device: WebGLDevice, gpuBuffer: IWebGL
|
||||
} else if (gpuBuffer.usage & BufferUsageBit.TRANSFER_SRC) {
|
||||
gpuBuffer.glTarget = gl.NONE;
|
||||
} else {
|
||||
error('Unsupported BufferType, create buffer failed.');
|
||||
errorID(16315);
|
||||
gpuBuffer.glTarget = gl.NONE;
|
||||
}
|
||||
}
|
||||
@@ -763,7 +763,7 @@ export function WebGLCmdFuncResizeBuffer (device: WebGLDevice, gpuBuffer: IWebGL
|
||||
|| (gpuBuffer.usage & BufferUsageBit.TRANSFER_SRC)) {
|
||||
gpuBuffer.glTarget = gl.NONE;
|
||||
} else {
|
||||
error('Unsupported BufferType, create buffer failed.');
|
||||
errorID(16315);
|
||||
gpuBuffer.glTarget = gl.NONE;
|
||||
}
|
||||
}
|
||||
@@ -824,7 +824,7 @@ export function WebGLCmdFuncUpdateBuffer (
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
error('Unsupported BufferType, update buffer failed.');
|
||||
errorID(16316);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -980,7 +980,7 @@ export function WebGLCmdFuncCreateTexture (device: WebGLDevice, gpuTexture: IWeb
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
error('Unsupported TextureType, create texture failed.');
|
||||
errorID(16317);
|
||||
gpuTexture.type = TextureType.TEX2D;
|
||||
gpuTexture.glTarget = gl.TEXTURE_2D;
|
||||
}
|
||||
@@ -1116,7 +1116,7 @@ export function WebGLCmdFuncResizeTexture (device: WebGLDevice, gpuTexture: IWeb
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
error('Unsupported TextureType, create texture failed.');
|
||||
errorID(16317);
|
||||
gpuTexture.type = TextureType.TEX2D;
|
||||
gpuTexture.glTarget = gl.TEXTURE_2D;
|
||||
}
|
||||
@@ -1200,19 +1200,19 @@ export function WebGLCmdFuncCreateFramebuffer (device: WebGLDevice, gpuFramebuff
|
||||
if (status !== gl.FRAMEBUFFER_COMPLETE) {
|
||||
switch (status) {
|
||||
case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: {
|
||||
error('glCheckFramebufferStatus() - FRAMEBUFFER_INCOMPLETE_ATTACHMENT');
|
||||
errorID(16318);
|
||||
break;
|
||||
}
|
||||
case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: {
|
||||
error('glCheckFramebufferStatus() - FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT');
|
||||
errorID(16319);
|
||||
break;
|
||||
}
|
||||
case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: {
|
||||
error('glCheckFramebufferStatus() - FRAMEBUFFER_INCOMPLETE_DIMENSIONS');
|
||||
errorID(16320);
|
||||
break;
|
||||
}
|
||||
case gl.FRAMEBUFFER_UNSUPPORTED: {
|
||||
error('glCheckFramebufferStatus() - FRAMEBUFFER_UNSUPPORTED');
|
||||
errorID(16321);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -1258,7 +1258,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
error('Unsupported ShaderType.');
|
||||
errorID(16322);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1270,8 +1270,8 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
gl.compileShader(gpuStage.glShader);
|
||||
|
||||
if (!gl.getShaderParameter(gpuStage.glShader, gl.COMPILE_STATUS)) {
|
||||
error(`${shaderTypeStr} in '${gpuShader.name}' compilation failed.`);
|
||||
error('Shader source dump:', gpuStage.source.replace(/^|\n/g, (): string => `\n${lineNumber++} `));
|
||||
errorID(16323, shaderTypeStr, gpuShader.name);
|
||||
errorID(16324, gpuStage.source.replace(/^|\n/g, (): string => `\n${lineNumber++} `));
|
||||
error(gl.getShaderInfoLog(gpuStage.glShader));
|
||||
|
||||
for (let l = 0; l < gpuShader.gpuStages.length; l++) {
|
||||
@@ -1314,9 +1314,9 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
}
|
||||
|
||||
if (gl.getProgramParameter(gpuShader.glProgram, gl.LINK_STATUS)) {
|
||||
debug(`Shader '${gpuShader.name}' compilation succeeded.`);
|
||||
debugID(16325, gpuShader.name);
|
||||
} else {
|
||||
error(`Failed to link shader '${gpuShader.name}'.`);
|
||||
errorID(16326, gpuShader.name);
|
||||
error(gl.getProgramInfoLog(gpuShader.glProgram));
|
||||
return;
|
||||
}
|
||||
@@ -2810,7 +2810,7 @@ export function WebGLCmdFuncCopyTexImagesToTexture (
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
error('Unsupported GL texture type, copy buffer to texture failed.');
|
||||
errorID(16327);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3016,7 +3016,7 @@ export function WebGLCmdFuncCopyBuffersToTexture (
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
error('Unsupported GL texture type, copy buffer to texture failed.');
|
||||
errorID(16327);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ export class WebGLDescriptorSetLayout extends DescriptorSetLayout {
|
||||
|
||||
private _gpuDescriptorSetLayout: IWebGLGPUDescriptorSetLayout | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initialize (info: Readonly<DescriptorSetLayoutInfo>): void {
|
||||
Array.prototype.push.apply(this._bindings, info.bindings);
|
||||
|
||||
|
||||
@@ -37,6 +37,10 @@ export class WebGLDescriptorSet extends DescriptorSet {
|
||||
|
||||
private _gpuDescriptorSet: IWebGLGPUDescriptorSet | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initialize (info: Readonly<DescriptorSetInfo>): void {
|
||||
this._layout = info.layout;
|
||||
const { bindings, descriptorIndices, descriptorCount } = (info.layout as WebGLDescriptorSetLayout).gpuDescriptorSetLayout;
|
||||
|
||||
@@ -61,13 +61,17 @@ import { WebGLCmdFuncCopyBuffersToTexture, WebGLCmdFuncCopyTextureToBuffers, Web
|
||||
import { GeneralBarrier } from '../base/states/general-barrier';
|
||||
import { TextureBarrier } from '../base/states/texture-barrier';
|
||||
import { BufferBarrier } from '../base/states/buffer-barrier';
|
||||
import { debug, error } from '../../core';
|
||||
import { debug, errorID } from '../../core';
|
||||
import { Swapchain } from '../base/swapchain';
|
||||
import { IWebGLExtensions, WebGLDeviceManager } from './webgl-define';
|
||||
import { IWebGLBindingMapping, IWebGLBlitManager } from './webgl-gpu-objects';
|
||||
import type { WebGLStateCache } from './webgl-state-cache';
|
||||
|
||||
export class WebGLDevice extends Device {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
get gl (): WebGLRenderingContext {
|
||||
return this._context!;
|
||||
}
|
||||
@@ -137,7 +141,7 @@ export class WebGLDevice extends Device {
|
||||
const gl = this._context = getContext(Device.canvas);
|
||||
|
||||
if (!gl) {
|
||||
error('This device does not support WebGL.');
|
||||
errorID(16333);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,11 @@ export class WebGLFramebuffer extends Framebuffer {
|
||||
private _gpuFramebuffer: IWebGLGPUFramebuffer | null = null;
|
||||
private _gpuColorTextures: (WebGLTexture | null)[] = [];
|
||||
private _gpuDepthStencilTexture: WebGLTexture | null | undefined;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
get needRebuild (): boolean {
|
||||
if (this.gpuFramebuffer) {
|
||||
for (let i = 0; i < this.gpuFramebuffer.gpuColorTextures.length; i++) {
|
||||
|
||||
@@ -39,15 +39,15 @@ import { WebGLCmdFuncBindStates, WebGLCmdFuncCreateBuffer, WebGLCmdFuncCreateInp
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
|
||||
export class WebGLIndirectDrawInfos {
|
||||
public counts: Int32Array;
|
||||
public offsets: Int32Array;
|
||||
public instances: Int32Array;
|
||||
public declare counts: Int32Array;
|
||||
public declare offsets: Int32Array;
|
||||
public declare instances: Int32Array;
|
||||
public drawCount = 0;
|
||||
public drawByIndex = false;
|
||||
public instancedDraw = false;
|
||||
|
||||
// staging buffer
|
||||
public byteOffsets: Int32Array;
|
||||
public declare byteOffsets: Int32Array;
|
||||
|
||||
private _capacity = 4;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { errorID } from '../../core/platform/debug';
|
||||
import { InputAssemblerInfo } from '../base/define';
|
||||
import { InputAssembler } from '../base/input-assembler';
|
||||
import { WebGLBuffer } from './webgl-buffer';
|
||||
@@ -36,9 +37,13 @@ export class WebGLInputAssembler extends InputAssembler {
|
||||
|
||||
private _gpuInputAssembler: IWebGLGPUInputAssembler | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initialize (info: Readonly<InputAssemblerInfo>): void {
|
||||
if (info.vertexBuffers.length === 0) {
|
||||
console.error('InputAssemblerInfo.vertexBuffers is null.');
|
||||
errorID(16331);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,7 +84,7 @@ export class WebGLInputAssembler extends InputAssembler {
|
||||
case 2: glIndexType = 0x1403; break; // WebGLRenderingContext.UNSIGNED_SHORT
|
||||
case 4: glIndexType = 0x1405; break; // WebGLRenderingContext.UNSIGNED_INT
|
||||
default: {
|
||||
console.error('Error index buffer stride.');
|
||||
errorID(16332);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ export class WebGLPipelineLayout extends PipelineLayout {
|
||||
get gpuPipelineLayout (): IWebGLGPUPipelineLayout { return this._gpuPipelineLayout!; }
|
||||
|
||||
private _gpuPipelineLayout: IWebGLGPUPipelineLayout | null = null;
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initialize (info: Readonly<PipelineLayoutInfo>): void {
|
||||
Array.prototype.push.apply(this._setLayouts, info.setLayouts);
|
||||
|
||||
@@ -53,6 +53,10 @@ export class WebGLPipelineState extends PipelineState {
|
||||
|
||||
private _gpuPipelineState: IWebGLGPUPipelineState | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initialize (info: Readonly<PipelineStateInfo>): void {
|
||||
this._primitive = info.primitive;
|
||||
this._shader = info.shader;
|
||||
|
||||
@@ -38,6 +38,7 @@ import { WebGLTexture } from './webgl-texture';
|
||||
import { RenderPass } from '../base/render-pass';
|
||||
import { WebGLRenderPass } from './webgl-render-pass';
|
||||
import { WebGLDeviceManager } from './webgl-define';
|
||||
import { errorID } from '../../core/platform/debug';
|
||||
|
||||
export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
public beginRenderPass (
|
||||
@@ -52,7 +53,10 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
WebGLDeviceManager.instance,
|
||||
(renderPass as WebGLRenderPass).gpuRenderPass,
|
||||
(framebuffer as WebGLFramebuffer).gpuFramebuffer,
|
||||
renderArea, clearColors, clearDepth, clearStencil,
|
||||
renderArea,
|
||||
clearColors,
|
||||
clearDepth,
|
||||
clearStencil,
|
||||
);
|
||||
this._isInRenderPass = true;
|
||||
}
|
||||
@@ -86,7 +90,7 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.error('Command \'draw\' must be recorded inside a render pass.');
|
||||
errorID(16328);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +142,7 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
WebGLCmdFuncUpdateBuffer(WebGLDeviceManager.instance, gpuBuffer, data as ArrayBuffer, 0, buffSize);
|
||||
}
|
||||
} else {
|
||||
console.error('Command \'updateBuffer\' must be recorded outside a render pass.');
|
||||
errorID(16329);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +153,7 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
WebGLCmdFuncCopyBuffersToTexture(WebGLDeviceManager.instance, buffers, gpuTexture, regions);
|
||||
}
|
||||
} else {
|
||||
console.error('Command \'copyBufferToTexture\' must be recorded outside a render pass.');
|
||||
errorID(16330);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,8 +169,14 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer {
|
||||
}
|
||||
|
||||
protected bindStates (): void {
|
||||
WebGLCmdFuncBindStates(WebGLDeviceManager.instance, this._curGPUPipelineState, this._curGPUInputAssembler,
|
||||
this._curGPUDescriptorSets, this._curDynamicOffsets, this._curDynamicStates);
|
||||
WebGLCmdFuncBindStates(
|
||||
WebGLDeviceManager.instance,
|
||||
this._curGPUPipelineState,
|
||||
this._curGPUInputAssembler,
|
||||
this._curGPUDescriptorSets,
|
||||
this._curDynamicOffsets,
|
||||
this._curDynamicStates,
|
||||
);
|
||||
this._isStateInvalied = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ export class WebGLQueue extends Queue {
|
||||
public numInstances = 0;
|
||||
public numTris = 0;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initialize (info: Readonly<QueueInfo>): void {
|
||||
this._type = info.type;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ export class WebGLRenderPass extends RenderPass {
|
||||
|
||||
private _gpuRenderPass: IWebGLGPURenderPass | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initialize (info: Readonly<RenderPassInfo>): void {
|
||||
this._colorInfos = info.colorAttachments;
|
||||
this._depthStencilInfo = info.depthStencilAttachment;
|
||||
|
||||
@@ -38,6 +38,10 @@ export class WebGLShader extends Shader {
|
||||
|
||||
private _gpuShader: IWebGLGPUShader | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initialize (info: Readonly<ShaderInfo>): void {
|
||||
this._name = info.name;
|
||||
this._stages = info.stages;
|
||||
|
||||
@@ -233,6 +233,10 @@ export class WebGLSwapchain extends Swapchain {
|
||||
private _extensions: IWebGLExtensions | null = null;
|
||||
private _blitManager: IWebGLBlitManager | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
|
||||
public initialize (info: Readonly<SwapchainInfo>): void {
|
||||
this._canvas = info.windowHandle;
|
||||
|
||||
@@ -311,7 +315,8 @@ export class WebGLSwapchain extends Swapchain {
|
||||
nullTexRegion.texSubres.layerCount = 6;
|
||||
WebGLDeviceManager.instance.copyBuffersToTexture(
|
||||
[nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff],
|
||||
this.nullTexCube, [nullTexRegion],
|
||||
this.nullTexCube,
|
||||
[nullTexRegion],
|
||||
);
|
||||
this._blitManager = new IWebGLBlitManager();
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user