Skip to content

Commit 1325c61

Browse files
Robot Falling of the Edge of the World [AARD-2034] (#1247)
Co-authored-by: Alexey Dmitriev <157652245+AlexD717@users.noreply.github.com>
2 parents d9011b1 + 3a47e22 commit 1325c61

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

fission/src/systems/World.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import DragModeSystem from "./scene/DragModeSystem"
77
import SceneRenderer from "./scene/SceneRenderer"
88
import SimulationSystem from "./simulation/SimulationSystem"
99
import RobotDimensionTracker from "./match_mode/RobotDimensionTracker"
10+
import RobotPositionTracker from "./simulation/RobotPositionTracker"
1011

1112
class World {
1213
private static _isAlive: boolean = false
@@ -119,6 +120,7 @@ class World {
119120
World._performanceMonitorSystem?.update(this._currentDeltaT)
120121

121122
RobotDimensionTracker.update(World._sceneRenderer)
123+
RobotPositionTracker.update(World._sceneRenderer)
122124
}
123125

124126
public static get currentDeltaT(): number {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import MirabufSceneObject from "@/mirabuf/MirabufSceneObject"
2+
import { MiraType } from "@/mirabuf/MirabufLoader"
3+
import SceneRenderer from "../scene/SceneRenderer"
4+
import SimulationSystem from "@/systems/simulation/SimulationSystem"
5+
import World from "../World"
6+
import { convertJoltMat44ToThreeMatrix4 } from "@/util/TypeConversions"
7+
import JOLT from "@/util/loading/JoltSyncLoader"
8+
import * as THREE from "three"
9+
10+
class RobotPositionTracker {
11+
private static _mapBoundaryY: number = -4
12+
private static _offMapPenalty: number = 0
13+
14+
public static update(sceneRenderer: SceneRenderer): void {
15+
const robots = [...sceneRenderer.sceneObjects.values()].filter(
16+
(obj): obj is MirabufSceneObject => obj instanceof MirabufSceneObject && obj.miraType === MiraType.ROBOT
17+
)
18+
19+
robots.forEach(robot => {
20+
const rootNodeId = robot.getRootNodeId()
21+
if (!rootNodeId) {
22+
return
23+
}
24+
25+
const rootBody = World.physicsSystem.getBody(rootNodeId)
26+
const rootTransform = convertJoltMat44ToThreeMatrix4(rootBody.GetWorldTransform())
27+
28+
const rootPosition = new THREE.Vector3()
29+
const rootRotation = new THREE.Quaternion()
30+
const rootScale = new THREE.Vector3()
31+
rootTransform.decompose(rootPosition, rootRotation, rootScale)
32+
33+
if (rootPosition.y < this._mapBoundaryY) {
34+
SimulationSystem.robotPenalty(robot, this._offMapPenalty, "Robot fell off the map")
35+
36+
// TODO: Once driver station is implemented, we should reset the robot to the driver station position
37+
const resetPosition = new JOLT.RVec3(0, 0.2, 0)
38+
const resetRotation = JOLT.Quat.prototype.sIdentity()
39+
const zeroVelocity = new JOLT.Vec3(0, 0, 0)
40+
41+
robot.mirabufInstance.parser.rigidNodes.forEach(rigidNode => {
42+
const bodyId = robot.mechanism.getBodyByNodeId(rigidNode.id)
43+
if (bodyId) {
44+
World.physicsSystem.setBodyPositionRotationAndVelocity(
45+
bodyId,
46+
resetPosition,
47+
resetRotation,
48+
zeroVelocity,
49+
zeroVelocity,
50+
true
51+
)
52+
}
53+
})
54+
55+
JOLT.destroy(resetPosition)
56+
JOLT.destroy(resetRotation)
57+
JOLT.destroy(zeroVelocity)
58+
}
59+
})
60+
}
61+
}
62+
63+
export default RobotPositionTracker

0 commit comments

Comments
 (0)