From 94bd99be5c3a7eed4d004dddfeea13db0ff8128b Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 12 Dec 2024 15:38:02 +0800 Subject: [PATCH 1/2] fixed #3d-tasks/18679: Invoke toLowerCase of undefined. Enum should be used instead of ccenum to generate reverse key. --- cocos/primitive/primitive.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cocos/primitive/primitive.ts b/cocos/primitive/primitive.ts index 9455de24558..8d616eeacce 100644 --- a/cocos/primitive/primitive.ts +++ b/cocos/primitive/primitive.ts @@ -26,7 +26,7 @@ import { ccclass, type, serializable, editable } from 'cc.decorator'; import { createMesh } from '../3d/misc'; import { Mesh } from '../3d/assets/mesh'; import * as primitives from '.'; -import { ccenum, cclegacy } from '../core'; +import { Enum, cclegacy } from '../core'; enum PrimitiveType { BOX = 0, @@ -38,7 +38,7 @@ enum PrimitiveType { PLANE = 6, QUAD = 7, } -ccenum(PrimitiveType); +Enum(PrimitiveType); /** * @en @@ -81,7 +81,8 @@ export class Primitive extends Mesh { * 根据`type`和`info`构建相应的网格。 */ public onLoaded (): void { - createMesh(primitives[PrimitiveType[this.type].toLowerCase()](this.info), this); + const factory = primitives[PrimitiveType[this.type].toLowerCase()] as (arg: typeof this.info) => primitives.IGeometry; + createMesh(factory(this.info), this); } } From 6c4257938f335123c68e9bac6550a9d4d5eefb74 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 13 Dec 2024 09:26:12 +0800 Subject: [PATCH 2/2] Add a comment for PrimitiveType. --- cocos/primitive/primitive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/primitive/primitive.ts b/cocos/primitive/primitive.ts index 8d616eeacce..84a09ad8926 100644 --- a/cocos/primitive/primitive.ts +++ b/cocos/primitive/primitive.ts @@ -38,7 +38,7 @@ enum PrimitiveType { PLANE = 6, QUAD = 7, } -Enum(PrimitiveType); +Enum(PrimitiveType); // Need reversed keys in Primitive.onLoaded, so use Enum to generate reversed keys. /** * @en