mirror of
https://github.com/cocos/cocos-engine.git
synced 2026-09-07 00:02:53 +08:00
* 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
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { director, Node, Vec3 } from "../../cocos/core";
|
|
import { physics } from "../../exports/physics-framework";
|
|
|
|
/**
|
|
* This function is used to test automatic sleep
|
|
*/
|
|
export default function (parent: Node, steps = 300) {
|
|
const nodeDynamicA = new Node('DynamicA');
|
|
parent.addChild(nodeDynamicA);
|
|
nodeDynamicA.worldPosition = new Vec3(0, 10, 0);
|
|
nodeDynamicA.addComponent(physics.SphereCollider);
|
|
const bodyA = nodeDynamicA.addComponent(physics.RigidBody) as physics.RigidBody;
|
|
|
|
const nodeDynamicB = new Node('DynamicB');
|
|
parent.addChild(nodeDynamicB);
|
|
nodeDynamicB.worldPosition = new Vec3(0, 5, 0);
|
|
const bodyB = nodeDynamicB.addComponent(physics.RigidBody) as physics.RigidBody;
|
|
nodeDynamicB.addComponent(physics.BoxCollider);
|
|
|
|
const nodeStatic = new Node('StaticB');
|
|
parent.addChild(nodeStatic);
|
|
nodeStatic.addComponent(physics.BoxCollider);
|
|
nodeStatic.worldScale = new Vec3(10, 1, 10);
|
|
|
|
expect(bodyA.isSleeping).toBe(false);
|
|
expect(bodyB.isSleeping).toBe(false);
|
|
expect(bodyA.isAwake).toBe(true);
|
|
expect(bodyB.isAwake).toBe(true);
|
|
|
|
const dt = physics.PhysicsSystem.instance.fixedTimeStep;
|
|
const middle = Math.floor(steps / 2);
|
|
for (let i = 0; i < steps; i++) {
|
|
if (i === middle) {
|
|
bodyA.wakeUp();
|
|
expect(bodyA.isSleeping).toBe(false);
|
|
expect(bodyA.isAwake).toBe(true);
|
|
}
|
|
director.tick(dt);
|
|
}
|
|
|
|
expect(bodyA.isSleeping).toBe(true);
|
|
expect(bodyB.isSleeping).toBe(true);
|
|
expect(bodyA.isAwake).toBe(false);
|
|
expect(bodyB.isAwake).toBe(false);
|
|
|
|
parent.destroyAllChildren();
|
|
parent.removeAllChildren();
|
|
}
|