-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deps): update deps, refactor examples (#189)
* fix(deps): update deps, refactor examples - add`type` setting to mutable props - use `canSleep` on immutable RigidBodyDesc creation * feat: add dynamic type example * fix(dynamic example): a bit more robust
- Loading branch information
Showing
41 changed files
with
391 additions
and
126 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@react-three/rapier": patch | ||
--- | ||
|
||
Fix issue with `canSleep` missing from RigidBodyDesc |
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": patch | ||
--- | ||
|
||
Enable dynamic changing of RigidBody `type` |
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
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
2 changes: 1 addition & 1 deletion
2
demo/src/api-usage/ApiUsageExample.tsx → ...rc/examples/api-usage/ApiUsageExample.tsx
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
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
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
2 changes: 1 addition & 1 deletion
2
demo/src/damping/DampingExample.tsx → demo/src/examples/damping/DampingExample.tsx
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
File renamed without changes
File renamed without changes
96 changes: 96 additions & 0 deletions
96
demo/src/examples/dynamic-type-change/DynamicTypeChangeExample.tsx
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,96 @@ | ||
import { Html } from "@react-three/drei"; | ||
import { useFrame, useThree } from "@react-three/fiber"; | ||
import { RigidBody, RigidBodyApi } from "@react-three/rapier"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import { useDemo } from "../../App"; | ||
import { useSuzanne } from "../all-shapes/AllShapesExample"; | ||
|
||
export const DynamicTypeChangeExample = () => { | ||
const { setCameraEnabled } = useDemo(); | ||
const monkee = useRef<RigidBodyApi>(null); | ||
const [dragging, setDragging] = useState(false); | ||
const [s] = useState<{ mouse: { x: number; y: number } | null }>({ | ||
mouse: null | ||
}); | ||
|
||
const { | ||
nodes: { Suzanne } | ||
} = useSuzanne(); | ||
|
||
const { mouse } = useThree(); | ||
|
||
useEffect(() => { | ||
if (dragging) { | ||
document.body.style.cursor = "grabbing"; | ||
setCameraEnabled?.(false); | ||
} else { | ||
document.body.style.cursor = ""; | ||
setCameraEnabled?.(true); | ||
s.mouse = null; | ||
} | ||
}, [dragging]); | ||
|
||
useFrame(() => { | ||
if (dragging) { | ||
if (!s.mouse) { | ||
s.mouse = { x: mouse.x, y: mouse.y }; | ||
} else { | ||
const { x, y } = monkee.current?.translation() || { x: 0, y: 0 }; | ||
|
||
monkee.current?.setTranslation({ | ||
x: x + (mouse.x - s.mouse.x) * 10, | ||
y: y + (mouse.y - s.mouse.y) * 10, | ||
z: 0 | ||
}); | ||
|
||
s.mouse = { x: mouse.x, y: mouse.y }; | ||
} | ||
} | ||
}); | ||
|
||
useEffect(() => { | ||
const handleMouseUp = () => { | ||
setDragging(false); | ||
}; | ||
window.addEventListener("pointerup", handleMouseUp); | ||
|
||
return () => { | ||
window.removeEventListener("pointerup", handleMouseUp); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<group> | ||
<RigidBody type={dragging ? "kinematicPosition" : "dynamic"} ref={monkee}> | ||
<mesh | ||
castShadow | ||
receiveShadow | ||
geometry={Suzanne.geometry} | ||
onPointerDown={() => { | ||
setDragging(true); | ||
}} | ||
onPointerOver={() => (document.body.style.cursor = "grab")} | ||
onPointerOut={() => (document.body.style.cursor = "")} | ||
> | ||
<meshStandardMaterial color="yellow" /> | ||
<Html | ||
style={{ | ||
pointerEvents: "none", | ||
width: 200, | ||
marginLeft: -100, | ||
marginTop: -100, | ||
borderRadius: 4, | ||
background: "rgba(255,255,255,.2)", | ||
padding: 8, | ||
textAlign: "center", | ||
backdropFilter: "blur(10px)" | ||
}} | ||
> | ||
<div>Drag me!</div> | ||
<div>Type: {dragging ? "kinematicPosition" : "dynamic"}</div> | ||
</Html> | ||
</mesh> | ||
</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
Oops, something went wrong.