我接入过CannonJS. 因为oimo没有ts描述文件 :(
建立一个单例里面跑Cannon.World
private constructor() {
this.world = new CANNON.World();
this.world.allowSleep = true;
Laya.timer.frameLoop(1, this, this.Step);
}
public Step() {
this.world.step(1 / 60);
}
再把CANNON.Body包装成组件
export class CannonRigidbody extends Laya.Script3D {
static map: { [key: number]: Laya.Sprite3D } = {};
body: CANNON.Body;
t: Laya.Transform3D;
public onCollisionCB: (s: Laya.Sprite3D) => void;
public ignoreRotate: boolean = false;
...
OnAwake里面创建CANNON.Body,
OnEnable里面把CANNON.Body加入到CANNON.World, OnDisable则移除,
onUpdate里面根据CANNONBody的信息更新(this.owner as Laya.MeshSprite).transfrom.(最好用插值,平滑点,四元数代码就拷贝Laya源码改改.)
isKinematic 则根据(this.owner as Laya.MeshSprite).transfrom的位置信息更新CANNONBody