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/Scoring Collisions #1035

Merged
merged 47 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
41c9f69
Collision with a sensor
a-crowell Jul 11, 2024
c4908fd
Merge remote-tracking branch 'origin/dev' into crowela/1731/scoring-p…
a-crowell Jul 11, 2024
847bd0c
Testing collision
a-crowell Jul 15, 2024
c664ec6
Merge remote-tracking branch 'origin/dev' into crowela/1731/scoring-p…
a-crowell Jul 15, 2024
3ba9fd4
Delete duplicate func
a-crowell Jul 16, 2024
0e8ce08
Merge branch 'dev' into crowela/1731/scoring-physics
a-crowell Jul 16, 2024
8837fa8
Of course the other one was removed
a-crowell Jul 16, 2024
61e624a
Start to ejectable-specific collision
a-crowell Jul 16, 2024
7aab74b
Gamepiece-specific collision
a-crowell Jul 16, 2024
1c65afc
Events!
a-crowell Jul 16, 2024
6fb8214
Event refactor
a-crowell Jul 17, 2024
bddff16
Refactored scoring collision and start to intake collision
a-crowell Jul 17, 2024
0632161
Debugging SetEjectable > isAdded(bodyID)
a-crowell Jul 17, 2024
9a460d3
Physics system be crazy
HunterBarclay Jul 17, 2024
a0f0ccc
Debug clean up
a-crowell Jul 17, 2024
f1f48e6
More testing and cleaning
a-crowell Jul 17, 2024
7afc125
Merge remote-tracking branch 'origin/dev' into crowela/1731/scoring-p…
a-crowell Jul 17, 2024
9d05c47
Bug handling
a-crowell Jul 17, 2024
bd64d9b
Merge remote-tracking branch 'origin/dev' into crowela/1731/scoring-p…
a-crowell Jul 17, 2024
93cee52
ScoringSceneObject made and partially gets changed by config panel
a-crowell Jul 18, 2024
fc3eb0f
Scoring zone rotation not messed up by scale and scoring zone detects…
a-crowell Jul 18, 2024
6e3dbad
Update works
a-crowell Jul 18, 2024
0b3704c
Positioning bug fix
a-crowell Jul 18, 2024
0c4b510
Multiple scoring zones
a-crowell Jul 19, 2024
4d240ca
Prefs render scoring zones
a-crowell Jul 19, 2024
eb2421e
A start to persistent
a-crowell Jul 19, 2024
96068c3
Print clean up
a-crowell Jul 19, 2024
e8050ce
Intake key check
a-crowell Jul 19, 2024
aff8e03
Clean up
a-crowell Jul 19, 2024
b4c074a
Persistent scoring
a-crowell Jul 19, 2024
350f8e0
Scoreboard
a-crowell Jul 22, 2024
d187634
Persistent points bug fix
a-crowell Jul 22, 2024
b86386a
Scoreboard on start up
a-crowell Jul 22, 2024
450560f
Refactoring and documentation
a-crowell Jul 22, 2024
064fed6
Merge remote-tracking branch 'origin/dev' into crowela/1731/scoring-p…
a-crowell Jul 22, 2024
b2a5f58
Simple requested changes
a-crowell Jul 23, 2024
1b90a26
More simple requested changes
a-crowell Jul 23, 2024
eea6684
Merge branch 'dev' into crowela/1731/scoring-physics
HunterBarclay Jul 25, 2024
2bcc84c
Merge branch 'dev' into crowela/1731/scoring-physics
LucaHaverty Jul 25, 2024
370334f
Added actual intake and eject controls
LucaHaverty Jul 25, 2024
ee5e06f
Format and lint fix
LucaHaverty Jul 25, 2024
bf61a33
At long last, persistent points
a-crowell Jul 25, 2024
8d63eea
Clean up and doc
a-crowell Jul 25, 2024
a638455
Commented out destroy gamepiece in config
a-crowell Jul 25, 2024
6aca4a5
Formatting
a-crowell Jul 25, 2024
7a5c888
Render scoreboard option and remove dispatch
a-crowell Jul 26, 2024
bfe788a
Saves after deleting zone and formatting
a-crowell Jul 26, 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
1 change: 1 addition & 0 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ function Synthesis() {
<Scene useStats={true} key="scene-in-toast-provider" />
<SceneOverlay />
<MainHUD key={"main-hud"} />
<ScoreboardPanel key="scoreboard" panelId="scoreboard" openLocation="top" sidePadding={8} />
{panelElements.length > 0 && panelElements}
{modalElement && (
<div className="absolute w-full h-full left-0 top-0" key={"modal-element"}>
Expand Down
19 changes: 19 additions & 0 deletions fission/src/mirabuf/EjectableSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ThreeVector3_JoltVec3,
} from "@/util/TypeConversions"
import * as THREE from "three"
import ScoringZoneSceneObject from "./ScoringZoneSceneObject"

class EjectableSceneObject extends SceneObject {
private _parentAssembly: MirabufSceneObject
Expand All @@ -23,6 +24,10 @@ class EjectableSceneObject extends SceneObject {
return this._gamePieceBodyId
}

public get parentBodyId() {
return this._parentBodyId
}

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

Expand All @@ -43,6 +48,20 @@ class EjectableSceneObject extends SceneObject {

World.PhysicsSystem.DisablePhysicsForBody(this._gamePieceBodyId)

// Checks if the gamepiece comes from a zone for persistent point score updates
// because gamepieces removed by intake are not detected in the collision listener
const zones = [...World.SceneRenderer.sceneObjects.entries()]
.filter(x => {
const y = x[1] instanceof ScoringZoneSceneObject
return y
})
.map(x => x[1]) as ScoringZoneSceneObject[]

zones.forEach(x => {
if (this._gamePieceBodyId)
ScoringZoneSceneObject.RemoveGamepiece(x, this._gamePieceBodyId)
})

console.debug("Ejectable created successfully!")
}
}
Expand Down
42 changes: 29 additions & 13 deletions fission/src/mirabuf/IntakeSensorSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
ThreeQuaternion_JoltQuat,
ThreeVector3_JoltVec3,
} from "@/util/TypeConversions"
import { OnContactPersistedEvent } from "@/systems/physics/ContactEvents"
import InputSystem from "@/systems/input/InputSystem"

class IntakeSensorSceneObject extends SceneObject {
private _parentAssembly: MirabufSceneObject
Expand All @@ -18,6 +20,7 @@ class IntakeSensorSceneObject extends SceneObject {

private _joltBodyId?: Jolt.BodyID
private _mesh?: THREE.Mesh
private _collision?: (e: OnContactPersistedEvent) => void

public constructor(parentAssembly: MirabufSceneObject) {
super()
Expand Down Expand Up @@ -49,6 +52,23 @@ class IntakeSensorSceneObject extends SceneObject {
)
World.SceneRenderer.scene.add(this._mesh)

this._collision = (event: OnContactPersistedEvent) => {
if (InputSystem.isKeyPressed("KeyQ")) {
if (this._joltBodyId && !World.PhysicsSystem.isPaused) {
const body1 = event.message.body1
const body2 = event.message.body2

if (body1.GetIndexAndSequenceNumber() == this._joltBodyId.GetIndexAndSequenceNumber()) {
this.IntakeCollision(body2)
} else if (body2.GetIndexAndSequenceNumber() == this._joltBodyId.GetIndexAndSequenceNumber()) {
this.IntakeCollision(body1)
}
}
}
}

OnContactPersistedEvent.AddListener(this._collision)

console.debug("Intake sensor created successfully!")
}
}
Expand All @@ -70,19 +90,6 @@ class IntakeSensorSceneObject extends SceneObject {
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?.isGamePiece) {
console.debug("Found game piece!")
this._parentAssembly.SetEjectable(hitRes.data.mBodyID, false)
}
}
}
}
}

Expand All @@ -98,6 +105,15 @@ class IntakeSensorSceneObject extends SceneObject {
World.SceneRenderer.scene.remove(this._mesh)
}
}

if (this._collision) OnContactPersistedEvent.RemoveListener(this._collision)
}

private IntakeCollision(gpID: Jolt.BodyID) {
const associate = <RigidNodeAssociate>World.PhysicsSystem.GetBodyAssociation(gpID)
if (associate?.isGamePiece) {
this._parentAssembly.SetEjectable(gpID, false)
}
}
}

Expand Down
23 changes: 22 additions & 1 deletion fission/src/mirabuf/MirabufSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain"
import InputSystem from "@/systems/input/InputSystem"
import TransformGizmos from "@/ui/components/TransformGizmos"
import { EjectorPreferences, FieldPreferences, IntakePreferences } from "@/systems/preferences/PreferenceTypes"
import { EjectorPreferences, FieldPreferences, IntakePreferences, ScoringZonePreferences } from "@/systems/preferences/PreferenceTypes"

Check warning on line 15 in fission/src/mirabuf/MirabufSceneObject.ts

View workflow job for this annotation

GitHub Actions / ESLint Format Validation

'ScoringZonePreferences' is defined but never used. Allowed unused vars must match /^_/u
a-crowell marked this conversation as resolved.
Show resolved Hide resolved
import PreferencesSystem from "@/systems/preferences/PreferencesSystem"
import { MiraType } from "./MirabufLoader"
import IntakeSensorSceneObject from "./IntakeSensorSceneObject"
import EjectableSceneObject from "./EjectableSceneObject"
import ScoringZoneSceneObject from "./ScoringZoneSceneObject"
import { SceneOverlayTag } from "@/ui/components/SceneOverlayEvents"
import { ProgressHandle } from "@/ui/components/ProgressNotificationData"

Expand Down Expand Up @@ -45,6 +46,7 @@

private _intakeSensor?: IntakeSensorSceneObject
private _ejectable?: EjectableSceneObject
private _scoringZones: ScoringZoneSceneObject[] = []

private _nameTag: SceneOverlayTag | undefined

Expand Down Expand Up @@ -148,6 +150,8 @@

// Intake
this.UpdateIntakeSensor()

this.UpdateScoringZones()
}

public Update(): void {
Expand Down Expand Up @@ -241,6 +245,9 @@
this._ejectable = undefined
}

this._scoringZones.forEach(zone => World.SceneRenderer.RemoveSceneObject(zone.id))
this._scoringZones = []

this._mechanism.nodeToBody.forEach(bodyId => {
World.PhysicsSystem.RemoveBodyAssocation(bodyId)
})
Expand Down Expand Up @@ -330,6 +337,7 @@
}

if (!this._ejectorPreferences || !this._ejectorPreferences.parentNode || !bodyId) {
console.log(`Configure an ejectable first.`)
return false
}

Expand All @@ -338,6 +346,19 @@
return true
}

public UpdateScoringZones(render?: boolean) {
this._scoringZones.forEach(zone => World.SceneRenderer.RemoveSceneObject(zone.id))
this._scoringZones = []

if (this._fieldPreferences && this._fieldPreferences.scoringZones) {
for (let i = 0; i < this._fieldPreferences.scoringZones.length; i++) {
const newZone = new ScoringZoneSceneObject(this, i, render ?? PreferencesSystem.getGlobalPreference("RenderScoringZones"))
this._scoringZones.push(newZone)
World.SceneRenderer.RegisterSceneObject(newZone)
}
}
}

/**
* Changes the mode of the mirabuf object from being interacted with to being placed.
*/
Expand Down
Loading
Loading