Skip to content

Commit f888449

Browse files
committed
Merge branch 'branp/198/user-select-add-joints' into zachr/302/joint-selection-ui
2 parents 66cf41b + 44e05e4 commit f888449

26 files changed

Lines changed: 348 additions & 250 deletions

fission/src/mirabuf/MirabufLoader.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import InitialConfigPanel from "@/panels/configuring/initial-config/InitialConfi
88
import { PAUSE_REF_ASSEMBLY_SPAWNING } from "@/systems/physics/PhysicsTypes.ts"
99
import { createMirabuf } from "@/mirabuf/MirabufSceneObject.ts"
1010
import { getTargetControls } from "@/systems/scene/CameraControls.ts"
11+
import { detectAndTagWheels } from "@/systems/simulation/synthesis_brain/WheelDetector"
1112
import type { EncodedAssembly, Message } from "@/systems/multiplayer/types.ts"
1213
import { ProgressHandle } from "@/components/ProgressNotificationData.ts"
1314

@@ -271,6 +272,10 @@ class MirabufCachingService {
271272
return
272273
}
273274

275+
if (assembly.dynamic) {
276+
detectAndTagWheels(assembly)
277+
}
278+
274279
const info = await MirabufCachingService.storeAssemblyInCache(assembly, { miraType })
275280
if (!info) return
276281

fission/src/mirabuf/MirabufSceneObject.ts

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,14 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
416416
)
417417

418418
const yUnitVec = new JOLT.Vec3(0, 1, 0)
419-
const initialRotation = JOLT.Quat.prototype.sRotation(yUnitVec, initialPos.yaw)
419+
const initialRotation = JOLT.Quat.prototype.sRotation(yUnitVec, initialPos.yaw) // STATIC_ALIAS
420420

421421
const blankVec = new JOLT.Vec3()
422422
this.mirabufInstance.parser.rigidNodes.forEach(rn => {
423423
const jBodyId = this.mechanism.getBodyByNodeId(rn.id)
424424
if (!jBodyId) return
425425

426-
const position = World.physicsSystem.getBody(jBodyId)!.GetPosition()
426+
const position = World.physicsSystem.getBody(jBodyId)!.GetPosition() // STATIC_ALIAS
427427
const offset = convertJoltRVec3ToJoltVec3(position.Sub(bodyCenter))
428428

429429
World.physicsSystem.setBodyPositionRotationAndVelocity(
@@ -435,15 +435,13 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
435435
false
436436
)
437437

438-
JOLT.destroy(position)
439438
JOLT.destroy(offset)
440439
})
441440

442441
this.updateMeshTransforms()
443442

444443
JOLT.destroy(bodyCenter)
445444
JOLT.destroy(initialTranslation)
446-
JOLT.destroy(initialRotation)
447445
JOLT.destroy(yUnitVec)
448446
JOLT.destroy(blankVec)
449447
}
@@ -461,6 +459,11 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
461459
public dispose(): void {
462460
this.mirabufInstance.dispose(World.sceneRenderer.scene)
463461

462+
if (this._unrotatedRootNodeToCenterPositionTranslation) {
463+
JOLT.destroy(this._unrotatedRootNodeToCenterPositionTranslation)
464+
this._unrotatedRootNodeToCenterPositionTranslation = undefined
465+
}
466+
464467
if (this._brain?.isSynthesis()) {
465468
this._brain.clearControls()
466469
}
@@ -545,7 +548,7 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
545548
* Matches mesh transforms to their Jolt counterparts.
546549
*/
547550
public updateMeshTransforms() {
548-
let weightedCOM = new JOLT.RVec3(0, 0, 0)
551+
const weightedCom = new THREE.Vector3()
549552
let totalMass = 0
550553

551554
// If this.dispose() has been ran then return
@@ -555,18 +558,15 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
555558
const body = World.physicsSystem.getBody(bodyId)
556559
if (!body) return
557560

558-
const transform = convertJoltMat44ToThreeMatrix4(body.GetWorldTransform())
561+
const transform = convertJoltMat44ToThreeMatrix4(body.GetWorldTransform()) // STATIC_ALIAS
559562
this.updateNodeParts(rn, transform)
560563

561-
const position = body.GetPosition()
564+
const position = body.GetPosition() // STATIC_ALIAS
562565
if (Number.isNaN(position.GetX())) {
563-
const vel = body.GetLinearVelocity()
566+
const vel = body.GetLinearVelocity() // STATIC_ALIAS
564567
console.warn(
565568
`Invalid Position.\nPosition => ${position.GetX()}, ${position.GetY()}, ${position.GetZ()}\nVelocity => ${vel.GetX()}, ${vel.GetY()}, ${vel.GetZ()}`
566569
)
567-
568-
JOLT.destroy(vel)
569-
JOLT.destroy(position)
570570
}
571571

572572
if (this._debugBodies) {
@@ -584,32 +584,24 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
584584
const inverseMass = body.GetMotionProperties().GetInverseMass()
585585

586586
if (inverseMass > 0) {
587-
const oldWeighedCOM = weightedCOM
588-
589587
const mass = 1 / inverseMass
590-
const com = body.GetCenterOfMassPosition().Mul(mass)
588+
const comPosition = body.GetCenterOfMassPosition() // STATIC_ALIAS
591589

592-
weightedCOM = weightedCOM.AddRVec3(com)
590+
weightedCom.addScaledVector(convertJoltVec3ToThreeVector3(comPosition, false), mass)
593591
totalMass += mass
594-
595-
JOLT.destroy(oldWeighedCOM)
596-
JOLT.destroy(com)
597592
}
598593
}
599594
})
600595
}
601596

602597
if (this._centerOfMassIndicator) {
603-
const setPositionAndVisibility = (netCoM: Jolt.RVec3) => {
604-
this._centerOfMassIndicator!.position.set(netCoM.GetX(), netCoM.GetY(), netCoM.GetZ())
605-
this._centerOfMassIndicator!.visible = PreferencesSystem.getUserPreference("ShowCenterOfMassIndicators")
598+
if (totalMass > 0) {
599+
weightedCom.divideScalar(totalMass)
606600
}
607601

608-
const com = totalMass > 0 ? weightedCOM.Div(totalMass) : weightedCOM
609-
setPositionAndVisibility(com)
602+
this._centerOfMassIndicator.position.copy(weightedCom)
603+
this._centerOfMassIndicator.visible = PreferencesSystem.getUserPreference("ShowCenterOfMassIndicators")
610604
}
611-
612-
JOLT.destroy(weightedCOM)
613605
}
614606

615607
public updateNodeParts(rn: RigidNodeReadOnly, transform: THREE.Matrix4) {
@@ -827,9 +819,9 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
827819

828820
const inverseRotation = this.getInverseRotationOfBody()
829821

830-
const biggest = JOLT.AABox.prototype.sBiggest()
822+
const biggest = JOLT.AABox.prototype.sBiggest() // STATIC_ALIAS
831823
const scale = new JOLT.Vec3(1, 1, 1)
832-
const identity = JOLT.Quat.prototype.sIdentity()
824+
const identity = JOLT.Quat.prototype.sIdentity() // STATIC_ALIAS
833825

834826
this.mirabufInstance.parser.rigidNodes.forEach(rigidNode => {
835827
const bodyId = this.mechanism.getBodyByNodeId(rigidNode.id)
@@ -883,8 +875,6 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
883875
JOLT.destroy(inverseRotation)
884876

885877
JOLT.destroy(scale)
886-
JOLT.destroy(biggest)
887-
JOLT.destroy(identity)
888878

889879
const mins = [this._furthestVertices.x.min, this._furthestVertices.y.min, this._furthestVertices.z.min]
890880
const maxes = [this._furthestVertices.x.max, this._furthestVertices.y.max, this._furthestVertices.z.max]
@@ -937,11 +927,12 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
937927

938928
// Finally, we just offset the root node to get the true center
939929
const position = convertJoltRVec3ToJoltVec3(rootBody.GetPosition().Add(offset))
940-
const transform = JOLT.Mat44.prototype.sRotationTranslation(rotation, position)
930+
const transform = JOLT.Mat44.prototype.sRotationTranslation(rotation, position) // STATIC_ALIAS
941931

942932
const orientedBoundingBox = new JOLT.OrientedBox(transform, halfExtent)
943933

944-
JOLT.destroy(transform)
934+
JOLT.destroy(offset)
935+
JOLT.destroy(position)
945936
JOLT.destroy(halfExtent)
946937

947938
return orientedBoundingBox
@@ -985,9 +976,8 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
985976

986977
const shape = body.GetShape()
987978
const scale = new JOLT.Vec3(1, 1, 1)
988-
const biggest = JOLT.AABox.prototype.sBiggest()
989-
990-
const identity = JOLT.Quat.prototype.sIdentity()
979+
const biggest = JOLT.AABox.prototype.sBiggest() // STATIC_ALIAS
980+
const identity = JOLT.Quat.prototype.sIdentity() // STATIC_ALIAS
991981
const triangleContext = new JOLT.ShapeGetTriangles(shape, biggest, shape.GetCenterOfMass(), identity, scale)
992982

993983
try {
@@ -1008,8 +998,6 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
1008998
} finally {
1009999
JOLT.destroy(triangleContext)
10101000
JOLT.destroy(scale)
1011-
JOLT.destroy(biggest)
1012-
JOLT.destroy(identity)
10131001
}
10141002
})
10151003

fission/src/mirabuf/RobotCameraSceneObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type Jolt from "@azaleacolburn/jolt-physics"
1+
import type Jolt from "@synthesis.adsk/jolt-physics"
22
import * as THREE from "three"
33
import type { CameraPreferences } from "@/systems/preferences/PreferenceTypes"
44
import SceneObject from "@/systems/scene/SceneObject"

fission/src/systems/multiplayer/MessageHandlers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,17 @@ function handlePeerUpdate(data: UpdateObjectData[], peerId: string, timestamp: n
133133
const clientBody = World.physicsSystem.getBody(bodyId)
134134
if (!clientBody) {
135135
console.error(`Body ${bodyId} on Scene Object ${sceneObject.assemblyName} not found`)
136+
JOLT.destroy(linearVelocity)
137+
JOLT.destroy(angularVelocity)
138+
JOLT.destroy(position)
139+
JOLT.destroy(rotation)
136140
return
137141
}
138142

139143
clientBody.SetLinearVelocity(linearVelocity)
140144
clientBody.SetAngularVelocity(angularVelocity)
145+
JOLT.destroy(linearVelocity)
146+
JOLT.destroy(angularVelocity)
141147
World.physicsSystem.setBodyPosition(bodyId, position)
142148
World.physicsSystem.setBodyRotation(bodyId, rotation)
143149
})

fission/src/systems/physics/ConstraintSettingsUtilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { convertMirabufVector3ToJoltRVec3, convertMirabufVector3ToJoltVec3 } fro
66

77
type LimitSpecs = Omit<DOFSpecs, "friction" | "axis">
88

9+
// Returns a STATIC_ALIAS `RVec3.AddRVec3()`'s scratch buffer.
910
export function createAnchorPoint(jointInstance: mirabuf.joint.JointInstance, jointDefinition: mirabuf.joint.Joint) {
1011
const jointOrigin = jointDefinition.origin
1112
? convertMirabufVector3ToJoltRVec3(jointDefinition.origin)

fission/src/systems/physics/Mechanism.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Mechanism {
2020
public nodeToBody: Map<RigidNodeId, Jolt.BodyID>
2121
public constraints: MechanismConstraint[] = []
2222
public stepListeners: Jolt.PhysicsStepListener[] = []
23+
public vehicleTesters: Jolt.VehicleCollisionTester[] = []
2324
public layerReserve?: LayerReserve
2425
public controllable: boolean
2526
public ghostBodies: Jolt.BodyID[] = []
@@ -45,6 +46,10 @@ class Mechanism {
4546
this.stepListeners.push(listener)
4647
}
4748

49+
public addVehicleTester(tester: Jolt.VehicleCollisionTester) {
50+
this.vehicleTesters.push(tester)
51+
}
52+
4853
public getBodyByNodeId(nodeId: string) {
4954
return this.nodeToBody.get(nodeId)
5055
}

0 commit comments

Comments
 (0)