Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intake and Ejector Configurator #1017

Merged
merged 49 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
98caf9f
Adding configure pickup in panelui
Dhruv-0-Arora Jul 3, 2024
b8ccf13
Merge remote-tracking branch 'origin/dhruv/1733/mirabuf-gizmo' into d…
Dhruv-0-Arora Jul 3, 2024
be8c4d0
Merge branch 'dhruv/1733/mirabuf-gizmo' into dhruv/1728/intake-ejecto…
Dhruv-0-Arora Jul 3, 2024
6196bb5
Merge remote-tracking branch 'origin/dhruv/1733/mirabuf-gizmo' into d…
Dhruv-0-Arora Jul 4, 2024
4d05972
Added transform gizmo bug fixes and also cancel functionality
Dhruv-0-Arora Jul 4, 2024
2810af4
Readded slider for sizing and configuration for the slider
Dhruv-0-Arora Jul 8, 2024
2f70b40
Merging dev
Dhruv-0-Arora Jul 8, 2024
72949b5
Merge branch 'dhruv/1733/mirabuf-gizmo' into dhruv/1728/intake-ejecto…
Dhruv-0-Arora Jul 8, 2024
e7da8c3
Quick fix
Dhruv-0-Arora Jul 8, 2024
bcc4e87
Merge remote-tracking branch 'origin/barclah/1682/mouse-interaction' …
Dhruv-0-Arora Jul 8, 2024
09faae5
Merge branch 'dhruv/1733/mirabuf-gizmo' into dhruv/1728/intake-ejecto…
Dhruv-0-Arora Jul 8, 2024
7ed6995
Added scaling functionality with slider
Dhruv-0-Arora Jul 8, 2024
49b9e5e
Raycasting work and basic implementation of pickup configuration
Dhruv-0-Arora Jul 9, 2024
518c7c5
Merge remote-tracking branch 'origin/dev' into dhruv/1728/intake-ejec…
Dhruv-0-Arora Jul 9, 2024
866936d
Added storing data functionality
Dhruv-0-Arora Jul 9, 2024
39c1316
Added configuration for shot trajectory
Dhruv-0-Arora Jul 9, 2024
cdbf94c
Merge remote-tracking branch 'origin/barclah/1682/mouse-interaction' …
Dhruv-0-Arora Jul 10, 2024
d29f443
Merge remote-tracking branch 'origin/dhruv/1733/mirabuf-gizmo' into d…
Dhruv-0-Arora Jul 10, 2024
85ed61a
Bug fix + ran prettier + fixed transform gizmo size from merge
Dhruv-0-Arora Jul 10, 2024
8f5b1da
Merge branch 'haverty/1692/preferences' into dhruv/1728/intake-ejecto…
LucaHaverty Jul 10, 2024
88b1ea3
Prevented select node from selecting a field or the ground
Dhruv-0-Arora Jul 10, 2024
6c0b41d
Ejector and intake config integration with preferences
LucaHaverty Jul 10, 2024
b546b3a
Merge branch 'dhruv/1728/intake-ejector-config' of github.com:autodes…
LucaHaverty Jul 10, 2024
56e38de
Ran prettier
Dhruv-0-Arora Jul 10, 2024
f7a9c90
Created a working formula to calculate the position of the pickup object
Dhruv-0-Arora Jul 12, 2024
1e74985
Add documentation + fixed the fields showing in the select panel + op…
Dhruv-0-Arora Jul 12, 2024
25422d4
Fixed filtering robots and fields + reimplemented the selectNode feature
Dhruv-0-Arora Jul 12, 2024
bb15c58
Optimized getting rotation and added implementation for configuring t…
Dhruv-0-Arora Jul 12, 2024
c2c0c3b
Merge remote-tracking branch 'origin/dev' into dhruv/1728/intake-ejec…
Dhruv-0-Arora Jul 12, 2024
040eed6
Solved gizmo transformation delta issue for ejector configuration.
HunterBarclay Jul 13, 2024
e2bd3fb
Updated intake preferences and copied ejector over to intake. Minor t…
HunterBarclay Jul 13, 2024
f62ce24
Formatted
HunterBarclay Jul 13, 2024
90f183b
Added new gamepiece association for detecting gamepieces
HunterBarclay Jul 13, 2024
1ba2663
Added intake sensor
HunterBarclay Jul 13, 2024
c110cf0
Ejectables done
HunterBarclay Jul 14, 2024
61d0b1f
Adjusted max ejection velocity
HunterBarclay Jul 14, 2024
e986aa4
Merge branch 'haverty/1692/preferences' into dhruv/1728/intake-ejecto…
HunterBarclay Jul 14, 2024
cbe34c8
Fixed label for intake size
HunterBarclay Jul 14, 2024
ccfb830
Formatted
HunterBarclay Jul 14, 2024
ae6a9df
Merge branch 'haverty/1692/preferences' into dhruv/1728/intake-ejecto…
HunterBarclay Jul 14, 2024
3e3a437
Merge branch 'dev' into dhruv/1728/intake-ejector-config
HunterBarclay Jul 15, 2024
7247694
Renamed BodyAssociated to BodyAssociate, made requested changes.
HunterBarclay Jul 15, 2024
f6495e7
Adding unit tests
HunterBarclay Jul 15, 2024
764749e
Fixed poker slider error
Dhruv-0-Arora Jul 15, 2024
f75fc6b
Merge remote-tracking branch 'origin/dev' into dhruv/1728/intake-ejec…
Dhruv-0-Arora Jul 15, 2024
46c49fa
Formatting
Dhruv-0-Arora Jul 15, 2024
0fc72c8
Fixing body associates
HunterBarclay Jul 15, 2024
14e878d
Removed unused var eslint complaint
a-crowell Jul 15, 2024
1b18b3f
made requested change
HunterBarclay Jul 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ import ScoringZonesPanel from "@/panels/configuring/scoring/ScoringZonesPanel"
import ZoneConfigPanel from "@/panels/configuring/scoring/ZoneConfigPanel"
import ScoreboardPanel from "@/panels/information/ScoreboardPanel"
import DriverStationPanel from "@/panels/simulation/DriverStationPanel"
import PokerPanel from "@/panels/PokerPanel.tsx"
import ManageAssembliesModal from "@/modals/spawning/ManageAssembliesModal.tsx"
import World from "@/systems/World.ts"
import { AddRobotsModal, AddFieldsModal, SpawningModal } from "@/modals/spawning/SpawningModals.tsx"
import ImportLocalMirabufModal from "@/modals/mirabuf/ImportLocalMirabufModal.tsx"
import APS from "./aps/APS.ts"
import ImportMirabufPanel from "@/ui/panels/mirabuf/ImportMirabufPanel.tsx"
import Skybox from "./ui/components/Skybox.tsx"
import PokerPanel from "@/panels/PokerPanel.tsx"
import ConfigureRobotModal from "./ui/modals/configuring/ConfigureRobotModal.tsx"

const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira"

Expand Down Expand Up @@ -129,7 +130,7 @@ function Synthesis() {
}
mainLoop()

World.SceneRenderer.updateSkyboxColors(defaultTheme)
World.SceneRenderer.UpdateSkyboxColors(defaultTheme)

// Cleanup
return () => {
Expand Down Expand Up @@ -213,15 +214,26 @@ const initialModals = [
<ConfigMotorModal key="config-motor" modalId="config-motor" />,
<ManageAssembliesModal key="manage-assemblies" modalId="manage-assemblies" />,
<ImportLocalMirabufModal key="import-local-mirabuf" modalId="import-local-mirabuf" />,
<ConfigureRobotModal key="config-robot" modalId="config-robot" />,
]

const initialPanels: ReactElement[] = [
<RobotSwitchPanel key="multibot" panelId="multibot" openLocation="right" sidePadding={8} />,
<DriverStationPanel key="driver-station" panelId="driver-station" />,
<SpawnLocationsPanel key="spawn-locations" panelId="spawn-locations" />,
<ScoreboardPanel key="scoreboard" panelId="scoreboard" />,
<ConfigureGamepiecePickupPanel key="config-gamepiece-pickup" panelId="config-gamepiece-pickup" />,
<ConfigureShotTrajectoryPanel key="config-shot-trajectory" panelId="config-shot-trajectory" />,
<ConfigureGamepiecePickupPanel
key="config-gamepiece-pickup"
panelId="config-gamepiece-pickup"
openLocation="right"
sidePadding={8}
/>,
<ConfigureShotTrajectoryPanel
key="config-shot-trajectory"
panelId="config-shot-trajectory"
openLocation="right"
sidePadding={8}
/>,
<ScoringZonesPanel key="scoring-zones" panelId="scoring-zones" />,
<ZoneConfigPanel key="zone-config" panelId="zone-config" />,
<ImportMirabufPanel key="import-mirabuf" panelId="import-mirabuf" />,
Expand Down
112 changes: 112 additions & 0 deletions fission/src/mirabuf/EjectableSceneObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import SceneObject from "@/systems/scene/SceneObject"
import MirabufSceneObject from "./MirabufSceneObject"
import Jolt from "@barclah/jolt-physics"
import World from "@/systems/World"
import {
Array_ThreeMatrix4,
JoltMat44_ThreeMatrix4,
JoltQuat_ThreeQuaternion,
ThreeQuaternion_JoltQuat,
ThreeVector3_JoltVec3,
} from "@/util/TypeConversions"
import * as THREE from "three"

class EjectableSceneObject extends SceneObject {
private _parentAssembly: MirabufSceneObject
private _gamePieceBodyId?: Jolt.BodyID

private _parentBodyId?: Jolt.BodyID
private _deltaTransformation?: THREE.Matrix4
private _ejectVelocity?: number

public get gamePieceBodyId() {
return this._gamePieceBodyId
}

public constructor(parentAssembly: MirabufSceneObject, gamePieceBody: Jolt.BodyID) {
super()

console.debug("Trying to create ejectable...")

this._parentAssembly = parentAssembly
this._gamePieceBodyId = gamePieceBody
}

public Setup(): void {
if (this._parentAssembly.ejectorPreferences && this._gamePieceBodyId) {
HunterBarclay marked this conversation as resolved.
Show resolved Hide resolved
this._parentBodyId = this._parentAssembly.mechanism.nodeToBody.get(
this._parentAssembly.ejectorPreferences.parentNode ?? this._parentAssembly.rootNodeId
)

this._deltaTransformation = Array_ThreeMatrix4(this._parentAssembly.ejectorPreferences.deltaTransformation)
this._ejectVelocity = this._parentAssembly.ejectorPreferences.ejectorVelocity

World.PhysicsSystem.DisablePhysicsForBody(this._gamePieceBodyId)

console.debug("Ejectable created successfully!")
}
}

public Update(): void {
if (this._parentBodyId && this._deltaTransformation && this._gamePieceBodyId) {
if (!World.PhysicsSystem.IsBodyAdded(this._gamePieceBodyId)) {
this._gamePieceBodyId = undefined
return
}

// I had a think and free wrote this matrix math on a whim. It worked first try and I honestly can't quite remember how it works... -Hunter
const gpBody = World.PhysicsSystem.GetBody(this._gamePieceBodyId)
const posToCOM = JoltMat44_ThreeMatrix4(gpBody.GetCenterOfMassTransform()).premultiply(
JoltMat44_ThreeMatrix4(gpBody.GetWorldTransform()).invert()
)

const body = World.PhysicsSystem.GetBody(this._parentBodyId)
const bodyTransform = posToCOM
.invert()
.premultiply(
this._deltaTransformation.clone().premultiply(JoltMat44_ThreeMatrix4(body.GetWorldTransform()))
)
const position = new THREE.Vector3(0, 0, 0)
const rotation = new THREE.Quaternion(0, 0, 0, 1)
bodyTransform.decompose(position, rotation, new THREE.Vector3(1, 1, 1))

World.PhysicsSystem.SetBodyPosition(this._gamePieceBodyId, ThreeVector3_JoltVec3(position), false)
World.PhysicsSystem.SetBodyRotation(this._gamePieceBodyId, ThreeQuaternion_JoltQuat(rotation), false)
}
}

public Eject() {
if (!this._parentBodyId || !this._ejectVelocity || !this._gamePieceBodyId) {
return
}

if (!World.PhysicsSystem.IsBodyAdded(this._gamePieceBodyId)) {
this._gamePieceBodyId = undefined
return
}

const parentBody = World.PhysicsSystem.GetBody(this._parentBodyId)
const gpBody = World.PhysicsSystem.GetBody(this._gamePieceBodyId)
const ejectDir = new THREE.Vector3(0, 0, 1)
.applyQuaternion(JoltQuat_ThreeQuaternion(gpBody.GetRotation()))
.normalize()

World.PhysicsSystem.EnablePhysicsForBody(this._gamePieceBodyId)
gpBody.SetLinearVelocity(
parentBody.GetLinearVelocity().Add(ThreeVector3_JoltVec3(ejectDir.multiplyScalar(this._ejectVelocity)))
)
gpBody.SetAngularVelocity(parentBody.GetAngularVelocity())

this._parentBodyId = undefined
}

public Dispose(): void {
console.debug("Destroying ejectable")

if (this._gamePieceBodyId) {
World.PhysicsSystem.EnablePhysicsForBody(this._gamePieceBodyId)
}
}
}

export default EjectableSceneObject
104 changes: 104 additions & 0 deletions fission/src/mirabuf/IntakeSensorSceneObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import SceneObject from "@/systems/scene/SceneObject"
import MirabufSceneObject, { RigidNodeAssociate } from "./MirabufSceneObject"
import Jolt from "@barclah/jolt-physics"
import * as THREE from "three"
import World from "@/systems/World"
import JOLT from "@/util/loading/JoltSyncLoader"
import {
Array_ThreeMatrix4,
JoltMat44_ThreeMatrix4,
ThreeQuaternion_JoltQuat,
ThreeVector3_JoltVec3,
} from "@/util/TypeConversions"

class IntakeSensorSceneObject extends SceneObject {
private _parentAssembly: MirabufSceneObject
private _parentBodyId?: Jolt.BodyID
private _deltaTransformation?: THREE.Matrix4

private _joltBodyId?: Jolt.BodyID
private _mesh?: THREE.Mesh

public constructor(parentAssembly: MirabufSceneObject) {
super()

console.debug("Trying to create intake sensor...")

this._parentAssembly = parentAssembly
}

public Setup(): void {
if (this._parentAssembly.intakePreferences) {
this._parentBodyId = this._parentAssembly.mechanism.nodeToBody.get(
this._parentAssembly.intakePreferences.parentNode ?? this._parentAssembly.rootNodeId
)

this._deltaTransformation = Array_ThreeMatrix4(this._parentAssembly.intakePreferences.deltaTransformation)

this._joltBodyId = World.PhysicsSystem.CreateSensor(
new JOLT.SphereShapeSettings(this._parentAssembly.intakePreferences.zoneDiameter / 2.0)
)
if (!this._joltBodyId) {
console.error("Failed to create intake. No Jolt Body")
return
}

this._mesh = World.SceneRenderer.CreateSphere(
this._parentAssembly.intakePreferences.zoneDiameter / 2.0,
World.SceneRenderer.CreateToonMaterial(0x5eeb67)
)
World.SceneRenderer.scene.add(this._mesh)

console.debug("Intake sensor created successfully!")
}
}

public Update(): void {
if (this._joltBodyId && this._parentBodyId && this._deltaTransformation) {
const parentBody = World.PhysicsSystem.GetBody(this._parentBodyId)
const bodyTransform = this._deltaTransformation
.clone()
.premultiply(JoltMat44_ThreeMatrix4(parentBody.GetWorldTransform()))
const position = new THREE.Vector3(0, 0, 0)
const rotation = new THREE.Quaternion(0, 0, 0, 1)
bodyTransform.decompose(position, rotation, new THREE.Vector3(1, 1, 1))

World.PhysicsSystem.SetBodyPosition(this._joltBodyId, ThreeVector3_JoltVec3(position))
World.PhysicsSystem.SetBodyRotation(this._joltBodyId, ThreeQuaternion_JoltQuat(rotation))

if (this._mesh) {
this._mesh.position.setFromMatrixPosition(bodyTransform)
this._mesh.rotation.setFromRotationMatrix(bodyTransform)
}

if (!World.PhysicsSystem.isPaused) {
// TEMPORARY GAME PIECE DETECTION
const hitRes = World.PhysicsSystem.RayCast(ThreeVector3_JoltVec3(position), new JOLT.Vec3(0, 0, 3))
if (hitRes) {
const gpAssoc = <RigidNodeAssociate>World.PhysicsSystem.GetBodyAssociation(hitRes.data.mBodyID)
// This works, however the check for game piece is doing two checks.
if (gpAssoc && gpAssoc.isGamePiece) {
HunterBarclay marked this conversation as resolved.
Show resolved Hide resolved
console.debug("Found game piece!")
this._parentAssembly.SetEjectable(hitRes.data.mBodyID, false)
}
}
}
}
}

public Dispose(): void {
console.debug("Destroying intake sensor")

if (this._joltBodyId) {
World.PhysicsSystem.DestroyBodyIds(this._joltBodyId)

if (this._mesh) {
this._mesh.geometry.dispose()
;(this._mesh.material as THREE.Material).dispose()
World.SceneRenderer.scene.remove(this._mesh)
}
}
}
}

export default IntakeSensorSceneObject
19 changes: 14 additions & 5 deletions fission/src/mirabuf/MirabufParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as THREE from "three"
import { mirabuf } from "@/proto/mirabuf"
import { MirabufTransform_ThreeMatrix4 } from "@/util/TypeConversions"

export type RigidNodeId = string

export enum ParseErrorSeverity {
Unimportable = 10,
LikelyIssues = 6,
Expand Down Expand Up @@ -60,8 +62,8 @@ class MirabufParser {
public get groundedNode() {
return this._groundedNode ? new RigidNodeReadOnly(this._groundedNode) : undefined
}
public get rigidNodes(): Array<RigidNodeReadOnly> {
return this._rigidNodes.map(x => new RigidNodeReadOnly(x))
public get rigidNodes(): Map<RigidNodeId, RigidNodeReadOnly> {
return new Map(this._rigidNodes.map(x => [x.id, new RigidNodeReadOnly(x)]))
}
public get directedGraph() {
return this._directedGraph
Expand Down Expand Up @@ -121,6 +123,7 @@ class MirabufParser {
const instNode = this.BinarySearchDesignTree(inst.info!.GUID!)
if (instNode) {
const gpRn = this.NewRigidNode(GAMEPIECE_SUFFIX)
gpRn.isGamePiece = true
this.MovePartToRigidNode(instNode!.value!, gpRn)
instNode.children &&
traverseTree(instNode.children, x => this.MovePartToRigidNode(x.value!, gpRn))
Expand Down Expand Up @@ -400,21 +403,23 @@ class MirabufParser {
*/
class RigidNode {
public isRoot: boolean
public id: string
public id: RigidNodeId
public parts: Set<string> = new Set()
public isDynamic: boolean
public isGamePiece: boolean

public constructor(id: string, isDynamic?: boolean) {
public constructor(id: RigidNodeId, isDynamic?: boolean, isGamePiece?: boolean) {
this.id = id
this.isDynamic = isDynamic ?? true
this.isRoot = false
this.isGamePiece = isGamePiece ?? false
}
}

export class RigidNodeReadOnly {
private _original: RigidNode

public get id(): string {
public get id(): RigidNodeId {
return this._original.id
}

Expand All @@ -430,6 +435,10 @@ export class RigidNodeReadOnly {
return this._original.isRoot
}

public get isGamePiece(): boolean {
return this._original.isGamePiece
}

public constructor(original: RigidNode) {
this._original = original
}
Expand Down
Loading
Loading