React Three Fiber i 3D w React
R3F (JSX dla Three.js), Drei (helpers), Rapier (fizyka), postprocessing (Bloom, DOF) i WebXR (VR/AR) w React.
6 narzędzi 3D dla React — porównanie
R3F, Drei, Rapier, postprocessing, @react-three/xr i Babylon.js — opis, zastosowanie i bundle.
| Narzędzie | Opis | Używaj do | Bundle |
|---|---|---|---|
| @react-three/fiber | React renderer dla Three.js | Cała 3D scena, gry, produkty | ~400KB (Three.js) |
| @react-three/drei | Helpers: Controls, Loaders, Shaders | Zawsze z R3F | ~50KB |
| @react-three/rapier | WebAssembly fizyka | Fizyczne symulacje, gry | ~800KB WASM |
| @react-three/postprocessing | Screen-space effects (Bloom, DOF) | Efekty wizualne, rendering jakość | ~200KB |
| @react-three/xr | VR/AR support WebXR | VR/AR experiences, Quest, Vision Pro | ~30KB |
| Babylon.js | Full game engine (alternative) | Game engine, wbudowana fizyka | ~700KB |
Często zadawane pytania
Co to jest React Three Fiber i jak działa 3D w React?
React Three Fiber (R3F, Poimandres collective): React renderer dla Three.js. Deklaratywne JSX dla 3D. Three.js pod spodem — pełna moc. Instalacja: npm install @react-three/fiber three. import {Canvas} from '@react-three/fiber'. Canvas: WebGL context + scene + camera + renderer. Pętla renderowania automatyczna. Resize handler. Pixelratio. Dpr: device pixel ratio. Podstawy: Canvas dpr={[1, 2]} style={{height: '100vh'}}. mesh — Three.Mesh (geometry + material). boxGeometry args={[1, 1, 1]}. meshStandardMaterial color='hotpink'. Każdy Three.js element -> JSX tag. THREE.BoxGeometry -> boxGeometry. THREE.MeshStandardMaterial -> meshStandardMaterial. camelCase konstruktory. args -> constructor arguments. Lights: ambientLight intensity={0.5}. pointLight position={[10, 10, 10]}. directionalLight. spotLight. Kamera: perspectiveCamera position={[5, 5, 5]}. orthographicCamera. useThree: {camera, gl, scene, viewport}. Resize: viewport.width, viewport.height. Event handling: onClick, onPointerOver, onPointerOut. mesh onClick={handleClick}. useFrame: called every frame (60fps). useFrame((state, delta) => {meshRef.current.rotation.y += delta}). Dostęp do renderer, clock. Refs: useRef na mesh. meshRef.current = Three.Mesh. Direct Three.js mutations. Geometria własna: Manualne position/normal/uv bufferAttributes.
Drei — pomocniki i komponenty dla React Three Fiber?
@react-three/drei: zestaw helpers i abstrakcji dla R3F. npm install @react-three/drei. OrbitControls: obracaj, zoom, pan myszą. import {OrbitControls} from '@react-three/drei'. OrbitControls enableZoom enablePan. Stars: losowe gwiazdy w tle. Stars radius={100} depth={50} count={5000} factor={4}. Environment: HDR environment lighting. Environment preset='sunset'. Presets: sunset, dawn, night, warehouse, forest, apartment, studio, city, park, lobby. Text: tekst 3D. Text font='/fonts/Inter-Bold.woff'. Text children='Hello 3D'. Float: animacja unoszenia. Float speed={2} floatIntensity={2}. MeshTransmissionMaterial: szkło, przezroczystość. MeshDistortMaterial: wave distortion. Html: HTML element w 3D space. Html position={[1, 1, 0]} as='div'. Dobry dla labels, popups. useGLTF: ładuj GLTF/GLB modele. const {scene, nodes, animations} = useGLTF('/model.glb'). primitive object={scene}. useTexture: ładuj tekstury. const texture = useTexture('/texture.jpg'). useAnimations: Three.js AnimationMixer. const {actions} = useAnimations(animations, group). actions.walk.play(). Instancing: InstancedMesh — tysiące obiektów. useInstances helper. Dobre dla particles, grass. Bounding Box: useBounds hook. Skupia kamerę na zaznaczonych obiektach. Softbox: softShadows(). Piękne miękkie cienie. Shadows: shadowMap w Canvas. castShadow, receiveShadow.
React Three Fiber — performance, fizyka i postprocessing?
Performance: useFrame zamiast setState — brak re-renderu. Mutations przez refs. InstancedMesh dla wielu identycznych obiektów. Levels of Detail (LOD): lod distances. Frustum culling: Three.js automatyczny. React Spring + R3F: @react-spring/three. useSpring dla 3D animations. Smooth interpolacja. Fizyka — Rapier (@react-three/rapier): WebAssembly physics engine. import {Physics, RigidBody} from '@react-three/rapier'. Physics: provider. RigidBody type='dynamic'. colliders='hull'. Typy rigidbody: fixed, dynamic, kinematic. Colliders: cuboid, ball, hull, trimesh. Forces: applyImpulse(). Gravity: -9.81. Postprocessing (@react-three/postprocessing): screen-space effects. EffectComposer. import {Bloom, Vignette, DepthOfField} from '@react-three/postprocessing'. Bloom — glowing lights. DepthOfField — bokeh. SSAO — ambient occlusion. Vignette — dark edges. Outline — edge highlight. Shaders custom (GLSL): shaderMaterial helper z drei. Uniforms. vertexShader, fragmentShader strings. glsl-literal IDE support. GPU particles: Points geometry. ShaderMaterial. Każdy punkt to particle. Textury: TextureLoader. RepeatWrapping. anisotropy dla jakości na kątach. Shadows: shadowMap: {enabled: true, type: PCFSoftShadowMap}. Mesh: castShadow, receiveShadow. Performance monitor: Perf (r3f-perf). FPS, draw calls, memory. ThreeJS performance tips: batchedMesh. texture atlas. dispose geometry/material. Garbage collection.
Ładowanie modeli 3D — GLTF, GLB i sketchfab?
GLTF (GL Transmission Format): standard formatu 3D. JSON + binary. GLB: binary GLTF (jeden plik). Preferowany dla web. Mniejszy, szybszy parse. Sketchfab: marketplace modeli 3D. Wiele darmowych GLB. Download i użyj w R3F. glTF Transform: optymalizacja modeli. gltf-transform optimize. Kompresja: KTX2 (Basis Universal) textury. Draco kompresja geometrii. Mniejszy rozmiar do 90%. Zaoszczędź transfer. useGLTF.preload('/model.glb'): preload przed renderem. Unikaj ładowania podczas render. Suspense boundary: Suspense fallback={Loading}. useGLTF zawiesza komponent podczas ładowania. GLB w public folder: Next.js — umieść w /public. R3F: useGLTF('/model.glb'). Vite: import url from './model.glb?url'. Animacje GLTF: mixer z useAnimations. clip.actions — lista animacji. crossFadeTo() — blend między animations. Loop.Once, Loop.Repeat, Loop.PingPong. Skeleton + Skinned Mesh: SkinnedMesh dla postaci. Bones hierarchy. Rigging w Blender. Export -> GLB. Draco loading: DRACOLoader. setDecoderPath z CDN. Mniejszy download = szybszy load. Babylon.js vs Three.js: Babylon.js — game engine. Wbudowane physics, audio, VR. Editor (Babylon Playground). Dokumentacja świetna. Three.js — więcej flexibility, mniejszy. R3F — React integration. PlayCanvas: online editor + engine. Collaboration. Game-focused. A-Frame: HTML-based VR/AR. WebXR. Doskonały dla AR quick start.
WebXR, VR i AR w React — jak budować immersive experiences?
WebXR: Web API dla VR i AR. Wymaga HTTPS. Wideo od urządzenia (AR). 6DOF tracking (VR). R3F + XR (@react-three/xr): XR komponent z R3F. XRButton — Enter VR/AR button. useXR hook. useController hook — VR controllers. useHand — hand tracking. XRInteractableObject. AR Hit Testing: ARButton. useHitTest hook. Umieszczaj obiekty na realnych powierzchniach. Meta Quest, Apple Vision Pro, PC VR. A-Frame: HTML/custom elements. Deklaratywne XR. Znacznie prostsze niż R3F+XR. Szybkie prototypy AR/VR. Brak React. 8th Wall: Web AR bez markerów. World tracking. Face tracking. Image tracking. Komercyjny ($). Three.js + 8th Wall. Model Viewer: google/model-viewer web component. GLB viewer w AR. AR Quick Look (iOS) + Scene Viewer (Android). Bez kodu JS. Embed link rel='ar'. WebAR.js: otwarte, darmowe AR. Marker-based (NFT, Hiro). Image tracking. Face tracking. A-Frame + AR.js. ZapWorks: Studio + Designer. Visual AR builder. Platforma komercyjna. VR performance: 90fps target (VR sickness). foveated rendering. Eye tracking dla foveation. Reduce draw calls. InstancedMesh. Spatial audio: Three.js AudioListener. PositionalAudio. PannerNode (Web Audio API). Haptics: XRGamepad.hapticActuators. pulse() — vibration feedback. Kiedy Web VR/AR: product visualization. Training simulation. Virtual showrooms. Education.
Powiązane artykuły
Skontaktuj się z nami
Porozmawiajmy o Twoim projekcie. Bezpłatna wycena w ciągu 24 godzin.
Wyślij zapytanie
Telefon
+48 790 814 814
Pon-Pt: 9:00 - 18:00
adam@fotz.pl
Odpowiadamy w ciągu 24h
Adres
Plac Wolności 16
61-739 Poznań
Godziny pracy
Wolisz porozmawiać?
Zadzwoń teraz i porozmawiaj z naszym specjalistą o Twoim projekcie.
Zadzwoń teraz