diff --git a/cocos/3d/framework/physics/collider-component.ts b/cocos/3d/framework/physics/collider-component.ts index c007a5f033..c85d86104f 100644 --- a/cocos/3d/framework/physics/collider-component.ts +++ b/cocos/3d/framework/physics/collider-component.ts @@ -97,23 +97,6 @@ export class ColliderComponentBase extends PhysicsBasedComponent { } super.onDestroy(); } - - public getGroup () { - return this._body!.getGroup(); - } - - public setGroup (v: number) { - return this._body!.setGroup(v); - } - - public getMask () { - return this._body!.getMask(); - } - - public setMask (v: number) { - return this._body!.setMask(v); - } - } @ccclass('cc.BoxColliderComponent') diff --git a/cocos/3d/framework/physics/detail/physics-based-component.ts b/cocos/3d/framework/physics/detail/physics-based-component.ts index 48bb3d1c9d..dddb71d751 100644 --- a/cocos/3d/framework/physics/detail/physics-based-component.ts +++ b/cocos/3d/framework/physics/detail/physics-based-component.ts @@ -46,6 +46,43 @@ export class PhysicsBasedComponent extends Component { } } + /** + * @return group ∈ [0, 31] (int) + */ + public getGroup (): number { + return this._body!.getGroup(); + } + + /** + * @param v ∈ [0, 31] (int) + */ + public setGroup (v: number) { + return this._body!.setGroup(v); + } + + /** + * @return (int) + */ + public getMask (): number { + return this._body!.getMask(); + } + + /** + * this will reset the mask + * @param v ∈ [0, 31] (int) + */ + public setMask (v: number) { + return this._body!.setMask(v); + } + + /** + * this will add a mask + * @param v ∈ [0, 31] (int) + */ + public addMask (v: number) { + return this._body!.addMask(v); + } + private _refSharedBody () { if (this._sharedBody) { return; diff --git a/cocos/3d/physics/api.ts b/cocos/3d/physics/api.ts index e453788be8..459b4bd457 100644 --- a/cocos/3d/physics/api.ts +++ b/cocos/3d/physics/api.ts @@ -64,15 +64,23 @@ export interface PhysicsWorldBase { export interface RigidBodyBase { // constructor (options?: ICreateBodyOptions); - /** group ∈ [0, 31] */ + /** @return group ∈ [0, 31] (int) */ getGroup (): number; - /** group ∈ [0, 31] */ + /** @param v ∈ [0, 31] (int) */ setGroup (v: number): void; - /** Mask ∈ [0, 31] */ + /** @return (int) */ getMask (): number; - /** Mask ∈ [0, 31] */ + /** + * this will reset the mask + * @param v ∈ [0, 31] (int) + */ setMask (v: number): void; + /** + * this will add a mask + * @param v ∈ [0, 31] (int) + */ + addMask (v: number): void; /** the body type */ getType (): ERigidBodyType; diff --git a/cocos/3d/physics/cannon-impl.ts b/cocos/3d/physics/cannon-impl.ts index bc4518d50c..42832b45db 100644 --- a/cocos/3d/physics/cannon-impl.ts +++ b/cocos/3d/physics/cannon-impl.ts @@ -168,12 +168,12 @@ function fillRaycastResult (result: RaycastResult, cannonResult: CANNON.RaycastR export class CannonRigidBody implements RigidBodyBase { - private _group: number = 0; - private _mask: number = 0; - get impl (): CANNON.Body { return this._cannonBody; } + + private _group: number = 0; + private _mask: number = 0; private _cannonBody: CANNON.Body; private _velocityResult: Vec3 = new Vec3(); private _useGravity = true; @@ -224,14 +224,17 @@ export class CannonRigidBody implements RigidBodyBase { } public getMask (): number { - return this._mask; + return this._cannonBody.collisionFilterMask; } public setMask (v: number): void { - this._mask = clamp(v, 0, 31); + v = clamp(Math.floor(v), 0, 31); this._cannonBody.collisionFilterMask = 1 << v; } - + public addMask (v: number): void { + v = Math.floor(v); + this._cannonBody.collisionFilterMask += 1 << v; + } public wakeUp (): void { return this._cannonBody.wakeUp(); } diff --git a/cocos/3d/physics/cocos/built-in-body.ts b/cocos/3d/physics/cocos/built-in-body.ts index ad1661f708..521489d74c 100644 --- a/cocos/3d/physics/cocos/built-in-body.ts +++ b/cocos/3d/physics/cocos/built-in-body.ts @@ -10,21 +10,20 @@ import { BuiltInWorld } from './built-in-world'; * Built-in static collider, no physical forces involved */ export class BuiltInBody implements RigidBodyBase { - /** id generator */ - private static idCounter: number = 0; /** id unique */ public get id () { return this._id; } + + public get collisionFilterGroup () { return this._collisionFilterGroup; } + + public get collisionFilterMask () { return this._collisionFilterMask; } + /** id generator */ + private static idCounter: number = 0; private readonly _id: number; private _type: ERigidBodyType = ERigidBodyType.DYNAMIC; private _group: number = 0; - private _mask: number = 0; - - public get collisionFilterGroup () { return this._collisionFilterGroup; } private _collisionFilterGroup: number = 1 << 0; - - public get collisionFilterMask () { return this._collisionFilterMask; } private _collisionFilterMask: number = 1 << 0; private _collisionCB: ICollisionCallback[] = []; @@ -47,16 +46,20 @@ export class BuiltInBody implements RigidBodyBase { return this._group; } public setGroup (v: number): void { - this._group = clamp(v, 0, 31); + this._group = clamp(Math.floor(v), 0, 31); this._collisionFilterGroup = 1 << v; } public getMask (): number { - return this._mask; + return this._collisionFilterMask; } public setMask (v: number): void { - this._mask = clamp(v, 0, 31); + v = clamp(Math.floor(v), 0, 31); this._collisionFilterMask = 1 << v; } + public addMask (v: number): void { + v = clamp(Math.floor(v), 0, 31); + this._collisionFilterMask += 1 << v; + } public intersects (body: BuiltInBody): boolean { // tslint:disable-next-line: prefer-for-of for (let i = 0; i < this._shapes.length; i++) {