Skip to content

Commit

Permalink
Add more feature cropping settings for RichText, Mask, Graphics, UISk…
Browse files Browse the repository at this point in the history
…ew, AffineTransform.
  • Loading branch information
dumganhar committed Feb 6, 2025
1 parent 78b61b2 commit da7c4b6
Show file tree
Hide file tree
Showing 29 changed files with 219 additions and 67 deletions.
4 changes: 4 additions & 0 deletions EngineErrorMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,10 @@ Invalid RichText img tag! The sprite frame name can't be found in the ImageAtlas

Graphics: There is no model in %s.

### 4501

Graphics feature is not enabled in 'Project Settings -> Feature Cropping', %s

### 4600

Script attached to '%s' is missing or invalid.
Expand Down
31 changes: 31 additions & 0 deletions cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,28 @@
"f0416e68-0200-4b77-a926-4f9d16e494da"
]
},
"rich-text": {
"modules": ["rich-text"],
"dependentModules": ["2d"]
},
"mask": {
"modules": ["mask"],
"dependentModules": ["2d"]
},
"graphics": {
"modules": ["graphics"],
"dependentModules": ["2d"]
},
"ui-skew": {
"modules": ["ui-skew"],
"dependentModules": ["2d"]
},
"ui": {
"modules": ["ui", "2d"]
},
"affine-transform": {
"modules": ["affine-transform"]
},
"particle": {
"modules": ["particle"],
"dependentAssets": [
Expand Down Expand Up @@ -692,6 +711,18 @@
"type": "boolean",
"value": false,
"internal": true
},
"USE_3D": {
"comment": "An internal constant to indicate whether we're using 3d module.",
"type": "boolean",
"value": true,
"internal": true
},
"USE_UI_SKEW": {
"comment": "An internal constant to indicate whether we're using ui-skew module.",
"type": "boolean",
"value": true,
"internal": true
}
},

Expand Down
1 change: 1 addition & 0 deletions cocos/2d/assembler/graphics/webgl/earcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
THE SOFTWARE.
*/

/** @mangle */
class Aim {
// vertex index in coordinates array
public declare i: number;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/graphics/webgl/graphics-assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Color, Vec3 } from '../../../../core';
import { IAssembler } from '../../../renderer/base';
import { MeshRenderData } from '../../../renderer/render-data';
import { IBatcher } from '../../../renderer/i-batcher';
import { Graphics } from '../../../components';
import { Graphics } from '../../../components/graphics';
import { LineCap, LineJoin, PointFlags } from '../types';
import { earcut as Earcut } from './earcut';
import { Impl, Point } from './impl';
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/graphics/webgl/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import { JSB } from 'internal:constants';
import { Color, Vec2 } from '../../../../core';
import { Graphics } from '../../../components';
import { Graphics } from '../../../components/graphics';
import { RenderData, MeshRenderData } from '../../../renderer/render-data';
import { RenderDrawInfoType } from '../../../renderer/render-draw-info';
import { arc, ellipse, roundRect, tesselateBezier } from '../helper';
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/graphics/webgl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import { UIRenderer } from '../../../framework/ui-renderer';
import { IAssemblerManager } from '../../../renderer/base';
import { Graphics } from '../../../components';
import { Graphics } from '../../../components/graphics';
import { graphicsAssembler as graphics } from './graphics-assembler';

const graphicsAssemblerManager: IAssemblerManager = {
Expand Down
1 change: 0 additions & 1 deletion cocos/2d/assembler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@

import './utils';

export * from './graphics';
export * from './label';
export * from './sprite';
3 changes: 0 additions & 3 deletions cocos/2d/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
*/

export * from './label';
export { Mask } from './mask';
export { RichText } from './rich-text';
export { Sprite } from './sprite';
export { UIMeshRenderer } from './ui-mesh-renderer';
export { LabelOutline } from './label-outline';
export { Graphics } from './graphics';
export { UIStaticBatch } from './ui-static-batch';
export { LabelShadow } from './label-shadow';
export { UIOpacity } from './ui-opacity';
Expand Down
1 change: 0 additions & 1 deletion cocos/2d/framework/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export * from './canvas';
export * from './ui-component';
export * from './ui-renderer';
export * from './ui-transform';
export * from './ui-skew';
export * from './deprecated';
export * from './render-root-2d';
export * from './sprite-renderer';
2 changes: 1 addition & 1 deletion cocos/2d/framework/ui-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Mat4, Rect, Size, Vec2, Vec3, geometry, warnID, visibleRect, approx, EP
import { director, DirectorEvent } from '../../game/director';
import { NodeEventType } from '../../scene-graph/node-event';
import { IMask } from '../../scene-graph/node-event-processor';
import { Mask } from '../components/mask';
import type { Mask } from '../components/mask';

const _vec2a = new Vec2();
const _vec2b = new Vec2();
Expand Down
3 changes: 0 additions & 3 deletions cocos/2d/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

import {
graphicsAssembler,
labelAssembler,
spriteAssembler,
} from './assembler';
Expand All @@ -48,13 +47,11 @@ export {
StencilManager,
spriteAssembler, // use less
labelAssembler, // use less
graphicsAssembler, // use less
};

cclegacy.UI = {
MeshBuffer, // use less
spriteAssembler, // use less
graphicsAssembler, // use less
labelAssembler, // use less
RenderData,
MeshRenderData,
Expand Down
1 change: 0 additions & 1 deletion cocos/core/math/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export { Vec4, v4 } from './vec4';
export { Quat, quat } from './quat';
export { Mat3 } from './mat3';
export { Mat4, mat4 } from './mat4';
export { AffineTransform } from './affine-transform';
export { Size, size } from './size';
export { Rect, rect } from './rect';
export { Color, color } from './color';
Expand Down
21 changes: 13 additions & 8 deletions cocos/dragon-bones/ArmatureDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { AttachUtil } from './AttachUtil';
import { CCFactory } from './CCFactory';
import { DragonBonesAsset } from './DragonBonesAsset';
import { DragonBonesAtlasAsset } from './DragonBonesAtlasAsset';
import { Graphics } from '../2d/components';
import type { Graphics } from '../2d/components/graphics';
import { CCArmatureDisplay } from './CCArmatureDisplay';
import { MaterialInstance } from '../render-scene/core/material-instance';
import { ArmatureSystem } from './ArmatureSystem';
Expand Down Expand Up @@ -998,14 +998,19 @@ export class ArmatureDisplay extends UIRenderer {
if (!this._debugDraw) {
const debugDrawNode = new Node('DEBUG_DRAW_NODE');
debugDrawNode.hideFlags |= CCObjectFlags.DontSave | CCObjectFlags.HideInHierarchy;
const debugDraw = debugDrawNode.addComponent(Graphics);
debugDraw.lineWidth = 1;
debugDraw.strokeColor = new Color(255, 0, 0, 255);

this._debugDraw = debugDraw;
let debugDraw: Graphics | undefined;
try {
debugDraw = debugDrawNode.addComponent('cc.Graphics') as Graphics;
debugDraw.lineWidth = 1;
debugDraw.strokeColor = new Color(255, 0, 0, 255);

this._debugDraw = debugDraw;
this._debugDraw.node.parent = this.node;
} catch (e: any) {
errorID(4501, e.message as string);
debugDrawNode.destroy();
}
}

this._debugDraw.node.parent = this.node;
} else if (this._debugDraw) {
this._debugDraw.node.parent = null;
}
Expand Down
26 changes: 16 additions & 10 deletions cocos/physics-2d/box2d-wasm/physics-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import { EDITOR_NOT_IN_PREVIEW } from 'internal:constants';
import { B2, getImplPtr, addImplPtrReference, addImplPtrReferenceWASM,
getTSObjectFromWASMObjectPtr, removeImplPtrReference, removeImplPtrReferenceWASM, B2ObjectType } from './instantiated';
import { IPhysicsWorld } from '../spec/i-physics-world';
import { IVec2Like, Vec3, Quat, Vec2, toDegree, Rect, CCObjectFlags, js } from '../../core';
import { IVec2Like, Vec3, Quat, Vec2, toDegree, Rect, CCObjectFlags, js, errorID } from '../../core';
import { PHYSICS_2D_PTM_RATIO, ERaycast2DType, ERigidBody2DType } from '../framework/physics-types';
import { Canvas } from '../../2d/framework';
import { Graphics } from '../../2d/components';
import type { Graphics } from '../../2d/components/graphics';

import { B2RigidBody2D } from './rigid-body';
import { PhysicsContactListener } from './platform/physics-contact-listener';
Expand Down Expand Up @@ -133,18 +133,24 @@ export class B2PhysicsWorld implements IPhysicsWorld {
node.worldPosition = Vec3.ZERO;
node.layer = Layers.Enum.UI_2D;

this._debugGraphics = node.addComponent(Graphics);
this._debugGraphics.lineWidth = 3;
try {
this._debugGraphics = node.addComponent('cc.Graphics') as Graphics;
this._debugGraphics.lineWidth = 3;

PhysicsDebugDraw._drawer = this._debugGraphics;
const debugDraw = B2.Draw.implement(PhysicsDebugDraw.callback);//new PhysicsDebugDraw();
PhysicsDebugDraw._drawer = this._debugGraphics;
const debugDraw = B2.Draw.implement(PhysicsDebugDraw.callback);//new PhysicsDebugDraw();

this._b2DebugDrawer = debugDraw;
this._world.SetDebugDraw(debugDraw as B2.Draw);
this._b2DebugDrawer = debugDraw;
this._world.SetDebugDraw(debugDraw as B2.Draw);
} catch (e: any) {
errorID(4501, e.message as string);
}
}

const parent = this._debugGraphics.node.parent!;
this._debugGraphics.node.setSiblingIndex(parent.children.length - 1);
if (this._debugGraphics) {
const parent = this._debugGraphics.node.parent!;
this._debugGraphics.node.setSiblingIndex(parent.children.length - 1);
}

if (this._b2DebugDrawer) {
this._b2DebugDrawer.SetFlags(this.debugDrawFlags);
Expand Down
2 changes: 1 addition & 1 deletion cocos/physics-2d/box2d-wasm/platform/physics-debug-draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import { B2, b2Mul } from '../instantiated';
import { Color } from '../../../core';
import { PHYSICS_2D_PTM_RATIO } from '../../framework';
import { Graphics } from '../../../2d';
import type { Graphics } from '../../../2d/components/graphics';

const _tmp_vec2 = { x: 0, y: 0 };
const _tmp_vec3 = { x: 0, y: 0 };
Expand Down
30 changes: 19 additions & 11 deletions cocos/physics-2d/box2d/physics-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import b2 from '@cocos/box2d';
import { EDITOR_NOT_IN_PREVIEW, TEST } from 'internal:constants';

import { IPhysicsWorld } from '../spec/i-physics-world';
import { IVec2Like, Vec3, Quat, Vec2, toDegree, Rect, CCObjectFlags, js } from '../../core';
import { IVec2Like, Vec3, Quat, Vec2, toDegree, Rect, CCObjectFlags, js, errorID } from '../../core';
import { PHYSICS_2D_PTM_RATIO, ERaycast2DType, ERigidBody2DType } from '../framework/physics-types';
import { b2RigidBody2D } from './rigid-body';
import { PhysicsContactListener } from './platform/physics-contact-listener';
Expand All @@ -38,6 +38,7 @@ import { b2Shape2D } from './shapes/shape-2d';
import { PhysicsDebugDraw } from './platform/physics-debug-draw';
import { Node, find, Layers } from '../../scene-graph';
import { director } from '../../game';
import type { Graphics } from '../../2d/components/graphics';

const tempVec3 = new Vec3();
const tempVec2_1 = new Vec2();
Expand Down Expand Up @@ -86,7 +87,7 @@ export class b2PhysicsWorld implements IPhysicsWorld {
this._raycastQueryCallback = new PhysicsRayCastCallback();
}

_debugGraphics: any = null;
_debugGraphics: Graphics | null = null;
_b2DebugDrawer: b2.Draw | null = null;

_debugDrawFlags = 0;
Expand Down Expand Up @@ -127,17 +128,24 @@ export class b2PhysicsWorld implements IPhysicsWorld {
node.worldPosition = Vec3.ZERO;
node.layer = Layers.Enum.UI_2D;

this._debugGraphics = node.addComponent('cc.Graphics');
this._debugGraphics.lineWidth = 3;

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const debugDraw = new PhysicsDebugDraw(this._debugGraphics);
this._b2DebugDrawer = debugDraw;
this._world.SetDebugDraw(debugDraw);
try {
this._debugGraphics = node.addComponent('cc.Graphics') as Graphics;
this._debugGraphics.lineWidth = 3;

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const debugDraw = new PhysicsDebugDraw(this._debugGraphics);
this._b2DebugDrawer = debugDraw;
this._world.SetDebugDraw(debugDraw);
} catch (e: any) {
errorID(4501, e.message as string);
node.destroy();
}
}

const parent = this._debugGraphics.node.parent!;
this._debugGraphics.node.setSiblingIndex(parent.children.length - 1);
if (this._debugGraphics) {
const parent = this._debugGraphics.node.parent!;
this._debugGraphics.node.setSiblingIndex(parent.children.length - 1);
}

if (this._b2DebugDrawer) {
this._b2DebugDrawer.SetFlags(this.debugDrawFlags);
Expand Down
2 changes: 1 addition & 1 deletion cocos/physics-2d/box2d/platform/physics-debug-draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import b2, { Vec2 } from '@cocos/box2d';
import { Color } from '../../../core';
import { PHYSICS_2D_PTM_RATIO } from '../../framework';
import { Graphics } from '../../../2d';
import type { Graphics } from '../../../2d/components/graphics';

const _tmp_vec2 = new b2.Vec2();
const _tmp_color = new Color();
Expand Down
2 changes: 0 additions & 2 deletions cocos/physics-2d/builtin/builtin-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

import { EDITOR_NOT_IN_PREVIEW, TEST } from 'internal:constants';
import { IPhysicsWorld } from '../spec/i-physics-world';
// import { Graphics } from '../../2d';
import { CCObjectFlags, Vec3, Color, IVec2Like, Vec2, Rect, js } from '../../core';
// import { Canvas } from '../../2d/framework';
import { BuiltinShape2D } from './shapes/shape-2d';
import { BuiltinBoxShape } from './shapes/box-shape-2d';
import { BuiltinCircleShape } from './shapes/circle-shape-2d';
Expand Down
3 changes: 2 additions & 1 deletion cocos/scene-graph/node-ui-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import { UIRenderer } from '../2d/framework/ui-renderer';
import { warnID } from '../core/platform/debug';
import { UIMeshRenderer } from '../2d';
import type { Node } from './node';
import type { UITransform, UISkew } from '../2d/framework';
import type { UITransform } from '../2d/framework';
import type { UISkew } from '../2d/framework/ui-skew';

/**
* @en Node's UI properties abstraction
Expand Down
Loading

0 comments on commit da7c4b6

Please sign in to comment.