-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathPhysicsSystem.test.ts
More file actions
74 lines (59 loc) · 2.9 KB
/
Copy pathPhysicsSystem.test.ts
File metadata and controls
74 lines (59 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { test, expect, describe, assert } from "vitest"
import PhysicsSystem, { LayerReserve } from "../systems/physics/PhysicsSystem"
import MirabufParser from "@/mirabuf/MirabufParser"
import MirabufCachingService, { MiraType } from "@/mirabuf/MirabufLoader"
describe("Physics Sanity Checks", () => {
test("Convex Hull Shape (Cube)", () => {
const points: Float32Array = new Float32Array([
0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5,
0.5, -0.5, 0.5, 0.5, -0.5,
])
const system = new PhysicsSystem()
const shapeResult = system.CreateConvexHull(points)
assert(shapeResult.HasError() == false, shapeResult.GetError().c_str())
expect(shapeResult.IsValid()).toBe(true)
const shape = shapeResult.Get()
expect(shape.GetVolume() - 1.0).toBeLessThan(0.001)
expect(shape.GetCenterOfMass().Length()).toBe(0.0)
shape.Release()
system.Destroy()
})
test("Convex Hull Shape (Tetrahedron)", () => {
const points: Float32Array = new Float32Array([0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0])
const system = new PhysicsSystem()
const shapeResult = system.CreateConvexHull(points)
assert(shapeResult.HasError() == false, shapeResult.GetError().c_str())
expect(shapeResult.IsValid()).toBe(true)
const shape = shapeResult.Get()
const bounds = shape.GetLocalBounds()
const boxSize = bounds.mMax.Sub(bounds.mMin)
expect(boxSize.GetX() - 1.0).toBeLessThan(0.001)
expect(boxSize.GetY() - 1.0).toBeLessThan(0.001)
expect(boxSize.GetZ() - 1.0).toBeLessThan(0.001)
expect(shape.GetVolume() - 1.0 / 6.0).toBeLessThan(0.001)
expect(shape.GetMassProperties().mMass - 6.0).toBeLessThan(0.001)
shape.Release()
system.Destroy()
})
})
describe("Mirabuf Physics Loading", () => {
test("Body Loading (Dozer)", async () => {
const assembly = await MirabufCachingService.CacheRemote("/api/mira/robots/Dozer_v9.mira", MiraType.ROBOT).then(
x => MirabufCachingService.Get(x!.id, MiraType.ROBOT)
)
const parser = new MirabufParser(assembly!)
const physSystem = new PhysicsSystem()
const mapping = physSystem.CreateBodiesFromParser(parser, new LayerReserve())
expect(mapping.size).toBe(7)
})
test("Body Loading (Multi-Joint Wheels)", async () => {
const assembly = await MirabufCachingService.CacheRemote(
"/api/mira/private/Multi-Joint_Wheels_v0.mira",
MiraType.ROBOT
).then(x => MirabufCachingService.Get(x!.id, MiraType.ROBOT))
const parser = new MirabufParser(assembly!)
const physSystem = new PhysicsSystem()
const mapping = physSystem.CreateBodiesFromParser(parser, new LayerReserve())
expect(mapping.size).toBe(9)
})
})