mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
5330e7ee5a
* add support to configurable constraint * add missing files * update packages * fix PhysX bugs,update error info * fix exports, deserialization. * just stage * Revert "just stage" This reverts commit 41dc157afec00bfeb077b12e64c45a951ab1f894. * fix problems * improve perf * tweak * fix merge errors * update errormap
96 lines
2.8 KiB
TypeScript
96 lines
2.8 KiB
TypeScript
import { director, game, Game } from "../../cocos/game";
|
|
import { physics, PhysicsMaterial, PhysicsSystem } from "../../exports/physics-framework";
|
|
|
|
import "../../exports/physics-physx";
|
|
import "../../exports/physics-builtin";
|
|
import waitForAmmoInstantiation from "../../exports/wait-for-ammo-instantiation";
|
|
waitForAmmoInstantiation(null);
|
|
import "../../exports/physics-ammo";
|
|
import "../../exports/physics-cannon";
|
|
import { InitPhysXLibs } from '../../cocos/physics/physx/physx-adapter';
|
|
InitPhysXLibs();
|
|
import EventTest from "./event";
|
|
import RaycastTest from "./raycast";
|
|
import SweepTest from "./sweep";
|
|
import SleepTest from "./sleep";
|
|
import StableTest from "./stability";
|
|
import VolumeTest from "./volume";
|
|
import FilterTest from "./filtering";
|
|
import DynamicTest from "./dynamic";
|
|
import ConstraintTest from "./constraint";
|
|
import CharacterController from "./characterController";
|
|
import { Node, Scene } from "../../cocos/scene-graph";
|
|
import { builtinResMgr } from "../../exports/base";
|
|
|
|
game.emit(Game.EVENT_PRE_SUBSYSTEM_INIT);
|
|
// Manually construct and register the system
|
|
PhysicsSystem.constructAndRegister();
|
|
//Manual load default builtin physics material
|
|
const builtinMaterial = builtinResMgr.get<PhysicsMaterial>('default-physics-material');
|
|
PhysicsSystem.instance.setDefaultPhysicsMaterial(builtinMaterial);
|
|
|
|
test(`physics test | selector`, done => {
|
|
physics.selector.switchTo('builtin');
|
|
expect(physics.selector.id).toBe('builtin');
|
|
done();
|
|
});
|
|
|
|
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);
|
|
|
|
// test sweep
|
|
SweepTest(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);
|
|
|
|
// test constraint
|
|
ConstraintTest(temp0);
|
|
|
|
// test character controller
|
|
CharacterController(temp0);
|
|
|
|
temp0.destroy();
|
|
scene.destroy();
|
|
// all works done
|
|
done();
|
|
});
|
|
} |