mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 16:52:43 +08:00
344d1eebde
* stash * stash * stash * update @cocos/ammo to 1.0.1 * tweaks * tweaks
60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
/**
|
|
* @hidden
|
|
*/
|
|
|
|
import { Vec3 } from '../../core/math';
|
|
import { BoxShape, PhysicsWorld, RigidBody, SphereShape, CapsuleShape } from './Physics-selector';
|
|
import { IRigidBody } from '../spec/i-rigid-body';
|
|
import { IBoxShape, ISphereShape, ICapsuleShape } from '../spec/i-physics-shape';
|
|
import { IPhysicsWorld } from '../spec/i-physics-world';
|
|
import { warn, error } from '../../core';
|
|
|
|
export function createPhysicsWorld (): IPhysicsWorld {
|
|
if (CC_DEBUG && checkPhysicsModule(PhysicsWorld)) { return null as any; }
|
|
return new PhysicsWorld() as IPhysicsWorld;
|
|
}
|
|
|
|
export function createRigidBody (): IRigidBody {
|
|
if (CC_DEBUG && checkPhysicsModule(RigidBody)) { return null as any; }
|
|
return new RigidBody!() as IRigidBody;
|
|
}
|
|
|
|
export function createBoxShape (size: Vec3): IBoxShape {
|
|
if (CC_DEBUG && checkPhysicsModule(BoxShape)) { return null as any; }
|
|
return new BoxShape(size) as IBoxShape;
|
|
}
|
|
|
|
export function createSphereShape (radius: number): ISphereShape {
|
|
if (CC_DEBUG && checkPhysicsModule(SphereShape)) { return null as any; }
|
|
return new SphereShape(radius) as ISphereShape;
|
|
}
|
|
|
|
export function createCapsuleShape (radius = 0.5, height = 2, dir = 1): ICapsuleShape {
|
|
if (CC_PHYSICS_BUILTIN || CC_PHYSICS_AMMO) {
|
|
if (CC_DEBUG && checkPhysicsModule(CapsuleShape)) { return null as any; }
|
|
return new CapsuleShape(radius, height, dir) as ICapsuleShape;
|
|
} else {
|
|
warn('[v1.0.3][Physics]: Currently cannon.js unsupport capsule collider');
|
|
/** apater */
|
|
return {
|
|
radius: radius, height: height, direction: dir,
|
|
material: null,
|
|
isTrigger: false,
|
|
center: new Vec3(),
|
|
__preload: () => { },
|
|
onLoad: () => { },
|
|
onEnable: () => { },
|
|
onDisable: () => { },
|
|
onDestroy: () => { }
|
|
} as any
|
|
}
|
|
}
|
|
|
|
export function checkPhysicsModule (obj: any) {
|
|
if (CC_DEBUG && !CC_EDITOR && obj == null) {
|
|
error("[Physics]: Please check to see if physics modules are included.");
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|