diff --git a/cocos/physics/bullet/bullet-bvh-triangle-mesh-shape.ts b/cocos/physics/bullet/bullet-bvh-triangle-mesh-shape.ts index ba86fc26902..03a7981b020 100644 --- a/cocos/physics/bullet/bullet-bvh-triangle-mesh-shape.ts +++ b/cocos/physics/bullet/bullet-bvh-triangle-mesh-shape.ts @@ -26,6 +26,7 @@ import { bt, EBulletType } from './instantiated'; import { Mesh } from '../../3d/assets'; import { cocos2BulletTriMesh } from './bullet-utils'; +/** @mangle */ export class BulletBvhTriangleMeshShape { private static readonly BulletBvhTriangleMeshShapeMap = new Map(); diff --git a/cocos/physics/bullet/bullet-cache.ts b/cocos/physics/bullet/bullet-cache.ts index 4d43528ebb7..93fd0960532 100644 --- a/cocos/physics/bullet/bullet-cache.ts +++ b/cocos/physics/bullet/bullet-cache.ts @@ -26,6 +26,7 @@ import { Collider, TriggerEventType, CollisionEventType, IContactEquation, Chara import { Vec3, Quat, Mat4, Color } from '../../core'; import { CharacterTriggerEventType } from '../framework'; import { bt, btCache } from './instantiated'; +import type { BulletWorld } from './bullet-world'; export const TriggerEventObject = { type: 'onTriggerEnter' as unknown as TriggerEventType, @@ -73,6 +74,8 @@ export class BulletCache { static isNotEmptyShape (ptr: Bullet.ptr): boolean { return ptr !== bt.EmptyShape_static(); } + static world: BulletWorld | null = null; + readonly BT_TRANSFORM_0 = bt.Transform_new(); readonly BT_TRANSFORM_1 = bt.Transform_new(); readonly BT_V3_0 = bt.Vec3_new(0, 0, 0); diff --git a/cocos/physics/bullet/bullet-contact-data.ts b/cocos/physics/bullet/bullet-contact-data.ts index 8023e26431c..a8ed8db8c5a 100644 --- a/cocos/physics/bullet/bullet-contact-data.ts +++ b/cocos/physics/bullet/bullet-contact-data.ts @@ -32,7 +32,7 @@ import { bullet2CocosQuat, bullet2CocosVec3 } from './bullet-utils'; export class BulletContactData implements IContactEquation { get isBodyA (): boolean { const sb = (this.event.selfCollider.shape as BulletShape).sharedBody.body; - return sb === bt.PersistentManifold_getBody0(this.event.impl); + return sb === bt.PersistentManifold_getBody0(this.event.impl as number); } impl: Bullet.ptr = 0; //btManifoldPoint @@ -61,7 +61,7 @@ export class BulletContactData implements IContactEquation { getLocalNormalOnA (out: IVec3Like): void { if (this.impl) { const bt_rot = BulletCache.instance.BT_QUAT_0; - const body = bt.PersistentManifold_getBody0(this.event.impl); + const body = bt.PersistentManifold_getBody0(this.event.impl as number); const trans = bt.CollisionObject_getWorldTransform(body); bt.Transform_getRotation(trans, bt_rot); const inv_rot = CC_QUAT_0; @@ -76,7 +76,7 @@ export class BulletContactData implements IContactEquation { getLocalNormalOnB (out: IVec3Like): void { if (this.impl) { const bt_rot = BulletCache.instance.BT_QUAT_0; - const body = bt.PersistentManifold_getBody1(this.event.impl); + const body = bt.PersistentManifold_getBody1(this.event.impl as number); const trans = bt.CollisionObject_getWorldTransform(body); bt.Transform_getRotation(trans, bt_rot); const inv_rot = CC_QUAT_0; diff --git a/cocos/physics/bullet/bullet-enum.ts b/cocos/physics/bullet/bullet-enum.ts index 935a943cbab..f1adf96dfb9 100644 --- a/cocos/physics/bullet/bullet-enum.ts +++ b/cocos/physics/bullet/bullet-enum.ts @@ -23,6 +23,7 @@ */ export enum EBtSharedBodyDirty { + NONE = 0, BODY_RE_ADD = 1, GHOST_RE_ADD = 2, } diff --git a/cocos/physics/bullet/bullet-env.ts b/cocos/physics/bullet/bullet-env.ts index 4a0f892466f..c2d09783826 100644 --- a/cocos/physics/bullet/bullet-env.ts +++ b/cocos/physics/bullet/bullet-env.ts @@ -23,15 +23,17 @@ */ import { btCache } from './instantiated'; +import type { BulletSharedBody } from './bullet-shared-body'; +import type { BulletCharacterController } from './character-controllers/bullet-character-controller'; // The import function used in c++ code, same as DLL Import export const importFunc = { syncPhysicsToGraphics (id: number): void { - const body = btCache.CACHE.getWrapper(id, btCache.BODY_CACHE_NAME); + const body = btCache.CACHE.getWrapper(id, btCache.BODY_CACHE_NAME); body.syncPhysicsToGraphics(); }, onShapeHitExt (hit: number, controller: number): void { - const cct = btCache.CACHE.getWrapper(controller, btCache.CCT_CACHE_NAME); + const cct = btCache.CACHE.getWrapper(controller, btCache.CCT_CACHE_NAME); cct.onShapeHitExt(hit); }, onDebugDrawLine (from: number, to: number, color: number): void { diff --git a/cocos/physics/bullet/bullet-interface.ts b/cocos/physics/bullet/bullet-interface.ts index 85097118cc4..72b762204c4 100644 --- a/cocos/physics/bullet/bullet-interface.ts +++ b/cocos/physics/bullet/bullet-interface.ts @@ -24,6 +24,7 @@ import { BulletShape } from './shapes/bullet-shape'; +/** @mangle */ export interface IBulletBodyStruct { readonly id: number; readonly body: Bullet.ptr; @@ -33,6 +34,7 @@ export interface IBulletBodyStruct { useCompound: boolean; } +/** @mangle */ export interface IBulletGhostStruct { readonly id: number; readonly ghost: Bullet.ptr; diff --git a/cocos/physics/bullet/bullet-rigid-body.ts b/cocos/physics/bullet/bullet-rigid-body.ts index 5b5c84bed64..ca51752d935 100644 --- a/cocos/physics/bullet/bullet-rigid-body.ts +++ b/cocos/physics/bullet/bullet-rigid-body.ts @@ -36,6 +36,7 @@ import { bt } from './instantiated'; const v3_0 = CC_V3_0; const v3_1 = CC_V3_1; +/** @mangle */ export class BulletRigidBody implements IRigidBody { get isAwake (): boolean { const state = bt.CollisionObject_getActivationState(this.impl); diff --git a/cocos/physics/bullet/bullet-shared-body.ts b/cocos/physics/bullet/bullet-shared-body.ts index 7039b651e98..27a7c469e38 100644 --- a/cocos/physics/bullet/bullet-shared-body.ts +++ b/cocos/physics/bullet/bullet-shared-body.ts @@ -46,6 +46,7 @@ let IDCounter = 0; * shared object, node : shared = 1 : 1 * body for static \ dynamic \ kinematic (collider) * ghost for trigger + * @mangle */ export class BulletSharedBody { private static idCounter = 0; @@ -425,7 +426,7 @@ export class BulletSharedBody { const bt_quat = BulletCache.instance.BT_QUAT_0; const bt_transform = BulletCache.instance.BT_TRANSFORM_0; bt.RigidBody_getWorldTransform(this.body, bt_transform); - const originPosPtr = bt.Transform_getRotationAndOrigin(bt_transform, bt_quat) as number; + const originPosPtr = bt.Transform_getRotationAndOrigin(bt_transform, bt_quat); this.node.worldRotation = bullet2CocosQuat(quat_0, bt_quat); this.node.worldPosition = bullet2CocosVec3(v3_0, originPosPtr); diff --git a/cocos/physics/bullet/bullet-world.ts b/cocos/physics/bullet/bullet-world.ts index c18f9e1d2de..7683c55ebad 100644 --- a/cocos/physics/bullet/bullet-world.ts +++ b/cocos/physics/bullet/bullet-world.ts @@ -48,6 +48,8 @@ const v3_1 = CC_V3_1; const v3_2 = CC_V3_2; const c_0 = CC_COLOR_0; const emitHit = new CharacterControllerContact(); + +/** @mangle */ export class BulletWorld implements IPhysicsWorld { setDefaultMaterial (v: PhysicsMaterial): void { //empty diff --git a/cocos/physics/bullet/character-controllers/bullet-box-character-controller.ts b/cocos/physics/bullet/character-controllers/bullet-box-character-controller.ts index a2f640d3074..a476fc8e32c 100644 --- a/cocos/physics/bullet/character-controllers/bullet-box-character-controller.ts +++ b/cocos/physics/bullet/character-controllers/bullet-box-character-controller.ts @@ -35,6 +35,7 @@ import { importFunc } from '../bullet-env'; const v3_0 = new Vec3(0, 0, 0); +/** @mangle */ export class BulletBoxCharacterController extends BulletCharacterController implements IBoxCharacterController { get component (): BoxCharacterController { return this._comp as BoxCharacterController; diff --git a/cocos/physics/bullet/character-controllers/bullet-capsule-character-controller.ts b/cocos/physics/bullet/character-controllers/bullet-capsule-character-controller.ts index 700e9724072..a63567e8513 100644 --- a/cocos/physics/bullet/character-controllers/bullet-capsule-character-controller.ts +++ b/cocos/physics/bullet/character-controllers/bullet-capsule-character-controller.ts @@ -35,6 +35,7 @@ import { importFunc } from '../bullet-env'; const v3_0 = new Vec3(0, 0, 0); +/** @mangle */ export class BulletCapsuleCharacterController extends BulletCharacterController implements ICapsuleCharacterController { get component (): CapsuleCharacterController { return this._comp as CapsuleCharacterController; diff --git a/cocos/physics/bullet/character-controllers/bullet-character-controller.ts b/cocos/physics/bullet/character-controllers/bullet-character-controller.ts index b29b029ea46..1620e01e7ed 100644 --- a/cocos/physics/bullet/character-controllers/bullet-character-controller.ts +++ b/cocos/physics/bullet/character-controllers/bullet-character-controller.ts @@ -38,6 +38,8 @@ import { TransformBit } from '../../../scene-graph'; const v3_0 = new Vec3(0, 0, 0); const v3_1 = new Vec3(0, 0, 0); const v3_2 = new Vec3(0, 0, 0); + +/** @mangle */ export abstract class BulletCharacterController implements IBaseCharacterController { readonly wrappedWorld: BulletWorld; private _isEnabled = false; diff --git a/cocos/physics/bullet/constraints/bullet-configurable-constraint.ts b/cocos/physics/bullet/constraints/bullet-configurable-constraint.ts index b11466a25b4..5ac96c4f7f9 100644 --- a/cocos/physics/bullet/constraints/bullet-configurable-constraint.ts +++ b/cocos/physics/bullet/constraints/bullet-configurable-constraint.ts @@ -50,6 +50,7 @@ enum BulletDofAxis { SWING2 = 5, } +/** @mangle */ export class BulletConfigurableConstraint extends BulletConstraint implements IConfigurableConstraint { private _setLimit (v: EConstraintMode, axis: number, lower: number, upper: number): void { switch (v) { diff --git a/cocos/physics/bullet/constraints/bullet-constraint.ts b/cocos/physics/bullet/constraints/bullet-constraint.ts index 21f7f32b83f..218a584ac6c 100644 --- a/cocos/physics/bullet/constraints/bullet-constraint.ts +++ b/cocos/physics/bullet/constraints/bullet-constraint.ts @@ -29,6 +29,7 @@ import { BulletRigidBody } from '../bullet-rigid-body'; import { bt, EBulletType } from '../instantiated'; import { BulletWorld } from '../bullet-world'; +/** @mangle */ export abstract class BulletConstraint implements IBaseConstraint { setConnectedBody (v: RigidBody | null): void { if (this._connectedBody === v) return; diff --git a/cocos/physics/bullet/constraints/bullet-fixed-constraint.ts b/cocos/physics/bullet/constraints/bullet-fixed-constraint.ts index b1fa7e8789a..1bc5a4c74b7 100644 --- a/cocos/physics/bullet/constraints/bullet-fixed-constraint.ts +++ b/cocos/physics/bullet/constraints/bullet-fixed-constraint.ts @@ -32,6 +32,7 @@ import { BulletCache, CC_MAT4_0, CC_QUAT_0, CC_V3_0 } from '../bullet-cache'; import { bt } from '../instantiated'; import { cocos2BulletQuat, cocos2BulletVec3 } from '../bullet-utils'; +/** @mangle */ export class BulletFixedConstraint extends BulletConstraint implements IFixedConstraint { setBreakForce (v: number): void { bt.TypedConstraint_setMaxImpulseThreshold(this._impl, v); diff --git a/cocos/physics/bullet/constraints/bullet-hinge-constraint.ts b/cocos/physics/bullet/constraints/bullet-hinge-constraint.ts index d736cb5e3c3..57c5762598e 100644 --- a/cocos/physics/bullet/constraints/bullet-hinge-constraint.ts +++ b/cocos/physics/bullet/constraints/bullet-hinge-constraint.ts @@ -33,6 +33,7 @@ import { bt } from '../instantiated'; import { cocos2BulletQuat, cocos2BulletVec3, force2Impulse } from '../bullet-utils'; import { toRadian } from '../../../core/math'; +/** @mangle */ export class BulletHingeConstraint extends BulletConstraint implements IHingeConstraint { setPivotA (v: IVec3Like): void { this.updateFrames(); diff --git a/cocos/physics/bullet/constraints/bullet-p2p-constraint.ts b/cocos/physics/bullet/constraints/bullet-p2p-constraint.ts index 2b402adc136..2f72c959cc5 100644 --- a/cocos/physics/bullet/constraints/bullet-p2p-constraint.ts +++ b/cocos/physics/bullet/constraints/bullet-p2p-constraint.ts @@ -32,6 +32,7 @@ import { BulletCache, CC_V3_0 } from '../bullet-cache'; import { bt } from '../instantiated'; import { cocos2BulletVec3 } from '../bullet-utils'; +/** @mangle */ export class BulletP2PConstraint extends BulletConstraint implements IPointToPointConstraint { setPivotA (v: IVec3Like): void { const cs = this.constraint; diff --git a/cocos/physics/bullet/instantiated.ts b/cocos/physics/bullet/instantiated.ts index 9138e178361..62a1d737571 100644 --- a/cocos/physics/bullet/instantiated.ts +++ b/cocos/physics/bullet/instantiated.ts @@ -27,6 +27,7 @@ import { BUILD, LOAD_BULLET_MANUALLY, NATIVE_CODE_BUNDLE_MODE } from 'internal:c import { game } from '../../game'; import { error, log, sys } from '../../core'; import { NativeCodeBundleMode } from '../../misc/webassembly-support'; +import type { BulletCache } from './bullet-cache'; //corresponds to bulletType in bullet-compile export enum EBulletType{ @@ -80,7 +81,7 @@ export enum EBulletDebugDrawModes } interface BtCache { - CACHE: any, + CACHE: typeof BulletCache, BODY_CACHE_NAME: string, CCT_CACHE_NAME: string, } diff --git a/cocos/physics/bullet/shapes/bullet-box-shape.ts b/cocos/physics/bullet/shapes/bullet-box-shape.ts index f6dca66e9b3..49ec8008e6b 100644 --- a/cocos/physics/bullet/shapes/bullet-box-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-box-shape.ts @@ -32,6 +32,7 @@ import { cocos2BulletVec3 } from '../bullet-utils'; import { BulletCache } from '../bullet-cache'; import { bt } from '../instantiated'; +/** @mangle */ export class BulletBoxShape extends BulletShape implements IBoxShape { updateSize (): void { const hf = BulletCache.instance.BT_V3_0; diff --git a/cocos/physics/bullet/shapes/bullet-capsule-shape.ts b/cocos/physics/bullet/shapes/bullet-capsule-shape.ts index 8635b83618e..60f988b3998 100644 --- a/cocos/physics/bullet/shapes/bullet-capsule-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-capsule-shape.ts @@ -28,6 +28,7 @@ import { CapsuleCollider } from '../../../../exports/physics-framework'; import { ICapsuleShape } from '../../spec/i-physics-shape'; import { bt } from '../instantiated'; +/** @mangle */ export class BulletCapsuleShape extends BulletShape implements ICapsuleShape { setCylinderHeight (v: number): void { this.updateProperties( diff --git a/cocos/physics/bullet/shapes/bullet-cone-shape.ts b/cocos/physics/bullet/shapes/bullet-cone-shape.ts index ab7ce0a0e57..14737dfb5dc 100644 --- a/cocos/physics/bullet/shapes/bullet-cone-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-cone-shape.ts @@ -29,6 +29,7 @@ import { IVec3Like, absMax } from '../../../core'; import { bt } from '../instantiated'; import { BulletCache } from '../bullet-cache'; +/** @mangle */ export class BulletConeShape extends BulletShape implements ICylinderShape { setHeight (v: number): void { this.updateProperties( diff --git a/cocos/physics/bullet/shapes/bullet-cylinder-shape.ts b/cocos/physics/bullet/shapes/bullet-cylinder-shape.ts index 1aa8913b270..324c0ab06ef 100644 --- a/cocos/physics/bullet/shapes/bullet-cylinder-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-cylinder-shape.ts @@ -29,6 +29,7 @@ import { IVec3Like, absMax } from '../../../core'; import { BulletCache } from '../bullet-cache'; import { bt } from '../instantiated'; +/** @mangle */ export class BulletCylinderShape extends BulletShape implements ICylinderShape { setHeight (v: number): void { this.updateProperties( diff --git a/cocos/physics/bullet/shapes/bullet-plane-shape.ts b/cocos/physics/bullet/shapes/bullet-plane-shape.ts index 8c1bf9a8534..5c4cf3502fe 100644 --- a/cocos/physics/bullet/shapes/bullet-plane-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-plane-shape.ts @@ -30,6 +30,7 @@ import { IVec3Like } from '../../../core'; import { BulletCache } from '../bullet-cache'; import { bt } from '../instantiated'; +/** @mangle */ export class BulletPlaneShape extends BulletShape implements IPlaneShape { setNormal (v: IVec3Like): void { cocos2BulletVec3(bt.StaticPlaneShape_getPlaneNormal(this.impl), v); diff --git a/cocos/physics/bullet/shapes/bullet-shape.ts b/cocos/physics/bullet/shapes/bullet-shape.ts index 0989df94de7..ac583b38b7c 100644 --- a/cocos/physics/bullet/shapes/bullet-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-shape.ts @@ -35,6 +35,8 @@ import { EColliderType } from '../../framework'; const v3_0 = CC_V3_0; const ccMaterialBooks = {}; + +/** @mangle */ export abstract class BulletShape implements IBaseShape { updateEventListener (): void { this._sharedBody.wrappedWorld.updateNeedEmitEvents(this.collider.needCollisionEvent || this.collider.needTriggerEvent); @@ -46,8 +48,8 @@ export abstract class BulletShape implements IBaseShape { if (this._compound) { if (!ccMaterialBooks[v1._uuid]) ccMaterialBooks[v1._uuid] = bt.ccMaterial_new(); const mat = ccMaterialBooks[v1._uuid]; - bt.ccMaterial_set(mat, v1.restitution, v1.friction, v1.rollingFriction, v1.spinningFriction); - bt.CollisionShape_setMaterial(this._impl, mat); + bt.ccMaterial_set(mat as number, v1.restitution, v1.friction, v1.rollingFriction, v1.spinningFriction); + bt.CollisionShape_setMaterial(this._impl, mat as number); } else { bt.CollisionObject_setMaterial(this._sharedBody.body, v1.restitution, v1.friction, v1.rollingFriction, v1.spinningFriction); } diff --git a/cocos/physics/bullet/shapes/bullet-simplex-shape.ts b/cocos/physics/bullet/shapes/bullet-simplex-shape.ts index 12e212910d3..8c09834f0ca 100644 --- a/cocos/physics/bullet/shapes/bullet-simplex-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-simplex-shape.ts @@ -30,6 +30,7 @@ import { IVec3Like } from '../../../core'; import { bt } from '../instantiated'; import { BulletCache } from '../bullet-cache'; +/** @mangle */ export class BulletSimplexShape extends BulletShape implements ISimplexShape { setShapeType (v: SimplexCollider.ESimplexType): void { // TODO: diff --git a/cocos/physics/bullet/shapes/bullet-sphere-shape.ts b/cocos/physics/bullet/shapes/bullet-sphere-shape.ts index bf075dccca7..2a9b82664ce 100644 --- a/cocos/physics/bullet/shapes/bullet-sphere-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-sphere-shape.ts @@ -30,6 +30,7 @@ import { BulletCache, CC_V3_0 } from '../bullet-cache'; import { bt } from '../instantiated'; import { absMaxComponent } from '../../../core'; +/** @mangle */ export class BulletSphereShape extends BulletShape implements ISphereShape { updateRadius (): void { bt.SphereShape_setUnscaledRadius(this.impl, this.getMinUnscaledRadius()); diff --git a/cocos/physics/bullet/shapes/bullet-terrain-shape.ts b/cocos/physics/bullet/shapes/bullet-terrain-shape.ts index 71b9674073c..e3d1f3e57a9 100644 --- a/cocos/physics/bullet/shapes/bullet-terrain-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-terrain-shape.ts @@ -31,6 +31,7 @@ import { ITerrainAsset } from '../../spec/i-external'; import { CC_V3_0, BulletCache } from '../bullet-cache'; import { bt } from '../instantiated'; +/** @mangle */ export class BulletTerrainShape extends BulletShape implements ITerrainShape { public get collider (): TerrainCollider { return this._collider as TerrainCollider; diff --git a/cocos/physics/bullet/shapes/bullet-trimesh-shape.ts b/cocos/physics/bullet/shapes/bullet-trimesh-shape.ts index b73cd2d3d72..c00e8d4f4d2 100644 --- a/cocos/physics/bullet/shapes/bullet-trimesh-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-trimesh-shape.ts @@ -31,8 +31,9 @@ import { BulletCache } from '../bullet-cache'; import { bt, EBulletType } from '../instantiated'; import { BulletBvhTriangleMeshShape } from '../bullet-bvh-triangle-mesh-shape'; +/** @mangle */ export class BulletTrimeshShape extends BulletShape implements ITrimeshShape { - private btBVHMeshShape; + private btBVHMeshShape: BulletBvhTriangleMeshShape | null = null; public get collider (): MeshCollider { return this._collider as MeshCollider; }