Skip to content

Commit a56fdff

Browse files
authored
refactor(physics): createAnchorPoint() returns Vec3 SYNTH-341 (#1490)
2 parents 2b7789f + 30fbb28 commit a56fdff

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

fission/src/systems/physics/ConstraintSettingsUtilities.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ import { convertMirabufVector3ToJoltRVec3, convertMirabufVector3ToJoltVec3 } fro
66

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

9-
// Returns a STATIC_ALIAS `RVec3.AddRVec3()`'s scratch buffer.
109
export function createAnchorPoint(jointInstance: mirabuf.joint.JointInstance, jointDefinition: mirabuf.joint.Joint) {
11-
const jointOrigin = jointDefinition.origin
10+
const anchorPoint = jointDefinition.origin
1211
? convertMirabufVector3ToJoltRVec3(jointDefinition.origin)
1312
: new JOLT.RVec3(0, 0, 0)
1413
// TODO: Offset transformation for robot builder.
1514
const jointOriginOffset = jointInstance.offset
16-
? convertMirabufVector3ToJoltRVec3(jointInstance.offset)
17-
: new JOLT.RVec3(0, 0, 0)
15+
? convertMirabufVector3ToJoltVec3(jointInstance.offset)
16+
: new JOLT.Vec3(0, 0, 0)
1817

19-
const anchorPoint = jointOrigin.AddRVec3(jointOriginOffset)
18+
anchorPoint.Add(jointOriginOffset)
2019

21-
JOLT.destroy(jointOrigin)
2220
JOLT.destroy(jointOriginOffset)
2321

2422
return anchorPoint

fission/src/systems/physics/PhysicsSystem.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ class PhysicsSystem extends WorldSystem {
609609

610610
const anchorPoint = createAnchorPoint(jointInstance, jointDefinition)
611611
hingeConstraintSettings.mPoint1 = hingeConstraintSettings.mPoint2 = anchorPoint
612+
JOLT.destroy(anchorPoint)
612613

613614
const rotationalFreedom = jointDefinition.rotational!.rotationalFreedom!
614615

@@ -642,6 +643,7 @@ class PhysicsSystem extends WorldSystem {
642643

643644
const anchorPoint = createAnchorPoint(jointInstance, jointDefinition)
644645
constraintSettings.mPoint1 = constraintSettings.mPoint2 = anchorPoint
646+
JOLT.destroy(anchorPoint)
645647

646648
const freedom = jointDefinition.prismatic!.prismaticFreedom!
647649

@@ -839,6 +841,7 @@ class PhysicsSystem extends WorldSystem {
839841

840842
JOLT.destroy(axis)
841843
JOLT.destroy(unitAxis)
844+
JOLT.destroy(anchorPoint)
842845

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

873877
return
874878
}
@@ -922,6 +926,8 @@ class PhysicsSystem extends WorldSystem {
922926

923927
JOLT.destroy(constraintSpecifications.axis)
924928
})
929+
930+
JOLT.destroy(anchorPoint)
925931
}
926932

927933
/**

0 commit comments

Comments
 (0)