Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// addContactMaterial (contactMaterial: ContactMaterial) {
// this._cannonWorld.addContactMaterial(contactMaterial._getImpl());
// }
addConstraint (constraint: CannonConstraint) {
this._world.addConstraint(constraint.impl);
}
removeConstraint (constraint: CannonConstraint) {
this._world.removeConstraint(constraint.impl);
}
}
const from = new CANNON.Vec3();
const to = new CANNON.Vec3();
function setupFromAndTo (worldRay: ray, distance: number) {
Vec3.copy(from, worldRay.o);
worldRay.computeHit(to, distance);
}
const raycastOpt: CANNON.IRaycastOptions = {
'checkCollisionResponse': false,
'collisionFilterGroup': -1,
'collisionFilterMask': -1,
'skipBackFaces': false
}
}
// addContactMaterial (contactMaterial: ContactMaterial) {
// this._cannonWorld.addContactMaterial(contactMaterial._getImpl());
// }
addConstraint (constraint: CannonConstraint) {
this._world.addConstraint(constraint.impl);
}
removeConstraint (constraint: CannonConstraint) {
this._world.removeConstraint(constraint.impl);
}
}
const from = new CANNON.Vec3();
const to = new CANNON.Vec3();
function setupFromAndTo (worldRay: ray, distance: number) {
Vec3.copy(from, worldRay.o);
worldRay.computeHit(to, distance);
}
const raycastOpt: CANNON.IRaycastOptions = {
'checkCollisionResponse': false,
'collisionFilterGroup': -1,
'collisionFilterMask': -1,
'skipBackFaces': false
}
}
const CollisionEventObject = {
type: 'onCollisionEnter' as ICollisionEventType,
selfCollider: null,
otherCollider: null,
// selfRigidBody: null,
// otherRigidBody: null,
contacts: [] as any,
};
const contactsPool = [] as any;
const _tCannonV1 = new CANNON.Vec3();
const _tCannonV2 = new CANNON.Vec3();
}
}
const CollisionEventObject = {
type: 'onCollisionEnter' as ICollisionEventType,
selfCollider: null,
otherCollider: null,
// selfRigidBody: null,
// otherRigidBody: null,
contacts: [] as any,
};
const contactsPool = [] as any;
const _tCannonV1 = new CANNON.Vec3();
const _tCannonV2 = new CANNON.Vec3();
constructor (options?: ICreateBodyOptions) {
options = options || {};
this._name = options.name || '';
this._body = new CANNON.Body({
type: ERigidBodyType.DYNAMIC,
});
setWrap(this._body, this);
this._body.sleepSpeedLimit = 0.1; // Body will feel sleepy if speed<1 (speed == norm of velocity)
this._body.sleepTimeLimit = 1; // Body falls asleep after 1s of sleepiness
this._onCollidedListener = this._onCollided.bind(this);
}
set allowSleep (v: boolean) {
this._world.allowSleep = v;
}
set gravity (gravity: Vec3) {
Vec3.copy(this._world.gravity, gravity);
}
// get defaultContactMaterial () {
// return this._defaultContactMaterial;
// }
readonly bodies: CannonSharedBody[] = [];
private _world: CANNON.World;
private _raycastResult = new CANNON.RaycastResult();
constructor () {
this._world = new CANNON.World();
this._world.broadphase = new CANNON.NaiveBroadphase();
}
step (deltaTime: number, timeSinceLastCalled?: number, maxSubStep?: number) {
// sync scene to physics
for (let i = 0; i < this.bodies.length; i++) {
this.bodies[i].syncSceneToPhysics();
}
this._world.step(deltaTime, timeSinceLastCalled, maxSubStep);
// sync physics to scene
for (let i = 0; i < this.bodies.length; i++) {
constructor (first: CannonSharedBody, firstPivot: Vec3, second: CannonSharedBody, secondPivot: Vec3, options?: any) {
super(new CANNON.PointToPointConstraint(
first.body,
Vec3.copy(new CANNON.Vec3(), firstPivot),
second.body,
Vec3.copy(new CANNON.Vec3(), secondPivot),
options === undefined ? undefined : options.maxForce));
}
}
constructor (first: any, second: any, distance?: number, options?: IDistanceConstraintOptions) {
super(new CANNON.DistanceConstraint(
first.impl,
second.impl,
distance!,
options === undefined ? undefined : options.maxForce));
}
}
constructor (first: CannonSharedBody, second: CannonSharedBody, distance?: number, options?: IDistanceConstraintOptions) {
super(new CANNON.DistanceConstraint(
first.body,
second.body,
distance!,
options === undefined ? undefined : options.maxForce));
}
}
constructor (size: Vec3) {
super();
Vec3.multiplyScalar(this.halfExtent, size, 0.5);
this._shape = new CANNON.Box(this.halfExtent.clone());
}