diff --git a/packages/react-three-cannon-examples/package.json b/packages/react-three-cannon-examples/package.json index 92b1af0f..7cab3546 100755 --- a/packages/react-three-cannon-examples/package.json +++ b/packages/react-three-cannon-examples/package.json @@ -21,8 +21,8 @@ ], "devDependencies": { "@react-three/cannon": "^6.6.0", - "@react-three/drei": "^9.80.1", - "@react-three/fiber": "^8.13.6", + "@react-three/drei": "^9.97.5", + "@react-three/fiber": "^8.15.16", "@types/lodash-es": "^4.17.6", "@types/react": "^18.0.5", "@types/react-dom": "^17.0.14", @@ -31,7 +31,6 @@ "@types/three": "^0.155.0", "@typescript-eslint/eslint-plugin": "^5.17.0", "@typescript-eslint/parser": "^5.17.0", - "@vitejs/plugin-react": "^2.2.0", "eslint": "^8.12.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-es": "^4.1.0", @@ -47,16 +46,17 @@ "react-router-dom": "^6.2.2", "styled-components": "^5.3.5", "three": "^0.155.0", - "three-stdlib": "^2.24.1", + "three-stdlib": "^2.29.4", "typescript": "^4.6.3", - "vite": "^3.2.2", + "vite": "^5.1.1", "vite-react-jsx": "^1.1.2", - "zustand": "^3.7.1" + "zustand": "^4.5.0" }, "lint-staged": { "*.{js,jsx,ts,tsx}": "eslint --cache --fix", "*.{js,json,jsx,md,ts,tsx}": "prettier --write" }, "license": "MIT", - "sideEffects": false + "sideEffects": false, + "type": "module" } diff --git a/packages/react-three-cannon-examples/src/demos/MondayMorning/index.tsx b/packages/react-three-cannon-examples/src/demos/MondayMorning/index.tsx index 1d791c9e..2d036fa1 100644 --- a/packages/react-three-cannon-examples/src/demos/MondayMorning/index.tsx +++ b/packages/react-three-cannon-examples/src/demos/MondayMorning/index.tsx @@ -9,8 +9,9 @@ import { usePointToPointConstraint, useSphere, } from '@react-three/cannon' +import { useGLTF } from '@react-three/drei' import type { BoxGeometryProps, MeshProps, MeshStandardMaterialProps, ThreeEvent } from '@react-three/fiber' -import { Canvas, useFrame, useLoader } from '@react-three/fiber' +import { Canvas, useFrame } from '@react-three/fiber' import type { ReactNode, RefObject } from 'react' import { createContext, @@ -25,7 +26,6 @@ import { } from 'react' import type { Group, Material, Mesh, Object3D, SpotLight } from 'three' import type { GLTF } from 'three-stdlib/loaders/GLTFLoader' -import { GLTFLoader } from 'three-stdlib/loaders/GLTFLoader' import type { ShapeName } from './createConfig' import { createRagdoll } from './createConfig' @@ -206,7 +206,7 @@ interface CupGLTF extends GLTF { } function Mug() { - const { nodes, materials } = useLoader(GLTFLoader, '/cup.glb') as CupGLTF + const { nodes, materials } = useGLTF('/cup.glb') as CupGLTF const [ref] = useCylinder( () => ({ args: [0.6, 0.6, 1, 16], @@ -292,8 +292,16 @@ const Lamp = () => { - - + + ) @@ -322,15 +330,11 @@ export default () => ( orthographic shadows style={{ cursor: 'none' }} - gl={{ - // todo: stop using legacy lights - useLegacyLights: true, - }} > - - + + diff --git a/packages/react-three-cannon-examples/src/demos/Pingpong/index.tsx b/packages/react-three-cannon-examples/src/demos/Pingpong/index.tsx index 3ee14937..931ca577 100644 --- a/packages/react-three-cannon-examples/src/demos/Pingpong/index.tsx +++ b/packages/react-three-cannon-examples/src/demos/Pingpong/index.tsx @@ -1,14 +1,13 @@ import { Physics, useBox, usePlane, useSphere } from '@react-three/cannon' +import { useGLTF } from '@react-three/drei' import { Canvas, useFrame, useLoader } from '@react-three/fiber' import lerp from 'lerp' import clamp from 'lodash-es/clamp' import { Suspense, useRef } from 'react' import type { Group, Material, Mesh, Object3D, Skeleton } from 'three' import { TextureLoader } from 'three' -import { DRACOLoader } from 'three-stdlib/loaders/DRACOLoader' import type { GLTF } from 'three-stdlib/loaders/GLTFLoader' -import { GLTFLoader } from 'three-stdlib/loaders/GLTFLoader' -import create from 'zustand' +import { create } from 'zustand' import earthImg from './resources/cross.jpg' import pingSound from './resources/ping.mp3' @@ -46,14 +45,8 @@ type PingPongGLTF = GLTF & { } } -const extensions = (loader: GLTFLoader) => { - const dracoLoader = new DRACOLoader() - dracoLoader.setDecoderPath('/draco-gltf/') - loader.setDRACOLoader(dracoLoader) -} - function Paddle() { - const { nodes, materials } = useLoader(GLTFLoader, '/pingpong.glb', extensions) as PingPongGLTF + const { nodes, materials } = useGLTF('/pingpong.glb', '/draco-gltf/') as PingPongGLTF const { pong } = useStore((state) => state.api) const welcome = useStore((state) => state.welcome) const count = useStore((state) => state.count) @@ -149,23 +142,20 @@ export default function () { return ( <> welcome && reset(false)} - gl={{ - // todo: stop using legacy lights - useLegacyLights: true, - }} + shadows > - - + + threeLine: Object3DNode } } @@ -114,7 +112,6 @@ function Raycast() { const Camera = () => { const cameraRef = useRef(null) - const controlsRef = useRef(null) const { gl, camera } = useThree() const set = useThree((state) => state.set) const size = useThree((state) => state.size) @@ -132,18 +129,16 @@ const Camera = () => { }, []) useFrame(() => { - if (!cameraRef.current || !controlsRef.current) return + if (!cameraRef.current) return cameraRef.current.updateMatrixWorld() - controlsRef.current.update() }) return ( <> - { } export default () => ( - + diff --git a/packages/react-three-cannon-examples/src/demos/RaycastVehicle/index.tsx b/packages/react-three-cannon-examples/src/demos/RaycastVehicle/index.tsx index 5b370f47..926e425c 100644 --- a/packages/react-three-cannon-examples/src/demos/RaycastVehicle/index.tsx +++ b/packages/react-three-cannon-examples/src/demos/RaycastVehicle/index.tsx @@ -54,18 +54,18 @@ const VehicleScene = () => { return ( <> - + - - + + - + - - - + + + diff --git a/packages/react-three-cannon-examples/src/demos/demo-CompoundBody.tsx b/packages/react-three-cannon-examples/src/demos/demo-CompoundBody.tsx index 400b6a96..5ed7e999 100644 --- a/packages/react-three-cannon-examples/src/demos/demo-CompoundBody.tsx +++ b/packages/react-three-cannon-examples/src/demos/demo-CompoundBody.tsx @@ -99,15 +99,7 @@ export default function (): JSX.Element { } return ( - + { return ( <> - + diff --git a/packages/react-three-cannon-examples/src/demos/demo-ConvexPolyhedron.tsx b/packages/react-three-cannon-examples/src/demos/demo-ConvexPolyhedron.tsx index 3afd689c..dff6b746 100644 --- a/packages/react-three-cannon-examples/src/demos/demo-ConvexPolyhedron.tsx +++ b/packages/react-three-cannon-examples/src/demos/demo-ConvexPolyhedron.tsx @@ -1,20 +1,19 @@ -import type { ConvexPolyhedronProps, PlaneProps } from '@react-three/cannon' +import type { ConvexPolyhedronProps, PlaneProps, Triplet } from '@react-three/cannon' import { Physics, useConvexPolyhedron, usePlane } from '@react-three/cannon' -import { Canvas, useLoader } from '@react-three/fiber' +import { useGLTF } from '@react-three/drei' +import { Canvas } from '@react-three/fiber' import { Suspense, useMemo, useRef, useState } from 'react' import type { BufferGeometry, Mesh } from 'three' import { BoxGeometry, ConeGeometry } from 'three' -import { Geometry } from 'three-stdlib/deprecated/Geometry' +import { Geometry } from 'three-stdlib' import type { GLTF } from 'three-stdlib/loaders/GLTFLoader' -import { GLTFLoader } from 'three-stdlib/loaders/GLTFLoader' -// Returns legacy geometry vertices, faces for ConvP -function toConvexProps(bufferGeometry: BufferGeometry): ConvexPolyhedronProps['args'] { +function toConvexProps(bufferGeometry: BufferGeometry): [vertices: Triplet[], faces: Triplet[]] { const geo = new Geometry().fromBufferGeometry(bufferGeometry) - // Merge duplicate vertices resulting from glTF export. - // Cannon assumes contiguous, closed meshes to work geo.mergeVertices() - return [geo.vertices.map((v) => [v.x, v.y, v.z]), geo.faces.map((f) => [f.a, f.b, f.c]), []] + const vertices: Triplet[] = geo.vertices.map((v) => [v.x, v.y, v.z]) + const faces: Triplet[] = geo.faces.map((f) => [f.a, f.b, f.c]) + return [vertices, faces] } type DiamondGLTF = GLTF & { @@ -27,7 +26,7 @@ function Diamond({ position, rotation }: ConvexPolyhedronProps) { nodes: { Cylinder: { geometry }, }, - } = useLoader(GLTFLoader, '/diamond.glb') as DiamondGLTF + } = useGLTF('/diamond.glb') as DiamondGLTF const args = useMemo(() => toConvexProps(geometry), [geometry]) const [ref] = useConvexPolyhedron(() => ({ args, mass: 100, position, rotation }), useRef(null)) @@ -92,34 +91,25 @@ const style = { function ConvexPolyhedron() { const [invertGravity, setInvertGravity] = useState(false) + const toggleInvertGravity = () => setInvertGravity(!invertGravity) return ( <> - + - { - setInvertGravity(!invertGravity) - }} - > + diff --git a/packages/react-three-cannon-examples/src/demos/demo-CubeHeap.tsx b/packages/react-three-cannon-examples/src/demos/demo-CubeHeap.tsx index 2b17c721..5644adeb 100644 --- a/packages/react-three-cannon-examples/src/demos/demo-CubeHeap.tsx +++ b/packages/react-three-cannon-examples/src/demos/demo-CubeHeap.tsx @@ -11,7 +11,7 @@ function Plane(props: PlaneProps) { const [ref] = usePlane(() => ({ ...props }), useRef(null)) return ( - + ) @@ -89,25 +89,19 @@ export default () => { return ( setGeometry((geometry) => (geometry === 'box' ? 'sphere' : 'box'))} onCreated={({ scene }) => (scene.background = new Color('lightblue'))} + onPointerMissed={() => setGeometry((geometry) => (geometry === 'box' ? 'sphere' : 'box'))} + shadows > - + diff --git a/packages/react-three-cannon-examples/src/demos/demo-Friction.tsx b/packages/react-three-cannon-examples/src/demos/demo-Friction.tsx index f1155bb2..ede575b8 100644 --- a/packages/react-three-cannon-examples/src/demos/demo-Friction.tsx +++ b/packages/react-three-cannon-examples/src/demos/demo-Friction.tsx @@ -177,17 +177,10 @@ function PhysicsContent() { export default () => ( <> - + - - + + diff --git a/packages/react-three-cannon-examples/src/demos/demo-Heightfield.tsx b/packages/react-three-cannon-examples/src/demos/demo-Heightfield.tsx index 2a6f9799..89cb6b4d 100644 --- a/packages/react-three-cannon-examples/src/demos/demo-Heightfield.tsx +++ b/packages/react-three-cannon-examples/src/demos/demo-Heightfield.tsx @@ -1,24 +1,13 @@ import type { Triplet } from '@react-three/cannon' import { Physics, useHeightfield, useSphere } from '@react-three/cannon' -import type { Node } from '@react-three/fiber' -import { Canvas, extend, useFrame, useThree } from '@react-three/fiber' +import { OrbitControls } from '@react-three/drei' +import { Canvas, useFrame, useThree } from '@react-three/fiber' import { useEffect, useLayoutEffect, useMemo, useRef } from 'react' import type { BufferGeometry, InstancedMesh, Mesh, PerspectiveCamera } from 'three' import { Color, Float32BufferAttribute } from 'three' -import { OrbitControls } from 'three-stdlib/controls/OrbitControls' import niceColors from '../colors' -extend({ OrbitControls }) - -declare global { - namespace JSX { - interface IntrinsicElements { - orbitControls: Node - } - } -} - type GenerateHeightmapArgs = { height: number number: number @@ -172,7 +161,6 @@ function Spheres({ columns, rows, spread }: { columns: number; rows: number; spr function Camera(): JSX.Element { const cameraRef = useRef(null) - const controlsRef = useRef(null) const { gl, camera } = useThree() const set = useThree((state) => state.set) const size = useThree((state) => state.size) @@ -190,17 +178,15 @@ function Camera(): JSX.Element { }, []) useFrame(() => { - if (!cameraRef.current || !controlsRef.current) return + if (!cameraRef.current) return cameraRef.current.updateMatrixWorld() - controlsRef.current.update() }) return ( <> - ( - + - - + + - + @@ -342,14 +343,7 @@ const style = { export default () => { return ( <> - + diff --git a/packages/react-three-cannon-examples/src/demos/demo-KinematicCube.tsx b/packages/react-three-cannon-examples/src/demos/demo-KinematicCube.tsx index 3f5dc31d..2bdb6e70 100644 --- a/packages/react-three-cannon-examples/src/demos/demo-KinematicCube.tsx +++ b/packages/react-three-cannon-examples/src/demos/demo-KinematicCube.tsx @@ -67,26 +67,19 @@ function InstancedSpheres({ number = 100 }) { } export default () => ( - - + + - + diff --git a/packages/react-three-cannon-examples/src/demos/demo-Paused.tsx b/packages/react-three-cannon-examples/src/demos/demo-Paused.tsx index f0db2dd4..609dc45f 100644 --- a/packages/react-three-cannon-examples/src/demos/demo-Paused.tsx +++ b/packages/react-three-cannon-examples/src/demos/demo-Paused.tsx @@ -57,7 +57,7 @@ function Scene({ isPaused = false }): JSX.Element { - + ) } diff --git a/packages/react-three-cannon-examples/src/demos/demo-SphereDebug.tsx b/packages/react-three-cannon-examples/src/demos/demo-SphereDebug.tsx index 0ae909a6..be64ca32 100644 --- a/packages/react-three-cannon-examples/src/demos/demo-SphereDebug.tsx +++ b/packages/react-three-cannon-examples/src/demos/demo-SphereDebug.tsx @@ -47,8 +47,8 @@ export default function App() { return ( - - + + diff --git a/packages/react-three-cannon-examples/src/demos/demo-Triggers.tsx b/packages/react-three-cannon-examples/src/demos/demo-Triggers.tsx index 25ad4642..5be8a66e 100644 --- a/packages/react-three-cannon-examples/src/demos/demo-Triggers.tsx +++ b/packages/react-three-cannon-examples/src/demos/demo-Triggers.tsx @@ -45,19 +45,12 @@ function Plane(props: PlaneProps) { export default () => { const [bg, setbg] = useState('#171720') return ( - + - - + + ( <> - + - - + + diff --git a/packages/react-three-cannon-examples/vite.config.ts b/packages/react-three-cannon-examples/vite.config.ts index 80316f3d..4f1b25a0 100644 --- a/packages/react-three-cannon-examples/vite.config.ts +++ b/packages/react-three-cannon-examples/vite.config.ts @@ -1,4 +1,3 @@ -import react from '@vitejs/plugin-react' import { defineConfig } from 'vite' -export default defineConfig({ plugins: [react()] }) +export default defineConfig({})