Skip to content

Commit

Permalink
issue #18056: [v3.8.6] Mangle properties of Bullet classes. (#18166)
Browse files Browse the repository at this point in the history
* issue #18056: [v3.8.6] Mangle properties of Bullet classes.

* Update.
  • Loading branch information
dumganhar authored Jan 13, 2025
1 parent 49502e6 commit 52ab800
Show file tree
Hide file tree
Showing 28 changed files with 44 additions and 10 deletions.
1 change: 1 addition & 0 deletions cocos/physics/bullet/bullet-bvh-triangle-mesh-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, BulletBvhTriangleMeshShape>();

Expand Down
3 changes: 3 additions & 0 deletions cocos/physics/bullet/bullet-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions cocos/physics/bullet/bullet-contact-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/bullet-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

export enum EBtSharedBodyDirty {
NONE = 0,
BODY_RE_ADD = 1,
GHOST_RE_ADD = 2,
}
Expand Down
6 changes: 4 additions & 2 deletions cocos/physics/bullet/bullet-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BulletSharedBody>(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<BulletCharacterController>(controller, btCache.CCT_CACHE_NAME);
cct.onShapeHitExt(hit);
},
onDebugDrawLine (from: number, to: number, color: number): void {
Expand Down
2 changes: 2 additions & 0 deletions cocos/physics/bullet/bullet-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import { BulletShape } from './shapes/bullet-shape';

/** @mangle */
export interface IBulletBodyStruct {
readonly id: number;
readonly body: Bullet.ptr;
Expand All @@ -33,6 +34,7 @@ export interface IBulletBodyStruct {
useCompound: boolean;
}

/** @mangle */
export interface IBulletGhostStruct {
readonly id: number;
readonly ghost: Bullet.ptr;
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/bullet-rigid-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion cocos/physics/bullet/bullet-shared-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions cocos/physics/bullet/bullet-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/constraints/bullet-constraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/constraints/bullet-p2p-constraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion cocos/physics/bullet/instantiated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -80,7 +81,7 @@ export enum EBulletDebugDrawModes
}

interface BtCache {
CACHE: any,
CACHE: typeof BulletCache,
BODY_CACHE_NAME: string,
CCT_CACHE_NAME: string,
}
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/shapes/bullet-box-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/shapes/bullet-capsule-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/shapes/bullet-cone-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/shapes/bullet-cylinder-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/shapes/bullet-plane-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions cocos/physics/bullet/shapes/bullet-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/shapes/bullet-simplex-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/shapes/bullet-sphere-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions cocos/physics/bullet/shapes/bullet-terrain-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion cocos/physics/bullet/shapes/bullet-trimesh-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 52ab800

Please sign in to comment.