Files
cocos4/tests/physics/physics.test.ts
T
jiaxin.lai 4cda45bfd9 physics unit-test and features base 3.3 (#9027)
* support ccd

* clearState after change type

* fix Instantiate rigid body with custom group

* add some extra functions

* update physics libs

* tweaks rigid body component

* add EVENT_UPDATE to PhysicsMaterial

* tweaks

* support switch physics backend

* remove redundant constants

* add config & min volume size

* update @cocos/physx to 1.0.4

* fix destroy cannon world

* correct init if manual construct physics system

* disable log info in test

* add some physics unit test

* add physics unit test

* make the config optional

* add runInEditor to selector

* pack physx js libs by default

* fix

* STASH

* stash

* tweaks

* rename

* update test

* support query trigger

* update @cocos/ammo to 1.1.6

* fix raycast with query trigger in physx

* raycast test with query trigger

* rename

* docs

* fix calculate local inertia (#8956)

* rename

* delete

* allow generate mesh/terrain collider at runtime

* tweaks

* use sap by default

* update @cocos/ammo to  1.1.8

* update @cocos/physx to 1.0.7

* update @cocos/cannon to 1.2.8

* update package-lock

* add ccd test

* remove config

* rename

* fix 2d phy sys typing

* support global allow sleep toggle for bullet

* tweaks

* use naive broadphase by default

* rename

* docs

* tweaks

* add missing jugement
2021-07-22 15:52:18 +08:00

70 lines
1.9 KiB
TypeScript

import { director, Node, Scene } from "../../cocos/core";
import { physics, PhysicsSystem } from "../../exports/physics-framework";
import "../../exports/physics-builtin";
import waitForAmmoInstantiation from "../../exports/wait-for-ammo-instantiation";
waitForAmmoInstantiation(null);
import "../../exports/physics-ammo";
import "../../exports/physics-physx";
import "../../exports/physics-cannon";
import EventTest from "./event";
import RaycastTest from "./raycast";
import SleepTest from "./sleep";
import StableTest from "./stability";
import VolumeTest from "./volume";
import FilterTest from "./filtering";
import DynamicTest from "./dynamic";
// Manually construct and register the system
PhysicsSystem.constructAndRegister();
for (const id in physics.selector.backend) {
test(`physics test | ${id}`, done => {
// test selector
physics.selector.switchTo(id);
expect(physics.selector.id).toBe(id);
const scene = new Scene('test');
director.runSceneImmediate(scene);
const temp0 = new Node();
scene.addChild(temp0);
// test events
EventTest(temp0);
// test raycast
RaycastTest(temp0);
if (physics.PhysicsSystem.PHYSICS_BUILTIN) {
temp0.destroy();
scene.destroy();
return done();
}
// test auto sleep state
SleepTest(temp0);
// test stable
[1, 0.5].forEach((v) => { StableTest(temp0, 500, v); });
if (physics.PhysicsSystem.PHYSICS_PHYSX) {
// test small scale in physx
[0.25, 0.15].forEach((v) => { StableTest(temp0, 500, v); });
}
// test volume
VolumeTest(temp0);
// test filter
FilterTest(temp0);
// test rigid body
DynamicTest(temp0);
temp0.destroy();
scene.destroy();
// all works done
done();
});
}