@gg-web-engine/matter 0.0.71 → 0.0.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/matter-character-controller.component.d.ts +191 -0
- package/dist/components/matter-character-controller.component.js +498 -0
- package/dist/components/matter-rigid-body.component.d.ts +17 -2
- package/dist/components/matter-rigid-body.component.js +27 -2
- package/dist/components/matter-trigger.component.d.ts +46 -4
- package/dist/components/matter-trigger.component.js +74 -4
- package/dist/components/matter-world.component.d.ts +32 -5
- package/dist/components/matter-world.component.js +119 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/matter-factory.d.ts +8 -1
- package/dist/matter-factory.js +116 -11
- package/dist/types.d.ts +2 -0
- package/package.json +5 -4
- package/test/components/matter-character-controller.component.spec.ts +298 -0
- package/test/components/matter-rigid-body-collision.spec.ts +27 -13
- package/test/components/matter-rigid-body.component.spec.ts +58 -0
- package/test/components/matter-trigger.component.spec.ts +41 -13
- package/test/components/matter-world.component.spec.ts +44 -9
|
@@ -118,12 +118,12 @@ describe('MatterWorldComponent', () => {
|
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
-
describe
|
|
121
|
+
describe('Raycast', () => {
|
|
122
122
|
it('should return no hit when ray does not intersect any object', () => {
|
|
123
123
|
// Create a square far away from the ray
|
|
124
124
|
const square = world.factory.createRigidBody(
|
|
125
125
|
{
|
|
126
|
-
shape: { shape: '
|
|
126
|
+
shape: { shape: 'BOX', dimensions: { x: 1, y: 1 } },
|
|
127
127
|
body: { bodyType: 'static', mass: 0 },
|
|
128
128
|
},
|
|
129
129
|
{ position: { x: 10, y: 10 } },
|
|
@@ -149,7 +149,7 @@ describe('MatterWorldComponent', () => {
|
|
|
149
149
|
// Create a square in the path of the ray
|
|
150
150
|
const square = world.factory.createRigidBody(
|
|
151
151
|
{
|
|
152
|
-
shape: { shape: '
|
|
152
|
+
shape: { shape: 'BOX', dimensions: { x: 2, y: 2 } },
|
|
153
153
|
body: { bodyType: 'static', mass: 0 },
|
|
154
154
|
},
|
|
155
155
|
{ position: { x: 0, y: -5 } },
|
|
@@ -186,7 +186,7 @@ describe('MatterWorldComponent', () => {
|
|
|
186
186
|
// Create a square that only belongs to group1
|
|
187
187
|
const square1 = world.factory.createRigidBody(
|
|
188
188
|
{
|
|
189
|
-
shape: { shape: '
|
|
189
|
+
shape: { shape: 'BOX', dimensions: { x: 2, y: 2 } },
|
|
190
190
|
body: {
|
|
191
191
|
bodyType: 'static',
|
|
192
192
|
mass: 0,
|
|
@@ -228,7 +228,7 @@ describe('MatterWorldComponent', () => {
|
|
|
228
228
|
// Create a square at a known distance
|
|
229
229
|
const square = world.factory.createRigidBody(
|
|
230
230
|
{
|
|
231
|
-
shape: { shape: '
|
|
231
|
+
shape: { shape: 'BOX', dimensions: { x: 2, y: 2 } },
|
|
232
232
|
body: { bodyType: 'static', mass: 0 },
|
|
233
233
|
},
|
|
234
234
|
{ position: { x: 0, y: -5 } },
|
|
@@ -259,7 +259,7 @@ describe('MatterWorldComponent', () => {
|
|
|
259
259
|
// Create a square that belongs to group1
|
|
260
260
|
const square = world.factory.createRigidBody(
|
|
261
261
|
{
|
|
262
|
-
shape: { shape: '
|
|
262
|
+
shape: { shape: 'BOX', dimensions: { x: 2, y: 2 } },
|
|
263
263
|
body: {
|
|
264
264
|
bodyType: 'static',
|
|
265
265
|
mass: 0,
|
|
@@ -289,7 +289,7 @@ describe('MatterWorldComponent', () => {
|
|
|
289
289
|
// Create two squares at different positions
|
|
290
290
|
const square1 = world.factory.createRigidBody(
|
|
291
291
|
{
|
|
292
|
-
shape: { shape: '
|
|
292
|
+
shape: { shape: 'BOX', dimensions: { x: 1, y: 1 } },
|
|
293
293
|
body: { bodyType: 'static', mass: 0 },
|
|
294
294
|
},
|
|
295
295
|
{ position: { x: 0, y: -3 } },
|
|
@@ -298,7 +298,7 @@ describe('MatterWorldComponent', () => {
|
|
|
298
298
|
|
|
299
299
|
const square2 = world.factory.createRigidBody(
|
|
300
300
|
{
|
|
301
|
-
shape: { shape: '
|
|
301
|
+
shape: { shape: 'BOX', dimensions: { x: 1, y: 1 } },
|
|
302
302
|
body: { bodyType: 'static', mass: 0 },
|
|
303
303
|
},
|
|
304
304
|
{ position: { x: 0, y: -7 } },
|
|
@@ -323,7 +323,7 @@ describe('MatterWorldComponent', () => {
|
|
|
323
323
|
// Create a square
|
|
324
324
|
const square = world.factory.createRigidBody(
|
|
325
325
|
{
|
|
326
|
-
shape: { shape: '
|
|
326
|
+
shape: { shape: 'BOX', dimensions: { x: 4, y: 4 } },
|
|
327
327
|
body: { bodyType: 'static', mass: 0 },
|
|
328
328
|
},
|
|
329
329
|
{ position: { x: 0, y: 0 } },
|
|
@@ -346,5 +346,40 @@ describe('MatterWorldComponent', () => {
|
|
|
346
346
|
// We just verify the method doesn't crash and returns a valid result
|
|
347
347
|
expect(result).toBeDefined();
|
|
348
348
|
});
|
|
349
|
+
|
|
350
|
+
it('should never resolve a hit against a trigger, even when the ray starts inside it', () => {
|
|
351
|
+
// A trigger is a sensor with no collision response (ITrigger2dComponent) and must never
|
|
352
|
+
// obstruct a raycast - a world-enclosing trigger (a map-bounds kill volume) would otherwise
|
|
353
|
+
// be "hit" at ~0 distance by every ray cast anywhere inside it. raycast() excludes sensor
|
|
354
|
+
// bodies from its candidate set outright (see its own doc).
|
|
355
|
+
const trigger = world.factory.createTrigger({ shape: 'BOX', dimensions: { x: 100, y: 100 } });
|
|
356
|
+
trigger.addToWorld({ physicsWorld: world } as any);
|
|
357
|
+
world.simulate(1);
|
|
358
|
+
|
|
359
|
+
// from well inside the trigger's volume, hitting nothing else
|
|
360
|
+
const result = world.raycast({
|
|
361
|
+
from: { x: 0, y: 0 },
|
|
362
|
+
to: { x: 0, y: 10 },
|
|
363
|
+
});
|
|
364
|
+
expect(result.hasHit).toBe(false);
|
|
365
|
+
|
|
366
|
+
// a real solid body behind/through the trigger must still be hit normally
|
|
367
|
+
const square = world.factory.createRigidBody(
|
|
368
|
+
{
|
|
369
|
+
shape: { shape: 'BOX', dimensions: { x: 2, y: 2 } },
|
|
370
|
+
body: { bodyType: 'static', mass: 0 },
|
|
371
|
+
},
|
|
372
|
+
{ position: { x: 0, y: -5 } },
|
|
373
|
+
);
|
|
374
|
+
square.addToWorld({ physicsWorld: world } as any);
|
|
375
|
+
world.simulate(1);
|
|
376
|
+
|
|
377
|
+
const throughResult = world.raycast({
|
|
378
|
+
from: { x: 0, y: 0 },
|
|
379
|
+
to: { x: 0, y: -10 },
|
|
380
|
+
});
|
|
381
|
+
expect(throughResult.hasHit).toBe(true);
|
|
382
|
+
expect(throughResult.hitBody).toBe(square);
|
|
383
|
+
});
|
|
349
384
|
});
|
|
350
385
|
});
|