THREE-XPBD icon indicating copy to clipboard operation
THREE-XPBD copied to clipboard

Refactoring / making physics code standalone

Open markeasting opened this issue 1 year ago • 0 comments

The current codebase is tightly coupled. For example, physics classes are using the (top-level) GUI layer.

Examples

RigidBody uses the BaseScene class

The addTo() method is a neat feature, but couples the entire class with BaseScene. The method should be moved to World or some util class.

https://github.com/markeasting/THREE-XPBD/blob/df1c273107dff7ea8cbedfc1d7a929c1b0aeb0df/src/physics/RigidBody.ts#L65-L79

The signature should probably become:

addTo(scene: THREE.Scene, world: World)

BaseSolver should be removed

The base solver is only providing debug features (and accesses the GUI layer via the Game class). There should be an external class that provides point/vector debugging features.

https://github.com/markeasting/THREE-XPBD/blob/df1c273107dff7ea8cbedfc1d7a929c1b0aeb0df/src/physics/solver/BaseSolver.ts#L26-L28

Settings / globals

Some parts of the code access application config via the Game class. They should be provided in another way. Even moving the config to window would be better.

https://github.com/markeasting/THREE-XPBD/blob/df1c273107dff7ea8cbedfc1d7a929c1b0aeb0df/src/physics/solver/BaseSolver.ts#L67-L68

GJK / EPA debugging code

The narrow phase code has debugging stuff that should be removed / handled outside of the class.

https://github.com/markeasting/THREE-XPBD/blob/df1c273107dff7ea8cbedfc1d7a929c1b0aeb0df/src/physics/narrowphase/GjkEpa.ts#L40-L45

markeasting avatar Feb 06 '24 09:02 markeasting