Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 4 additions & 6 deletions fission/src/systems/physics/ConstraintSettingsUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ import { convertMirabufVector3ToJoltRVec3, convertMirabufVector3ToJoltVec3 } fro

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

// Returns a STATIC_ALIAS `RVec3.AddRVec3()`'s scratch buffer.
export function createAnchorPoint(jointInstance: mirabuf.joint.JointInstance, jointDefinition: mirabuf.joint.Joint) {
const jointOrigin = jointDefinition.origin
const anchorPoint = jointDefinition.origin
? convertMirabufVector3ToJoltRVec3(jointDefinition.origin)
: new JOLT.RVec3(0, 0, 0)
// TODO: Offset transformation for robot builder.
const jointOriginOffset = jointInstance.offset
? convertMirabufVector3ToJoltRVec3(jointInstance.offset)
: new JOLT.RVec3(0, 0, 0)
? convertMirabufVector3ToJoltVec3(jointInstance.offset)
: new JOLT.Vec3(0, 0, 0)

const anchorPoint = jointOrigin.AddRVec3(jointOriginOffset)
anchorPoint.Add(jointOriginOffset)

JOLT.destroy(jointOrigin)
JOLT.destroy(jointOriginOffset)

return anchorPoint
Expand Down
6 changes: 6 additions & 0 deletions fission/src/systems/physics/PhysicsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ class PhysicsSystem extends WorldSystem {

const anchorPoint = createAnchorPoint(jointInstance, jointDefinition)
hingeConstraintSettings.mPoint1 = hingeConstraintSettings.mPoint2 = anchorPoint
JOLT.destroy(anchorPoint)

const rotationalFreedom = jointDefinition.rotational!.rotationalFreedom!

Expand Down Expand Up @@ -642,6 +643,7 @@ class PhysicsSystem extends WorldSystem {

const anchorPoint = createAnchorPoint(jointInstance, jointDefinition)
constraintSettings.mPoint1 = constraintSettings.mPoint2 = anchorPoint
JOLT.destroy(anchorPoint)

const freedom = jointDefinition.prismatic!.prismaticFreedom!

Expand Down Expand Up @@ -839,6 +841,7 @@ class PhysicsSystem extends WorldSystem {

JOLT.destroy(axis)
JOLT.destroy(unitAxis)
JOLT.destroy(anchorPoint)

const vehicleConstraint = this.createVehicleConstraint(wheelSettings, bodyMain, maxAcc, urdfWheelBasis)
const { listener, tester } = this.createVehicleListeners(vehicleConstraint, bodyWheel)
Expand Down Expand Up @@ -869,6 +872,7 @@ class PhysicsSystem extends WorldSystem {
const dofs = jointDefinition.custom?.dofs
if (!dofs || dofs.length < 3) {
console.warn("Empty degrees-of-freedom in joint definition for ball constraint")
JOLT.destroy(anchorPoint)

return
}
Expand Down Expand Up @@ -922,6 +926,8 @@ class PhysicsSystem extends WorldSystem {

JOLT.destroy(constraintSpecifications.axis)
})

JOLT.destroy(anchorPoint)
}

/**
Expand Down
Loading