mirror of
https://github.com/cocos/cocos-engine.git
synced 2026-09-07 08:09:13 +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
89 lines
3.3 KiB
TypeScript
89 lines
3.3 KiB
TypeScript
import { director, game, geometry, Node, Vec3 } from "../../cocos/core";
|
|
import { physics } from "../../exports/physics-framework";
|
|
|
|
/**
|
|
* This function is used to test the filtering
|
|
*/
|
|
export default function (parent: Node, _steps = 0) {
|
|
|
|
// group mask
|
|
{
|
|
const nodeStatic = new Node('StaticB');
|
|
parent.addChild(nodeStatic);
|
|
nodeStatic.worldScale = new Vec3(20, 0.01, 20);
|
|
nodeStatic.worldPosition = new Vec3(0, -0.005, 0);
|
|
const boxStatic = nodeStatic.addComponent(physics.BoxCollider) as physics.BoxCollider;
|
|
const bodyStatic = nodeStatic.addComponent(physics.RigidBody) as physics.RigidBody;
|
|
bodyStatic.type = physics.ERigidBodyType.STATIC;
|
|
|
|
const gA = 1 << 2;
|
|
const gB = 1 << 5;
|
|
bodyStatic.setGroup(gA);
|
|
expect(boxStatic.getGroup()).toBe(gA);
|
|
bodyStatic.addGroup(gB);
|
|
expect(boxStatic.getGroup()).toBe(gA + gB);
|
|
bodyStatic.removeGroup(gA);
|
|
expect(boxStatic.getGroup()).toBe(gB);
|
|
|
|
bodyStatic.setMask(gA);
|
|
expect(boxStatic.getMask()).toBe(gA);
|
|
bodyStatic.addMask(gB);
|
|
expect(boxStatic.getMask()).toBe(gA + gB);
|
|
bodyStatic.removeMask(gA);
|
|
expect(boxStatic.getMask()).toBe(gB);
|
|
nodeStatic.destroy();
|
|
nodeStatic.removeFromParent();
|
|
}
|
|
|
|
// collision matrix
|
|
{
|
|
const config = {
|
|
collisionGroups: [
|
|
{
|
|
"index": 1,
|
|
"name": "BIT_1"
|
|
},
|
|
{
|
|
"index": 2,
|
|
"name": "BIT_2"
|
|
}
|
|
],
|
|
collisionMatrix: {
|
|
"0": 5, // can collide with Default\BIT_2
|
|
"1": 6, // can collide with BIT_1\BIT_2
|
|
"2": 7 // can collide with Default\BIT_1\BIT_2
|
|
}
|
|
};
|
|
physics.PhysicsSystem.instance.resetConfiguration(config);
|
|
|
|
const node1 = new Node('1');
|
|
const boxNode1 = node1.addComponent(physics.BoxCollider) as physics.BoxCollider;
|
|
const bodyNode1 = node1.addComponent(physics.RigidBody) as physics.RigidBody;
|
|
bodyNode1.group = physics.PhysicsGroup['BIT_1'];
|
|
parent.addChild(node1);
|
|
expect(boxNode1.getGroup()).toBe(physics.PhysicsGroup['BIT_1']);
|
|
expect(boxNode1.getGroup()).toBe(bodyNode1.getGroup());
|
|
expect(boxNode1.getMask()).toBe(bodyNode1.getMask());
|
|
expect(bodyNode1.getMask()).toBe(
|
|
physics.PhysicsSystem.instance.collisionMatrix[physics.PhysicsGroup['BIT_1']]
|
|
);
|
|
node1.destroy();
|
|
node1.removeFromParent();
|
|
|
|
const node2 = new Node('2');
|
|
parent.addChild(node2);
|
|
const boxNode2 = node2.addComponent(physics.BoxCollider) as physics.BoxCollider;
|
|
const bodyNode2 = node2.addComponent(physics.RigidBody) as physics.RigidBody;
|
|
expect(boxNode2.getGroup()).toBe(physics.PhysicsGroup.DEFAULT);
|
|
expect(boxNode2.getGroup()).toBe(bodyNode2.getGroup());
|
|
expect(boxNode2.getMask()).toBe(bodyNode2.getMask());
|
|
expect(bodyNode2.getMask()).toBe(
|
|
physics.PhysicsSystem.instance.collisionMatrix[physics.PhysicsGroup.DEFAULT]
|
|
);
|
|
node2.destroy();
|
|
node2.removeFromParent();
|
|
|
|
parent.destroyAllChildren();
|
|
parent.removeAllChildren();
|
|
}
|
|
} |