forked from pmndrs/react-three-rapier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: K1940 <[email protected]>
- Loading branch information
1 parent
0c88645
commit a71ede9
Showing
21 changed files
with
433 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json", | ||
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", | ||
"changelog": "@changesets/cli/changelog", | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "public", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": ["demo"] | ||
"ignore": ["demo"], | ||
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": { | ||
"onlyUpdatePeerDependentsWhenOutOfRange": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@react-three/rapier-addons": patch | ||
--- | ||
|
||
Update changeset settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@react-three/rapier": minor | ||
--- | ||
|
||
Adds basic snapshot capabilities by adding `setWorld` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## Description | ||
<!-- A summary of the changes. Add a video or screenshot if it makes sense! --> | ||
|
||
### Type of change | ||
<!-- Remove unrelated items --> | ||
|
||
- 🐛 Bug fix | ||
- ✨ New feature | ||
- 📦 Other (tests, refactoring, docs, etc.) | ||
|
||
### Checklist: | ||
<!-- Check all that apply, remove any that don't --> | ||
|
||
- [ ] 🔍 I have performed a self-review of my code | ||
- [ ] 💬 I have commented my code, particularly in hard-to-understand areas | ||
- [ ] 📗 I have made corresponding changes to the documentation | ||
- [ ] ⭐️ My changes generate no new warnings | ||
- [ ] 🧪 I have added tests | ||
- [ ] 🟢 All new and existing unit tests pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Box, Sphere, useTexture } from "@react-three/drei"; | ||
import { RigidBody, useRapier } from "@react-three/rapier"; | ||
import { RepeatWrapping } from "three"; | ||
import { Demo } from "../../App"; | ||
|
||
import React, { useRef } from "react"; | ||
|
||
import { useControls, button } from "leva"; | ||
|
||
export const SnapshotExample: Demo = () => { | ||
const floor = useTexture( | ||
new URL("../damping/white.png", import.meta.url).toString() | ||
); | ||
const ramp = useTexture( | ||
new URL("../damping/red.png", import.meta.url).toString() | ||
); | ||
const ball = useTexture( | ||
new URL("../damping/green.png", import.meta.url).toString() | ||
); | ||
|
||
floor.wrapS = floor.wrapT = RepeatWrapping; | ||
|
||
const balls = Array.from(Array(10).keys()); | ||
|
||
const { world, setWorld, rapier } = useRapier(); | ||
const worldSnapshot = useRef<Uint8Array>(); | ||
|
||
useControls({ | ||
takeSnapshot: button(() => (worldSnapshot.current = world.takeSnapshot())), | ||
restoreSnapshot: button( | ||
() => | ||
!!worldSnapshot.current && | ||
setWorld(rapier.World.restoreSnapshot(worldSnapshot.current)) | ||
) | ||
}); | ||
|
||
return ( | ||
<> | ||
<group> | ||
<RigidBody type="fixed" colliders="cuboid"> | ||
<Box args={[40, 1, 100]} position={[18, -1, 25]}> | ||
<meshStandardMaterial map={floor} /> | ||
</Box> | ||
</RigidBody> | ||
|
||
<RigidBody type="fixed" colliders="cuboid"> | ||
<Box | ||
args={[40, 0.5, 14]} | ||
position={[18, 2, -5]} | ||
rotation={[Math.PI / 8, 0, 0]} | ||
> | ||
<meshStandardMaterial map={ramp} /> | ||
</Box> | ||
</RigidBody> | ||
|
||
{balls.map((i) => ( | ||
<RigidBody | ||
key={i} | ||
colliders="ball" | ||
position={[i * 3, 10, -10]} | ||
angularDamping={i / 10} | ||
> | ||
<Sphere> | ||
<meshStandardMaterial map={ball} /> | ||
</Sphere> | ||
</RigidBody> | ||
))} | ||
</group> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/react-three-rapier/tests/__snapshots__/physics.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`physics > snapshots > restores snapshots correctly 1`] = ` | ||
[ | ||
Vector3 { | ||
"x": 0, | ||
"y": -13.761244773864746, | ||
"z": 0, | ||
}, | ||
Vector3 { | ||
"x": 2, | ||
"y": -11.761244773864746, | ||
"z": 2, | ||
}, | ||
Vector3 { | ||
"x": -2, | ||
"y": -15.761244773864746, | ||
"z": -2, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`physics > snapshots > restores snapshots correctly 2`] = ` | ||
[ | ||
Vector3 { | ||
"x": 0, | ||
"y": -13.761244773864746, | ||
"z": 0, | ||
}, | ||
Vector3 { | ||
"x": 2, | ||
"y": -11.761244773864746, | ||
"z": 2, | ||
}, | ||
Vector3 { | ||
"x": -2, | ||
"y": -15.761244773864746, | ||
"z": -2, | ||
}, | ||
] | ||
`; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.