Files
cocos-engine/tests/physics/volume.ts
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

38 lines
1.3 KiB
TypeScript

import { director, Node, Vec3 } from "../../cocos/core";
import { physics } from "../../exports/physics-framework";
/**
* This function is used to test the behavior of different volume ratios
*/
export default function (parent: Node, steps = 120, ratios = 0.2) {
const nodeStatic = new Node('StaticB');
parent.addChild(nodeStatic);
nodeStatic.addComponent(physics.BoxCollider);
nodeStatic.worldScale = new Vec3(20, 0.01, 20);
nodeStatic.worldPosition = new Vec3(0, -0.005, 0);
const high = new Node('high');
parent.addChild(high);
const highBody = high.addComponent(physics.RigidBody) as physics.RigidBody;
high.addComponent(physics.BoxCollider);
const initPos = new Vec3(0, 0.5 + ratios, 0);
high.worldPosition = initPos;
const low = new Node('low');
parent.addChild(low);
low.addComponent(physics.RigidBody);
low.addComponent(physics.BoxCollider);
low.worldScale = new Vec3(ratios, ratios, ratios);
low.worldPosition = new Vec3(0, ratios / 2, 0);
const dt = physics.PhysicsSystem.instance.fixedTimeStep;
for (let i = 0; i < steps; i++) {
director.tick(dt);
}
expect(high.worldPosition.equals(initPos, 0.01)).toBe(true);
parent.destroyAllChildren();
parent.removeAllChildren();
}