Skip to content

Commit

Permalink
fix: disable problematic interpolation for now
Browse files Browse the repository at this point in the history
  • Loading branch information
wiledal committed Aug 29, 2022
1 parent 77635c4 commit e229bd2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-walls-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-three/rapier": patch
---

Disable problematic translation interpolation for now
18 changes: 18 additions & 0 deletions demo/src/transforms/Transforms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ export const Transforms: Demo = () => {
/>
</RigidBody>
</group>

<group rotation={[0, 3, 0]}>
<RigidBody colliders="ball">
<Sphere position={[2, 2, 2]} />
</RigidBody>

<RigidBody colliders="ball">
<Sphere position={[2, 10, 2]} scale={0.3} castShadow receiveShadow>
<meshPhysicalMaterial />
</Sphere>
</RigidBody>

<RigidBody colliders="ball">
<Sphere position={[-2, 10, 2]} scale={0.3} castShadow receiveShadow>
<meshPhysicalMaterial />
</Sphere>
</RigidBody>
</group>
</group>
);
};
14 changes: 7 additions & 7 deletions packages/react-three-rapier/src/Physics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
TempContactManifold,
World,
} from "@dimforge/rapier3d-compat";
import { InstancedMesh, Matrix, Matrix4, Mesh, Object3D, Vector3 } from "three";
import { InstancedMesh, Matrix, Matrix4, Mesh, Object3D, Quaternion, Vector3 } from "three";
import {
rapierQuaternionToQuaternion,
rapierVector3ToVector3,
Expand Down Expand Up @@ -195,8 +195,8 @@ export const Physics: FC<RapierWorldProps> = ({
* @see https://gafferongames.com/post/fix_your_timestep/
*/
let previousTranslations: Record<string, {
rotation: Rapier.Rotation,
translation: Rapier.Vector3
rotation: Quaternion,
translation: Vector3
}> = {}

// don't step time forwards if paused
Expand All @@ -212,8 +212,8 @@ export const Physics: FC<RapierWorldProps> = ({
// Collect previous state
world.bodies.forEach(b => {
previousTranslations[b.handle] = {
rotation: b.rotation(),
translation: b.translation()
rotation: rapierQuaternionToQuaternion(b.rotation()).normalize(),
translation: rapierVector3ToVector3(b.translation())
}
})

Expand Down Expand Up @@ -253,8 +253,8 @@ export const Physics: FC<RapierWorldProps> = ({

let newTranslation = rapierVector3ToVector3(rigidBody.translation())
let newRotation = rapierQuaternionToQuaternion(rigidBody.rotation())
let interpolatedTranslation = oldState ? rapierVector3ToVector3(oldState.translation).lerp(newTranslation, interpolationAlpha) : newTranslation
let interpolatedRotation = oldState ? rapierQuaternionToQuaternion(oldState.rotation).slerp(newRotation, interpolationAlpha) : newRotation
let interpolatedTranslation = oldState ? oldState.translation.lerp(newTranslation, 1) : newTranslation
let interpolatedRotation = oldState ? oldState.rotation.slerp(newRotation, interpolationAlpha) : newRotation

state.setMatrix(
_matrix4
Expand Down

1 comment on commit e229bd2

@vercel
Copy link

@vercel vercel bot commented on e229bd2 Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-three-rapier – ./

react-three-rapier-pmndrs.vercel.app
react-three-rapier-git-main-pmndrs.vercel.app
react-three-rapier.pmnd.rs

Please sign in to comment.