Skip to content

Commit

Permalink
Don't update scene objects of sleeping bodies.
Browse files Browse the repository at this point in the history
  • Loading branch information
hmans committed Sep 26, 2022
1 parent ccae725 commit fac8ca5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/six-cows-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hmans/physics3d": patch
---

Don't update scene objects of sleeping bodies.
3 changes: 2 additions & 1 deletion packages/hmans-physics3d/src/RigidBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const RigidBody = forwardRef<RigidBodyEntity, RigidBodyProps>(
/* TODO: set these relative to the physics world object! */

/* Make sure the scene object's world matrix is up to date */
sceneObject.current.updateMatrix()
sceneObject.current.updateMatrixWorld()

/* Assign to state */
Expand Down Expand Up @@ -90,7 +91,7 @@ export const RigidBody = forwardRef<RigidBodyEntity, RigidBodyProps>(
useImperativeHandle(ref, () => state)

return (
<group ref={sceneObject} {...groupProps}>
<group ref={sceneObject} {...groupProps} matrixAutoUpdate={false}>
<RigidBodyContext.Provider value={state}>
{children}
</RigidBodyContext.Provider>
Expand Down
3 changes: 3 additions & 0 deletions packages/hmans-physics3d/src/World.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const World = ({

const { body, sceneObject } = entity

if (body.isSleeping()) continue

/* Get transform from rigidbody */
const position = new THREE.Vector3().copy(
body.translation() as THREE.Vector3
Expand All @@ -65,6 +67,7 @@ export const World = ({
/* Apply transform to scene object */
sceneObject.position.copy(position)
sceneObject.quaternion.copy(quaternion)
sceneObject.updateMatrix()
}

/* Handle collision events */
Expand Down

0 comments on commit fac8ca5

Please sign in to comment.