|
1 | 1 | import {
|
2 |
| - Camera, |
3 | 2 | BoxColliderShape,
|
4 |
| - Layer, |
5 |
| - StaticCollider, |
6 |
| - DynamicCollider, |
7 |
| - HitResult, |
| 3 | + Camera, |
8 | 4 | CharacterController,
|
9 |
| - CapsuleColliderShape, |
10 |
| - SphereColliderShape, |
11 |
| - Script, |
| 5 | + Collider, |
12 | 6 | ColliderShape,
|
| 7 | + DynamicCollider, |
13 | 8 | Entity,
|
14 |
| - Collider |
| 9 | + HitResult, |
| 10 | + Layer, |
| 11 | + Script, |
| 12 | + SphereColliderShape, |
| 13 | + StaticCollider |
15 | 14 | } from "@galacean/engine-core";
|
16 | 15 | import { Ray, Vector3 } from "@galacean/engine-math";
|
17 | 16 | import { LitePhysics } from "@galacean/engine-physics-lite";
|
@@ -136,6 +135,75 @@ describe("Physics Test", () => {
|
136 | 135 | engineLite.run();
|
137 | 136 | });
|
138 | 137 |
|
| 138 | + it("removeShape", () => { |
| 139 | + const scene = engineLite.sceneManager.activeScene; |
| 140 | + const root = scene.createRootEntity("root"); |
| 141 | + const removeShapeRoot1 = root.createChild("root"); |
| 142 | + removeShapeRoot1.transform.position = new Vector3(1000, 1000, 1000); |
| 143 | + |
| 144 | + const enterEvent = []; |
| 145 | + const collider1 = removeShapeRoot1.addComponent(StaticCollider); |
| 146 | + const box1 = new BoxColliderShape(); |
| 147 | + enterEvent[box1.id] = []; |
| 148 | + collider1.addShape(box1); |
| 149 | + removeShapeRoot1.addComponent( |
| 150 | + class extends Script { |
| 151 | + onTriggerEnter(other: ColliderShape): void { |
| 152 | + ++enterEvent[box1.id][other.id]; |
| 153 | + } |
| 154 | + } |
| 155 | + ); |
| 156 | + const removeShapeRoot2 = root.createChild("root"); |
| 157 | + removeShapeRoot2.transform.position = new Vector3(1000, 1000, 1000); |
| 158 | + const collider2 = removeShapeRoot2.addComponent(StaticCollider); |
| 159 | + const box2 = new BoxColliderShape(); |
| 160 | + enterEvent[box2.id] = []; |
| 161 | + collider2.addShape(box2); |
| 162 | + removeShapeRoot2.addComponent( |
| 163 | + class extends Script { |
| 164 | + onTriggerEnter(other: ColliderShape) { |
| 165 | + ++enterEvent[box2.id][other.id]; |
| 166 | + } |
| 167 | + } |
| 168 | + ); |
| 169 | + // @ts-ignore |
| 170 | + engineLite.physicsManager._update(8); |
| 171 | + // Remove collider shape. |
| 172 | + removeShapeRoot2.isActive = false; |
| 173 | + const removeShapeRoot3 = root.createChild("root"); |
| 174 | + removeShapeRoot3.transform.position = new Vector3(1000, 1000, 1000); |
| 175 | + const collider3 = removeShapeRoot3.addComponent(StaticCollider); |
| 176 | + const box3 = new BoxColliderShape(); |
| 177 | + enterEvent[box3.id] = []; |
| 178 | + collider3.addShape(box3); |
| 179 | + removeShapeRoot3.addComponent( |
| 180 | + class extends Script { |
| 181 | + onTriggerEnter(other: ColliderShape) { |
| 182 | + ++enterEvent[box3.id][other.id]; |
| 183 | + } |
| 184 | + } |
| 185 | + ); |
| 186 | + removeShapeRoot2.isActive = true; |
| 187 | + enterEvent[box1.id][box2.id] = 0; |
| 188 | + enterEvent[box1.id][box3.id] = 0; |
| 189 | + enterEvent[box2.id][box1.id] = 0; |
| 190 | + enterEvent[box2.id][box3.id] = 0; |
| 191 | + enterEvent[box3.id][box1.id] = 0; |
| 192 | + enterEvent[box3.id][box2.id] = 0; |
| 193 | + // @ts-ignore |
| 194 | + engineLite.physicsManager._update(8); |
| 195 | + expect(enterEvent[box1.id][box2.id]).to.eq(1); |
| 196 | + expect(enterEvent[box1.id][box3.id]).to.eq(1); |
| 197 | + expect(enterEvent[box2.id][box1.id]).to.eq(1); |
| 198 | + expect(enterEvent[box2.id][box3.id]).to.eq(1); |
| 199 | + expect(enterEvent[box3.id][box1.id]).to.eq(1); |
| 200 | + expect(enterEvent[box3.id][box2.id]).to.eq(1); |
| 201 | + |
| 202 | + removeShapeRoot1.destroy(); |
| 203 | + removeShapeRoot2.destroy(); |
| 204 | + removeShapeRoot3.destroy(); |
| 205 | + }); |
| 206 | + |
139 | 207 | it("constructor", () => {
|
140 | 208 | expect(engineLite.physicsManager.gravity.y).to.eq(-9.81);
|
141 | 209 | expect(engineLite.physicsManager.fixedTimeStep).to.eq(1 / 60);
|
|
0 commit comments