Compare commits

...

17 Commits

Author SHA1 Message Date
hyde zhou e5183b796a bump version to 4.0.0-alpha.22 (#155) 2026-06-15 16:14:03 +08:00
昌敦伟 32478c1a9c fix(assets): update default cubemap resources (#152) 2026-06-04 09:56:43 +08:00
hyde zhou 74e632a3d6 bump version to 4.0.0-alpha.21 (#153) 2026-06-04 09:55:11 +08:00
orchid-world 26883ba6f4 fix(physics-2d): correct circle collider world position (#142) 2026-06-03 14:29:15 +08:00
orchid-world 055c70f8d2 fix(physics-2d): avoid debug draw crash when toggling flags (#139)
Clear cached debug graphics instead of detaching the debug draw node when
debugDrawFlags is set to None. This keeps the cached node in a valid scene
state and prevents null parent access when debug draw is enabled again.

Add a regression test for toggling Box2D debug draw flags.
2026-06-03 14:28:19 +08:00
bofeng-song 99f6db401c Fix the issue where cli class-registered does not receive messages. (#150) 2026-06-03 14:15:15 +08:00
hyde zhou 9390ee6bc0 Revert "fix codegen (#148)" (#149)
This reverts commit 7f258dac58.
2026-06-02 19:26:13 +08:00
hyde zhou 7f258dac58 fix codegen (#148) 2026-06-02 18:59:58 +08:00
orchid-world 5c99570616 feat(2d): support rounded rect mask radius (#140) 2026-06-02 18:26:55 +08:00
hyde zhou 821928733b bump version to 4.0.0-alpha.20 (#145) 2026-06-01 18:03:01 +08:00
hyde zhou f567861ff6 bump version to 4.0.0-alpha.19 (#143) 2026-05-25 14:33:54 +08:00
hyde zhou a7a20b64ab bump version to 4.0.0-alpha.18 (#137) 2026-05-19 23:40:06 +08:00
hyde zhou 7c75834010 bump version to 4.0.0-alpha.17 (#135) 2026-05-11 23:18:35 +08:00
hyde zhou 8fd985af75 bump version to 4.0.0-alpha.16 (#134) 2026-05-07 15:35:41 +08:00
qiuguohua cc97bc8af4 V4.0.0 fix get window info cache (#123) 2026-05-07 15:16:18 +08:00
tangkai 92124590fe update (#131) 2026-04-29 16:10:42 +08:00
tangkai 822ac6026c update assets.js (#129) 2026-04-29 13:04:48 +08:00
28 changed files with 187 additions and 35 deletions
+56 -4
View File
@@ -64,10 +64,10 @@ function _calculateCircle (center: Vec3, radius: Vec3, segments: number): Vec3[]
*/
export enum MaskType {
/**
* @en Rect mask.
* @en Rect mask, supports rounded corners by setting radius.
*
* @zh
* 使用矩形作为遮罩。
* 使用矩形作为遮罩,可通过 radius 设置圆角。
*/
GRAPHICS_RECT = 0,
@@ -215,6 +215,32 @@ export class Mask extends Component {
this._updateGraphics();
}
/**
* @en
* The radius for rounded corners of rect mask.
*
* @zh
* 矩形遮罩的圆角半径。
*/
@visible(function (this: Mask) {
return this.type === MaskType.GRAPHICS_RECT;
})
@tooltip('i18n:mask.radius')
@range([0, Number.POSITIVE_INFINITY])
get radius (): number {
return this._radius;
}
set radius (value) {
const radius = clamp(value, 0, Number.POSITIVE_INFINITY);
if (this._radius === radius) {
return;
}
this._radius = radius;
this._updateGraphics();
}
/**
* @en
* The mask image.
@@ -289,6 +315,9 @@ export class Mask extends Component {
@serializable
protected _segments = 64;
@serializable
protected _radius = 0;
@serializable
protected _alphaThreshold = 0.1;
@@ -350,7 +379,25 @@ export class Mask extends Component {
testPt.y += ap.y * h;
let result = false;
if (this.type === MaskType.GRAPHICS_RECT || this.type === MaskType.GRAPHICS_STENCIL || this.type === MaskType.SPRITE_STENCIL) {
if (this.type === MaskType.GRAPHICS_RECT) {
result = testPt.x >= 0 && testPt.y >= 0 && testPt.x <= w && testPt.y <= h;
const radius = Math.min(this._radius, w / 2, h / 2);
if (result && radius > 0) {
let dx = 0;
let dy = 0;
if (testPt.x < radius) {
dx = testPt.x - radius;
} else if (testPt.x > w - radius) {
dx = testPt.x - (w - radius);
}
if (testPt.y < radius) {
dy = testPt.y - radius;
} else if (testPt.y > h - radius) {
dy = testPt.y - (h - radius);
}
result = dx * dx + dy * dy <= radius * radius;
}
} else if (this.type === MaskType.GRAPHICS_STENCIL || this.type === MaskType.SPRITE_STENCIL) {
result = testPt.x >= 0 && testPt.y >= 0 && testPt.x <= w && testPt.y <= h;
} else if (this.type === MaskType.GRAPHICS_ELLIPSE) {
const rx = w / 2;
@@ -423,7 +470,12 @@ export class Mask extends Component {
const x = -width * ap.x;
const y = -height * ap.y;
if (this._type === MaskType.GRAPHICS_RECT) {
graphics.rect(x, y, width, height);
const radius = Math.min(this._radius, width / 2, height / 2);
if (radius > 0) {
graphics.roundRect(x, y, width, height, radius);
} else {
graphics.rect(x, y, width, height);
}
} else if (this._type === MaskType.GRAPHICS_ELLIPSE) {
const center = new Vec3(x + width / 2, y + height / 2, 0);
const radius = new Vec3(width / 2, height / 2, 0);
+10 -3
View File
@@ -195,15 +195,22 @@ function define (className, baseClass, options): any {
renderName = 'render_stage';
}
// 增加了 hidden: 开头标识,使它最终不会显示在 Editor inspector 的添加组件列表里
window.EditorExtends && window.EditorExtends.Component.addMenu(cls, `hidden:${renderName}/${className}`, -1);
if (globalThis.EditorExtends) {
globalThis.EditorExtends.Component.addMenu(cls, `hidden:${renderName}/${className}`, -1);
}
}
// Note: `options.ctor` should be the same as `cls` except if
// cc-class is defined by `cc.Class({/* ... */})`.
// In such case, `options.ctor` may be `undefined`.
// So we can not use `options.ctor`. Instead, we should use `cls` which is the "real" registered cc-class.
EditorExtends.emit('class-registered', cls, frame, className);
// Emit via globalThis.EditorExtends to ensure the event reaches
// both the engine-internal and the scene-bundle event systems.
if (globalThis.EditorExtends) {
globalThis.EditorExtends.emit('class-registered', cls, frame, className);
} else {
EditorExtends.emit('class-registered', cls, frame, className);
}
}
if (frame) {
+1 -1
View File
@@ -141,7 +141,7 @@ export class b2PhysicsWorld implements IPhysicsWorld {
if (!v) {
if (this._debugGraphics) {
this._debugGraphics.node.parent = null;
this._debugGraphics.clear();
}
}
@@ -34,8 +34,8 @@ export class b2CircleShape extends b2Shape2D implements ICircleShape {
_worldPosition = new Vec2();
get worldPosition (): Vec2 {
const p = (this._shapes[0] as b2jsb.CircleShape).m_p;
return this._worldPosition.set(p.x * PHYSICS_2D_PTM_RATIO, p.y * PHYSICS_2D_PTM_RATIO);
const comp = this.collider as CircleCollider2D;
return Vec2.transformMat4(this._worldPosition, comp.offset, comp.node.worldMatrix);
}
_createShapes (scaleX: number, scaleY: number, relativePositionX: number, relativePositionY: number): any[] {
+1 -1
View File
@@ -114,7 +114,7 @@ export class B2PhysicsWorld implements IPhysicsWorld {
if (!v) {
if (this._debugGraphics) {
this._debugGraphics.node.parent = null;
this._debugGraphics.clear();
}
}
@@ -37,8 +37,8 @@ export class B2CircleShape extends B2Shape2D implements ICircleShape {
_worldPosition = new Vec2();
get worldPosition (): Vec2 {
const p = B2.CircleShapeGetPosition(this._shapes[0]) as B2.Vec2;
return this._worldPosition.set(p.x * PHYSICS_2D_PTM_RATIO, p.y * PHYSICS_2D_PTM_RATIO);
const comp = this.collider as CircleCollider2D;
return Vec2.transformMat4(this._worldPosition, comp.offset, comp.node.worldMatrix);
}
_createShapes (scaleX: number, scaleY: number, relativePositionX: number, relativePositionY: number): number[] { //B2.CircleShape[]
+1 -1
View File
@@ -100,7 +100,7 @@ export class b2PhysicsWorld implements IPhysicsWorld {
if (!v) {
if (this._debugGraphics) {
this._debugGraphics.node.parent = null;
this._debugGraphics.clear();
}
}
@@ -37,8 +37,8 @@ export class b2CircleShape extends b2Shape2D implements ICircleShape {
_worldPosition = new Vec2();
get worldPosition (): Vec2 {
const p = (this._shapes[0] as b2.CircleShape).m_p;
return this._worldPosition.set(p.x * PHYSICS_2D_PTM_RATIO, p.y * PHYSICS_2D_PTM_RATIO);
const comp = this.collider as CircleCollider2D;
return Vec2.transformMat4(this._worldPosition, comp.offset, comp.node.worldMatrix);
}
_createShapes (scaleX: number, scaleY: number, relativePositionX: number, relativePositionY: number): any[] {
Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 945 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "6ef37a33-5db9-4231-9855-f72b8428f6fa",
"files": [],
"subMetas": {},
"userData": {}
}
@@ -0,0 +1,19 @@
{
"ver": "1.0.4",
"importer": "texture-cube",
"imported": true,
"uuid": "a4063d6c-c46e-482a-bf84-99eb9fbb2789",
"files": [
".json"
],
"subMetas": {},
"userData": {
"wrapModeS": "repeat",
"wrapModeT": "repeat",
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0,
"isRGBE": false
}
}
+3 -3
View File
@@ -39,9 +39,9 @@ module.exports = {
newRenderTexture: 'Render Texture',
newScene: 'Scene',
newScene:{
'2d': '2D',
'3d': '3D',
quality: 'Quality',
'2d': '2D Scene',
'3d': '3D Scene',
quality: 'High Quality Scene',
},
newPrefab: 'Node Prefab',
newMaterial: 'Material',
+1
View File
@@ -779,6 +779,7 @@ module.exports = link(mixin({
},
mask: {
type: 'The mask type',
radius: 'The radius for rounded corners of rect mask',
spriteFrame: 'The mask image',
inverted: 'The Reverse mask (Not supported Canvas Mode)',
alphaThreshold:
+3 -3
View File
@@ -38,9 +38,9 @@ module.exports = {
newCubeMap: '立方体贴图',
newScene: '场景',
newScene:{
'2d': '2D',
'3d': '3D',
quality: '质量',
'2d': '2D 场景',
'3d': '3D 场景',
quality: '高质量场景',
},
newPrefab: '预制 (Prefab)',
newRenderTexture: '渲染纹理 (Render Texture)',
+1
View File
@@ -760,6 +760,7 @@ module.exports = link(mixin({
},
mask: {
type: '遮罩类型',
radius: '矩形遮罩的圆角半径',
spriteFrame: '遮罩所需要的贴图',
inverted: '反向遮罩(不支持 Canvas 模式)',
alphaThreshold: 'Alpha 阈值,只有当模板的像素的 Alpha 大于 Alpha Threshold 时,才会绘制内容(不支持 Canvas 模式)',
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "cocos-creator",
"version": "4.0.0-alpha.15",
"version": "4.0.0-alpha.22",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "cocos-creator",
"version": "4.0.0-alpha.15",
"version": "4.0.0-alpha.22",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "cocos-creator",
"version": "4.0.0-alpha.15",
"version": "4.0.0-alpha.22",
"description": "Cocos Creator is a cross-platform 2D & 3D game engine written in C++ and TypeScript, licensed under MIT.",
"homepage": "http://www.cocos.com",
"license": "MIT",
-7
View File
@@ -124,13 +124,6 @@ minigame.createInnerAudioContext = createInnerAudioContextPolyfill(wx, {
onSeek: false,
}, true);
let _cachedSystemInfo: SystemInfo = wx.getWindowInfo();
minigame.onWindowResize?.((): void => {
// update cached system info
_cachedSystemInfo = wx.getWindowInfo() as SystemInfo;
});
minigame.getWindowInfo = (): SystemInfo => _cachedSystemInfo;
// #region SafeArea
// FIX_ME: wrong safe area when orientation is landscape left
minigame.getSafeArea = (): SafeArea => {
+11 -1
View File
@@ -24,7 +24,7 @@
*/
import { ALIPAY, BYTEDANCE, HUAWEI, OPPO, RUNTIME_BASED, SUD, SUDV2, VIVO, MIGU, HONOR, WECHAT, XIAOMI, DEBUG, TEST, TAOBAO, TAOBAO_MINIGAME, WECHAT_MINI_PROGRAM } from 'internal:constants';
import { minigame, SystemInfo as MinigameSystemInfo } from 'pal/minigame';
import { minigame, SystemInfo as MinigameSystemInfo, WindowInfo } from 'pal/minigame';
import { IFeatureMap } from 'pal/system-info';
import { EventTarget } from '../../../cocos/core/event';
import { checkPalIntegrity, withImpl } from '../../integrity-check';
@@ -100,7 +100,10 @@ if (BYTEDANCE) {
}
const originalGetSystemInfoSync = minigame.getSystemInfoSync;
// Some platforms may not have this interface(getWindowInfo).
const originalGetWindowInfo = minigame.getWindowInfo;
let _cachedSystemInfo: MinigameSystemInfo = originalGetSystemInfoSync.call(minigame);
let _cachedWindowInfo: WindowInfo | undefined = originalGetWindowInfo?.call(minigame);
function testAndUpdateSystemInfoCache (testAmount: number, testInterval: number): void {
let successfullyTestTimes = 0;
@@ -127,12 +130,19 @@ if (WECHAT && versionCompare(minigame.getAppBaseInfo().SDKVersion, '2.25.3') < 0
minigame.onWindowResize?.(() => {
// update cached system info
_cachedSystemInfo = originalGetSystemInfoSync.call(minigame);
_cachedWindowInfo = originalGetWindowInfo?.call(minigame);
});
minigame.getSystemInfoSync = function (): MinigameSystemInfo {
return _cachedSystemInfo;
};
if (originalGetWindowInfo !== undefined) {
minigame.getWindowInfo = function (): WindowInfo {
return _cachedWindowInfo!;
};
}
class SystemInfo extends EventTarget {
public declare readonly networkType: NetworkType;
public declare readonly isNative: boolean;
+20 -1
View File
@@ -1,3 +1,5 @@
/// <reference types="jest" />
import { EPSILON, Quat, Vec2, Vec3 } from "../../cocos/core";
import { director } from "../../cocos/game";
import { Node } from "../../cocos/scene-graph";
@@ -40,4 +42,21 @@ export default function (parent: Node, _steps = 0) {
parent.removeAllChildren();
}
}
// circle worldPosition
{
const nodeCollider = new Node('CircleCollider2D');
parent.addChild(nodeCollider);
nodeCollider.worldPosition = new Vec3(10, 20, 0);
nodeCollider.addComponent(physics2d.RigidBody2D);
const collider = nodeCollider.addComponent(physics2d.CircleCollider2D) as physics2d.CircleCollider2D;
collider.offset = new Vec2(2, -3);
collider.apply();
expect(Vec2.equals(collider.worldPosition, new Vec2(12, 17))).toBe(true);
parent.destroyAllChildren();
parent.removeAllChildren();
}
}
+37
View File
@@ -0,0 +1,37 @@
import * as physics2d from "../../exports/physics-2d-framework";
/**
* 验证 Box2D 后端关闭调试绘制时保留调试节点,避免再次开启时父节点为空。
*/
export default function DebugDrawTest (): void {
if (physics2d.selector.id === 'builtin') {
return;
}
const parent = {};
const clear = jest.fn();
const debugGraphics = {
clear,
node: {
parent,
},
};
const physicsWorld = physics2d.PhysicsSystem2D.instance.physicsWorld as unknown as {
_debugGraphics: typeof debugGraphics | null;
};
physicsWorld._debugGraphics = debugGraphics;
try {
physics2d.PhysicsSystem2D.instance.debugDrawFlags = physics2d.EPhysics2DDrawFlags.Shape;
physics2d.PhysicsSystem2D.instance.debugDrawFlags = physics2d.EPhysics2DDrawFlags.None;
expect(clear).toHaveBeenCalledTimes(1);
expect(debugGraphics.node.parent).toBe(parent);
physics2d.PhysicsSystem2D.instance.debugDrawFlags = physics2d.EPhysics2DDrawFlags.Shape;
expect(debugGraphics.node.parent).toBe(parent);
} finally {
physics2d.PhysicsSystem2D.instance.debugDrawFlags = physics2d.EPhysics2DDrawFlags.None;
physicsWorld._debugGraphics = null;
}
}
+5 -1
View File
@@ -12,6 +12,7 @@ import RigidBodyTest from "./rigid-body";
import ColliderTest from "./collider";
import SceneQueryTest from "./scene-query";
import EventTest from "./events";
import DebugDrawTest from "./debug-draw";
game.emit(Game.EVENT_PRE_SUBSYSTEM_INIT);
physics2d.PhysicsSystem2D.constructAndRegister();
@@ -50,10 +51,13 @@ for (const id in physics2d.selector.backend) {
//test events
EventTest(temp0);
//test debug draw
DebugDrawTest();
// destroy test scene
temp0.destroy();
scene.destroy();
// all works done
done();
})
}
}